|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Offset (inflate/deflate) an arbitrary simple polygon. More...
#include <geom_algorithms.H>
Classes | |
| struct | AugVertex |
| Augmented vertex in the cleaned polygon. More... | |
| struct | Intersection |
| Intersection found between edge i and edge j of the raw polygon. More... | |
| struct | Result |
| The result of an offset operation, which may produce multiple polygons. More... | |
Public Types | |
| enum class | JoinType { Miter , Bevel } |
| Strategy for connecting offset edges at vertices. More... | |
Public Member Functions | |
| Result | operator() (const Polygon &poly, const Geom_Number &distance, const JoinType join=JoinType::Miter, const Geom_Number &miter_limit=Geom_Number(2)) const |
| Offset a simple polygon by the given distance. | |
| Polygon | offset_polygon (const Polygon &poly, const Geom_Number &distance, JoinType join=JoinType::Miter, const Geom_Number &miter_limit=Geom_Number(2)) const |
| Convenience: return the single largest-area result polygon. | |
Static Private Member Functions | |
| static Geom_Number | abs_area (const Polygon &p) |
| static void | offset_edge (const Point &a, const Point &b, const Geom_Number &d, const bool inward, Point &oa, Point &ob) |
| Compute two points on the offset line of edge (a→b) shifted by |d| along its outward or inward normal. | |
| static Point | line_intersect (const Point &a1, const Point &a2, const Point &b1, const Point &b2) |
| Line–line intersection of (a1,a2) and (b1,b2). | |
| static Geom_Number | sq_dist (const Point &a, const Point &b) |
| Compute the squared distance between two points. | |
| static Array< Point > | compute_raw_offset (const Array< Point > &v, const Geom_Number &distance, const JoinType join, const Geom_Number &miter_limit) |
| 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 Array< Intersection > | find_self_intersections (const Array< Point > &raw) |
| O(n²) scan for all proper self-intersections. | |
| static void | sort_by_alpha (Array< size_t > &idx, const Array< Geom_Number > &keys) |
| Insertion-sort indices by alpha key. | |
| static Array< AugVertex > | build_augmented (const Array< Point > &raw, const Array< Intersection > &isects) |
| Build the augmented vertex list with crossing links. | |
| static Polygon | build_poly (const Array< Point > &pts) |
| Build a polygon from a point array. | |
| static Array< Polygon > | extract_contours (Array< AugVertex > &aug) |
| Walk the augmented polygon and extract valid CCW contours. | |
| static Result | cleanup (const Array< Point > &raw) |
| Full cleanup pipeline. | |
Offset (inflate/deflate) an arbitrary simple polygon.
Unlike ConvexPolygonOffset, this class handles non-convex (simple) polygons. The raw miter-join offset polygon may self-intersect at reflex vertices; a self-intersection cleanup phase extracts the valid contours.
|d| along its outward (d>0) or inward (d<0) normal, then join consecutive offset edges at their miter point (line–line intersection). An optional miter limit replaces excessively long miter joins with bevel (two-point) joins.Definition at line 9071 of file geom_algorithms.H.
Strategy for connecting offset edges at vertices.
| Enumerator | |
|---|---|
| Miter | Extend edges until they intersect. |
| Bevel | Connect edge endpoints with a straight line. |
Definition at line 9077 of file geom_algorithms.H.
|
inlinestaticprivate |
Definition at line 9169 of file geom_algorithms.H.
References Aleph::GeomPolygonUtils::signed_double_area().
Referenced by offset_polygon().
|
inlinestaticprivate |
Build the augmented vertex list with crossing links.
Definition at line 9382 of file geom_algorithms.H.
References Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), k, m, Aleph::PolygonOffset::AugVertex::pt, Aleph::Array< T >::reserve(), OhashCommon< HashTbl, Key >::size(), Aleph::Array< T >::size(), and sort_by_alpha().
Referenced by cleanup().
Build a polygon from a point array.
Definition at line 9465 of file geom_algorithms.H.
References Aleph::Polygon::add_vertex(), Aleph::Polygon::close(), and Aleph::divide_and_conquer_partition_dp().
Referenced by cleanup(), and extract_contours().
Full cleanup pipeline.
Definition at line 9546 of file geom_algorithms.H.
References build_augmented(), build_poly(), Aleph::divide_and_conquer_partition_dp(), extract_contours(), find_self_intersections(), Aleph::PolygonOffset::Result::polygons, r, and Aleph::GeomPolygonUtils::signed_double_area().
Referenced by operator()().
|
inlinestaticprivate |
Definition at line 9203 of file geom_algorithms.H.
References Bevel, Aleph::divide_and_conquer_partition_dp(), Aleph::join(), line_intersect(), Miter, offset_edge(), Aleph::Array< T >::reserve(), Aleph::Array< T >::size(), and sq_dist().
Referenced by operator()().
|
inlinestaticprivate |
Compute parameter t of point I along directed edge P→Q.
Definition at line 9317 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp().
Referenced by find_self_intersections().
|
inlinestaticprivate |
Walk the augmented polygon and extract valid CCW contours.
At each intersection vertex, jump to the partner first (switching to the other branch of the crossing) and then walk forward. This traces the inner contours correctly for self-intersecting offset polygons.
Definition at line 9482 of file geom_algorithms.H.
References Aleph::Array< T >::append(), build_poly(), Aleph::divide_and_conquer_partition_dp(), N, Aleph::GeomPolygonUtils::signed_double_area(), and Aleph::Array< T >::size().
Referenced by cleanup().
|
inlinestaticprivate |
O(n²) scan for all proper self-intersections.
Definition at line 9326 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), edge_param(), Aleph::Segment::intersection_with(), and Aleph::Segment::intersects_properly_with().
Referenced by cleanup().
|
inlinestaticprivate |
Line–line intersection of (a1,a2) and (b1,b2).
Definition at line 9186 of file geom_algorithms.H.
References Aleph::ConvexPolygonOffset::line_intersect().
Referenced by compute_raw_offset().
|
inlinestaticprivate |
Compute two points on the offset line of edge (a→b) shifted by |d| along its outward or inward normal.
Delegates to mpfr arithmetic.
Definition at line 9178 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::ConvexPolygonOffset::offset_edge().
Referenced by compute_raw_offset().
|
inline |
Convenience: return the single largest-area result polygon.
Definition at line 9147 of file geom_algorithms.H.
References abs_area(), Aleph::divide_and_conquer_partition_dp(), Aleph::join(), and r.
|
inline |
Offset a simple polygon by the given distance.
| poly | A closed simple polygon. |
| distance | Positive = outward (expand), negative = inward (shrink). |
| join | Join strategy (Miter or Bevel). |
| miter_limit | When miter distance exceeds miter_limit * |d|, fall back to bevel join. |
Definition at line 9115 of file geom_algorithms.H.
References ah_domain_error_if, cleanup(), compute_raw_offset(), Aleph::divide_and_conquer_partition_dp(), Aleph::GeomPolygonUtils::ensure_ccw(), Aleph::GeomPolygonUtils::extract_vertices(), Aleph::Polygon::is_closed(), Aleph::join(), Aleph::PolygonOffset::Result::polygons, r, and Aleph::Polygon::size().
|
inlinestaticprivate |
Insertion-sort indices by alpha key.
Definition at line 9363 of file geom_algorithms.H.
References keys, and Aleph::Array< T >::size().
Referenced by build_augmented().
|
inlinestaticprivate |
Compute the squared distance between two points.
Definition at line 9195 of file geom_algorithms.H.
References Aleph::Point::get_x(), and Aleph::Point::get_y().
Referenced by compute_raw_offset().