Skip to content

Conversation

@jrmoulton
Copy link
Contributor

Add subtree_root field to QueryFilter to enable restricting spatial queries to specific subtrees. This allows applications to scope hit testing and rectangle queries to particular branches of the tree.

  • Add QueryFilter::in_subtree() builder method
  • Add Tree::is_descendant_of() helper for subtree membership checks
  • Update QueryFilter::matches() to respect subtree boundaries
  • Add tests demonstrating subtree isolation
  • Update documentation

The descendant check is O(depth), there could be ways to improve this but I haven't done it here

Add subtree_root field to QueryFilter to enable restricting spatial queries 
to specific subtrees. This allows applications to scope hit testing and 
rectangle queries to particular branches of the tree.

- Add QueryFilter::in_subtree() builder method
- Add Tree::is_descendant_of() helper for subtree membership checks  
- Update QueryFilter::matches() to respect subtree boundaries
- Update hit_test_point and intersect_rect to use new filtering
- Add tests demonstrating subtree isolation
- Update documentation and regenerate README

The O(depth) descendant check scales well for typical use cases where 
subtree queries target shallow branches. This approach preserves the 
single spatial index while enabling clean subtree scoping.
Comment on lines +151 to +152
if let Some(subtree_root) = self.subtree_root
&& !tree.is_descendant_of(node_id, subtree_root)
Copy link
Contributor

@tomcur tomcur Dec 7, 2025

Choose a reason for hiding this comment

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

As you mentioned this isn't completely ideal (O(n) by itself, but for every node in the subtree!). I'm not too concerned for now, as that's only paid if it's actually used.

We can probably make this O(1) through something like building a tight post ordering and keeping track of subtree size, I've needed to do something similar in https://github.com/endoli/fiksi/blob/4fd727e696a98d9368c66e51b23db238d023dad9/solvi/src/decomposition/sparse/cholesky.rs#L164-L174 but that doesn't do anything for incremental updates.

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