130template <
typename T = Empty_Class>
231 if (p.get_x() ==
root->
x())
233 if (p.get_y() ==
root->
y())
249 if (p.get_x() <
root->
x())
291 if (p.get_y() ==
root->
y())
293 if (p.get_x() ==
root->
x())
309 if (p.get_y() <
root->
y())
370 if (
root->
y() == p.get_y())
372 if (
root->
x() == p.get_x())
378 if (p.get_y() <
root->
y())
389 if (
root->
x() == p.get_x())
391 if (
root->
y() == p.get_y())
397 if (p.get_x() <
root->
x())
472 if (p.get_x() <
root->
x())
503 if (p.get_y() <
root->
y())
Core definitions, constants, and utility macros for Aleph-w.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
2D k-d tree for efficient spatial point operations.
static Node * lr_search(Node *root, const Point &p) noexcept
Search with left-right (X) split pattern.
K2Tree()
Default constructor - creates an empty tree with zero-sized region.
constexpr size_t size() const noexcept
Get the number of points in the tree.
Node * root
Root of the tree.
static void range(Node *root, const Rectangle &rect, DynList< Point > *q)
Recursively find points within a rectangle.
K2Tree(const K2Tree &)=delete
size_t N
Number of points in the tree.
Point pmin
Lower-left corner of reference rectangle.
Point pmax
Upper-right corner of reference rectangle.
Node * min_node
Current nearest node (for nearest())
Point nearest(const Point &p) noexcept
Find the nearest point to a query point.
void lr_nearest(Node *root, const Point &p) noexcept
Recursively find nearest neighbor (X-split level).
K2Tree(const Point &__pmin, const Point &__pmax)
Construct a k-d tree with specified bounding region.
K2Tree & operator=(const K2Tree &)=delete
Node * bu_insert(Node *root, const Point &p)
Insert into tree with bottom-up (Y) split.
bool contains(const Point &p) const noexcept
Check if the tree contains a point.
void range(const Rectangle &rect, DynList< Point > *l)
Find all points within a rectangle.
Node * lr_insert(Node *root, const Point &p)
Insert into tree with left-right (X) split.
constexpr bool is_empty() const noexcept
Check if the tree is empty.
K2Tree(const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax)
Construct a k-d tree with specified coordinate bounds.
~K2Tree()
Destructor - frees all nodes.
Point * insert(const Point &p)
Insert a point into the tree.
Geom_Number min_dist2
Current minimum squared distance.
void bu_nearest(Node *root, const Point &p) noexcept
Recursively find nearest neighbor (Y-split level).
void destroy_tree(Node *node) noexcept
Recursively delete all nodes.
static Node * bu_search(Node *root, const Point &p) noexcept
Search with bottom-up (Y) split pattern.
bool contains(const Point &p) const
void set_rect(const Geom_Number &__xmin, const Geom_Number &__ymin, const Geom_Number &__xmax, const Geom_Number &__ymax)
const Geom_Number & get_xmin() const
const Geom_Number & get_ymin() const
const Geom_Number & get_xmax() const
Geom_Number distance_squared_to(const Point &p) const
bool intersects(const Rectangle &that) const
const Geom_Number & get_ymax() const
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.
Internal node structure for the k-d tree.
const Geom_Number & ymin() const noexcept
Node * rt
Right/top subtree.
const Geom_Number & xmin() const noexcept
const Geom_Number & x() const noexcept
Node * lb
Left/bottom subtree.
void set_rect(const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax) noexcept
Set the rectangular region for this node.
Point point
The point stored at this node.
const Geom_Number & y() const noexcept
const Geom_Number & ymax() const noexcept
void set_rect(const Point &pmin, const Point &pmax) noexcept
Set the rectangular region using corner points.
const Geom_Number & xmax() const noexcept
Node(const Point &__point) noexcept
Construct a node with a given point.
Rectangle rect
The axis-aligned rectangle for this node's region.