Skip to main content

Polygon

Struct Polygon 

Source
pub struct Polygon {
    pub vertices: Vec<Point>,
}

Fields§

§vertices: Vec<Point>

Implementations§

Source§

impl Polygon

Source

pub fn new(vertices: Vec<Point>) -> Self

Source

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().

Source

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.

Source

pub fn signed_area(&self) -> f64

Calculate the signed area of the polygon.

Counter-clockwise polygon -> positive Clockwise polygon -> negative

Source

pub fn area(&self) -> f64

Calculate the absolute area of the polygon.

Source

pub fn centroid(&self) -> Point

Calculate the centroid of the polygon.

Source

pub fn moment_of_inertia_x(&self) -> f64

Calculate the second moment of area about the global x-axis.

Source

pub fn moment_of_inertia_y(&self) -> f64

Calculate the second moment of area about the global y-axis.

Source

pub fn product_of_inertia_xy(&self) -> f64

Calculate the product of area about the global axes.

Source

pub fn centroidal_moment_of_inertia_x(&self) -> f64

Calculate the second moment of area about the centroidal x-axis.

Source

pub fn centroidal_moment_of_inertia_y(&self) -> f64

Calculate the second moment of area about the centroidal y-axis.

Source

pub fn centroidal_product_of_inertia_xy(&self) -> f64

Calculate the product of area about the centroidal axes.

Source

pub fn rotate(&self, angle: f64) -> Self

Rotate all vertices about the origin by angle radians (CCW positive).

Source

pub fn contains_point(&self, point: Point) -> bool

Check if a point is inside the polygon (ray casting algorithm).

Source

pub fn perimeter(&self) -> f64

Calculate the perimeter of the polygon.

Source

pub fn max_fiber_distance_y(&self) -> f64

Maximum fiber distance from centroid in Y direction (for section modulus).

Source

pub fn max_fiber_distance_x(&self) -> f64

Maximum fiber distance from centroid in X direction (for section modulus).

Source

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.

Source

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.

Source

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.

Source

pub fn try_new(vertices: Vec<Point>) -> Result<Self, PolygonError>

Validating constructor: returns an error if the polygon has self-intersections or is otherwise invalid.

Checks:

  • At least 3 distinct vertices
  • All vertices are finite
  • Non-zero area
  • No self-intersections

Trait Implementations§

Source§

impl BoundaryExtrema for Polygon

Source§

fn extreme_distances(&self, center: Point, direction: Point) -> (f64, f64)

Signed distances (min, max) from center projected onto direction. Read more
Source§

fn extreme_y(&self, center: Point) -> (f64, f64)

Convenience: extreme distances along the global Y axis.
Source§

fn extreme_x(&self, center: Point) -> (f64, f64)

Convenience: extreme distances along the global X axis.
Source§

impl Clone for Polygon

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Polygon

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.