Skip to content

Use explicit stack in DouglasPeuckerLineSimplifier (#1127)#1216

Open
grootstebozewolf wants to merge 1 commit into
locationtech:masterfrom
grootstebozewolf:fix/1127-dp-simplify-explicit-stack
Open

Use explicit stack in DouglasPeuckerLineSimplifier (#1127)#1216
grootstebozewolf wants to merge 1 commit into
locationtech:masterfrom
grootstebozewolf:fix/1127-dp-simplify-explicit-stack

Conversation

@grootstebozewolf

Copy link
Copy Markdown
Contributor

Summary

  • Fixes StackOverflowError in DouglasPeuckerLineSimplifier.simplifySection on long, highly oscillatory linework where each split peels one vertex (recursion depth O(n)), as reported in DouglasPeuckerLineSimplifier.simplifySection() recursive calls cause StackOverflowError #1127.
  • Rewrites section simplification as an iterative pair-stack, preserving left-then-right split order and the same flatten logic as the recursive form.
  • Adds a zig-zag regression test (5000 vertices, tolerance 0) that forces deep unbalanced splits and checks all points are retained.

Risk / approach

A max-depth bail-out would change results. An explicit stack matches the maintainer suggestion on #1127 and keeps algorithm semantics while bounding memory by the heap rather than the JVM call stack.

Test plan

  • mvn -pl modules/core test -Dtest=DouglasPeuckerSimplifierTest — 21 tests, 0 failures (includes new SOE case)
  • TopologyPreservingSimplifierTest + VWSimplifierTest — 38 tests, 0 failures
  • Optional: run under reduced -Xss if maintainers want a hard recursive SOE repro for comparison

Fixes #1127

Recursive simplifySection can throw StackOverflowError on long, highly
oscillatory linework where each split peels one vertex (depth O(n)).
Rewrite as an iterative pair-stack, preserving left-then-right split
order and results. Add a zig-zag regression test that forces deep
unbalanced splits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DouglasPeuckerLineSimplifier.simplifySection() recursive calls cause StackOverflowError

1 participant