Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SnapRoundingNoder fix #504

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions include/geos/noding/snapround/SnapRoundingIntersectionAdder.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ namespace snapround { // geos::noding::snapround
class GEOS_DLL SnapRoundingIntersectionAdder: public SegmentIntersector { // implements SegmentIntersector

private:
/**
* The division factor used to determine
* nearness distance tolerance for interior intersection detection.
*/
static constexpr int NEARNESS_FACTOR = 100;

algorithm::LineIntersector li;
std::unique_ptr<std::vector<geom::Coordinate>> intersections;
Expand All @@ -95,7 +90,11 @@ class GEOS_DLL SnapRoundingIntersectionAdder: public SegmentIntersector { // imp

public:

SnapRoundingIntersectionAdder(const geom::PrecisionModel* newPm);
SnapRoundingIntersectionAdder(double p_nearnessTol)
: SegmentIntersector()
, intersections(new std::vector<geom::Coordinate>)
, nearnessTol(p_nearnessTol)
{}

std::unique_ptr<std::vector<geom::Coordinate>> getIntersections() { return std::move(intersections); };

Expand Down
5 changes: 5 additions & 0 deletions include/geos/noding/snapround/SnapRoundingNoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ namespace snapround { // geos::noding::snapround
class GEOS_DLL SnapRoundingNoder : public Noder {

private:
/**
* The division factor used to determine
* nearness distance tolerance for interior intersection detection.
*/
static constexpr int INTERSECTION_NEARNESS_FACTOR = 100;

// Members
const geom::PrecisionModel* pm;
Expand Down
9 changes: 0 additions & 9 deletions src/noding/snapround/SnapRoundingIntersectionAdder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ namespace noding { // geos.noding
namespace snapround { // geos.noding.snapround


SnapRoundingIntersectionAdder::SnapRoundingIntersectionAdder(const geom::PrecisionModel* newPm)
: SegmentIntersector()
, intersections(new std::vector<geom::Coordinate>)
// , pm(newPm)
{
double snapGridSize = 1.0 / newPm->getScale();
nearnessTol = snapGridSize / NEARNESS_FACTOR;
}

/*public*/
void
SnapRoundingIntersectionAdder::processIntersections(
Expand Down
6 changes: 3 additions & 3 deletions src/noding/snapround/SnapRoundingNoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ SnapRoundingNoder::snapRound(std::vector<SegmentString*>& inputSegStrings, std::
void
SnapRoundingNoder::addIntersectionPixels(std::vector<SegmentString*>& segStrings)
{
SnapRoundingIntersectionAdder intAdder(pm);
MCIndexNoder noder;
noder.setSegmentIntersector(&intAdder);
double tolerance = 1.0 / pm->getScale() / INTERSECTION_NEARNESS_FACTOR;
SnapRoundingIntersectionAdder intAdder(tolerance);
MCIndexNoder noder(&intAdder, tolerance);
noder.computeNodes(&segStrings);
std::unique_ptr<std::vector<Coordinate>> intPts = intAdder.getIntersections();
pixelIndex.addNodes(*intPts);
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/capi/GEOSGeom_setPrecisionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,27 @@ void object::test<10> ()
ensure_geometry_equals(geom2_, "LINEARRING EMPTY");
}

// Reduce polygon precision, corner case / Trac #1127
template<>
template<>
void object::test<11> ()
{
// POLYGON((
// 100 49.5, (1)
// 100 300, (2)
// 320 60, (3)
// 340 49.9, (4)
// 360 50.1, (5)
// 380 49.5, (6)
// 100 49.5 (7)
// ))
// * points 4 and 5 are close (less than 100.0/100) to segment (6, 7);
// * Y coordinates of points 4 and 5 are rounded to different values, 0 and 100 respectively;
// * point 4 belongs to monotone chain of size > 1 -- segments (2, 3) and (3, 4)
geom1_ = fromWKT("POLYGON((100 49.5, 100 300, 320 60, 340 49.9, 360 50.1, 380 49.5, 100 49.5))");
geom2_ = GEOSGeom_setPrecision(geom1_, 100.0, 0);
ensure(geom2_ != nullptr); // just check that valid geometry is constructed
}

} // namespace tut