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: PolygonOuter 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
impl Geometry
Sourcepub fn new(outer: Polygon, holes: Vec<Polygon>) -> Self
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.
Sourcepub fn from_points(points: Vec<Point>, holes: Vec<Vec<Point>>) -> Self
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=...).
Sourcepub fn from_section(section: &Section) -> Self
pub fn from_section(section: &Section) -> Self
Convert a single-boundary Section into a geometry.
Sourcepub fn rotate(self, angle_degrees: f64) -> Self
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).
Sourcepub fn rotate_about(self, angle_degrees: f64, point: Point) -> Self
pub fn rotate_about(self, angle_degrees: f64, point: Point) -> Self
Rotate about an explicit point.
Sourcepub fn mirror(self, axis: Axis) -> Self
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.
Sourcepub fn shift(self, dx: f64, dy: f64) -> Self
pub fn shift(self, dx: f64, dy: f64) -> Self
Translate by (dx, dy).
Mirrors Geometry.shift(x_offset, y_offset).
Sourcepub fn align_center(&self) -> Self
pub fn align_center(&self) -> Self
Return a copy translated so that the centroid sits at the origin.
Mirrors Geometry.align_center().
Sourcepub fn align_to(&self, other: &Self) -> Self
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)).
Sourcepub fn offset(&self, amount: f64) -> Option<Self>
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).
Sourcepub fn split_section(
&self,
a: Point,
b: Point,
) -> (Option<Geometry>, Option<Geometry>)
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.
Sourcepub fn union(&self, other: &Self) -> Result<CompoundGeometry, BooleanError>
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.
Sourcepub fn intersection(
&self,
other: &Self,
) -> Result<CompoundGeometry, BooleanError>
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.
Sourcepub fn subtract(&self, other: &Self) -> Result<CompoundGeometry, BooleanError>
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.
Sourcepub fn apply_transforms(&self) -> Self
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.
Sourcepub fn area(&self) -> f64
pub fn area(&self) -> f64
Net area of the geometry (outer minus holes), after applying transforms.