|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Closest pair of points via divide and conquer. More...
#include <geom_algorithms.H>
Classes | |
| struct | ByYCmp |
| Strict weak order for sorting points by (y,x). More... | |
| struct | LexicographicCmp |
| Strict weak order for sorting points lexicographically by (x,y). More... | |
| struct | Result |
Public Member Functions | |
| Result | operator() (const DynList< Point > &point_set) const |
| Compute the closest pair of points. | |
| Segment | closest_segment (DynList< Point > &point_set) const |
| Convenience wrapper returning the closest segment. | |
Static Private Member Functions | |
| static Geom_Number | dist2 (const Point &a, const Point &b) |
| Squared Euclidean distance between two points. | |
| static Result | make_result (const Point &a, const Point &b) |
Construct a Result object for a pair (a,b). | |
| static Result | brute_force (const Array< Point > &px, const size_t l, const size_t r) |
| Brute-force closest pair on a small subarray. | |
| static Result | recurse (const Array< Point > &px, const size_t l, const size_t r, Array< Point > &py) |
| Recursive divide-and-conquer step. | |
Closest pair of points via divide and conquer.
Computes the pair of points with minimum Euclidean distance using a classic O(n log n) divide-and-conquer algorithm.
Geom_Number) for distance comparisons.Definition at line 843 of file geom_algorithms.H.
|
inlinestaticprivate |
Brute-force closest pair on a small subarray.
| px | Points sorted by x. |
| l | Left index (inclusive). |
| r | Right index (exclusive). |
r - l >= 2. Definition at line 927 of file geom_algorithms.H.
References Aleph::ClosestPairDivideAndConquer::Result::distance_squared, Aleph::divide_and_conquer_partition_dp(), l, make_result(), and r.
Referenced by recurse().
|
inline |
Convenience wrapper returning the closest segment.
| point_set | Input set of points. |
Definition at line 1052 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::ClosestPairDivideAndConquer::Result::first, and r.
|
inlinestaticprivate |
Squared Euclidean distance between two points.
Uses exact arithmetic (Geom_Number).
Definition at line 904 of file geom_algorithms.H.
References Aleph::Point::distance_squared_to().
Referenced by make_result().
|
inlinestaticprivate |
Construct a Result object for a pair (a,b).
Definition at line 912 of file geom_algorithms.H.
References dist2().
Referenced by brute_force(), and recurse().
|
inline |
Compute the closest pair of points.
| point_set | Input set of points. |
| domain_error | if point_set has fewer than 2 points. |
Definition at line 1024 of file geom_algorithms.H.
References ah_domain_error_if, Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::HTList::Iterator::has_curr(), Aleph::quicksort_op(), and recurse().
|
inlinestaticprivate |
Recursive divide-and-conquer step.
Splits the x-sorted array at mid, recurses on left/right halves, then checks a y-sorted "strip" around the split line to account for cross-boundary pairs.
| px | Points sorted by x. |
| l | Left index (inclusive). |
| r | Right index (exclusive). |
| py | Points in the range [l,r) sorted by y. |
Definition at line 955 of file geom_algorithms.H.
References brute_force(), Aleph::ClosestPairDivideAndConquer::Result::distance_squared, Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), l, make_result(), r, recurse(), and Aleph::Array< T >::reserve().
Referenced by operator()(), and recurse().