Skip to main content

Geometry

Struct Geometry 

Source
pub struct Geometry {
    pub outer: Polygon,
    pub holes: Vec<Polygon>,
    pub transforms: Vec<Transform>,
}
Expand description

A single connected region: an outer boundary plus optional holes, optionally followed by a list of transforms.

Mirrors sectionproperties.pre.geometry.Geometry.

Fields§

§outer: Polygon

Outer boundary (normalised to CCW).

§holes: Vec<Polygon>

Hole boundaries (each normalised to CW).

§transforms: Vec<Transform>

Geometric transforms applied in order (see Geometry).

Implementations§

Source§

impl Geometry

Source

pub fn new(outer: Polygon, holes: Vec<Polygon>) -> Self

Create a new geometry from an outer polygon and optional holes.

The outer boundary is normalised to counter-clockwise orientation and each hole to clockwise orientation, matching the convention used by Section.

Source

pub fn from_points(points: Vec<Point>, holes: Vec<Vec<Point>>) -> Self

Create a geometry from outer and hole point loops.

Mirrors Geometry.from_points(points, holes=...).

Source

pub fn from_section(section: &Section) -> Self

Convert a single-boundary Section into a geometry.

Source

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

Rotate counter-clockwise about the origin by angle_degrees degrees.

Mirrors Geometry.rotate(angle_degrees, rot_point).

Source

pub fn rotate_about(self, angle_degrees: f64, point: Point) -> Self

Rotate about an explicit point.

Source

pub fn mirror(self, axis: Axis) -> Self

Reflect about the x or y axis.

Mirrors Geometry.mirror(axis, mirror_point); here reflection is always about the global axes.

Source

pub fn shift(self, dx: f64, dy: f64) -> Self

Translate by (dx, dy).

Mirrors Geometry.shift(x_offset, y_offset).

Source

pub fn align_center(&self) -> Self

Return a copy translated so that the centroid sits at the origin.

Mirrors Geometry.align_center().

Source

pub fn align_to(&self, other: &Self) -> Self

Translate this geometry so its bounding box aligns with other.

For each axis independently the nearest bounding-box edge is moved onto the corresponding edge of other’s box, matching the behaviour of Geometry.align_to(other, pt=(0, 0)).

Source

pub fn offset(&self, amount: f64) -> Option<Self>

Offset the geometry by amount using mitred corners.

Positive amounts grow the geometry, negative amounts shrink it. The outer boundary is offset by +amount and each hole by -amount. Returns None if any boundary degenerates.

Mirrors Geometry.offset(amount).

Source

pub fn split_section( &self, a: Point, b: Point, ) -> (Option<Geometry>, Option<Geometry>)

Split the geometry into two halves either side of the line through points a and b.

Mirrors Geometry.split_section(point_a, point_b). Returns (below, above); each side is None when empty.

Source

pub fn union(&self, other: &Self) -> Result<CompoundGeometry, BooleanError>

Boolean union with other.

Mirrors Geometry | other (shapely union). Returns a CompoundGeometry that can represent multiple disconnected regions.

Source

pub fn intersection( &self, other: &Self, ) -> Result<CompoundGeometry, BooleanError>

Boolean intersection with other.

Mirrors Geometry & other (shapely intersection). Returns a CompoundGeometry that can represent multiple disconnected regions.

Source

pub fn subtract(&self, other: &Self) -> Result<CompoundGeometry, BooleanError>

Boolean difference: this geometry minus other.

Mirrors Geometry - other (shapely difference). Returns a CompoundGeometry that can represent multiple disconnected regions.

Source

pub fn apply_transforms(&self) -> Self

Return a copy of this geometry with the transforms applied to all vertices.

Transforms are applied in the order they appear in Geometry::transforms.

Source

pub fn area(&self) -> f64

Net area of the geometry (outer minus holes), after applying transforms.

Source

pub fn centroid(&self) -> Point

Centroid of the geometry using the composite area formula.

Source

pub fn bounds(&self) -> (f64, f64, f64, f64)

Bounding box of the geometry: (min_x, max_x, min_y, max_y).

Source

pub fn perimeter(&self) -> f64

Perimeter of the geometry (outer + holes), after applying transforms.

Trait Implementations§

Source§

impl Clone for Geometry

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 Geometry

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.