UAV Coverage Path Planner
test_torres_etal_2016.cpp
Go to the documentation of this file.
1 
7 /*
8 * Copyright (c) 2017 Takaki Ueno
9 * Released under the MIT license
10 */
11 
12 #include <torres_etal_2016.hpp>
13 
14 // gtest
15 #include <gtest/gtest.h>
16 
17 // c++ libraries
18 #include <array>
19 #include <vector>
20 
21 // geometry_msgs
22 #include <geometry_msgs/Point.h>
23 
27 TEST(Torres16Test, CalcSweepDirectionTest)
28 {
29  std::vector<geometry_msgs::Point> polygon;
30 
31  // Vertices of polygon
32  geometry_msgs::Point p1, p2, p3, p4, p5;
33 
34  // Edges of polygon
35  std::array<geometry_msgs::Point, 2> e1, e2, e3, e4, e5;
36 
37  // TestCase1
38  // coordinate of vertex1: (1.5, 2.5)
39  // coordinate of vertex2: (0.5, 1.0)
40  // coordinate of vertex3: (6.0, 1.0)
41  // expected direction: edge2 -> vertex1
42  p1.x = 1.5;
43  p1.y = 2.5;
44  p2.x = 0.5;
45  p2.y = 1.0;
46  p3.x = 6.0;
47  p3.y = 1.0;
48  polygon.push_back(p1);
49  polygon.push_back(p2);
50  polygon.push_back(p3);
51 
52  e1.at(0) = p1;
53  e1.at(1) = p2;
54  e2.at(0) = p2;
55  e2.at(1) = p3;
56  e3.at(0) = p3;
57  e3.at(1) = p1;
58 
59  Direction dir = sweepDirection(polygon);
60 
61  EXPECT_DOUBLE_EQ(e2.front().x, dir.base_edge.front().x);
62  EXPECT_DOUBLE_EQ(e2.front().y, dir.base_edge.front().y);
63  EXPECT_DOUBLE_EQ(e2.back().x, dir.base_edge.back().x);
64  EXPECT_DOUBLE_EQ(e2.back().y, dir.base_edge.back().y);
65  EXPECT_DOUBLE_EQ(p1.x, dir.opposed_vertex.x);
66  EXPECT_DOUBLE_EQ(p1.y, dir.opposed_vertex.y);
67 
68  polygon.clear();
69 
70  // TestCase2
71  // coordinate of vertex1: (2.0, 4.0)
72  // coordinate of vertex2: (1.0, 1.0)
73  // coordinate of vertex3: (5.0, 1.0)
74  // coordinate of vertex4: (6.0, 3.0)
75  // expected direction: edge2 -> vertex1
76  p1.x = 2.0;
77  p1.y = 4.0;
78  p2.x = 1.0;
79  p2.y = 1.0;
80  p3.x = 5.0;
81  p3.y = 1.0;
82  p4.x = 6.0;
83  p4.y = 3.0;
84  polygon.push_back(p1);
85  polygon.push_back(p2);
86  polygon.push_back(p3);
87  polygon.push_back(p4);
88 
89  e1.at(0) = p1;
90  e1.at(1) = p2;
91  e2.at(0) = p2;
92  e2.at(1) = p3;
93  e3.at(0) = p3;
94  e3.at(1) = p4;
95  e4.at(0) = p4;
96  e4.at(1) = p1;
97 
98  dir = sweepDirection(polygon);
99 
100  EXPECT_DOUBLE_EQ(e2.front().x, dir.base_edge.front().x);
101  EXPECT_DOUBLE_EQ(e2.front().y, dir.base_edge.front().y);
102  EXPECT_DOUBLE_EQ(e2.back().x, dir.base_edge.back().x);
103  EXPECT_DOUBLE_EQ(e2.back().y, dir.base_edge.back().y);
104  EXPECT_DOUBLE_EQ(p1.x, dir.opposed_vertex.x);
105  EXPECT_DOUBLE_EQ(p1.y, dir.opposed_vertex.y);
106 
107  polygon.clear();
108 
109  // TestCase3
110  // coordinate of vertex1: (1.0, 3.0)
111  // coordinate of vertex2: (2.0, 1.0)
112  // coordinate of vertex3: (5.0, 0.5)
113  // coordinate of vertex4: (5.5, 2.5)
114  // coordinate of vertex5: (3.0, 4.0)
115  // expected direction: edge2 -> vertex5
116  p1.x = 1.0;
117  p1.y = 3.0;
118  p2.x = 2.0;
119  p2.y = 1.0;
120  p3.x = 5.0;
121  p3.y = 0.5;
122  p4.x = 5.5;
123  p4.y = 2.5;
124  p5.x = 3.0;
125  p5.y = 4.0;
126  polygon.push_back(p1);
127  polygon.push_back(p2);
128  polygon.push_back(p3);
129  polygon.push_back(p4);
130  polygon.push_back(p5);
131 
132  e1.at(0) = p1;
133  e1.at(1) = p2;
134  e2.at(0) = p2;
135  e2.at(1) = p3;
136  e3.at(0) = p3;
137  e3.at(1) = p4;
138  e4.at(0) = p4;
139  e4.at(1) = p5;
140  e5.at(0) = p5;
141  e5.at(1) = p1;
142 
143  dir = sweepDirection(polygon);
144 
145  EXPECT_DOUBLE_EQ(e4.front().x, dir.base_edge.front().x);
146  EXPECT_DOUBLE_EQ(e4.front().y, dir.base_edge.front().y);
147  EXPECT_DOUBLE_EQ(e4.back().x, dir.base_edge.back().x);
148  EXPECT_DOUBLE_EQ(e4.back().y, dir.base_edge.back().y);
149  EXPECT_DOUBLE_EQ(p2.x, dir.opposed_vertex.x);
150  EXPECT_DOUBLE_EQ(p2.y, dir.opposed_vertex.y);
151 
152  polygon.clear();
153 }
154 
155 int main(int argc, char** argv)
156 {
157  ::testing::InitGoogleTest(&argc, argv);
158  return RUN_ALL_TESTS();
159 }
Utility for computational geometry.
TEST(Torres16Test, CalcSweepDirectionTest)
Test for sweepDirection()
int main(int argc, char **argv)
Storage for line sweep direction.