ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
QuadTree.h
Go to the documentation of this file.
1/**
2 * @file QuadTree.h
3 * @brief Defines the QuadTree class for spatial partitioning in 2D space.
4 *
5 * The QuadTree class provides a hierarchical structure for efficient spatial
6 * partitioning and management of 2D entities like triangles. It supports
7 * insertion, intersection checks, and dynamic rebuilding of the tree.
8 *
9 * @date 22/12/2024
10 * @version 1.0
11 * @author moepforfreedom, Coela Can't
12 */
13
14#pragma once
15
16#include "Node.h"
17
18/**
19 * @class QuadTree
20 * @brief Represents a quadtree for spatial partitioning of 2D entities.
21 */
22class QuadTree {
23private:
24 BoundingBox2D bbox; ///< Bounding box representing the spatial extent of the quadtree.
25 Node root; ///< Root node of the quadtree.
26 uint16_t count = 0; ///< Current count of entities in the quadtree.
27
28 /**
29 * @brief Recursively finds the node intersecting with a given point.
30 * @param node Pointer to the current node being checked.
31 * @param p The point to check for intersection.
32 * @return Pointer to the intersecting node, or nullptr if no intersection.
33 */
34 Node* Intersect(Node* node, const Vector2D& p);
35
36public:
37 /**
38 * @brief Constructs a QuadTree with specified bounds.
39 * @param min Minimum bounds of the quadtree.
40 * @param max Maximum bounds of the quadtree.
41 */
42 QuadTree(const Vector2D& min, const Vector2D& max);
43
44 /**
45 * @brief Destructor for the QuadTree class.
46 */
47 ~QuadTree();
48
49 /**
50 * @brief Inserts a triangle entity into the quadtree.
51 * @param triangle Pointer to the Triangle2D entity to insert.
52 * @return True if the entity was successfully inserted, otherwise false.
53 */
54 bool Insert(Triangle2D* triangle);
55
56 /**
57 * @brief Finds the node intersecting with a given point.
58 * @param p The point to check for intersection.
59 * @return Pointer to the intersecting node, or nullptr if no intersection.
60 */
61 Node* Intersect(const Vector2D& p);
62
63 /**
64 * @brief Rebuilds the quadtree, recalculating all spatial partitions.
65 */
66 void Rebuild();
67};
Defines the Node class for quadtree spatial partitioning in 2D space.
Represents a 2D axis-aligned bounding box.
Represents a node in a quadtree structure for spatial partitioning.
Definition Node.h:23
Represents a quadtree for spatial partitioning of 2D entities.
Definition QuadTree.h:22
~QuadTree()
Destructor for the QuadTree class.
Definition QuadTree.cpp:5
Node root
Root node of the quadtree.
Definition QuadTree.h:25
BoundingBox2D bbox
Bounding box representing the spatial extent of the quadtree.
Definition QuadTree.h:24
Node * Intersect(Node *node, const Vector2D &p)
Recursively finds the node intersecting with a given point.
Definition QuadTree.cpp:15
bool Insert(Triangle2D *triangle)
Inserts a triangle entity into the quadtree.
Definition QuadTree.cpp:7
uint16_t count
Current count of entities in the quadtree.
Definition QuadTree.h:26
void Rebuild()
Rebuilds the quadtree, recalculating all spatial partitions.
Definition QuadTree.cpp:29
Represents a 2D triangle with support for UV mapping, depth, and intersection testing.
Definition Triangle2D.h:25
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27