Skip to content

Commit

Permalink
Merge branch 'fix_force_lhr-rhr_3D' into 'master'
Browse files Browse the repository at this point in the history
ForceOrderPoints: also allow for 3D geometries

Closes #268

See merge request sfcgal/SFCGAL!326
  • Loading branch information
lbartoletti committed Jul 12, 2024
2 parents 543674d + 8d60a55 commit 9945387
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 32 deletions.
59 changes: 27 additions & 32 deletions src/detail/transform/ForceOrderPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,45 @@ ForceOrderPoints::transform(Point & /*p*/)
void
ForceOrderPoints::visit(Triangle &t)
{
if (!t.is3D()) {
if (!algorithm::isCounterClockWiseOriented(t)) {
// not pointing up, reverse
if (_orientCCW) {
t.reverse();
}
} else {
if (!_orientCCW) {
t.reverse();
}
if (!algorithm::isCounterClockWiseOriented(t)) {
// not pointing up, reverse
if (_orientCCW) {
t.reverse();
}
} else {
if (!_orientCCW) {
t.reverse();
}

Transform::visit(t);
}

Transform::visit(t);
}

void
ForceOrderPoints::visit(Polygon &p)
{
if (!p.is3D()) {
LineString &ext = p.exteriorRing();
LineString &ext = p.exteriorRing();

if (!algorithm::isCounterClockWiseOriented(p.exteriorRing())) {
// exterior ring not pointing up, reverse
if (_orientCCW) {
ext.reverse();
}
} else {
if (!_orientCCW) {
ext.reverse();
}
if (!algorithm::isCounterClockWiseOriented(p.exteriorRing())) {
// exterior ring not pointing up, reverse
if (_orientCCW) {
ext.reverse();
}

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

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

Transform::visit(p);
if (algorithm::isCounterClockWiseOriented(inter) == isCCWO) {
inter.reverse();
}
}

Transform::visit(p);
}

} // namespace SFCGAL::transform
23 changes: 23 additions & 0 deletions test/unit/SFCGAL/capi/sfcgal_cTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,27 @@ BOOST_AUTO_TEST_CASE(testForceLHR)
delete[] wkbApi;
}

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

std::string strGeom{"POLYGON((0 5 1,0 0 2,5 0 3,5 5 4,0 5 1),(2 1 1,1 1 2,1 "
"2 3,2 2 4,2 1 1),(4 3 1,3 3 2,3 4 3,4 4 4,4 3 1))"};
std::string expectedGeom{
"POLYGON Z((0 5 1,5 5 4,5 0 3,0 0 2,0 5 1),(2 1 1,2 2 4,1 2 3,1 1 2,2 1 "
"1),(4 3 1,4 4 4,3 4 3,3 3 2,4 3 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(expectedGeom, strApi);
delete[] wkbApi;
}
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 9945387

Please sign in to comment.