Skip to content

Commit

Permalink
Shortcut through simplification step if distanceTolerance is negative
Browse files Browse the repository at this point in the history
If the simplification tolerance has been set to less than 0.0 then there's
no need to run the DouglasPeuckerSimplifier algorithm. This change
checks the tolerance and simply returns a copy of the Geometry if no
simplification is requested.
This change is required for the case where the user wants no
simplification to take place e.g. to preserve all intersection nodes.
Without this change any negative value for distanceTolerance is squared
inside DPTransformer and immediately loses its meaning.
  • Loading branch information
davecraig committed Nov 8, 2024
1 parent dc17a1c commit 8c4e1fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ void simplifyLineStringIfToleranceIsSet() {
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
Expand Down

0 comments on commit 8c4e1fc

Please sign in to comment.