|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Spatial point index for O(log n) nearest-neighbor queries. More...
#include <geom_algorithms.H>
Classes | |
| struct | DebugPartition |
| Represents a spatial partition or leaf in the KD-tree. More... | |
| struct | DebugSnapshot |
| A complete snapshot of the tree for debugging. More... | |
Public Member Functions | |
| KDTreePointSearch (const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax) | |
| Construct an empty KD-tree for the given bounding region. | |
| bool | insert (const Point &p) |
| Insert a point. Returns true if inserted, false if duplicate. | |
| bool | contains (const Point &p) const |
| Check if a point exists in the tree. | |
| std::optional< Point > | nearest (const Point &p) const |
Find the nearest neighbor to query point p. | |
| void | range (const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax, DynList< Point > *out) const |
| Collect all points inside the given rectangle. | |
| size_t | size () const noexcept |
| Return the number of points in the tree. | |
| bool | is_empty () const noexcept |
| Return true if the tree is empty. | |
| template<typename Op > | |
| void | for_each (Op &&op) const |
| Apply an operation to every point (inorder traversal). | |
| DebugSnapshot | debug_snapshot () const |
| Build a deterministic geometric partition snapshot for visualization. | |
Static Public Member Functions | |
| static KDTreePointSearch | build (const Array< Point > &points, const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax) |
| Build a balanced KD-tree from a point array. | |
Static Private Member Functions | |
| static bool | lexicographic_less (const Point &a, const Point &b) |
| static Array< Point > | unique_points (Array< Point > points) |
Private Attributes | |
| K2Tree | tree |
| Array< Point > | points_ |
| Rectangle | bounds_ |
Spatial point index for O(log n) nearest-neighbor queries.
This is a thin wrapper around K2Tree<> (see tpl_2dtree.H) that provides a convenient interface consistent with the other geometry algorithms in this file.
Definition at line 8104 of file geom_algorithms.H.
|
inline |
Construct an empty KD-tree for the given bounding region.
| xmin | Minimum x of bounding box. |
| ymin | Minimum y of bounding box. |
| xmax | Maximum x of bounding box. |
| ymax | Maximum y of bounding box. |
Definition at line 8163 of file geom_algorithms.H.
|
inlinestatic |
Build a balanced KD-tree from a point array.
| points | Input points (duplicates removed internally). |
| xmin | Minimum x of bounding box. |
| ymin | Minimum y of bounding box. |
| xmax | Maximum x of bounding box. |
| ymax | Maximum y of bounding box. |
Definition at line 8180 of file geom_algorithms.H.
References K2Tree< T >::build(), Aleph::divide_and_conquer_partition_dp(), and unique_points().
Check if a point exists in the tree.
Definition at line 8201 of file geom_algorithms.H.
References K2Tree< T >::contains(), and tree.
|
inline |
Build a deterministic geometric partition snapshot for visualization.
The snapshot uses the current point set and alternates split axis by depth (x/y), producing a balanced partition tree suitable for didactic rendering.
Definition at line 8240 of file geom_algorithms.H.
References Aleph::KDTreePointSearch::DebugSnapshot::bounds, bounds_, Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), Aleph::Point::get_y(), points_, Aleph::quicksort_op(), Aleph::KDTreePointSearch::DebugPartition::region, Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
Apply an operation to every point (inorder traversal).
Definition at line 8228 of file geom_algorithms.H.
References K2Tree< T >::for_each(), and tree.
Insert a point. Returns true if inserted, false if duplicate.
Definition at line 8192 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), K2Tree< T >::insert(), points_, and tree.
|
inlinenoexcept |
Return true if the tree is empty.
Definition at line 8224 of file geom_algorithms.H.
References K2Tree< T >::is_empty(), and tree.
|
inlinestaticprivate |
Definition at line 8110 of file geom_algorithms.H.
References Aleph::Point::get_x(), and Aleph::Point::get_y().
Referenced by unique_points().
Find the nearest neighbor to query point p.
Definition at line 8207 of file geom_algorithms.H.
References K2Tree< T >::nearest(), and tree.
|
inline |
Collect all points inside the given rectangle.
Definition at line 8213 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), K2Tree< T >::range(), and tree.
|
inlinenoexcept |
Return the number of points in the tree.
Definition at line 8221 of file geom_algorithms.H.
References K2Tree< T >::size(), and tree.
|
inlinestaticprivate |
Definition at line 8117 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), lexicographic_less(), Aleph::quicksort_op(), Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
Referenced by build().
|
private |
Definition at line 8108 of file geom_algorithms.H.
Referenced by debug_snapshot().
Definition at line 8107 of file geom_algorithms.H.
Referenced by debug_snapshot(), and insert().
|
private |
Definition at line 8106 of file geom_algorithms.H.
Referenced by contains(), for_each(), insert(), is_empty(), nearest(), range(), and size().