pub struct Polygon {
pub vertices: Vec<Point>,
}Fields§
§vertices: Vec<Point>Implementations§
Source§impl Polygon
impl Polygon
Sourcepub fn new(vertices: Vec<Point>) -> Self
pub fn new(vertices: Vec<Point>) -> Self
Create a polygon from a list of vertices.
Consecutive duplicate vertices and a trailing vertex that closes back on the first are removed automatically.
§Panics
Panics if:
- fewer than 3 vertices are provided,
- any vertex has a non-finite
xory, - fewer than 3 distinct vertices remain after deduplication,
- the polygon has (near-)zero signed area (degenerate).
The area check uses a numerically stable vertex-reference formula so that polygons far from the origin are not spuriously rejected.
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.
Uses a vertex-reference two-pass strategy: the first vertex is
used as a reference point so that all shifted coordinates are small
(order of polygon extent). The centroid offset is computed in these
shifted coordinates, then the moment integral is evaluated about the
centroid. This avoids the catastrophic cancellation that occurs in
Ix_global - A * y_c² when the polygon is far from the origin.
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.
Uses the same vertex-reference two-pass strategy as
centroidal_moment_of_inertia_x.
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.
Uses the same vertex-reference two-pass strategy as
centroidal_moment_of_inertia_x.
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.