fix(convert_osm): replace clip_map with overlap-based boundary clipping - #1178
Open
AlyZaki wants to merge 1 commit into
Open
fix(convert_osm): replace clip_map with overlap-based boundary clipping#1178AlyZaki wants to merge 1 commit into
AlyZaki wants to merge 1 commit into
Conversation
The current clip_map silently drops any building where a single vertex lies outside the GPS boundary polygon. At city edges this removes buildings that are 95% inside the map — one corner clips a boundary way and the whole building disappears. Replace with clip_map_resilient() which retains buildings with >=5% area overlap. The overlap is computed via polygon intersection, only called for buildings not fully inside (fast path) and whose bounding boxes overlap the boundary bbox (cheap early rejection before the expensive intersection test). Additional guards: degenerate polygons (<4 ring points) and NaN coordinates are logged and dropped rather than causing arithmetic panics downstream. Tested against Cairo urban core (~750K buildings, complex boundary polygon).
dabreegster
reviewed
May 18, 2026
| // Pre-compute boundary bounding box for cheap early rejection. | ||
| // Buildings whose bbox doesn't overlap the boundary bbox can't overlap the boundary. | ||
| let boundary_pts: Vec<_> = boundary_polygon.get_outer_ring().points().clone(); | ||
| let (bnd_min_x, bnd_max_x, bnd_min_y, bnd_max_y) = boundary_pts.iter().fold( |
Collaborator
There was a problem hiding this comment.
geom::Bounds::from_polygons can do this
| } | ||
|
|
||
| // Guard: NaN coordinates | ||
| if outer_pts.iter().any(|pt| !pt.x().is_finite() || !pt.y().is_finite()) { |
Collaborator
There was a problem hiding this comment.
Like my comment in the other PR -- this should either be prevented outright in the input, or at worst, filtered out upfront when parsing from OSM (streets_reader/src/osm_reader/reader.rs in the osm2streets repo)
|
|
||
| clip_map(&mut map, timer); | ||
| crate::clip_resilient::clip_map_resilient(&mut map, timer); | ||
|
|
Collaborator
There was a problem hiding this comment.
I'm not a fan of dead code hanging around, so if we go with the new approach, please delete the old method. And then calling it "resilient" is kind of redundant; it's just the only way to clip the map, and it handles more cases
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.
The current
clip_mapdrops any building where a single vertex falls outside the GPS boundarypolygon. At city edges this quietly removes buildings that are 95% inside the map — one corner
clips a boundary way and the whole building disappears. You only notice the effect when zoomed in
on the border and see a sudden gap in the building layer.
Fix
New
clip_resilient.rswithclip_map_resilient()that keeps buildings with ≥5% area overlapinstead of requiring all vertices to be inside.
To avoid making it slow on large maps, there are two cheap rejection steps before the expensive
polygon intersection call:
the intersection call entirely (handles buildings clearly outside)
Polygon intersection is only computed for buildings near the boundary — which is where you actually
want the precision.
Additional guards that prevent panics further downstream:
No new dependencies. Tested against Cairo urban core (~750K buildings).
Developed while importing Cairo urban core OSM data for a city simulation research project at Egypt University of Informatics.