Add simplify (Douglas-Peucker) and is_closed_polygon#33
Open
gistrec wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the remaining two
PolyUtilfunctions from android-maps-utils, completing upstream parity:geo::simplify(poly, tolerance)— Douglas-Peucker decimation: keeps vertices farther thantolerancemeters from the simplified shape, always keeps the endpoints, returns only original input points. Closed polygons (is_closed_polygon) are simplified including the closing segment via the upstream trick of nudging the last point by 1e-11° on a working copy — the input is never modified (unlike the Java original, which mutates and restores the input list).geo::is_closed_polygon(poly)— non-empty path with equal first and last points. Deliberate divergence: equality is the library's approximateLatLngcomparison (longitudes modulo 360°), so a ring closing across the antimeridian —(10, 180)…(10, -180)— counts as closed; Java compares exactly.Distances come from
distance_to_segment, so its approximation limits apply (documented). Worst-case complexity is O(n²).Stacked on #32 (
feature/polyline-encoding): the simplify tests decode the upstream test fixtures (95-point LINE, OVAL_POLYGON) withgeo::decode. CI will run once this is retargeted tomasterafter #32 merges.Parity validation
All expected sizes from upstream
PolyUtilTestreproduce exactly:Plus the upstream invariants as a shared helper: endpoints preserved, output is an ordered subset of the input,
path_length(simplified) ≤ path_length(input).Docs
docs/api.md: newis_closed_polygonandsimplifysections, both added to thePathlist; error-handling convention extended (simplifyreturns an owning container, can throwstd::bad_alloc).README.md: Polygon utilities bullet mentions Douglas-Peucker simplification; header size claim refreshed (40 → 44 KB).Test plan
geo_utils_cpp_tests: 43/43 pass locally (6 new tests)-Wall -Wextra -Wpedantic -Wconversion -Wshadow -Werrormasteronce Add encode/decode for the Google Encoded Polyline format #32 merges