Skip to main content

CrossSection

Struct CrossSection 

Source
pub struct CrossSection { /* private fields */ }

Implementations§

Source§

impl CrossSection

Source

pub fn new(polygons: Polygons) -> Self

Source

pub fn from_polygons_fill(polygons: Polygons) -> Self

Create a CrossSection from polygons, normalizing via Clipper2 Union. Mirrors C++ CrossSection(Polygons, FillRule) constructor which runs the polygons through C2::Union to merge overlapping regions.

Source

pub fn from_rect(rect: &Rect) -> Self

Create a CrossSection from a Rect (axis-aligned rectangle). Matches C++ CrossSection(Rect) constructor.

Source

pub fn square(size: f64) -> Self

Source

pub fn square_vec2(size: Vec2, center: bool) -> Self

Create a rectangle of size (w, h), optionally centered at origin. Matches C++ CrossSection::Square(vec2, center).

Source

pub fn circle(radius: f64, segments: i32) -> Self

Source

pub fn to_polygons(&self) -> Polygons

Source

pub fn translate(&self, v: Vec2) -> Self

Source

pub fn area(&self) -> f64

Source

pub fn bounds(&self) -> Rect

Source

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

Source

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

Source

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

Source

pub fn scale(&self, v: Vec2) -> Self

Source

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

Source

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

Mirror through a line perpendicular to the given axis vector. Matches C++ CrossSection::Mirror(ax) which uses I - 2*n*n^T.

Source

pub fn is_empty(&self) -> bool

Source

pub fn num_vert(&self) -> usize

Source

pub fn num_contour(&self) -> usize

Source

pub fn decompose(&self) -> Vec<Self>

Decompose into connected components. Each component maintains its contours (outer boundary + holes).

Source

pub fn simplify(&self, epsilon: f64) -> Self

Simplify contours by removing near-collinear vertices. Mirrors C++ CrossSection::Simplify(epsilon=1e-6): normalizes via union, filters tiny polygons, then applies SimplifyPaths with epsilon.

Source

pub fn offset(&self, delta: f64) -> Self

Source

pub fn offset_with_params( &self, delta: f64, join_type: i32, miter_limit: f64, circular_segments: i32, ) -> Self

Offset with explicit join type and segment count. join_type: 0=Square, 1=Round, 2=Miter

Source

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

Source

pub fn from_polygon_with_fill_rule(polygon: Vec<Vec2>, fill_rule: i32) -> Self

Create CrossSection from a simple polygon with a specified fill rule. fill_rule: 0=EvenOdd, 1=NonZero, 2=Positive, 3=Negative

Source

pub fn warp<F: FnMut(&mut Vec2)>(&self, f: F) -> Self

Apply a function to every vertex in-place.

Source

pub fn batch_boolean(sections: &[Self], op: OpType) -> Self

Batch boolean operation on a slice of CrossSections. OpType::Add = union, Subtract = difference, Intersect = intersection.

Source

pub fn hull_cross_sections(sections: &[Self]) -> Self

Compute convex hull of all vertices in a slice of CrossSections.

Source

pub fn hull_points(points: &[Vec2]) -> Self

Compute convex hull of a set of 2D points (Andrew’s monotone chain).

Source

pub fn compose(sections: &[Self]) -> Self

Compose (merge) multiple CrossSections by combining all their contours. Matches C++ CrossSection::Compose(vector) which unions all polygons.

Trait Implementations§

Source§

impl Clone for CrossSection

Source§

fn clone(&self) -> CrossSection

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 CrossSection

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CrossSection

Source§

fn default() -> CrossSection

Returns the “default value” for a type. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.