514 if (parent ==
nullptr)
517 if (
NW_CHILD(parent)->get_num_points() +
518 NE_CHILD(parent)->get_num_points() +
519 SW_CHILD(parent)->get_num_points() +
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
constexpr bool is_empty() const noexcept
Return true if list is empty.
Node for QuadTree spatial data structure.
bool contains(const Point &p) const noexcept
Check if a point is contained in this node's region.
const Geom_Number & get_min_y() const noexcept
Get minimum Y coordinate of this region.
const Geom_Number & get_max_y() const noexcept
Get maximum Y coordinate of this region.
void empty() noexcept
Remove all points from this node and mark it as White.
Geom_Number get_mid_x() const noexcept
Get midpoint X coordinate.
QuadNode * get_child_to(const Point &p) const
Find which child node should contain a given point.
DynList< Point > & get_points_set() noexcept
Get reference to the points list (for direct manipulation).
Geom_Number get_mid_y() const noexcept
Get midpoint Y coordinate.
const Geom_Number & get_min_x() const noexcept
Get minimum X coordinate of this region.
Point & add_point(const Point &p)
Add a point to this node.
Point * search_point(const Point &p) noexcept
Search for a point in this node.
bool is_leaf() const noexcept
Check if this node is a leaf (has no children).
bool remove_point(const Point &p)
Remove a point from this node.
size_t get_num_points() noexcept
Get total number of points in this subtree.
const Geom_Number & get_max_x() const noexcept
Get maximum X coordinate of this region.
@ Gray
Internal node with children.
@ Black
Leaf node with points.
QuadTree - Hierarchical spatial index for 2D points.
size_t max_num_points_per_node
Maximum points per leaf node before splitting.
void empty(Node *&r) noexcept
Recursively delete all nodes.
~QuadTree()
Destructor - frees all nodes.
void for_each(Op &op)
Apply an operation to each node in the tree.
QuadTree(const Geom_Number &min_x, const Geom_Number &max_x, const Geom_Number &min_y, const Geom_Number &max_y, const size_t &_max_num_points_per_node=1)
Construct a quadtree with specified region and capacity.
void for_each(Op &&op=Op())
Apply operation to each node (rvalue reference version).
void remove(const Point &p)
Remove a point from the tree.
QuadTree()
Default constructor - creates an uninitialized tree.
Point * search(const Point &p) noexcept
Search for a point in the tree.
Node * search_container_node(const Point &p) noexcept
Find the leaf node containing a point.
Point * insert(const Geom_Number &x, const Geom_Number &y)
Insert a point given by coordinates.
void copy_tree(QuadNode *src, QuadNode *&tgt, QuadNode *tgt_parent=nullptr)
Deep copy a tree structure.
const Node * get_root() const noexcept
Get the root node (const version).
void split(Node *node)
Subdivide a leaf node into four children.
void operate_on_nodes(Node *r, Op &op)
Apply operation to all nodes in the tree.
QuadTree(const QuadTree &tree)
Copy constructor - creates a deep copy of the tree.
QuadTree(QuadTree &&tree) noexcept
Move constructor - transfers ownership.
bool contains(const Point &p) const noexcept
Check if a point is within the tree's region.
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
size_t get_max_num_points_per_node() const noexcept
Get the maximum points per leaf node.
QuadTree & operator=(const QuadTree &tree)
Copy assignment operator - creates a deep copy.
void join(Node *node)
Merge four child nodes back into their parent.
Point * insert(const Point &p)
Insert a point into the tree.
void set_max_num_points_per_node(const size_t &_max_num_points_per_node) noexcept
Set the maximum points per leaf node.
Node * get_root() noexcept
Get the root node.
Node * root
Root node of the tree.
void empty()
Remove all points from the tree, keeping only the root.
static bool is_leaf(BinNode< std::string > *p) noexcept
DynList< T > maps(const C &c, Op op)
Classic map operation.
QuadTree node implementation for spatial data structures.