11#include " ../examples/utils.hpp"
22#include < catch.hpp>
3+ #include < cmath>
34#include < delaunator.hpp>
45
56namespace {
@@ -13,14 +14,30 @@ void validate(const std::vector<double>& coords) {
1314 (i2 != delaunator::INVALID_INDEX) && (d.halfedges [i2] != i)));
1415 }
1516 }
17+
18+ SECTION (" validate triangulation" ) {
19+ double hull_area = d.get_hull_area ();
20+ double triangles_area = 0.0 ;
21+
22+ for (size_t i = 0 ; i < d.triangles .size (); i += 3 ) {
23+ const double ax = coords[2 * d.triangles [i]];
24+ const double ay = coords[2 * d.triangles [i] + 1 ];
25+ const double bx = coords[2 * d.triangles [i + 1 ]];
26+ const double by = coords[2 * d.triangles [i + 1 ] + 1 ];
27+ const double cx = coords[2 * d.triangles [i + 2 ]];
28+ const double cy = coords[2 * d.triangles [i + 2 ] + 1 ];
29+ triangles_area += std::fabs ((by - ay) * (cx - bx) - (bx - ax) * (cy - by));
30+ }
31+ REQUIRE (triangles_area == Approx (hull_area));
32+ }
1633}
1734} // namespace
1835
1936TEST_CASE (" triangles match JS version ouput" , " [Delaunator]" ) {
2037 std::string points_str = utils::read_file (" ./test/test-files/playgrounds-1356-epsg-3857.geojson" );
2138 std::string triangles_str = utils::read_file (" ./test/test-files/playgrounds-1356-triangles.json" );
2239 std::vector<double > coords = utils::get_geo_json_points (points_str);
23- std::vector<double > triangles = utils::get_array_points (triangles_str);
40+ std::vector<size_t > triangles = utils::get_array_points< size_t > (triangles_str);
2441 delaunator::Delaunator delaunator (coords);
2542
2643 SECTION (" length of triangles is the same" ) {
@@ -29,7 +46,7 @@ TEST_CASE("triangles match JS version ouput", "[Delaunator]") {
2946
3047 SECTION (" values are the same" ) {
3148 for (std::size_t i = 0 ; i < triangles.size (); i++) {
32- REQUIRE (delaunator.triangles [i] == Approx ( triangles[i]) );
49+ REQUIRE (delaunator.triangles [i] == triangles[i]);
3350 }
3451 }
3552}
@@ -48,3 +65,8 @@ TEST_CASE("mapbox/delaunator/issues/24", "[Delaunator]") {
4865 std::vector<double > coords = { 382 , 302 , 382 , 328 , 382 , 205 , 623 , 175 , 382 , 188 , 382 , 284 , 623 , 87 , 623 , 341 , 141 , 227 };
4966 validate (coords);
5067}
68+
69+ TEST_CASE (" mapbox/delaunator/issues/13" , " [Delaunator]" ) {
70+ std::vector<double > coords = { 4 , 1 , 3.7974166882130675 , 2.0837249985614585 , 3.2170267516619773 , 3.0210869309396715 , 2.337215067329615 , 3.685489874065187 , 1.276805078389906 , 3.9872025288851036 , 0.17901102978375127 , 3.885476929518457 , -0.8079039091377689 , 3.3940516818407187 , -1.550651407188842 , 2.5792964886320684 , -1.9489192990517052 , 1.5512485534497125 , -1.9489192990517057 , 0.44875144655029087 , -1.5506514071888438 , -0.5792964886320653 , -0.8079039091377715 , -1.394051681840717 , 0.17901102978374794 , -1.8854769295184561 , 1.276805078389902 , -1.987202528885104 , 2.337215067329611 , -1.6854898740651891 , 3.217026751661974 , -1.021086930939675 , 3.7974166882130653 , -0.08372499856146409 };
71+ validate (coords);
72+ }
0 commit comments