pub struct Polygon {
pub vertices: Vec<Point>,
}Fields§
§vertices: Vec<Point>Implementations§
Source§impl Polygon
impl Polygon
pub fn new(vertices: Vec<Point>) -> Self
Sourcepub fn offset(&self, distance: f64) -> Option<Polygon>
pub fn offset(&self, distance: f64) -> Option<Polygon>
Offset the polygon by distance using mitred corners.
Positive distances grow a CCW polygon outward; negative distances shrink
it. Returns None if the offset polygon degenerates (e.g. an inward
offset larger than the polygon size).
Mirrors shapely’s buffer(distance, join_style=mitre) used by Python
sectionproperties’ Geometry.offset().
Sourcepub fn offset_with_style(
&self,
distance: f64,
join_style: JoinStyle,
mitre_limit: f64,
) -> Option<Polygon>
pub fn offset_with_style( &self, distance: f64, join_style: JoinStyle, mitre_limit: f64, ) -> Option<Polygon>
Offset the polygon with explicit join style and mitre limit.
join_style controls corner treatment:
Miter: Extend offset edges until they intersect (default)Round: Arc of radius |distance| (approximated with segments)Bevel: Connect offset edges with a single segment
mitre_limit (only for Miter) caps the mitre length to mitre_limit * |distance|.
Exceeding corners are bevelled instead. Typical value: 2.0.
Sourcepub fn signed_area(&self) -> f64
pub fn signed_area(&self) -> f64
Calculate the signed area of the polygon.
Counter-clockwise polygon -> positive Clockwise polygon -> negative
Sourcepub fn moment_of_inertia_x(&self) -> f64
pub fn moment_of_inertia_x(&self) -> f64
Calculate the second moment of area about the global x-axis.
Sourcepub fn moment_of_inertia_y(&self) -> f64
pub fn moment_of_inertia_y(&self) -> f64
Calculate the second moment of area about the global y-axis.
Sourcepub fn product_of_inertia_xy(&self) -> f64
pub fn product_of_inertia_xy(&self) -> f64
Calculate the product of area about the global axes.
Sourcepub fn centroidal_moment_of_inertia_x(&self) -> f64
pub fn centroidal_moment_of_inertia_x(&self) -> f64
Calculate the second moment of area about the centroidal x-axis.
Sourcepub fn centroidal_moment_of_inertia_y(&self) -> f64
pub fn centroidal_moment_of_inertia_y(&self) -> f64
Calculate the second moment of area about the centroidal y-axis.
Sourcepub fn centroidal_product_of_inertia_xy(&self) -> f64
pub fn centroidal_product_of_inertia_xy(&self) -> f64
Calculate the product of area about the centroidal axes.
Sourcepub fn rotate(&self, angle: f64) -> Self
pub fn rotate(&self, angle: f64) -> Self
Rotate all vertices about the origin by angle radians (CCW positive).
Sourcepub fn contains_point(&self, point: Point) -> bool
pub fn contains_point(&self, point: Point) -> bool
Check if a point is inside the polygon (ray casting algorithm).
Sourcepub fn max_fiber_distance_y(&self) -> f64
pub fn max_fiber_distance_y(&self) -> f64
Maximum fiber distance from centroid in Y direction (for section modulus).
Sourcepub fn max_fiber_distance_x(&self) -> f64
pub fn max_fiber_distance_x(&self) -> f64
Maximum fiber distance from centroid in X direction (for section modulus).
Sourcepub fn clip_halfspace(
&self,
n_x: f64,
n_y: f64,
c: f64,
below: bool,
) -> Option<Polygon>
pub fn clip_halfspace( &self, n_x: f64, n_y: f64, c: f64, below: bool, ) -> Option<Polygon>
Clip the polygon against the half-plane nx*x + ny*y <= c
(below = true) or >= c (below = false), using
Sutherland-Hodgman clipping. Returns None when nothing remains.
Sourcepub fn split_by_line(
&self,
a: Point,
b: Point,
) -> (Option<Polygon>, Option<Polygon>)
pub fn split_by_line( &self, a: Point, b: Point, ) -> (Option<Polygon>, Option<Polygon>)
Split the polygon into the two halves lying either side of the line
through points a and b.
Returns (below, above); either side may be None when the line does
not cut the polygon. Mirrors Python bisect_section helpers used by
Section.split_section.
Sourcepub fn has_self_intersections(&self) -> bool
pub fn has_self_intersections(&self) -> bool
Check if the polygon has self-intersections (non-adjacent edges crossing).
Returns true if any two non-adjacent edges intersect in their interiors.
This does not count shared vertices (adjacent edges) as intersections.