Add Octrees - #3
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request introduces a new 3D spatial partitioning structure (OctTree) to complement the existing QuadTree and RTree implementations. The OctTree provides efficient 3D AABB queries, ray intersection support, and generic intersection capabilities.
Changes:
- Added a complete OctTree implementation with supporting data structures (AABB, CenteredAABB, Point, nodes, free lists)
- Extended benchmarks to compare QuadTree, RTree, and OctTree performance for insertions, AABB queries, and ray casting
- Exported OctTree and related types in the public API
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/octree.rs | Module definition and integration tests for OctTree functionality |
| src/octree/octree.rs | Core OctTree implementation with insert, remove, query, and cleanup operations |
| src/octree/aabb.rs | 3D axis-aligned bounding box structure with intersection logic |
| src/octree/centered_aabb.rs | Centered AABB representation for efficient octant splitting |
| src/octree/point.rs | Simple 3D point structure |
| src/octree/octants.rs | Octant encoding and manipulation for spatial partitioning |
| src/octree/node.rs | Node structure representing octree branches and leaves |
| src/octree/node_data.rs | Runtime node metadata including bounds and depth |
| src/octree/node_info.rs | Public node information accessor |
| src/octree/node_list.rs | Stack-based node list for traversal |
| src/octree/oct_rect.rs | Octree root boundary descriptor |
| src/octree/free_list.rs | Indexed free list for efficient element storage |
| src/octree/error.rs | Error types for octree operations |
| src/octree/octree_element.rs | Element wrapper with ID and bounds |
| src/lib.rs | Exports OctTree in public API |
| benches/bench_compare_3d.rs | Benchmark comparison of RTree, QuadTree, and OctTree |
| CHANGELOG.md | Documents new features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| /// Removes the nth element from the free list. | ||
| pub fn erase(&mut self, n: IndexType) { | ||
| self.first_free = SENTINEL; |
There was a problem hiding this comment.
Setting first_free to SENTINEL unconditionally at the start of erase will break the free list chain. This line should be removed, as first_free should only be updated after linking the erased element to the existing free list (line 86-87).
| self.first_free = SENTINEL; |
| /// - `free_list::SENTINEL` if neither of which exists. | ||
| /// | ||
| /// If this node is the first child node and pointed to by | ||
| /// the free node pointer, all subsequent nodes of the same parent (i.e., the next three nodes). |
There was a problem hiding this comment.
Corrected spelling of 'recieve' to 'receive'.
| /// - `free_list::SENTINEL` if neither of which exists. | ||
| /// | ||
| /// If this node is the first child node and pointed to by | ||
| /// the free node pointer, all subsequent nodes of the same parent (i.e., the next three nodes). |
There was a problem hiding this comment.
The comment contains a typo: 'NODE_INDEX_IS_BRANCH if it this node' should be 'NODE_IS_BRANCH if this node'.
| /// the free node pointer, all subsequent nodes of the same parent (i.e., the next three nodes). | |
| /// the free node pointer, all subsequent nodes of the same parent (i.e., the next three nodes). | |
| /// Stores the number of elements in the leaf or `NODE_IS_BRANCH` if this node is | |
| /// a branch (i.e., not a leaf). |
This pull request introduces a new 3D spatial partitioning structure (
OctTree) with full axis-aligned bounding box (AABB) support, public exports, and comprehensive unit tests. It also adds a newRTreeimplementation, extends benchmarks to compare QuadTree, RTree, and OctTree for both insertion and query performance, and includes new intersection and ray-casting tests and benchmarks. The changes are grouped into new features, benchmarking enhancements, and public API updates.New spatial partitioning features:
OctTreestructure with support for 3D AABB queries, ray intersection, and generic intersection. Comprehensive unit tests cover insertion, intersection, ray casting, and cleanup scenarios (src/octree.rs,src/octree/aabb.rs,src/octree/centered_aabb.rs). [1] [2] [3]RTreeimplementation with bounding box and ray intersection queries, and comparison benchmarks against QuadTree (CHANGELOG.md).Benchmarking enhancements:
benches/bench_compare_3d.rs). [1] [2] [3] [4] [5] [6] [7] [8]Public API updates:
OctTreeand related types in the crate root, making them available for public use (src/lib.rs).Please let me know if you want to dive into the implementation details or see how the benchmarks compare between the different spatial partitioning structures!