pub fn buffer_convex_polygon<G, P>(
polygon: &G,
distance: f64,
join: JoinStrategy,
) -> Polygon<P>where
G: PolygonTrait<Point = P>,
P: PointMut + Default + Copy,
P::Scalar: CoordinateScalar + Into<f64> + FromF64,
<P::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,Expand description
Buffer a convex polygon outward by a positive distance, rounding
the corners per join.
Each vertex of a convex polygon becomes a circular arc of radius
distance in the offset boundary; the arcs are joined by the offset
edges. Mirrors the convex case of boost::geometry::buffer
(algorithms/buffer.hpp) with a join_round strategy.
§Panics
Does not panic; a polygon with fewer than 3 exterior vertices returns an empty ring’s polygon.
§Examples
use geometry_cs::Cartesian;
use geometry_model::{polygon, Point2D, Polygon};
use geometry_overlay::buffer::{buffer_convex_polygon, JoinStrategy};
use geometry_algorithm::ring_area;
use geometry_trait::Polygon as _;
type P = Point2D<f64, Cartesian>;
let sq: Polygon<P> = polygon![[(0.0, 0.0), (2.0, 0.0), (2.0, 2.0), (0.0, 2.0), (0.0, 0.0)]];
let grown = buffer_convex_polygon(&sq, 1.0, JoinStrategy::Round { points_per_circle: 720 });
// Area = s² + 4·s·d + π·d² = 4 + 8 + π.
let expected = 4.0 + 8.0 + core::f64::consts::PI;
assert!((ring_area(grown.exterior()).abs() - expected).abs() < 5e-2);