Expand description
Ring (closed polygon) utility functions.
A ring is a Vec<[i64; 2]> of vertices in order (first != last, closing edge implied). All operations use exact integer arithmetic — no epsilon, no floating point.
Input contract for decompose():
- Rings must be CCW (counter-clockwise)
- Rings must be simple (no self-intersections)
- Collinear vertices should be removed for cleaner decomposition
Functions§
- ensure_
ccw - Ensure the ring is CCW. Reverses in place if CW.
- is_ccw
- True if the ring is counter-clockwise (positive signed area).
- is_
simple - True if the ring has no self-intersections (is simple). O(n²) check — all non-adjacent edge pairs. A ring with n < 3 vertices is not simple.
- normalize_
ring - Normalize a ring: remove collinear vertices, ensure CCW winding. Does NOT check for simplicity (caller must ensure input is simple). Returns None if the result has fewer than 3 vertices (degenerate).
- remove_
collinear - Remove collinear vertices from a ring. A vertex is collinear if cross(prev, curr, next) == 0 (exact integer test). Returns a new ring with collinear vertices removed. The result may have fewer vertices, but preserves the polygon shape exactly.
- rotate_
ring - Rotate ring so that index
startbecomes index 0. Preserves winding. - signed_
area_ 2x - Twice the signed area of the ring (positive = CCW, negative = CW). Uses the shoelace formula with i128 intermediate arithmetic. NOT the same as twice_area_fp2 in area.rs — this preserves sign for orientation detection.