14 auto triangles = triangulator(p);
16 EXPECT_EQ(triangles.size(), 1u);
30 auto triangles = triangulator(p);
32 EXPECT_EQ(triangles.size(), 2u);
46 auto triangles = triangulator(p);
48 EXPECT_EQ(triangles.size(), 2u);
63 auto triangles = triangulator(p);
65 EXPECT_EQ(triangles.size(), 3u);
78 EXPECT_THROW((
void) triangulator(p), std::domain_error);
94 (void) triangulator(p);
109 EXPECT_THROW((
void) p.
close(), std::domain_error);
124 EXPECT_EQ(hull.
size(), 3u);
139 EXPECT_EQ(hull.
size(), 4u);
155 EXPECT_EQ(hull.
size(), 4u);
170 EXPECT_EQ(hull.
size(), 4u);
184 EXPECT_EQ(hull.
size(), 3u);
198 EXPECT_EQ(hull.
size(), 3u);
210 EXPECT_EQ(qh(points).
size(), 0u);
211 EXPECT_EQ(gw(points).
size(), 0u);
212 EXPECT_EQ(bf(points).
size(), 0u);
229 EXPECT_EQ(qh_hull.
size(), 1u);
230 EXPECT_EQ(gw_hull.
size(), 1u);
231 EXPECT_EQ(bf_hull.
size(), 1u);
232 EXPECT_TRUE(polygon_contains_vertex(qh_hull,
Point(7, 9)));
233 EXPECT_TRUE(polygon_contains_vertex(gw_hull,
Point(7, 9)));
234 EXPECT_TRUE(polygon_contains_vertex(bf_hull,
Point(7, 9)));
249 EXPECT_EQ(qh(points).
size(), 1u);
250 EXPECT_EQ(gw(points).
size(), 1u);
251 EXPECT_EQ(bf(points).
size(), 1u);
269 EXPECT_EQ(hull.
size(), 4u);
270 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(0, 0)));
271 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(5, 0)));
272 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(5, 5)));
273 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(0, 5)));
274 EXPECT_FALSE(polygon_contains_vertex(hull,
Point(2, 2)));
297 "case_andrew_collinear_endpoints", scene,
298 "Andrew monotonic chain / collinear input");
301 EXPECT_EQ(hull.
size(), 2u);
303 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(0, 0)));
304 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(4, 0)));
305 EXPECT_FALSE(polygon_contains_vertex(hull,
Point(2, 0)));
323 EXPECT_EQ(hull.
size(), 4u);
324 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(0, 0)));
325 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(5, 0)));
326 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(5, 5)));
327 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(0, 5)));
328 EXPECT_FALSE(polygon_contains_vertex(hull,
Point(2, 2)));
351 "case_graham_collinear_endpoints", scene,
352 "Graham scan / collinear input");
355 EXPECT_EQ(hull.
size(), 2u);
357 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(0, 0)));
358 EXPECT_TRUE(polygon_contains_vertex(hull,
Point(4, 4)));
359 EXPECT_FALSE(polygon_contains_vertex(hull,
Point(2, 2)));
373 EXPECT_TRUE(matches_unordered_pair(res.
first, res.
second,
391 EXPECT_TRUE(matches_unordered_pair(res.
first, res.
second,
414 "case_closest_pair_duplicate_zero", scene,
415 "Closest pair / duplicate points");
435 EXPECT_TRUE(matches_unordered_pair(res.
first, res.
second,
450 EXPECT_THROW((
void) cp(points), std::domain_error);
465 EXPECT_EQ(d.distance_squared, 32);
466 EXPECT_TRUE(matches_unordered_pair(d.first, d.second,
468 matches_unordered_pair(d.first, d.second,
484 EXPECT_EQ(
w.width_squared, 16);
499 EXPECT_EQ(d.distance_squared, 29);
502 EXPECT_EQ(
w.width_squared, 4);
531 EXPECT_THROW((
void) calipers.
diameter(concave), std::domain_error);
532 EXPECT_THROW((
void) calipers.
minimum_width(concave), std::domain_error);
545 EXPECT_THROW((
void) calipers.
diameter(open), std::domain_error);
546 EXPECT_THROW((
void) calipers.
minimum_width(open), std::domain_error);
561 PointInPolygonWinding::Location::Inside);
563 PointInPolygonWinding::Location::Boundary);
565 PointInPolygonWinding::Location::Outside);
585 PointInPolygonWinding::Location::Inside);
587 PointInPolygonWinding::Location::Outside);
589 PointInPolygonWinding::Location::Boundary);
601 EXPECT_THROW((
void) pip.
locate(open,
Point(1, 1)), std::domain_error);
624 EXPECT_EQ(
r.size(), 4u);
625 EXPECT_TRUE(
r.is_closed());
626 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 2)));
627 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 2)));
628 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 4)));
629 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 4)));
652 EXPECT_EQ(
r.size(), 4u);
653 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 2)));
654 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 2)));
655 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 4)));
656 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 4)));
679 EXPECT_EQ(
r.size(), 0u);
708 "case_convex_polygon_intersection_touching_edge", scene,
709 "Convex intersection / touching edge");
712 EXPECT_EQ(
r.size(), 2u);
713 EXPECT_FALSE(
r.is_closed());
714 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 0)));
715 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 2)));
737 EXPECT_THROW((
void) inter(concave, square), std::domain_error);
738 EXPECT_THROW((
void) inter(square, concave), std::domain_error);
757 EXPECT_THROW((
void) inter(open, square), std::domain_error);
758 EXPECT_THROW((
void) inter(square, open), std::domain_error);
776 EXPECT_EQ(
r.size(), 4u);
777 EXPECT_TRUE(
r.is_closed());
778 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(0, 0)));
779 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 0)));
780 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 4)));
781 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(0, 4)));
799 EXPECT_EQ(
r.size(), 4u);
800 EXPECT_TRUE(
r.is_closed());
801 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(0, 0)));
802 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 0)));
803 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 4)));
804 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(0, 4)));
829 for (
size_t i = 0; i < hs2.
size(); ++i)
833 EXPECT_EQ(
r.size(), 4u);
834 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 2)));
835 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 2)));
836 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 4)));
837 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(2, 4)));
853 for (
size_t i = 0; i < hs.
size(); ++i)
857 "case_halfplane_inconsistent_empty", scene,
858 "Half-plane intersection / inconsistent constraints");
860 EXPECT_EQ(
r.size(), 0u);
873 EXPECT_EQ(
r.size(), 0u);
882 ASSERT_EQ(
r.sites.size(), 3u);
883 ASSERT_EQ(
r.triangles.size(), 1u);
885 const auto & t =
r.triangles(0);
896 ASSERT_EQ(
r.sites.size(), 4u);
897 ASSERT_EQ(
r.triangles.size(), 2u);
899 for (
size_t i = 0; i <
r.triangles.size(); ++i)
901 const auto & t =
r.triangles(i);
902 EXPECT_LT(t.i,
r.sites.size());
903 EXPECT_LT(t.j,
r.sites.size());
904 EXPECT_LT(t.k,
r.sites.size());
906 Orientation::COLLINEAR);
917 EXPECT_EQ(
r.sites.size(), 4u);
918 EXPECT_EQ(
r.triangles.size(), 2u);
927 EXPECT_EQ(
r.sites.size(), 4u);
928 EXPECT_EQ(
r.triangles.size(), 0u);
939 shuffled.append(
Point(0, 1));
940 shuffled.append(
Point(0, 0));
941 shuffled.append(
Point(1, 0));
942 auto r2 = delaunay(shuffled);
945 for (
size_t i = 0; i < r1.sites.size(); ++i)
947 for (
size_t i = 0; i < r1.triangles.size(); ++i)
949 const auto & t = r1.triangles(i);
955 "case_delaunay_cocircular_deterministic", scene,
956 "Delaunay cocircular tie-break");
958 ASSERT_EQ(r1.sites.size(), r2.sites.size());
959 ASSERT_EQ(r1.triangles.size(), r2.triangles.size());
961 for (
size_t i = 0; i < r1.sites.size(); ++i)
962 EXPECT_EQ(r1.sites(i), r2.sites(i));
967 for (
size_t i = 0; i < t1.
size(); ++i)
969 EXPECT_EQ(t1(i).a, t2(i).a);
970 EXPECT_EQ(t1(i).b, t2(i).b);
971 EXPECT_EQ(t1(i).c, t2(i).c);
981 EXPECT_EQ(
r.sites.size(), 3u);
982 EXPECT_EQ(
r.vertices.size(), 1u);
983 EXPECT_EQ(
r.edges.size(), 3u);
984 EXPECT_EQ(
r.cells.size(), 3u);
986 size_t unbounded = 0;
987 for (
size_t i = 0; i <
r.edges.size(); ++i)
988 if (
r.edges(i).unbounded)
991 EXPECT_FALSE(
r.edges(i).direction ==
Point(0, 0));
993 EXPECT_EQ(unbounded, 3u);
995 for (
size_t i = 0; i <
r.cells.size(); ++i)
997 EXPECT_FALSE(
r.cells(i).bounded);
998 EXPECT_EQ(
r.cells(i).vertices.size(), 1u);
1008 EXPECT_EQ(
r.sites.size(), 4u);
1009 EXPECT_EQ(
r.vertices.size(), 2u);
1010 EXPECT_EQ(
r.cells.size(), 4u);
1013 size_t unbounded = 0;
1014 for (
size_t i = 0; i <
r.edges.size(); ++i)
1015 if (
r.edges(i).unbounded)
1020 EXPECT_EQ(bounded, 1u);
1021 EXPECT_EQ(unbounded, 4u);
1023 for (
size_t i = 0; i <
r.cells.size(); ++i)
1024 EXPECT_FALSE(
r.cells(i).bounded);
1033 ASSERT_GE(dt.triangles.size(), 2u);
1036 auto r = voronoi(dt);
1038 size_t bounded_edges = 0;
1039 for (
size_t e = 0; e <
r.edges.size(); ++e)
1041 const auto & edge =
r.edges(e);
1049 for (
size_t t = 0; t < dt.triangles.size(); ++t)
1051 const auto & tri = dt.triangles(t);
1052 const bool has_u = tri.i == edge.site_u or tri.j == edge.site_u or
1053 tri.k == edge.site_u;
1054 const bool has_v = tri.i == edge.site_v or tri.j == edge.site_v or
1055 tri.k == edge.site_v;
1056 if (has_u
and has_v)
1060 ASSERT_EQ(incident.
size(), 2u);
1062 const auto & t0 = dt.triangles(incident(0));
1063 const auto & t1 = dt.triangles(incident(1));
1064 ASSERT_NE(
orientation(dt.sites(t0.i), dt.sites(t0.j), dt.sites(t0.k)),
1065 Orientation::COLLINEAR);
1066 ASSERT_NE(
orientation(dt.sites(t1.i), dt.sites(t1.j), dt.sites(t1.k)),
1067 Orientation::COLLINEAR);
1069 const Point c0 = circumcenter_of(dt.sites(t0.i), dt.sites(t0.j), dt.sites(t0.k));
1070 const Point c1 = circumcenter_of(dt.sites(t1.i), dt.sites(t1.j), dt.sites(t1.k));
1071 EXPECT_TRUE(matches_unordered_pair(edge.src, edge.tgt, c0, c1));
1074 EXPECT_GT(bounded_edges, 0u);
1092 ASSERT_EQ(cells.
size(),
r.sites.size());
1095 for (
size_t i = 0; i < cells.
size(); ++i)
1097 EXPECT_TRUE(cells(i).is_closed());
1098 EXPECT_GE(cells(i).
size(), 3u);
1099 EXPECT_TRUE(pip.
contains(cells(i),
r.sites(i)));
1112 box_cw.add_vertex(
Point(-10, 10));
1113 box_cw.add_vertex(
Point(10, 10));
1114 box_cw.add_vertex(
Point(10, -10));
1118 ASSERT_EQ(cells.
size(),
r.sites.size());
1121 for (
size_t i = 0; i < cells.
size(); ++i)
1123 EXPECT_TRUE(cells(i).is_closed());
1124 EXPECT_GE(cells(i).
size(), 3u);
1125 EXPECT_TRUE(pip.
contains(cells(i),
r.sites(i)));
1138 concave.add_vertex(
Point(6, 0));
1139 concave.add_vertex(
Point(3, 2));
1140 concave.add_vertex(
Point(6, 6));
1141 concave.add_vertex(
Point(0, 6));
1144 EXPECT_THROW((
void) voronoi.
clipped_cells(
r, concave), std::domain_error);
1163 ASSERT_EQ(cells.
size(),
r.sites.size());
1166 for (
size_t i = 0; i < cells.
size(); ++i)
1168 EXPECT_EQ(cells(i).site_index, i);
1169 EXPECT_EQ(cells(i).site,
r.sites(i));
1170 EXPECT_TRUE(cells(i).polygon.is_closed());
1171 EXPECT_GE(cells(i).polygon.
size(), 3u);
1172 EXPECT_TRUE(pip.
contains(cells(i).polygon, cells(i).site));
1189 auto triangles = triangulator(p);
1191 EXPECT_EQ(triangles.size(), 4u);
1209 for (
int i = 0; i <
N; ++i)
1210 for (
int j = 0; j < 3; ++j)
1211 points.
append(
Point(i * 7 + j * 3, j * 11 + i * 5));
1214 auto r = delaunay(points);
1216 EXPECT_GE(
r.sites.size(), 3u);
1217 EXPECT_GE(
r.triangles.size(), 1u);
1220 for (
size_t t = 0; t <
r.triangles.size(); ++t)
1222 const auto & tri =
r.triangles(t);
1223 const Point cc = circumcenter_of(
r.sites(tri.i),
r.sites(tri.j),
1226 for (
size_t s = 0; s <
r.sites.size(); ++s)
1228 if (s == tri.i or s == tri.j or s == tri.k)
1242 for (
int x = 0; x < 10; ++x)
1243 for (
int y = 0;
y < 10; ++
y)
1247 auto r = delaunay(points);
1249 EXPECT_EQ(
r.sites.size(), 100u);
1251 EXPECT_EQ(
r.triangles.size(), 2u * 9u * 9u);
1254 for (
size_t t = 0; t <
r.triangles.size(); ++t)
1256 const auto & tri =
r.triangles(t);
1257 EXPECT_NE(
orientation(
r.sites(tri.i),
r.sites(tri.j),
r.sites(tri.k)),
1258 Orientation::COLLINEAR);
1273 ASSERT_GE(dt.triangles.size(), 3u);
1276 auto r = voronoi(dt);
1277 ASSERT_EQ(
r.cells.size(),
r.sites.size());
1279 for (
size_t s = 0; s <
r.cells.size(); ++s)
1283 for (
size_t t = 0; t < dt.triangles.size(); ++t)
1285 const auto & tri = dt.triangles(t);
1286 if (tri.i == s or tri.j == s or tri.k == s)
1287 expected.append(circumcenter_of(dt.sites(tri.i),
1293 const auto & cell_verts =
r.cells(s).vertices;
1294 EXPECT_EQ(cell_verts.size(),
expected.size())
1295 <<
"Mismatch for site " << s;
1297 for (
size_t v = 0; v < cell_verts.size(); ++v)
1300 for (
size_t e = 0; e <
expected.size(); ++e)
1306 EXPECT_TRUE(found) <<
"Cell " << s <<
" has unexpected vertex";
1316 for (
int i = 0; i < 8; ++i)
1317 for (
int j = 0; j < 8; ++j)
1318 points.
append(
Point(i * 3 + (j % 2), j * 3 + (i % 2)));
1321 auto dt = delaunay(points);
1324 auto r = voronoi(dt);
1325 ASSERT_EQ(
r.cells.size(),
r.sites.size());
1328 size_t bounded_count = 0;
1329 for (
size_t s = 0; s <
r.cells.size(); ++s)
1331 if (
r.cells(s).bounded)
1335 EXPECT_GE(
r.cells(s).vertices.size(), 1u);
1337 EXPECT_GT(bounded_count, 0u);
1355 auto triangles = triangulator(p);
1357 EXPECT_EQ(triangles.size(), 3u);
1374 auto triangles = triangulator(p);
1376 EXPECT_EQ(triangles.size(), 4u);
1390 auto triangles = triangulator(p);
1392 EXPECT_EQ(triangles.size(), 1u);
1409 auto triangles = triangulator(p);
1412 EXPECT_EQ(triangles.size(), 4u);
1433 EXPECT_EQ(
r.size(), 3u);
1434 EXPECT_TRUE(
r.is_closed());
1435 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(0, 0)));
1436 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(0, 3)));
1437 EXPECT_TRUE(polygon_contains_vertex(
r,
Point(4, 0)));
1457 EXPECT_EQ(
r.size(), 5u);
1458 EXPECT_TRUE(
r.is_closed());
1485 auto r = delaunay(empty);
1487 EXPECT_EQ(
r.sites.size(), 0u);
1488 EXPECT_EQ(
r.triangles.size(), 0u);
1495 auto r = delaunay({
Point(5, 5)});
1497 EXPECT_EQ(
r.sites.size(), 1u);
1498 EXPECT_EQ(
r.triangles.size(), 0u);
1507 EXPECT_EQ(
r.sites.size(), 2u);
1508 EXPECT_EQ(
r.triangles.size(), 0u);
1517 EXPECT_EQ(
r.sites.size(), 1u);
1518 EXPECT_EQ(
r.triangles.size(), 0u);
1527 EXPECT_EQ(
r.sites.size(), 2u);
1528 EXPECT_EQ(
r.triangles.size(), 0u);
1538 auto r = voronoi(empty);
1540 EXPECT_EQ(
r.sites.size(), 0u);
1541 EXPECT_EQ(
r.vertices.size(), 0u);
1542 EXPECT_EQ(
r.edges.size(), 0u);
1543 EXPECT_EQ(
r.cells.size(), 0u);
1550 auto r = voronoi({
Point(5, 5)});
1552 EXPECT_EQ(
r.sites.size(), 1u);
1553 EXPECT_EQ(
r.vertices.size(), 0u);
1554 EXPECT_EQ(
r.edges.size(), 0u);
1563 EXPECT_EQ(
r.sites.size(), 2u);
1564 EXPECT_EQ(
r.edges.size(), 0u);
1573 EXPECT_EQ(
r.sites.size(), 4u);
1574 EXPECT_EQ(
r.edges.size(), 0u);
1596 auto triangles = triangulator(p);
1599 EXPECT_GE(triangles.size(), 1u);
1603 for (
auto it = triangles.get_it(); it.has_curr(); it.next_ne())
1613 const size_t N = 200;
1615 for (
size_t i = 0; i <
N; ++i)
1626 auto triangles = triangulator(p);
1629 EXPECT_EQ(triangles.size(),
N - 2);
1633 for (
auto it = triangles.get_it(); it.has_curr(); it.next_ne())
1643 <<
"Triangulation area (" << total_area.
get_d()
1653 const size_t spikes = 5;
1654 for (
size_t i = 0; i < spikes; ++i)
1670 const size_t n = 2 * spikes;
1672 auto triangles = triangulator(p);
1674 EXPECT_EQ(triangles.size(), n - 2);
1678 for (
auto it = triangles.get_it(); it.has_curr(); it.next_ne())
1693 const size_t N = 100;
1695 for (
size_t i = 0; i <
N; ++i)
1704 auto hull_qh = qh(pts);
1707 auto hull_andrew = andrew(pts);
1710 auto hull_graham = graham(pts);
1713 EXPECT_EQ(hull_qh.size(),
N);
1714 EXPECT_EQ(hull_andrew.size(),
N);
1715 EXPECT_EQ(hull_graham.size(),
N);
1718 EXPECT_TRUE(polygon_is_convex(hull_qh));
1719 EXPECT_TRUE(polygon_is_convex(hull_andrew));
1720 EXPECT_TRUE(polygon_is_convex(hull_graham));
1723 EXPECT_TRUE(is_ccw(hull_qh)) <<
"QuickHull result not CCW";
1724 EXPECT_TRUE(is_ccw(hull_andrew)) <<
"Andrew result not CCW";
1725 EXPECT_TRUE(is_ccw(hull_graham)) <<
"Graham result not CCW";
1734 {0, 0}, {100, 0}, {200, 0}, {50, 100}, {150, 100}
1737 std::mt19937
rng(42);
1738 std::uniform_real_distribution<double>
offset(-5.0, 5.0);
1740 for (
size_t c = 0; c < 5; ++c)
1741 for (
size_t i = 0; i < 2000; ++i)
1746 auto hull_qh = qh(pts);
1749 auto hull_andrew = andrew(pts);
1752 EXPECT_TRUE(polygon_is_convex(hull_qh));
1753 EXPECT_TRUE(polygon_is_convex(hull_andrew));
1754 EXPECT_EQ(hull_qh.size(), hull_andrew.size());
1757 EXPECT_TRUE(all_points_inside_or_on(pts, hull_qh));
1765 std::mt19937
rng(123);
1766 std::uniform_real_distribution<double> dist(-1000.0, 1000.0);
1768 for (
size_t i = 0; i < 100000; ++i)
1772 auto hull_qh = qh(pts);
1775 auto hull_andrew = andrew(pts);
1778 EXPECT_TRUE(polygon_is_convex(hull_qh));
1779 EXPECT_TRUE(polygon_is_convex(hull_andrew));
1780 EXPECT_EQ(hull_qh.size(), hull_andrew.size());
1781 EXPECT_GE(hull_qh.size(), 3u);
1792 for (
size_t i = 0; i <
N; ++i)
1803 EXPECT_EQ(
r.sites.size(),
N);
1804 EXPECT_GE(
r.triangles.size(), 1u);
1807 for (
size_t t = 0; t <
r.triangles.size(); ++t)
1809 const auto & tri =
r.triangles(t);
1810 EXPECT_NE(
orientation(
r.sites(tri.i),
r.sites(tri.j),
r.sites(tri.k)),
1811 Orientation::COLLINEAR);
1829 EXPECT_GE(
r.triangles.size(), 1u);
1833 for (
size_t t = 0; t <
r.triangles.size(); ++t)
1835 const auto & tri =
r.triangles(t);
1836 const Point & a =
r.sites(tri.i);
1837 const Point & b =
r.sites(tri.j);
1838 const Point & c =
r.sites(tri.k);
1840 if (
orientation(a, b, c) == Orientation::COLLINEAR)
1843 Point cc = circumcenter_of(a, b, c);
1846 for (
size_t s = 0; s <
r.sites.size(); ++s)
1848 if (s == tri.i or s == tri.j or s == tri.k)
1853 <<
"Site " << s <<
" is strictly inside circumcircle of triangle " << t;
1864 std::mt19937
rng(77);
1865 std::uniform_real_distribution<double> dist(-500.0, 500.0);
1867 const size_t N = 2000;
1868 for (
size_t i = 0; i <
N; ++i)
1874 EXPECT_EQ(
r.sites.size(),
N);
1875 EXPECT_GE(
r.triangles.size(), 1u);
1878 size_t violations = 0;
1879 for (
size_t t = 0; t <
r.triangles.size(); ++t)
1881 const auto & tri =
r.triangles(t);
1882 const Point & a =
r.sites(tri.i);
1883 const Point & b =
r.sites(tri.j);
1884 const Point & c =
r.sites(tri.k);
1886 if (
orientation(a, b, c) == Orientation::COLLINEAR)
1889 Point cc = circumcenter_of(a, b, c);
1892 for (
size_t s = 0; s <
r.sites.size(); ++s)
1894 if (s == tri.i or s == tri.j or s == tri.k)
1902 EXPECT_EQ(violations, 0u)
1903 << violations <<
" Delaunay circumcircle violations found";
Andrew's monotonic chain convex hull algorithm.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
T & append(const T &data)
Append a copy of data
void reserve(size_t cap)
Reserves cap cells into the array.
Brute force convex hull algorithm.
Closest pair of points via divide and conquer.
Segment closest_segment(DynList< Point > &point_set) const
Convenience wrapper returning the closest segment.
Basic exact intersection for closed convex polygons.
Polygon triangulation using the ear-cutting algorithm.
Exact Delaunay triangulation using the Bowyer-Watson incremental algorithm.
Iterator on the items of list.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
Gift wrapping (Jarvis march) convex hull algorithm.
Graham scan convex hull algorithm.
bool has_curr() const noexcept
Exact bounded intersection of half-planes.
static Array< HalfPlane > from_convex_polygon(const Polygon &poly)
Build half-planes from the edges of a closed convex polygon.
Number Theoretic Transform over Z / MOD Z.
Exact point-in-polygon classification via winding number.
static bool strictly_contains(const Polygon &poly, const Point &p)
Return true only for strict interior points.
static Location locate(const Polygon &poly, const Point &p)
Classify point location with respect to a polygon.
static bool contains(const Polygon &poly, const Point &p)
Return true if the point is inside or on the boundary.
Represents a point with rectangular coordinates in a 2D plane.
Geom_Number distance_squared_to(const Point &that) const
Calculates the squared Euclidean distance to another point.
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the polygon.
void close()
Close the polygon.
const bool & is_closed() const
Check if the polygon is closed.
const size_t & size() const
Get the number of vertices.
QuickHull convex hull algorithm.
Rotating calipers metrics for convex polygons.
static DiameterResult diameter(const Polygon &poly)
Compute convex polygon diameter (farthest vertex pair).
static WidthResult minimum_width(const Polygon &poly)
Compute the minimum width of a closed convex polygon.
Represents a line segment between two points.
const Point & get_tgt_point() const noexcept
Gets the target point of the segment.
const Point & get_src_point() const noexcept
Gets the source point of the segment.
Voronoi diagram derived as the dual of a Delaunay triangulation.
static Array< ClippedCell > clipped_cells_indexed(const Array< Point > &sites, const Polygon &clip)
Clip Voronoi cells and return explicit site-indexed records.
static Array< Polygon > clipped_cells(const Array< Point > &sites, const Polygon &clip)
Clip Voronoi cells against a closed convex polygon.
Minimal std::expected-style result type for C++20.
TEST_F(GeomAlgorithmsTest, TriangulateTriangle)
double triangle_area(const Triangle &t)
Calculate area of a triangle using cross product.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_cos_function > > cos(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sin_function > > sin(const __gmp_expr< T, U > &expr)
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
void add_polygon_vertices(SvgScene &scene, const ::Polygon &poly, const bool as_highlight=false)
std::filesystem::path emit_case_svg(const std::string &case_id, const SvgScene &scene, const std::string ¬e="")
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
and
Check uniqueness with explicit hash + equality functors.
Orientation orientation(const Point &a, const Point &b, const Point &c)
Return the orientation of the triple (a, b, c).
mpq_class Geom_Number
Numeric type used by the geometry module.
static Geom_Number polygon_area(const Polygon &poly)
static Geom_Number poly_area(const Polygon &p)
static Rectangle box(const int x1, const int y1, const int x2, const int y2)
Geom_Number distance_squared
::Array<::Polygon > polygons
::Array<::Point > highlighted_points
::Array<::Segment > segments