@@ -238,6 +238,7 @@ TEST(alt_geometry, disjoint)
238
238
using autoware::universe_utils::disjoint;
239
239
using autoware::universe_utils::alt::ConvexPolygon2d;
240
240
using autoware::universe_utils::alt::PointList2d;
241
+ using autoware::universe_utils::alt::Polygon2d;
241
242
242
243
{ // Disjoint
243
244
PointList2d vertices1;
@@ -276,6 +277,56 @@ TEST(alt_geometry, disjoint)
276
277
277
278
EXPECT_FALSE (result);
278
279
}
280
+
281
+ { // Disjoint (one concave polygon is within the hole of the other)
282
+ PointList2d outer1;
283
+ outer1.push_back ({-1.0 , -1.0 });
284
+ outer1.push_back ({-1.0 , 3.0 });
285
+ outer1.push_back ({3.0 , 3.0 });
286
+ outer1.push_back ({3.0 , -1.0 });
287
+
288
+ PointList2d inner1;
289
+ inner1.push_back ({0.0 , 0.0 });
290
+ inner1.push_back ({0.0 , 2.0 });
291
+ inner1.push_back ({1.0 , 1.0 });
292
+ inner1.push_back ({2.0 , 2.0 });
293
+ inner1.push_back ({2.0 , 0.0 });
294
+
295
+ PointList2d outer2;
296
+ outer2.push_back ({0.5 , 0.5 });
297
+ outer2.push_back ({0.5 , 1.0 });
298
+ outer2.push_back ({1.0 , 0.5 });
299
+
300
+ const auto result =
301
+ disjoint (Polygon2d::create (outer1, {inner1}).value (), Polygon2d::create (outer2, {}).value ());
302
+
303
+ EXPECT_TRUE (result);
304
+ }
305
+
306
+ { // Not disjoint (one concave polygon and the hole of the other share a vertex)
307
+ PointList2d outer1;
308
+ outer1.push_back ({-1.0 , -1.0 });
309
+ outer1.push_back ({-1.0 , 3.0 });
310
+ outer1.push_back ({3.0 , 3.0 });
311
+ outer1.push_back ({3.0 , -1.0 });
312
+
313
+ PointList2d inner1;
314
+ inner1.push_back ({0.0 , 0.0 });
315
+ inner1.push_back ({0.0 , 2.0 });
316
+ inner1.push_back ({1.0 , 1.0 });
317
+ inner1.push_back ({2.0 , 2.0 });
318
+ inner1.push_back ({2.0 , 0.0 });
319
+
320
+ PointList2d outer2;
321
+ outer2.push_back ({1.0 , 1.0 });
322
+ outer2.push_back ({1.5 , 0.5 });
323
+ outer2.push_back ({0.5 , 0.5 });
324
+
325
+ const auto result =
326
+ disjoint (Polygon2d::create (outer1, {inner1}).value (), Polygon2d::create (outer2, {}).value ());
327
+
328
+ EXPECT_FALSE (result);
329
+ }
279
330
}
280
331
281
332
TEST (alt_geometry, distance)
@@ -1422,6 +1473,72 @@ TEST(alt_geometry, disjointRand)
1422
1473
}
1423
1474
}
1424
1475
1476
+ TEST (alt_geometry, disjointConcaveRand)
1477
+ {
1478
+ std::vector<autoware::universe_utils::Polygon2d> polygons;
1479
+ constexpr auto polygons_nb = 100 ;
1480
+ constexpr auto max_vertices = 10 ;
1481
+ constexpr auto max_values = 1000 ;
1482
+
1483
+ autoware::universe_utils::StopWatch<std::chrono::nanoseconds, std::chrono::nanoseconds> sw;
1484
+ for (auto vertices = 4UL ; vertices < max_vertices; ++vertices) {
1485
+ double ground_truth_disjoint_ns = 0.0 ;
1486
+ double ground_truth_not_disjoint_ns = 0.0 ;
1487
+ double alt_disjoint_ns = 0.0 ;
1488
+ double alt_not_disjoint_ns = 0.0 ;
1489
+ int disjoint_count = 0 ;
1490
+
1491
+ polygons.clear ();
1492
+ for (auto i = 0 ; i < polygons_nb; ++i) {
1493
+ polygons.push_back (autoware::universe_utils::random_concave_polygon (vertices, max_values));
1494
+ }
1495
+ for (auto i = 0UL ; i < polygons.size (); ++i) {
1496
+ for (auto j = 0UL ; j < polygons.size (); ++j) {
1497
+ sw.tic ();
1498
+ const auto ground_truth = boost::geometry::disjoint (polygons[i], polygons[j]);
1499
+ if (ground_truth) {
1500
+ ++disjoint_count;
1501
+ ground_truth_disjoint_ns += sw.toc ();
1502
+ } else {
1503
+ ground_truth_not_disjoint_ns += sw.toc ();
1504
+ }
1505
+
1506
+ const auto alt_poly1 =
1507
+ autoware::universe_utils::alt::Polygon2d::create (polygons[i]).value ();
1508
+ const auto alt_poly2 =
1509
+ autoware::universe_utils::alt::Polygon2d::create (polygons[j]).value ();
1510
+ sw.tic ();
1511
+ const auto alt = autoware::universe_utils::disjoint (alt_poly1, alt_poly2);
1512
+ if (alt) {
1513
+ alt_disjoint_ns += sw.toc ();
1514
+ } else {
1515
+ alt_not_disjoint_ns += sw.toc ();
1516
+ }
1517
+
1518
+ if (ground_truth != alt) {
1519
+ std::cout << " Failed for the 2 polygons: " ;
1520
+ std::cout << boost::geometry::wkt (polygons[i]) << boost::geometry::wkt (polygons[j])
1521
+ << std::endl;
1522
+ }
1523
+ EXPECT_EQ (ground_truth, alt);
1524
+ }
1525
+ }
1526
+ std::printf (
1527
+ " polygons_nb = %d, vertices = %ld, %d / %d disjoint pairs\n " , polygons_nb, vertices,
1528
+ disjoint_count, polygons_nb * polygons_nb);
1529
+ std::printf (
1530
+ " \t Disjoint:\n\t\t Boost::geometry = %2.2f ms\n\t\t Alt = %2.2f ms\n " ,
1531
+ ground_truth_disjoint_ns / 1e6 , alt_disjoint_ns / 1e6 );
1532
+ std::printf (
1533
+ " \t Not disjoint:\n\t\t Boost::geometry = %2.2f ms\n\t\t Alt = %2.2f ms\n " ,
1534
+ ground_truth_not_disjoint_ns / 1e6 , alt_not_disjoint_ns / 1e6 );
1535
+ std::printf (
1536
+ " \t Total:\n\t\t Boost::geometry = %2.2f ms\n\t\t Alt = %2.2f ms\n " ,
1537
+ (ground_truth_not_disjoint_ns + ground_truth_disjoint_ns) / 1e6 ,
1538
+ (alt_not_disjoint_ns + alt_disjoint_ns) / 1e6 );
1539
+ }
1540
+ }
1541
+
1425
1542
TEST (alt_geometry, intersectsRand)
1426
1543
{
1427
1544
std::vector<autoware::universe_utils::Polygon2d> polygons;
0 commit comments