Improve Robustness and Clarity of FastQuadTree
Implementation
#67
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR improves the
FastQuadTree
class for quadtree collision detection in the following ways:items
list is not empty, avoiding cryptic errors and improving API safetyget_rect
helper function to cleanly support objects with a.rect
attribute, ensuring consistency throughoutboundary.colliderect(rect)
before checking children quadrantsTypeError
in__iter__
by chaining only non-None quadrant listsif
statements for quadrant placement rather than short-circuitingand
, reorders logic for readability and consistency and applies correct type annotations usingOptional
and explicitlist[Rect]
quadtree_vs_brute_benchmark.py
, a performance comparison script between brute-force collision detection andFastQuadTree
, including detailed timing metrics for build and query operationsquadtree_depth_benchmark.py
, a benchmarking tool using CLI arguments to assess the impact of quadtree depth on build and query performance, outputs timing results across multiple depth levels to assist with fine-tuning configurationsquadtree_visualizer.py
, a standalone tool for visually inspecting FastQuadTree query behavior, it renders tile rectangles, highlights collision hits from spatial queries, and includes an interactive toggle for displaying resultsthis shows increasing build time with depth, and a sweet spot around depth 3 where query time is lowest.
FastQuadTree is ~35% faster for querying under these conditions.