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

Make the algorithm faster with a spatial index #7

Open
mourner opened this issue Aug 31, 2016 · 0 comments
Open

Make the algorithm faster with a spatial index #7

mourner opened this issue Aug 31, 2016 · 0 comments

Comments

@mourner
Copy link
Member

mourner commented Aug 31, 2016

Currently the algorithm is relatively slow because checking each probe is expensive — you have to loop through all polygon points to do two things:

  1. Determine if the probe is inside or outside the polygon.
  2. Find the distance from the probe to the polygon.

In theory, we could make this much faster by indexing polygon segments with RBush (or any fast RTree index in other impementations), and then do the above with:

  1. A zero-height bbox query that loops through all intersecting edges (very fast for all practical polygons) to determine if inside or outside.
  2. A kNN-like tree search to find the closest edge for point-to-polygon calculation. Can be borrowed from Concaveman.

The current algorithm is O(NM), where M is the number of probes.

The new one would be O(N log N) for indexing + O(M log N) for checking probes, or O((M + N) log N in average, which should be MUCH faster.

cc @urschrei @chau-intl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant