Skip to content

Use faster bbox-specialised clipping algorithm #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2023
Merged

Conversation

systemed
Copy link
Owner

@systemed systemed commented Mar 24, 2023

When writing tiles, we spend a lot of time in boost::geometry::intersection. This is an all-purpose polygon intersection routine. Our needs are more specialised: we just want to clip polygons to a rectangular bounding box.

This PR replaces the call to boost::geometry::intersection with a simpler and (hopefully) faster clipping routine - the Sutherland-Hodgman algorithm, ported from https://github.com/mapbox/lineclip.

Comparative timings:

  • Devon: 88s (master) -> 30s (this branch)
  • Maine: 34m37 -> 4m23
  • Antarctica: 7hr29 -> 2hr10 (on HDD: looks IO-bound so could be sped up further)
  • Europe: 8hr12 (v2.0) -> 4hr34 (with --store)

File size is similar and as yet I haven't spotted any rendering artefacts.

@mourner
Copy link

mourner commented Mar 25, 2023

Impressive performance wins! Happy to see that code being useful :)

@systemed
Copy link
Owner Author

Huge thanks for the original - it's not often that one encounters such a dramatic performance boost! Plus of course we benefit from @kleunen's magical geometry-correction code which neatly removes the edge artefacts from Sutherland-Hodgman.

@systemed systemed merged commit 4937dae into master Mar 25, 2023
@systemed systemed deleted the fast_clip branch March 25, 2023 23:16
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