Swaths_test.py
Go to the documentation of this file.
1 #==============================================================================
2 # Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 # Author: Gonzalo Mier
4 # BSD-3 License
5 #==============================================================================
6 
7 import pytest
8 import fields2cover as f2c
9 
10 def near(a, b):
11  assert pytest.approx(a) == pytest.approx(b)
12 
13 
15  ring = f2c.LinearRing();
16  ring.addPoint(-10, 0);
17  ring.addPoint(-10, 20);
18  ring.addPoint(10, 20);
19  ring.addPoint(10, 0);
20  ring.addPoint(-10, 0);
21  polygon = f2c.Cell();
22  polygon.addRing(ring);
23  polys = f2c.Cells();
24  polys.addGeometry(polygon);
25  line = f2c.LineString();
26  line.addPoint(-20, -10);
27  line.addPoint(-5, 5);
28 
29  swaths = f2c.Swaths();
30  near(swaths.size(), 0);
31  swaths.append(line, polys, 1.0);
32  near(swaths.size(), 1);
33  swaths.append(line, polys, 2.0);
34  near(swaths.size(), 2);
35  line.addPoint(-19.9, -10);
36  line.addPoint(-5, 5.1);
37  swaths.append(line, polys, 3.0);
38  near(swaths.size(), 4);
39  lines = f2c.MultiLineString();
40  lines.addGeometry(line);
41  lines.addGeometry(f2c.LineString(f2c.VectorPoint([f2c.Point(-10,0),f2c.Point(10,20)])));
42  swaths.append(lines, polygon, 4);
43  near(swaths.size(), 8);
44  swaths.append(lines, polys, 5);
45  near(swaths.size(), 12);
46  lines.addGeometry(f2c.LineString(f2c.VectorPoint(
47  [f2c.Point(1e5, 1e5),f2c.Point(1e5+1, 1e5+1)])));
48  swaths.append(lines, polys, 6);
49  near(swaths.size(), 16);
50 
51 
53  n = 5;
54  swaths = f2c.Swaths();
55  for i in range(n - 1, 0, -1):
56  swaths.emplace_back(f2c.LineString(f2c.VectorPoint(
57  [f2c.Point(i, i), f2c.Point(i, i + 1)])), i, i);
58  swaths.sort();
59  for i in range(1, n):
60  near(swaths[i-1].getWidth(), i);
61 
62 
64  n = 10;
65  swaths = f2c.Swaths();
66  for i in range(1, n + 1):
67  swaths.emplace_back(f2c.LineString(f2c.VectorPoint(
68  [f2c.Point(i, i), f2c.Point(i, i + 1)])), i);
69  swaths.reverseDirOddSwaths();
70  for i in range(1, n):
71  assert not (swaths[i].hasSameDir(swaths[i-1]));
72 
73 
74 
75 
76 
Swaths_test.near
def near(a, b)
Definition: Swaths_test.py:10
Swaths_test.test_fields2cover_types_swaths_reverseDirOddSwaths
def test_fields2cover_types_swaths_reverseDirOddSwaths()
Definition: Swaths_test.py:63
Swaths_test.test_fields2cover_types_swaths_sort
def test_fields2cover_types_swaths_sort()
Definition: Swaths_test.py:52
Swaths_test.test_fields2cover_types_swaths_append
def test_fields2cover_types_swaths_append()
Definition: Swaths_test.py:14


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31