improbable-eng / phtree-cpp

PH-Tree C++ implementation by Improbable.
Apache License 2.0
22 stars 15 forks source link

filter: Add FilterSphere #16

Closed ctbur closed 2 years ago

ctbur commented 2 years ago

Changes

Add the FilterSphere filter than can filter points for a sphere given a center and a radius.

Unfortunately I had to use a scalar converter that needs to be hand-picked and match the multidimensional converter used in the tree. Please let me know how it can be improved.

Verification

Added a test case.

improbable-til commented 2 years ago

The normal converters can only convert PhPoint instances. I think it would be good if you could use the same converter that is used for the PhTree itself. I see two options: 1) Extend one of the existing converters and add pre()/post() functions for scalars. This could then be used to also create the PhTree itself. 2) Adapt the filter to work with PhPoints.

ctbur commented 2 years ago

Thanks. Approach 2. worked and gave a much cleaner result. We actually just need to clamp the center point in the node's AABB to get the closest distance, so only comparisons are needed, no calculations.

improbable-til commented 2 years ago

LGTM. Nice contribution, thanks!