Skip to main content

Polygon

Struct Polygon 

Source
pub struct Polygon<T: Number, const N: usize> { /* private fields */ }
Expand description

A simple 2d polygon in an N dimensional space, defined by its vertices and holes, and the plane it lies on

Implementations§

Source§

impl<T> Polygon<T, 3>
where T: Number,

Source

pub fn tessellate_earcut<N: Index>(&self) -> TessellatedPolygon<'_, T, 3, N>

Run earcut tessellation on the polygon

Source

pub fn tessellate_earcut_with<N: Index>( &self, earcut: &mut Earcut<T>, ) -> TessellatedPolygon<'_, T, 3, N>

Use earcut tessellation on the polygon

Source

pub fn tessellate_earcut_using_transform<N: Index>( &self, ) -> TessellatedPolygon<'_, T, 3, N>

Use earcut tessellation using

Source

pub fn tessellate_delaunay<S: Index>(&self) -> TessellatedPolygon<'_, T, 3, S>
where T: SpadeNum,

Tessellate the polygon using Delaunay triangulation via the spade crate.

Projects vertices onto the dominant plane axis (same projection as tessellate_earcut) and feeds them into a fresh [DelaunayTriangulation]. Holes are not supported by the plain Delaunay algorithm; use tessellate_earcut when holes are present.

Source

pub fn tessellate_delaunay_with<S: Index>( &self, triangulation: &mut DelaunayTriangulation<DelaunayVertex<T>>, ) -> TessellatedPolygon<'_, T, 3, S>
where T: SpadeNum,

Tessellate the polygon using a caller-supplied [DelaunayTriangulation].

The triangulation is cleared before use so that it can be reused across multiple calls without heap re-allocation (mirroring the earcut _with API pattern).

Source

pub fn tessellate_delaunay_using_transform<S: Index>( &self, ) -> TessellatedPolygon<'_, T, 3, S>
where T: SpadeNum,

Source§

impl<T, const N: usize> Polygon<T, N>
where T: Number,

Source

pub fn from_points_and_plane( vertices: impl Into<Vec<Point<T, N>>>, plane: Plane<T, N>, ) -> Result<Self, String>

Source

pub fn face_key(&self) -> Option<FaceKey>

Source

pub fn set_face_key(&mut self, key: Option<FaceKey>)

Source

pub fn holes(&self) -> &[Array1<usize>]

Source

pub fn vertices(&self) -> ArrayView1<'_, Point<T, N>>

Source

pub fn translate(self, offset: impl Into<SVector<T, N>>) -> Self

Source

pub fn plane(&self) -> Plane<T, N>

Source

pub fn transform(self, transform: Transform<T, TAffine, N>) -> Self

Takes an affine transformation matrix and applies it to a n dimensional point polygon

Source

pub fn bounding_box(&self) -> AxisAlignedBoundingBox<T, N>

Source

pub fn map_vertices<F>(self, f: F) -> Self
where F: Fn(Point<T, N>) -> Point<T, N>,

Source

pub fn cast<T2: Number>(self) -> Polygon<T2, N>
where T: AsPrimitive<T2>,

Cast the polygon’s numeric type from T to T2.

Source§

impl<T> Polygon<T, 3>
where T: Number,

Source

pub fn from_points( vertices: impl IntoIterator<Item = Point3<T>>, ) -> Result<Self, PolygonError>

Construct a polygon from a list of coplanar 3D points. The plane is derived from the first three vertices. Returns an error if fewer than 3 vertices are provided, or if any vertex is not coplanar with the plane defined by the first three.

Source

pub fn circle(radius: T, segments: usize, plane: Plane<T, 3>) -> Self

Source

pub fn square(size: T, plane: Plane<T, 3>) -> Self

Source

pub fn rotate(self, rotation: Matrix3<T>) -> Self

Rotate all vertices and the plane by a 3×3 rotation matrix.

The rotation matrix must be orthogonal (e.g., from [euler_rotation_matrix]). For an orthogonal matrix, the plane distance is preserved.

Source

pub fn rotate_euler(self, angles_deg: Vector3<T>) -> Self

Rotate by Euler angles (degrees), applied as Z × Y × X.

Source

pub fn flip(self) -> Self

Source

pub fn flip_in_place(&mut self)

Source

pub fn recompute_plane(&mut self)

Recompute the cached plane from the current vertices via Newell’s method (normal oriented by winding, matching Plane::from_points, but robust to near-collinear leading vertices).

Required after any vertex map that doesn’t preserve the plane normal (e.g. non-uniform scale): a stale plane makes BSP classification inconsistent with the vertices, which cascades into unbounded polygon splitting.

Trait Implementations§

Source§

impl<T: Clone + Number, const N: usize> Clone for Polygon<T, N>

Source§

fn clone(&self) -> Polygon<T, N>

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<T: Debug + Number, const N: usize> Debug for Polygon<T, N>

Source§

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

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

impl<T, const N: usize> Mul<Polygon<T, N>> for SMatrix<T, N, N>
where T: Number,

Source§

type Output = Polygon<T, N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Polygon<T, N>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: PartialEq + Number, const N: usize> PartialEq for Polygon<T, N>

Source§

fn eq(&self, other: &Polygon<T, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Number, const N: usize> StructuralPartialEq for Polygon<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for Polygon<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for Polygon<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for Polygon<T, N>

§

impl<T, const N: usize> Sync for Polygon<T, N>

§

impl<T, const N: usize> Unpin for Polygon<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnsafeUnpin for Polygon<T, N>
where T: UnsafeUnpin,

§

impl<T, const N: usize> UnwindSafe for Polygon<T, N>

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

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

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ConditionalSend for T
where T: Send,

§

impl<T> OpaqueAttachment for T
where T: Send + Sync + 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

impl<T> Settings for T
where T: 'static + Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,