From 1981abc62309e7b2de4bad88ac7c3f13750a49ae Mon Sep 17 00:00:00 2001 From: Dave Craig Date: Sat, 9 Nov 2024 15:29:36 +0000 Subject: [PATCH] Shortcut through simplification step if distanceTolerance is negative (#1093) --- .../planetiler/geo/DouglasPeuckerSimplifier.java | 2 +- .../onthegomap/planetiler/FeatureMergeTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/DouglasPeuckerSimplifier.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/DouglasPeuckerSimplifier.java index ac76603a..6ccb2bca 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/DouglasPeuckerSimplifier.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/DouglasPeuckerSimplifier.java @@ -38,7 +38,7 @@ public class DouglasPeuckerSimplifier { * @return the simplified geometry */ public static Geometry simplify(Geometry geom, double distanceTolerance) { - if (geom.isEmpty()) { + if (geom.isEmpty() || (distanceTolerance < 0.0)) { return geom.copy(); } diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java index 4a3a38ca..5a1b713a 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java @@ -165,6 +165,21 @@ class FeatureMergeTest { true ) ); + // but doesn't resimplify if the tolerance is negative even when resimplify=true + assertEquals( + List.of( + feature(1, newLineString(10, 10, 20, 20, 30, 30), Map.of("a", 1)) + ), + FeatureMerge.mergeLineStrings( + List.of( + feature(1, newLineString(10, 10, 20, 20, 30, 30), Map.of("a", 1)) + ), + 0, + -1, + 0, + true + ) + ); } @Test