53# define PARENT(p) ((p)->get_parent())
54# define NW_CHILD(p) ((p)->get_nw_child())
55# define NE_CHILD(p) ((p)->get_ne_child())
56# define SW_CHILD(p) ((p)->get_sw_child())
57# define SE_CHILD(p) ((p)->get_se_child())
58# define COLOR(p) ((p)->get_color())
59# define LEVEL(p) ((p)->get_level())
166 if (v->is_sw_child())
169 if (v->is_se_child())
176 else if (v->is_nw_child())
188 if (v->is_nw_child())
191 if (v->is_ne_child())
198 else if (v->is_sw_child())
210 if (v->is_nw_child())
213 if (v->is_sw_child())
220 else if (v->is_ne_child())
232 if (v->is_ne_child())
235 if (v->is_se_child())
242 else if (v->is_nw_child())
292 return node->points.size();
440 <<
"This node does not contain that point";
467 color = Color::Black;
510 for (Point & point :
points)
527 const Point & curr = it.get_curr_ne();
542 color = Color::White;
582 for (Point & point :
points)
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
void empty() noexcept
empty the list
Node for QuadTree spatial data structure.
DynList< QuadNode * > get_neighbors()
Find all adjacent leaf nodes.
Color & get_color() noexcept
Get reference to color (for reading/writing via COLOR macro).
Side
Cardinal directions for neighbor navigation.
@ South
Southern neighbor.
@ North
Northern neighbor.
bool is_sw_child() const noexcept
Check if this node is the SW child of its parent.
static QuadNode * get_east_neighbor(QuadNode *v) noexcept
Find the eastern neighbor of a node.
static size_t count_points(QuadNode *node) noexcept
Recursively count all points in a subtree.
QuadNode *& get_sw_child() noexcept
Get reference to SW child (for reading/writing via SW_CHILD macro).
Geom_Number min_y
Minimum Y coordinate.
QuadNode *& get_se_child() noexcept
Get reference to SE child (for reading/writing via SE_CHILD macro).
void set_region(const Geom_Number &_min_x, const Geom_Number &_max_x, const Geom_Number &_min_y, const Geom_Number &_max_y) noexcept
Set the region boundaries for this node.
static QuadNode * get_west_neighbor(QuadNode *v) noexcept
Find the western neighbor of a node.
static void get_neighbors_by_side(QuadNode *node, const Side &side, DynList< QuadNode * > &neighbors)
Recursively collect leaf neighbors on a given side.
bool contains(const Point &p) const noexcept
Check if a point is contained in this node's region.
unsigned long & get_level() noexcept
Get reference to level (for reading/writing via LEVEL macro).
Geom_Number get_height() const noexcept
Get height of this region.
Geom_Number max_x
Maximum X coordinate.
static QuadNode * get_south_neighbor(QuadNode *v) noexcept
Find the southern neighbor of a node.
bool is_ne_child() const noexcept
Check if this node is the NE child of its parent.
Geom_Number max_y
Maximum Y coordinate.
QuadNode *& get_ne_child() noexcept
Get reference to NE child (for reading/writing via NE_CHILD macro).
QuadNode() noexcept
Default constructor - creates a white (empty) node.
const Geom_Number & get_min_y() const noexcept
Get minimum Y coordinate of this region.
bool is_se_child() const noexcept
Check if this node is the SE child of its parent.
const Geom_Number & get_max_y() const noexcept
Get maximum Y coordinate of this region.
void for_each_point(Op &&op=Op())
Apply operation to each point (rvalue reference version).
QuadNode * ne_child
Northeast child.
Geom_Number min_x
Minimum X coordinate.
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 * parent
Parent node (nullptr for root)
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.
Quad
Quadrant directions for child nodes.
QuadNode(const Geom_Number &_min_x, const Geom_Number &_max_x, const Geom_Number &_min_y, const Geom_Number &_max_y, QuadNode *_parent=nullptr) noexcept
Construct a node with specified region bounds.
const Geom_Number & get_min_x() const noexcept
Get minimum X coordinate of this region.
QuadNode * sw_child
Southwest child.
Geom_Number get_width() const noexcept
Get width of this region.
bool is_nw_child() const noexcept
Check if this node is the NW child of its parent.
static QuadNode * get_north_neighbor(QuadNode *v) noexcept
Find the northern neighbor of a node.
QuadNode *& get_nw_child() noexcept
Get reference to NW child (for reading/writing via NW_CHILD macro).
QuadNode & operator=(const QuadNode &)=delete
Point & add_point(const Point &p)
Add a point to this node.
unsigned long level
Depth in the tree (0 for root)
Point * search_point(const Point &p) noexcept
Search for a point in this node.
void for_each_point(Op &op)
Apply operation to each point in this node.
QuadNode(const QuadNode &)=delete
QuadNode * se_child
Southeast child.
bool is_leaf() const noexcept
Check if this node is a leaf (has no children).
DynList< Point > points
Points stored in this node (only for leaves)
bool remove_point(const Point &p)
Remove a point from this node.
Color color
Node state (White/Gray/Black)
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.
Color
Node color states for quadtree nodes.
@ Gray
Internal node with children.
@ Black
Leaf node with points.
QuadNode *& get_parent() noexcept
Get reference to parent node (for reading/writing via PARENT macro).
QuadNode * nw_child
Northwest child.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
2D point and geometric utilities.