From 6e3765db0beb597d096d6ce84ed4d26e2fe9e8af Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Tue, 5 Nov 2024 13:58:12 -0800 Subject: [PATCH] Fix TaggedLineString to return correct vertex --- .../jts/simplify/TaggedLineString.java | 14 ++++++++++++++ .../simplify/TopologyPreservingSimplifierTest.java | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java b/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java index d76bfaae0d..968da172bc 100644 --- a/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java +++ b/modules/core/src/main/java/org/locationtech/jts/simplify/TaggedLineString.java @@ -60,7 +60,21 @@ public int size() { return parentLine.getNumPoints(); } + /** + * Returns a vertex of the component, + * in either simplified or original form. + * Once the component is simplified a vertex of the simplified linework + * must be returned. + * Otherwise the simplified linework could be jumped by a flattened line + * which does not cross an original vertex, and so is reported as valid. + * + * @return a component vertex + */ public Coordinate getComponentPoint() { + //-- simplified vertex + if (resultSegs.size() > 0) + return resultSegs.get(0).p0; + //-- original vertex return getParentCoordinates()[1]; } diff --git a/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java b/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java index f162c0841f..3028f958aa 100644 --- a/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java +++ b/modules/core/src/test/java/org/locationtech/jts/simplify/TopologyPreservingSimplifierTest.java @@ -249,8 +249,7 @@ private void checkTPS(String wkt, double tolerance, String wktExpected) { Geometry geom = read(wkt); Geometry actual = TopologyPreservingSimplifier.simplify(geom, tolerance); Geometry expected = read(wktExpected); - //TODO: add this once the "skipping over rings" problem is fixed - //checkValid(actual); + checkValid(actual); checkEqual(expected, actual); }