Skip to main content

offset_polygon

Function offset_polygon 

Source
pub fn offset_polygon(
    polygon: &[(f64, f64)],
    distance: f64,
) -> Vec<Vec<(f64, f64)>>
Expand description

Offsets a simple polygon by distance using the default miter limit (2.0).

Positive distance expands the polygon outward (for CCW winding). Negative distance shrinks inward. Zero distance returns the original polygon.

Returns a Vec of polygon rings. The result may be empty if the polygon collapses, or contain multiple rings if the offset causes topology splits.

§Arguments

  • polygon - A simple polygon as a slice of (f64, f64) vertices
  • distance - Offset distance (positive = outward, negative = inward)

§Complexity

O(n) for convex polygons, O(n^2) worst case for concave polygons due to self-intersection resolution.

§Example

use u_geometry::offset::offset_polygon;

let square = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)];
let result = offset_polygon(&square, 1.0);
assert_eq!(result.len(), 1);