ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
QuadTree Class Reference

Represents a quadtree for spatial partitioning of 2D entities. More...

#include <QuadTree.h>

Collaboration diagram for QuadTree:

Public Member Functions

 QuadTree (const Vector2D &min, const Vector2D &max)
 Constructs a QuadTree with specified bounds.
 
 ~QuadTree ()
 Destructor for the QuadTree class.
 
bool Insert (Triangle2D *triangle)
 Inserts a triangle entity into the quadtree.
 
NodeIntersect (const Vector2D &p)
 Finds the node intersecting with a given point.
 
void Rebuild ()
 Rebuilds the quadtree, recalculating all spatial partitions.
 

Private Member Functions

NodeIntersect (Node *node, const Vector2D &p)
 Recursively finds the node intersecting with a given point.
 

Private Attributes

BoundingBox2D bbox
 Bounding box representing the spatial extent of the quadtree.
 
Node root
 Root node of the quadtree.
 
uint16_t count = 0
 Current count of entities in the quadtree.
 

Detailed Description

Represents a quadtree for spatial partitioning of 2D entities.

Definition at line 22 of file QuadTree.h.

Constructor & Destructor Documentation

◆ QuadTree()

QuadTree ( const Vector2D min,
const Vector2D max 
)

Constructs a QuadTree with specified bounds.

Parameters
minMinimum bounds of the quadtree.
maxMaximum bounds of the quadtree.

Definition at line 3 of file QuadTree.cpp.

◆ ~QuadTree()

~QuadTree ( )

Destructor for the QuadTree class.

Definition at line 5 of file QuadTree.cpp.

Member Function Documentation

◆ Insert()

bool Insert ( Triangle2D triangle)

Inserts a triangle entity into the quadtree.

Parameters
trianglePointer to the Triangle2D entity to insert.
Returns
True if the entity was successfully inserted, otherwise false.

Definition at line 7 of file QuadTree.cpp.

References count, Node::Insert(), and root.

Referenced by Rasterizer::Rasterize().

◆ Intersect() [1/2]

Node * Intersect ( const Vector2D p)

Finds the node intersecting with a given point.

Parameters
pThe point to check for intersection.
Returns
Pointer to the intersecting node, or nullptr if no intersection.

Definition at line 25 of file QuadTree.cpp.

References Intersect(), and root.

◆ Intersect() [2/2]

Node * Intersect ( Node node,
const Vector2D p 
)
private

Recursively finds the node intersecting with a given point.

Parameters
nodePointer to the current node being checked.
pThe point to check for intersection.
Returns
Pointer to the intersecting node, or nullptr if no intersection.

Definition at line 15 of file QuadTree.cpp.

References BoundingBox2D::Contains(), Node::GetBBox(), Node::GetChildNodes(), Intersect(), and Node::IsLeaf().

Referenced by Intersect(), Intersect(), and Rasterizer::Rasterize().

◆ Rebuild()

void Rebuild ( )

Rebuilds the quadtree, recalculating all spatial partitions.

Definition at line 29 of file QuadTree.cpp.

References root, and Node::Subdivide().

Referenced by Rasterizer::Rasterize().

Member Data Documentation

◆ bbox

BoundingBox2D bbox
private

Bounding box representing the spatial extent of the quadtree.

Definition at line 24 of file QuadTree.h.

◆ count

uint16_t count = 0
private

Current count of entities in the quadtree.

Definition at line 26 of file QuadTree.h.

Referenced by Insert().

◆ root

Node root
private

Root node of the quadtree.

Definition at line 25 of file QuadTree.h.

Referenced by Insert(), Intersect(), and Rebuild().


The documentation for this class was generated from the following files: