Skip to content

Add Octrees - #3

Open
sunsided wants to merge 1 commit into
mainfrom
feature/octree
Open

Add Octrees#3
sunsided wants to merge 1 commit into
mainfrom
feature/octree

Conversation

@sunsided

@sunsided sunsided commented Feb 6, 2026

Copy link
Copy Markdown
Owner

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 new RTree implementation, 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:

  • Introduced a 3D OctTree structure 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]
  • Added a new RTree implementation with bounding box and ray intersection queries, and comparison benchmarks against QuadTree (CHANGELOG.md).

Benchmarking enhancements:

  • Extended 3D benchmarks to include OctTree alongside QuadTree and RTree, covering inserts, AABB queries, and ray intersection scenarios (benches/bench_compare_3d.rs). [1] [2] [3] [4] [5] [6] [7] [8]

Public API updates:

  • Exported OctTree and 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!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/octree/free_list.rs

/// Removes the nth element from the free list.
pub fn erase(&mut self, n: IndexType) {
self.first_free = SENTINEL;

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Suggested change
self.first_free = SENTINEL;

Copilot uses AI. Check for mistakes.
Comment thread src/octree/node.rs
/// - `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).

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

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

Corrected spelling of 'recieve' to 'receive'.

Copilot uses AI. Check for mistakes.
Comment thread src/octree/node.rs
/// - `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).

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

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

The comment contains a typo: 'NODE_INDEX_IS_BRANCH if it this node' should be 'NODE_IS_BRANCH if this node'.

Suggested change
/// 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).

Copilot uses AI. Check for mistakes.
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