Skip to content

Conversation

@louis-e
Copy link
Owner

@louis-e louis-e commented Nov 23, 2025

This was accidentally removed by #586 (comment), but we need it for generation performance reasons.

Problem

After removing Sutherland-Hodgman clipping, large area generation became slow due to processing full OSM polygons instead of bbox-clipped versions. Additionally, polygons extending beyond the bbox boundary were rendered with diagonal cuts instead of following the bbox edges.

Solution

  1. Reintroduce Sutherland-Hodgman clipping with proper corner insertion - when a polygon exits one bbox edge and enters another, insert the appropriate corner points to follow the bbox boundary instead of creating diagonal cuts.

  2. Dual storage for ways - store unclipped ways in ways_map for relation member lookup (required for merge_loopy_loops to match endpoint IDs), while using clipped ways for standalone element processing.

  3. Separate clipping paths:

    • Water relations: Skip pre-clipping, clip after ring merging in water_areas.rs
    • Non-water relations: Clip member ways during parsing
    • Standalone ways: Clip during parsing based on closed/open detection
  4. Edge-specific clamping - during each Sutherland-Hodgman pass, clamp intersection points only to the current edge to prevent premature corner artifacts.

Changes

  • highways.rs: Made build_highway_connectivity_map public, changed generate_highways to accept pre-built connectivity map
  • osm_parser.rs: Reintroduced Sutherland-Hodgman with corner insertion; added is_water_element() detection; separate clipping logic for closed polygons vs open polylines
  • water_areas.rs: Renamed clipping function to clip_water_ring_to_bbox(); added corner insertion for water polygons; added empty vector guards in merge_loopy_loops
  • data_processing.rs: Removed debug logging
  • gui.rs: Reset debug flag to false
image

@louis-e louis-e marked this pull request as ready for review November 23, 2025 16:35
@github-actions
Copy link

github-actions bot commented Nov 23, 2025

⏱️ Benchmark run finished in 1m 5s
🧠 Peak memory usage: 935 MB

📈 Compared against baseline: 69s
🧮 Delta: -4s
🔢 Commit: 83e9a63

🟢 Generation time is unchanged.

You can retrigger the benchmark by commenting retrigger-benchmark.

@louis-e louis-e marked this pull request as draft November 23, 2025 22:55
… water rendering

- Fix O(n*m) performance regression in highway processing by building connectivity map once
- Store unclipped ways in ways_map for proper relation member merging (merge_loopy_loops)
- Use clipped ways for standalone way processing
- Add empty vector guard in merge_loopy_loops to prevent panic
- Expose build_highway_connectivity_map as public API
- Add debug_logging module for development diagnostics
@louis-e louis-e force-pushed the reintroduce-sutherland-hodgeman branch from ac884b8 to 41fc566 Compare November 26, 2025 12:39
@louis-e
Copy link
Owner Author

louis-e commented Nov 26, 2025

retrigger-benchmark

@louis-e louis-e marked this pull request as ready for review November 26, 2025 14:02
@louis-e
Copy link
Owner Author

louis-e commented Nov 26, 2025

retrigger-benchmark

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@louis-e louis-e changed the title Restore node filtering for performance without breaking water features Reintroduce Sutherland-Hodgman Clipping Algorithm Nov 28, 2025
@louis-e
Copy link
Owner Author

louis-e commented Nov 28, 2025

retrigger-benchmark

@louis-e
Copy link
Owner Author

louis-e commented Nov 28, 2025

This was frustrating and took days but it looks like it's working now. Will do some more tests in the next week. Feedback is appreciated

@louis-e
Copy link
Owner Author

louis-e commented Nov 28, 2025

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@louis-e louis-e merged commit 7d86854 into main Nov 28, 2025
2 checks passed
@louis-e louis-e deleted the reintroduce-sutherland-hodgeman branch November 28, 2025 10:28
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.

2 participants