Skip to content

Commit

Permalink
Merge branch 'fix_force_lhr-rhr_268' into 'master'
Browse files Browse the repository at this point in the history
ForceOrderPoints: fix interior ring order

Closes #268

See merge request sfcgal/SFCGAL!324
  • Loading branch information
lbartoletti committed Jul 12, 2024
2 parents 81fdf79 + c2dcf4c commit 543674d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/detail/transform/ForceOrderPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,12 @@ ForceOrderPoints::visit(Polygon &p)
}
}

const bool isCCWO{algorithm::isCounterClockWiseOriented(ext)};
for (size_t i = 0; i < p.numInteriorRings(); ++i) {
LineString inter = p.interiorRingN(i);
LineString &inter = p.interiorRingN(i);

if (algorithm::isCounterClockWiseOriented(inter)) {
// interior ring is pointing up, reverse
if (_orientCCW) {
inter.reverse();
}
} else {
if (!_orientCCW) {
inter.reverse();
}
if (algorithm::isCounterClockWiseOriented(inter) == isCCWO) {
inter.reverse();
}
}

Expand Down
43 changes: 43 additions & 0 deletions test/unit/SFCGAL/capi/sfcgal_cTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,47 @@ BOOST_AUTO_TEST_CASE(testLineSubstring)

BOOST_CHECK(sfcgal_geometry_covers_3d(ls, g2.get()));
}

BOOST_AUTO_TEST_CASE(testForceRHR)
{
sfcgal_set_error_handlers(printf, on_error);

std::string strGeom{"POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,2 1,2 2,1 2,1 1))"};

std::unique_ptr<Geometry> const geom(io::readWkt(strGeom));

sfcgal_geometry_t *rhr = sfcgal_geometry_force_rhr(geom.get());
// retrieve wkb from C api
char *wkbApi;
size_t wkbLen;
sfcgal_geometry_as_text_decim(rhr, 0, &wkbApi, &wkbLen);
std::string strApi(wkbApi, wkbLen);

// check
BOOST_CHECK_EQUAL(strGeom, strApi);
delete[] wkbApi;
}

BOOST_AUTO_TEST_CASE(testForceLHR)
{
sfcgal_set_error_handlers(printf, on_error);

std::string strGeom{"POLYGON((0 0,0 5,5 5,5 0,0 0),(1 1,2 1,2 2,1 2,1 1))"};
std::string expectedGeom{
"POLYGON((0 0,5 0,5 5,0 5,0 0),(1 1,1 2,2 2,2 1,1 1))"};

std::unique_ptr<Geometry> const geom(io::readWkt(strGeom));

sfcgal_geometry_t *lhr = sfcgal_geometry_force_lhr(geom.get());
// retrieve wkb from C api
char *wkbApi;
size_t wkbLen;
sfcgal_geometry_as_text_decim(lhr, 0, &wkbApi, &wkbLen);
std::string strApi(wkbApi, wkbLen);

// check
BOOST_CHECK_EQUAL(expectedGeom, strApi);
delete[] wkbApi;
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 543674d

Please sign in to comment.