Skip to content

Commit

Permalink
Fix TPSimplifier endpoint removal indexing (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts authored Jun 14, 2024
1 parent 1672c03 commit 586780f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ private static Coordinate[] extractCoordinates(List<LineSegment> segs)
return pts;
}

void removeRingEndpoint()
LineSegment removeRingEndpoint()
{
LineSegment firstSeg = (LineSegment) resultSegs.get(0);
LineSegment lastSeg = (LineSegment) resultSegs.get(resultSegs.size() - 1);

firstSeg.p0 = lastSeg.p0;
resultSegs.remove(resultSegs.size() - 1);
return firstSeg;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ private void simplifyRingEndpoint(double distanceTolerance)
Coordinate endPt = firstSeg.p0;
if (simpSeg.distance(endPt) <= distanceTolerance
&& isTopologyValid(line, firstSeg, lastSeg, simpSeg)) {
line.removeRingEndpoint();
//-- don't know if segments are original or new, so remove from all indexes
inputIndex.remove(firstSeg);
inputIndex.remove(lastSeg);
outputIndex.remove(firstSeg);
outputIndex.remove(lastSeg);

LineSegment flatSeg = line.removeRingEndpoint();
outputIndex.add(flatSeg);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ public void testPolygonIntersectingSegments() {
"MULTIPOLYGON (((0.63 0.2, 0.35 0, 0.73 0.66, 0.63 0.2)), ((1.42 4.01, 3.45 0.7, 1.79 1.47, 0 0.57, 1.42 4.01)))");
}

//-- test added in https://github.com/libgeos/geos/pull/1110
public void testRingEndpointRemoval() {
checkTPS("POLYGON ((-222601.33094265286 6299915.50260568, -222599.13611514607 6299917.747821213, -222599.09754554977 6299925.149899498, -222599.07870256738 6299925.234615005, -222595.52372420163 6299932.934861557, -222510 6300300, -221720.85158014414 6300132.680680807, -222448.77936063593 6299647.669870703, -222618.41756525903 6299886.966175825, -222618.40178141624 6299887.020684309, -222616.09648739762 6299892.144482262, -222601.33094265286 6299915.50260568), (-222456.68914400978 6299947.489843342, -222455.07603815367 6299939.772017001, -222455.07542453965 6299939.691595431, -222456.57057590774 6299931.950053182, -222462.75368034307 6299916.87367865, -222465.9575074078 6299911.582542387, -222465.99782740293 6299911.534645676, -222483.5296791599 6299864.079888968, -222484.09789251382 6299852.105440594, -222485.11401620077 6299846.692173677, -222485.13170293145 6299846.639453617, -222487.58585740798 6299841.7086228, -222490.56062790897 6299837.359974515, -222415.1394852571 6299926.6972160805, -222421.19226152284 6299963.389132584, -222467.0202338936 6299970.185860572, -222465.71145777934 6299968.200784476, -222465.69955208438 6299968.180154371, -222464.63560265294 6299966.053788407, -222456.68914400978 6299947.489843342))",
20,
"POLYGON ((-222618.41756525903 6299886.966175825, -222510 6300300, -221720.85158014414 6300132.680680807, -222448.77936063593 6299647.669870703, -222618.41756525903 6299886.966175825), (-222467.0202338936 6299970.185860572, -222456.57057590774 6299931.950053182, -222490.56062790897 6299837.359974515, -222415.1394852571 6299926.6972160805, -222421.19226152284 6299963.389132584, -222467.0202338936 6299970.185860572))");
}

private void checkTPS(String wkt, double tolerance, String wktExpected) {
Geometry geom = read(wkt);
Geometry actual = TopologyPreservingSimplifier.simplify(geom, tolerance);
Expand Down

0 comments on commit 586780f

Please sign in to comment.