|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Boolean operations on simple polygons (union, intersection, difference) using the Greiner-Hormann algorithm. More...
#include <geom_algorithms.H>
Classes | |
| struct | GHNode |
| struct | IsectPair |
| Intersection pair found between edge i of A and edge j of B. More... | |
Public Types | |
| enum class | Op { INTERSECTION , UNION , DIFFERENCE } |
| Type of Boolean operation to perform. More... | |
Public Member Functions | |
| Array< Polygon > | operator() (const Polygon &a, const Polygon &b, Op op) const |
| Compute a boolean operation on two simple polygons. | |
| Array< Polygon > | intersection (const Polygon &a, const Polygon &b) const |
| Convenience: intersection. | |
| Array< Polygon > | polygon_union (const Polygon &a, const Polygon &b) const |
| Convenience: union. | |
| Array< Polygon > | difference (const Polygon &a, const Polygon &b) const |
| Convenience: difference (a minus b). | |
Static Private Member Functions | |
| static Array< Point > | extract (const Polygon &p) |
| Extract vertices from a polygon into an Array. | |
| static void | ensure_ccw (Array< Point > &v) |
| Ensure vertices are in CCW order. | |
| static void | reverse_array (Array< Point > &v) |
| Reverse a vertex array in place. | |
| static Polygon | build_poly (const Array< Point > &pts) |
| Build a polygon from a vertex array (bypasses colinearity merge). | |
| static Geom_Number | edge_param (const Point &P, const Point &Q, const Point &I) |
| Compute parameter t of point I along directed edge P→Q. | |
| static bool | point_inside_ccw (const Array< Point > &poly, const Point &p) |
| Point-in-polygon test on a CCW vertex array (winding number). | |
| static void | sort_indices_by_alpha (Array< size_t > &idx, const Array< Geom_Number > &keys) |
| Insertion-sort indices by a key array. | |
| static Array< Polygon > | greiner_hormann (const Array< Point > &va, const Array< Point > &vb, bool start_entering) |
| Run Greiner-Hormann and return result polygons. | |
| static Array< Polygon > | compute_intersection (const Polygon &a, const Polygon &b) |
| static Array< Polygon > | compute_union (const Polygon &a, const Polygon &b) |
| static Array< Polygon > | compute_difference (const Polygon &a, const Polygon &b) |
Boolean operations on simple polygons (union, intersection, difference) using the Greiner-Hormann algorithm.
Implements general boolean operations on arbitrary simple polygons, including concave ones, via the Greiner-Hormann clipping algorithm:
O(n·m + k log k) where n, m are vertex counts and k is the number of intersection points.
Definition at line 11335 of file geom_algorithms.H.
Type of Boolean operation to perform.
| Enumerator | |
|---|---|
| INTERSECTION | Find regions common to both polygons. |
| UNION | Find regions covered by either polygon. |
| DIFFERENCE | Find regions in the first polygon not covered by the second. |
Definition at line 11341 of file geom_algorithms.H.
|
inlinestaticprivate |
Build a polygon from a vertex array (bypasses colinearity merge).
Definition at line 11434 of file geom_algorithms.H.
References Aleph::Polygon::add_vertex(), Aleph::Polygon::close(), and Aleph::divide_and_conquer_partition_dp().
Referenced by greiner_hormann().
|
inlinestaticprivate |
Definition at line 11796 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), ensure_ccw(), extract(), greiner_hormann(), point_inside_ccw(), and reverse_array().
Referenced by operator()().
|
inlinestaticprivate |
Definition at line 11734 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), ensure_ccw(), extract(), greiner_hormann(), and point_inside_ccw().
Referenced by operator()().
|
inlinestaticprivate |
Definition at line 11764 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), ensure_ccw(), extract(), greiner_hormann(), and point_inside_ccw().
Referenced by operator()().
|
inline |
Convenience: difference (a minus b).
Definition at line 11390 of file geom_algorithms.H.
References DIFFERENCE.
|
inlinestaticprivate |
Compute parameter t of point I along directed edge P→Q.
Definition at line 11446 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp().
Referenced by greiner_hormann().
Ensure vertices are in CCW order.
Definition at line 11417 of file geom_algorithms.H.
References Aleph::GeomPolygonUtils::ensure_ccw().
Referenced by compute_difference(), compute_intersection(), and compute_union().
|
inlinestaticprivate |
Extract vertices from a polygon into an Array.
Definition at line 11411 of file geom_algorithms.H.
References Aleph::GeomPolygonUtils::extract_vertices().
Referenced by compute_difference(), compute_intersection(), and compute_union().
|
inlinestaticprivate |
Run Greiner-Hormann and return result polygons.
| va | CCW vertices of A. |
| vb | CCW vertices of B. |
| start_entering | true → start at entering intersections (intersection op); false → start at exiting (union op). |
Definition at line 11517 of file geom_algorithms.H.
References Aleph::Array< T >::append(), build_poly(), Aleph::divide_and_conquer_partition_dp(), edge_param(), Aleph::Segment::intersection_with(), Aleph::Segment::intersects_properly_with(), k, point_inside_ccw(), Aleph::BooleanPolygonOperations::GHNode::pt, Aleph::Array< T >::reserve(), Aleph::Array< T >::size(), and sort_indices_by_alpha().
Referenced by compute_difference(), compute_intersection(), and compute_union().
|
inline |
Convenience: intersection.
Definition at line 11376 of file geom_algorithms.H.
References INTERSECTION.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Compute a boolean operation on two simple polygons.
| a | First polygon (must be closed and simple). |
| b | Second polygon (must be closed and simple). |
| op | The operation to perform. |
Definition at line 11358 of file geom_algorithms.H.
References ah_domain_error_if, compute_difference(), compute_intersection(), compute_union(), DIFFERENCE, Aleph::divide_and_conquer_partition_dp(), INTERSECTION, Aleph::Polygon::is_closed(), Aleph::Polygon::size(), and UNION.
|
inlinestaticprivate |
Point-in-polygon test on a CCW vertex array (winding number).
Definition at line 11456 of file geom_algorithms.H.
References Aleph::area_of_parallelogram(), Aleph::Segment::contains(), Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_y(), and Aleph::Array< T >::size().
Referenced by compute_difference(), compute_intersection(), compute_union(), and greiner_hormann().
|
inlinestaticprivate |
Reverse a vertex array in place.
Definition at line 11423 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::Array< T >::size().
Referenced by compute_difference().
|
inlinestaticprivate |
Insertion-sort indices by a key array.
Definition at line 11484 of file geom_algorithms.H.
References keys, and Aleph::Array< T >::size().
Referenced by greiner_hormann().