30 #include <gtest/gtest.h> 34 TEST(GeometryUtilTests, ClosestPointToLinesInvalid)
90 EXPECT_FLOAT_EQ(point.
x(), 0);
91 EXPECT_FLOAT_EQ(point.
y(), 0);
92 EXPECT_FLOAT_EQ(point.
z(), 0);
100 EXPECT_FLOAT_EQ(point.
x(), 0);
101 EXPECT_FLOAT_EQ(point.
y(), 0);
102 EXPECT_FLOAT_EQ(point.
z(), 0);
110 EXPECT_FLOAT_EQ(point.
x(), 0);
111 EXPECT_FLOAT_EQ(point.
y(), 0);
112 EXPECT_FLOAT_EQ(point.
z(), 0);
120 EXPECT_FLOAT_EQ(point.
x(), 0);
121 EXPECT_FLOAT_EQ(point.
y(), 0);
122 EXPECT_FLOAT_EQ(point.
z(), 0);
130 EXPECT_FLOAT_EQ(point.
x(), 0);
131 EXPECT_FLOAT_EQ(point.
y(), 0);
132 EXPECT_FLOAT_EQ(point.
z(), 10);
140 EXPECT_FLOAT_EQ(point.
x(), 0);
141 EXPECT_FLOAT_EQ(point.
y(), 0);
142 EXPECT_FLOAT_EQ(point.
z(), 10);
145 TEST(GeometryUtilTests, ProjectPointToLineSegment3D)
151 EXPECT_FLOAT_EQ(p3.
x(), p4.
x());
152 EXPECT_FLOAT_EQ(p3.
y(), p4.
y());
153 EXPECT_FLOAT_EQ(p3.
z(), p4.
z());
156 EXPECT_FLOAT_EQ(p3.
x(), p4.x());
157 EXPECT_FLOAT_EQ(p3.
y(), p4.y());
158 EXPECT_FLOAT_EQ(p3.
z(), p4.z());
162 EXPECT_FLOAT_EQ(p3.x(), p4.x());
163 EXPECT_FLOAT_EQ(p3.y(), p4.y());
164 EXPECT_FLOAT_EQ(p3.z(), p4.z());
168 EXPECT_FLOAT_EQ(0, p4.x());
169 EXPECT_FLOAT_EQ(0, p4.y());
170 EXPECT_FLOAT_EQ(0, p4.z());
174 EXPECT_FLOAT_EQ(5, p4.x());
175 EXPECT_FLOAT_EQ(0, p4.y());
176 EXPECT_FLOAT_EQ(0, p4.z());
180 EXPECT_FLOAT_EQ(5, p4.x());
181 EXPECT_FLOAT_EQ(0, p4.y());
182 EXPECT_FLOAT_EQ(0, p4.z());
186 EXPECT_FLOAT_EQ(0, p4.x());
187 EXPECT_FLOAT_EQ(0, p4.y());
188 EXPECT_FLOAT_EQ(0, p4.z());
192 EXPECT_FLOAT_EQ(10, p4.x());
193 EXPECT_FLOAT_EQ(0, p4.y());
194 EXPECT_FLOAT_EQ(0, p4.z());
200 EXPECT_FLOAT_EQ(1, p4.x());
201 EXPECT_FLOAT_EQ(1, p4.y());
202 EXPECT_FLOAT_EQ(1, p4.z());
207 EXPECT_FLOAT_EQ(5, p4.x());
208 EXPECT_FLOAT_EQ(5, p4.y());
209 EXPECT_FLOAT_EQ(0, p4.z());
212 EXPECT_FLOAT_EQ(5, p4.x());
213 EXPECT_FLOAT_EQ(5, p4.y());
214 EXPECT_FLOAT_EQ(0, p4.z());
218 EXPECT_FLOAT_EQ(0, p4.x());
219 EXPECT_FLOAT_EQ(0, p4.y());
220 EXPECT_FLOAT_EQ(0, p4.z());
223 TEST(GeometryUtilTests, ProjectPointToLineSegment2D)
229 EXPECT_FLOAT_EQ(p3[0], p4[0]);
230 EXPECT_FLOAT_EQ(p3[1], p4[1]);
233 EXPECT_FLOAT_EQ(p3[0], p4[0]);
234 EXPECT_FLOAT_EQ(p3[1], p4[1]);
236 p3 = cv::Vec2d(0, 0);
238 EXPECT_FLOAT_EQ(p3[0], p4[0]);
239 EXPECT_FLOAT_EQ(p3[1], p4[1]);
241 p3 = cv::Vec2d(0, 1);
243 EXPECT_FLOAT_EQ(0, p4[0]);
244 EXPECT_FLOAT_EQ(0, p4[1]);
246 p3 = cv::Vec2d(5, -1);
248 EXPECT_FLOAT_EQ(5, p4[0]);
249 EXPECT_FLOAT_EQ(0, p4[1]);
251 p3 = cv::Vec2d(-5, -1);
253 EXPECT_FLOAT_EQ(0, p4[0]);
254 EXPECT_FLOAT_EQ(0, p4[1]);
256 p3 = cv::Vec2d(15, -1);
258 EXPECT_FLOAT_EQ(10, p4[0]);
259 EXPECT_FLOAT_EQ(0, p4[1]);
261 p1 = cv::Vec2d(0, 0);
262 p2 = cv::Vec2d(10, 10);
263 p3 = cv::Vec2d(1, 1);
265 EXPECT_FLOAT_EQ(1, p4[0]);
266 EXPECT_FLOAT_EQ(1, p4[1]);
268 p2 = cv::Vec2d(10, 10);
269 p3 = cv::Vec2d(0, 10);
271 EXPECT_FLOAT_EQ(5, p4[0]);
272 EXPECT_FLOAT_EQ(5, p4[1]);
275 EXPECT_FLOAT_EQ(5, p4[0]);
276 EXPECT_FLOAT_EQ(5, p4[1]);
278 p3 = cv::Vec2d(-100, 10);
280 EXPECT_FLOAT_EQ(0, p4[0]);
281 EXPECT_FLOAT_EQ(0, p4[1]);
284 TEST(GeometryUtilTests, DistanceFromLineSegment3D)
324 TEST(GeometryUtilTests, DistanceFromLineSegment2D)
332 p3 = cv::Vec2d(0, 0);
335 p3 = cv::Vec2d(0, 1);
338 p3 = cv::Vec2d(5, -1);
341 p1 = cv::Vec2d(0, 0);
342 p2 = cv::Vec2d(10, 10);
343 p3 = cv::Vec2d(1, 1);
346 p2 = cv::Vec2d(10, 10);
347 p3 = cv::Vec2d(0, 10);
351 p3 = cv::Vec2d(-100, 10);
358 std::vector<cv::Vec2d> polygon1;
359 polygon1.push_back(cv::Vec2d(1, 1));
360 polygon1.push_back(cv::Vec2d(1, -1));
361 polygon1.push_back(cv::Vec2d(-1, -1));
362 polygon1.push_back(cv::Vec2d(-1, 1));
372 std::vector<cv::Vec2d> polygon2;
373 polygon2.push_back(cv::Vec2d(1, 1));
374 polygon2.push_back(cv::Vec2d(1, -1));
375 polygon2.push_back(cv::Vec2d(-1, -1));
376 polygon2.push_back(cv::Vec2d(-1, 1));
377 polygon2.push_back(cv::Vec2d(1, 1));
378 polygon2.push_back(cv::Vec2d(1, 1));
391 std::vector<cv::Vec2d> polygon1;
392 polygon1.push_back(cv::Vec2d(1, 1));
393 polygon1.push_back(cv::Vec2d(1, -1));
394 polygon1.push_back(cv::Vec2d(-1, -1));
395 polygon1.push_back(cv::Vec2d(-1, 1));
405 std::vector<cv::Vec2d> polygon2;
406 polygon2.push_back(cv::Vec2d(1, 1));
407 polygon2.push_back(cv::Vec2d(1, -1));
408 polygon2.push_back(cv::Vec2d(-1, -1));
409 polygon2.push_back(cv::Vec2d(-1, 1));
410 polygon2.push_back(cv::Vec2d(1, 1));
411 polygon2.push_back(cv::Vec2d(1, 1));
423 int main(
int argc,
char **argv)
425 testing::InitGoogleTest(&argc, argv);
427 return RUN_ALL_TESTS();
bool PointInPolygon(const std::vector< cv::Vec2d > &polygon, const cv::Vec2d &point)
double DistanceFromPolygon(const std::vector< cv::Vec2d > &polygon, const cv::Vec2d &point)
TEST(GeometryUtilTests, ClosestPointToLinesInvalid)
TFSIMD_FORCE_INLINE const tfScalar & x() const
int main(int argc, char **argv)
TFSIMD_FORCE_INLINE const tfScalar & z() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
tf::Vector3 ProjectToLineSegment(const tf::Vector3 &line_start, const tf::Vector3 &line_end, const tf::Vector3 &point)
bool ClosestPointToLines(const tf::Vector3 &a1, const tf::Vector3 &a2, const tf::Vector3 &b1, const tf::Vector3 &b2, tf::Vector3 &point)
double DistanceFromLineSegment(const tf::Vector3 &line_start, const tf::Vector3 &line_end, const tf::Vector3 &point)