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,
impl<T> Polygon<T, 3>where
T: Number,
Sourcepub fn tessellate_earcut<N: Index>(&self) -> TessellatedPolygon<'_, T, 3, N>
pub fn tessellate_earcut<N: Index>(&self) -> TessellatedPolygon<'_, T, 3, N>
Run earcut tessellation on the polygon
Sourcepub fn tessellate_earcut_with<N: Index>(
&self,
earcut: &mut Earcut<T>,
) -> TessellatedPolygon<'_, T, 3, N>
pub fn tessellate_earcut_with<N: Index>( &self, earcut: &mut Earcut<T>, ) -> TessellatedPolygon<'_, T, 3, N>
Use earcut tessellation on the polygon
Sourcepub fn tessellate_earcut_using_transform<N: Index>(
&self,
) -> TessellatedPolygon<'_, T, 3, N>
pub fn tessellate_earcut_using_transform<N: Index>( &self, ) -> TessellatedPolygon<'_, T, 3, N>
Use earcut tessellation using
Sourcepub fn tessellate_delaunay<S: Index>(&self) -> TessellatedPolygon<'_, T, 3, S>where
T: SpadeNum,
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.
Sourcepub fn tessellate_delaunay_with<S: Index>(
&self,
triangulation: &mut DelaunayTriangulation<DelaunayVertex<T>>,
) -> TessellatedPolygon<'_, T, 3, S>where
T: SpadeNum,
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).
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,
impl<T, const N: usize> Polygon<T, N>where
T: Number,
pub fn from_points_and_plane( vertices: impl Into<Vec<Point<T, N>>>, plane: Plane<T, N>, ) -> Result<Self, String>
pub fn face_key(&self) -> Option<FaceKey>
pub fn set_face_key(&mut self, key: Option<FaceKey>)
pub fn holes(&self) -> &[Array1<usize>] ⓘ
pub fn vertices(&self) -> ArrayView1<'_, Point<T, N>>
pub fn translate(self, offset: impl Into<SVector<T, N>>) -> Self
pub fn plane(&self) -> Plane<T, N>
Sourcepub fn transform(self, transform: Transform<T, TAffine, N>) -> Selfwhere
Const<N>: ToTypenum + DimNameAdd<U1>,
<Const<N> as ToTypenum>::Typenum: Add<UInt<UTerm, B1>>,
DefaultAllocator: Allocator<DimNameSum<Const<N>, U1>, DimNameSum<Const<N>, U1>> + Allocator<DimNameSum<Const<N>, U1>>,
pub fn transform(self, transform: Transform<T, TAffine, N>) -> Selfwhere
Const<N>: ToTypenum + DimNameAdd<U1>,
<Const<N> as ToTypenum>::Typenum: Add<UInt<UTerm, B1>>,
DefaultAllocator: Allocator<DimNameSum<Const<N>, U1>, DimNameSum<Const<N>, U1>> + Allocator<DimNameSum<Const<N>, U1>>,
Takes an affine transformation matrix and applies it to a n dimensional point polygon
pub fn bounding_box(&self) -> AxisAlignedBoundingBox<T, N>
pub fn map_vertices<F>(self, f: F) -> Self
Sourcepub fn cast<T2: Number>(self) -> Polygon<T2, N>where
T: AsPrimitive<T2>,
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,
impl<T> Polygon<T, 3>where
T: Number,
Sourcepub fn from_points(
vertices: impl IntoIterator<Item = Point3<T>>,
) -> Result<Self, PolygonError>
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.
pub fn circle(radius: T, segments: usize, plane: Plane<T, 3>) -> Self
pub fn square(size: T, plane: Plane<T, 3>) -> Self
Sourcepub fn rotate(self, rotation: Matrix3<T>) -> Self
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.
Sourcepub fn rotate_euler(self, angles_deg: Vector3<T>) -> Self
pub fn rotate_euler(self, angles_deg: Vector3<T>) -> Self
Rotate by Euler angles (degrees), applied as Z × Y × X.
pub fn flip(self) -> Self
pub fn flip_in_place(&mut self)
Sourcepub fn recompute_plane(&mut self)
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: PartialEq + Number, const N: usize> PartialEq for Polygon<T, N>
impl<T: PartialEq + Number, const N: usize> PartialEq for Polygon<T, N>
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>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.