Skip to content
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

speed up large polygon intersections using STRtrees. #259

Open
wants to merge 47 commits into
base: as/stabletasks
Choose a base branch
from

Conversation

asinghvi17
Copy link
Member

@asinghvi17 asinghvi17 commented Feb 14, 2025

This PR uses STRtrees to substantially accelerate polygon queries. It pulls the actual looping all the way out and allows the use of STRtrees to skip substantial sections of polygons.

There are three methods here:

  • naive, n*m nested loop
  • loop over all edges of a, strtree on b
  • dual tree query on strtrees from a and b

This algorithm should be easily portable to s2 when that becomes available - and the structure allows e.g. manifold passthrough as well.


This PR also adds a LoopStateMachine module that basically just defines an Action wrapper struct, and a macro that can take care of that action wrapper struct.

With this macro, a function running within a loop can return Break() or Continue() which indicates to the caller that it should break or continue.

E.g.:

f(i) = i == 3 ? Break() : i
count = 1
for i in 1:5
    count = @processloopaction f(i)
end
count # 2

TODOs:

  • add rejection tests for duplicate points
  • add lopsided single tree query
  • add dual tree query
  • figure out good heuristics for when to choose which
  • add more tests and benchmarks with complex polygons

@asinghvi17
Copy link
Member Author

@rafaqz this is where I want to make it super easy to have a DimMatrix of benchmarks, to test scaling dynamics....

@asinghvi17 asinghvi17 changed the title speed up large polygon intersections using an STRtree on poly b speed up large polygon intersections using STRtrees. Feb 14, 2025
- Move STRDualQuery and the utils to utils/
- Create a new module LoopStateMachine that just defines some actions, and a macro @processloopactions that you can use to break out of a loop if you want, in a `map_some_things(f1, f2, f3, ...)`.

Add tests for LoopStateMachine
Use LoopStateMachine in the maybe function I added to clipping processor
@asinghvi17
Copy link
Member Author

I just realized, the tests aren't actually testing anything :D

@asinghvi17 asinghvi17 added the enhancement New feature or request label Feb 14, 2025
@asinghvi17 asinghvi17 self-assigned this Feb 14, 2025
* lay off 3/4 of the testsets

this uses the ContextTestSet from Test to reduce the amount of visual cruft.  It doesn't reduce it all the way but it can help.

Next step is to have a custom testset that can elide the excessive display.

* print better context

* also test densified geoms
@asinghvi17
Copy link
Member Author

See #260 for the testset diff

@asinghvi17
Copy link
Member Author

Seems the densified module isn't actually testing anything...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants