spiral_order_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  n = 11;
16  size = 6;
17  swaths = f2c.Swaths();
18  for i in range(1, n):
19  swaths.push_back(f2c.Swath(f2c.LineString(f2c.VectorPoint( \
20  [f2c.Point(0, i), f2c.Point(1, i)])), i, i));
21 
22  swath_order = f2c.RP_Spiral(size);
23  swaths = swath_order.genSortedSwaths(swaths);
24 
25  near(swaths[0].getWidth(), 1);
26  near(swaths[1].getWidth(), 6);
27  near(swaths[2].getWidth(), 2);
28  near(swaths[3].getWidth(), 5);
29  near(swaths[4].getWidth(), 3);
30  near(swaths[5].getWidth(), 4);
31  near(swaths[6].getWidth(), 7);
32  near(swaths[7].getWidth(), 10);
33  near(swaths[8].getWidth(), 8);
34  near(swaths[9].getWidth(), 9);
35 
37  n = 11;
38  size = 5;
39  swaths = f2c.Swaths();
40  for i in range(1, n):
41  swaths.push_back(f2c.Swath(f2c.LineString(f2c.VectorPoint( \
42  [f2c.Point(0, i), f2c.Point(1, i)])), i, i));
43 
44  swath_sorter = f2c.RP_Spiral(size);
45  swaths = swath_sorter.genSortedSwaths(swaths);
46 
47  near(swaths[0].getWidth(), 1);
48  near(swaths[1].getWidth(), 5);
49  near(swaths[2].getWidth(), 2);
50  near(swaths[3].getWidth(), 4);
51  near(swaths[4].getWidth(), 3);
52  near(swaths[5].getWidth(), 10);
53  near(swaths[6].getWidth(), 6);
54  near(swaths[7].getWidth(), 9);
55  near(swaths[8].getWidth(), 7);
56  near(swaths[9].getWidth(), 8);
57 
59  n = 11;
60  size = 6;
61  swaths = f2c.Swaths();
62  for i in range(1, n):
63  swaths.push_back(f2c.Swath(f2c.LineString(f2c.VectorPoint( \
64  [f2c.Point(0, i), f2c.Point(1, i)])), i, i));
65 
66  swath_sorter = f2c.RP_Spiral();
67  swath_sorter.setSpiralSize(size);
68 
69  swaths = swath_sorter.genSortedSwaths(swaths);
70 
71  near(swaths[0].getWidth(), 1);
72  near(swaths[1].getWidth(), 6);
73  near(swaths[2].getWidth(), 2);
74  near(swaths[3].getWidth(), 5);
75  near(swaths[4].getWidth(), 3);
76  near(swaths[5].getWidth(), 4);
77  near(swaths[6].getWidth(), 7);
78  near(swaths[7].getWidth(), 10);
79  near(swaths[8].getWidth(), 8);
80  near(swaths[9].getWidth(), 9);
81 
83  n = 11;
84  size = 5;
85  swaths = f2c.Swaths();
86  for i in range(1, n):
87  swaths.push_back(f2c.Swath(f2c.LineString(f2c.VectorPoint( \
88  [f2c.Point(0, i), f2c.Point(1, i)])), i, i));
89 
90  swath_sorter = f2c.RP_Spiral();
91  swath_sorter.setSpiralSize(size);
92 
93  swaths = swath_sorter.genSortedSwaths(swaths);
94 
95  near(swaths[0].getWidth(), 1);
96  near(swaths[1].getWidth(), 5);
97  near(swaths[2].getWidth(), 2);
98  near(swaths[3].getWidth(), 4);
99  near(swaths[4].getWidth(), 3);
100  near(swaths[5].getWidth(), 10);
101  near(swaths[6].getWidth(), 6);
102  near(swaths[7].getWidth(), 9);
103  near(swaths[8].getWidth(), 7);
104  near(swaths[9].getWidth(), 8);
105 
107  n = 11;
108  swaths = f2c.Swaths();
109  for i in range(1, n):
110  swaths.push_back(f2c.Swath(f2c.LineString(f2c.VectorPoint( \
111  [f2c.Point(0, i), f2c.Point(1, i)])), i, i));
112 
113  swath_sorter = f2c.RP_Spiral();
114  swaths = swath_sorter.genSortedSwaths(swaths);
115 
116  near(swaths[0].getWidth(), 1);
117  near(swaths[1].getWidth(), 2);
118  near(swaths[2].getWidth(), 3);
119  near(swaths[3].getWidth(), 4);
120  near(swaths[4].getWidth(), 5);
121  near(swaths[5].getWidth(), 6);
122  near(swaths[6].getWidth(), 7);
123  near(swaths[7].getWidth(), 8);
124  near(swaths[8].getWidth(), 9);
125  near(swaths[9].getWidth(), 10);
126 
128  n = 11;
129  swaths = f2c.Swaths();
130  for i in range(1, n):
131  swaths.push_back(f2c.Swath(f2c.LineString(f2c.VectorPoint( \
132  [f2c.Point(0, i), f2c.Point(1, i)])), i, i));
133 
134  swath_sorter = f2c.RP_Spiral();
135 
136  swaths = swath_sorter.genSortedSwaths(swaths);
137 
138  near(swaths[0].getWidth(), 1);
139  near(swaths[1].getWidth(), 2);
140  near(swaths[2].getWidth(), 3);
141  near(swaths[3].getWidth(), 4);
142  near(swaths[4].getWidth(), 5);
143  near(swaths[5].getWidth(), 6);
144  near(swaths[6].getWidth(), 7);
145  near(swaths[7].getWidth(), 8);
146  near(swaths[8].getWidth(), 9);
147  near(swaths[9].getWidth(), 10);
spiral_order_test.test_fields2cover_route_spiral_genSortedSwathsDefaultSize
def test_fields2cover_route_spiral_genSortedSwathsDefaultSize()
Definition: spiral_order_test.py:106
spiral_order_test.test_fields2cover_route_spiral_genSortedSwathsEvenSize
def test_fields2cover_route_spiral_genSortedSwathsEvenSize()
Definition: spiral_order_test.py:58
spiral_order_test.test_fields2cover_route_spiral_genSortedSwathsOddSize
def test_fields2cover_route_spiral_genSortedSwathsOddSize()
Definition: spiral_order_test.py:82
spiral_order_test.test_fields2cover_route_spiral_genSortedSwathsOdd
def test_fields2cover_route_spiral_genSortedSwathsOdd()
Definition: spiral_order_test.py:36
spiral_order_test.test_fields2cover_route_spiral_genSortedSwathsDefaultCstr
def test_fields2cover_route_spiral_genSortedSwathsDefaultCstr()
Definition: spiral_order_test.py:127
spiral_order_test.near
def near(a, b)
Definition: spiral_order_test.py:10
spiral_order_test.test_fields2cover_route_spiral_genSortedSwathsEven
def test_fields2cover_route_spiral_genSortedSwathsEven()
Definition: spiral_order_test.py:14


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