spiral_order_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include "fields2cover/types.h"
4 
5 TEST(fields2cover_route_spiral, genSortedSwaths_even) {
6  const int n = 11;
7  const int size = 6;
9  for (int i = 1; i < n; ++i) {
10  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i);
11  }
12 
13  f2c::rp::SpiralOrder swath_sorter(size);
14 
15  swaths = swath_sorter.genSortedSwaths(swaths);
16 
17  EXPECT_EQ(swaths[0].getWidth(), 1);
18  EXPECT_EQ(swaths[1].getWidth(), 6);
19  EXPECT_EQ(swaths[2].getWidth(), 2);
20  EXPECT_EQ(swaths[3].getWidth(), 5);
21  EXPECT_EQ(swaths[4].getWidth(), 3);
22  EXPECT_EQ(swaths[5].getWidth(), 4);
23  EXPECT_EQ(swaths[6].getWidth(), 7);
24  EXPECT_EQ(swaths[7].getWidth(), 10);
25  EXPECT_EQ(swaths[8].getWidth(), 8);
26  EXPECT_EQ(swaths[9].getWidth(), 9);
27 }
28 
29 TEST(fields2cover_route_spiral, genSortedSwaths_odd) {
30  const int n = 11;
31  const int size = 5;
33  for (int i = 1; i < n; ++i) {
34  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i);
35  }
36 
37  f2c::rp::SpiralOrder swath_sorter(size);
38 
39  swaths = swath_sorter.genSortedSwaths(swaths);
40 
41  EXPECT_EQ(swaths[0].getWidth(), 1);
42  EXPECT_EQ(swaths[1].getWidth(), 5);
43  EXPECT_EQ(swaths[2].getWidth(), 2);
44  EXPECT_EQ(swaths[3].getWidth(), 4);
45  EXPECT_EQ(swaths[4].getWidth(), 3);
46  EXPECT_EQ(swaths[5].getWidth(), 10);
47  EXPECT_EQ(swaths[6].getWidth(), 6);
48  EXPECT_EQ(swaths[7].getWidth(), 9);
49  EXPECT_EQ(swaths[8].getWidth(), 7);
50  EXPECT_EQ(swaths[9].getWidth(), 8);
51 }
52 
53 TEST(fields2cover_route_spiral, genSortedSwaths_even_size) {
54  const int n = 11;
55  const int size = 6;
57  for (int i = 1; i < n; ++i) {
58  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i);
59  }
60 
61  f2c::rp::SpiralOrder swath_sorter;
62  swath_sorter.setSpiralSize(size);
63 
64  swaths = swath_sorter.genSortedSwaths(swaths);
65 
66  EXPECT_EQ(swaths[0].getWidth(), 1);
67  EXPECT_EQ(swaths[1].getWidth(), 6);
68  EXPECT_EQ(swaths[2].getWidth(), 2);
69  EXPECT_EQ(swaths[3].getWidth(), 5);
70  EXPECT_EQ(swaths[4].getWidth(), 3);
71  EXPECT_EQ(swaths[5].getWidth(), 4);
72  EXPECT_EQ(swaths[6].getWidth(), 7);
73  EXPECT_EQ(swaths[7].getWidth(), 10);
74  EXPECT_EQ(swaths[8].getWidth(), 8);
75  EXPECT_EQ(swaths[9].getWidth(), 9);
76 }
77 
78 TEST(fields2cover_route_spiral, genSortedSwaths_odd_size) {
79  const int n = 11;
80  const int size = 5;
82  for (int i = 1; i < n; ++i) {
83  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i);
84  }
85 
86  f2c::rp::SpiralOrder swath_sorter;
87  swath_sorter.setSpiralSize(size);
88 
89  swaths = swath_sorter.genSortedSwaths(swaths);
90 
91  EXPECT_EQ(swaths[0].getWidth(), 1);
92  EXPECT_EQ(swaths[1].getWidth(), 5);
93  EXPECT_EQ(swaths[2].getWidth(), 2);
94  EXPECT_EQ(swaths[3].getWidth(), 4);
95  EXPECT_EQ(swaths[4].getWidth(), 3);
96  EXPECT_EQ(swaths[5].getWidth(), 10);
97  EXPECT_EQ(swaths[6].getWidth(), 6);
98  EXPECT_EQ(swaths[7].getWidth(), 9);
99  EXPECT_EQ(swaths[8].getWidth(), 7);
100  EXPECT_EQ(swaths[9].getWidth(), 8);
101 }
102 
103 TEST(fields2cover_route_spiral, genSortedSwaths_default_size) {
104  const int n = 11;
106  for (int i = 1; i < n; ++i) {
107  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i);
108  }
109 
110  f2c::rp::SpiralOrder swath_sorter;
111 
112  swaths = swath_sorter.genSortedSwaths(swaths);
113 
114  EXPECT_EQ(swaths[0].getWidth(), 1);
115  EXPECT_EQ(swaths[1].getWidth(), 2);
116  EXPECT_EQ(swaths[2].getWidth(), 3);
117  EXPECT_EQ(swaths[3].getWidth(), 4);
118  EXPECT_EQ(swaths[4].getWidth(), 5);
119  EXPECT_EQ(swaths[5].getWidth(), 6);
120  EXPECT_EQ(swaths[6].getWidth(), 7);
121  EXPECT_EQ(swaths[7].getWidth(), 8);
122  EXPECT_EQ(swaths[8].getWidth(), 9);
123  EXPECT_EQ(swaths[9].getWidth(), 10);
124 }
125 
126 TEST(fields2cover_route_spiral, genSortedSwaths_default_cstr) {
127  const int n = 11;
129  for (int i = 1; i < n; ++i) {
130  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i);
131  }
132 
133  f2c::rp::SpiralOrder swath_sorter;
134 
135  swaths = swath_sorter.genSortedSwaths(swaths);
136 
137  EXPECT_EQ(swaths[0].getWidth(), 1);
138  EXPECT_EQ(swaths[1].getWidth(), 2);
139  EXPECT_EQ(swaths[2].getWidth(), 3);
140  EXPECT_EQ(swaths[3].getWidth(), 4);
141  EXPECT_EQ(swaths[4].getWidth(), 5);
142  EXPECT_EQ(swaths[5].getWidth(), 6);
143  EXPECT_EQ(swaths[6].getWidth(), 7);
144  EXPECT_EQ(swaths[7].getWidth(), 8);
145  EXPECT_EQ(swaths[8].getWidth(), 9);
146  EXPECT_EQ(swaths[9].getWidth(), 10);
147 }
148 
149 
150 TEST(fields2cover_route_spiral, genSortedSwaths_bigger_than_8_bulk) {
151  const int size = 10;
153  for (int i = 1; i <= size; ++i) {
154  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i);
155  }
156  f2c::rp::SpiralOrder swath_sorter;
157  swath_sorter.setSpiralSize(size);
158  swaths = swath_sorter.genSortedSwaths(swaths);
159 
160  EXPECT_EQ(swaths[0].getWidth(), 1);
161  EXPECT_EQ(swaths[1].getWidth(), 10);
162  EXPECT_EQ(swaths[2].getWidth(), 2);
163  EXPECT_EQ(swaths[3].getWidth(), 9);
164  EXPECT_EQ(swaths[4].getWidth(), 3);
165  EXPECT_EQ(swaths[5].getWidth(), 8);
166  EXPECT_EQ(swaths[6].getWidth(), 4);
167  EXPECT_EQ(swaths[7].getWidth(), 7);
168  EXPECT_EQ(swaths[8].getWidth(), 5);
169  EXPECT_EQ(swaths[9].getWidth(), 6);
170 }
171 
172 
173 
174 
175 
176 
177 
178 
179 
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
types.h
TEST
TEST(fields2cover_route_spiral, genSortedSwaths_even)
Definition: spiral_order_test.cpp:5
spiral_order.h
f2c::rp::SingleCellSwathsOrderBase::genSortedSwaths
virtual F2CSwaths genSortedSwaths(const F2CSwaths &swaths, uint32_t variant=0) const
Definition: single_cell_swaths_order_base.cpp:12
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
f2c::rp::SpiralOrder::setSpiralSize
void setSpiralSize(size_t sp_size)
Definition: spiral_order.cpp:12
f2c::rp::SpiralOrder
Definition: spiral_order.h:10
f2c::types::Swaths
Definition: Swaths.h:20
F2CPoint
f2c::types::Point F2CPoint
Definition: types.h:38


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