pub struct Polygon<T>(/* private fields */);Expand description
A convex polygon.
The N represents how many points the polygon can have before it needs
to allocate onto the heap. If you know your shapes will never have more
than N edges, you can set it to that value and avoid heap allocations.
Implementations§
Source§impl<T: Num> Polygon<T>
impl<T: Num> Polygon<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new empty polygon with at least the specified capacity.
Sourcepub fn from_arr<const LEN: usize>(arr: [Vec2<T>; LEN]) -> Self
pub fn from_arr<const LEN: usize>(arr: [Vec2<T>; LEN]) -> Self
Create a new polygon using the array of points.
Sourcepub fn from_slice<const LEN: usize>(slice: &[Vec2<T>]) -> Self
pub fn from_slice<const LEN: usize>(slice: &[Vec2<T>]) -> Self
Create a new polygon using the slice of points.
pub fn from_rect(rect: Rect<T>) -> Self
Sourcepub fn from_tri(tri: Triangle<T>) -> Self
pub fn from_tri(tri: Triangle<T>) -> Self
Create a polygon representation of the provided triangle.
Sourcepub fn points_mut(&mut self) -> &mut [Vec2<T>]
pub fn points_mut(&mut self) -> &mut [Vec2<T>]
Mutable reference to the polygon’s points.
Sourcepub fn resize_with<F: FnMut() -> Vec2<T>>(&mut self, new_size: usize, f: F)
pub fn resize_with<F: FnMut() -> Vec2<T>>(&mut self, new_size: usize, f: F)
Resize the polygon, using the provided function to create new points.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Polygon<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Polygon<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: Num> Extend<Vec2<T>> for Polygon<T>
impl<T: Num> Extend<Vec2<T>> for Polygon<T>
Source§fn extend<I: IntoIterator<Item = Vec2<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Vec2<T>>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<T> IntoIterator for Polygon<T>
impl<T> IntoIterator for Polygon<T>
Source§impl<T: Num> Numeric for Polygon<T>
impl<T: Num> Numeric for Polygon<T>
type AsU8 = Polygon<u8>
type AsU16 = Polygon<u16>
type AsU32 = Polygon<u32>
type AsU64 = Polygon<u64>
type AsU128 = Polygon<u128>
type AsUSize = Polygon<usize>
type AsI8 = Polygon<i8>
type AsI16 = Polygon<i16>
type AsI32 = Polygon<i32>
type AsI64 = Polygon<i64>
type AsI128 = Polygon<i128>
type AsISize = Polygon<isize>
type AsF32 = Polygon<f32>
type AsF64 = Polygon<f64>
fn to_u8(self) -> Self::AsU8
fn to_u16(self) -> Self::AsU16
fn to_u32(self) -> Self::AsU32
fn to_u64(self) -> Self::AsU64
fn to_u128(self) -> Self::AsU128
fn to_usize(self) -> Self::AsUSize
fn to_i8(self) -> Self::AsI8
fn to_i16(self) -> Self::AsI16
fn to_i32(self) -> Self::AsI32
fn to_i64(self) -> Self::AsI64
fn to_i128(self) -> Self::AsI128
fn to_isize(self) -> Self::AsISize
fn to_f32(self) -> Self::AsF32
fn to_f64(self) -> Self::AsF64
impl<T> StructuralPartialEq for Polygon<T>
Auto Trait Implementations§
impl<T> Freeze for Polygon<T>
impl<T> RefUnwindSafe for Polygon<T>where
T: RefUnwindSafe,
impl<T> Send for Polygon<T>where
T: Send,
impl<T> Sync for Polygon<T>where
T: Sync,
impl<T> Unpin for Polygon<T>where
T: Unpin,
impl<T> UnwindSafe for Polygon<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Polygonal<T> for S
impl<T, S> Polygonal<T> for S
Source§fn nearest_vertex(&self, source: Vec2<T>) -> Vec2<T>
fn nearest_vertex(&self, source: Vec2<T>) -> Vec2<T>
Get the nearest point on this polygon to the source point.
Source§fn all_edges<F>(&self, cond: F) -> bool
fn all_edges<F>(&self, cond: F) -> bool
Iterate all polygonal edges of the shape, returning true if
any of them satisfy the conditional function provided.
Source§fn all_normals<F>(&self, cond: F) -> bool
fn all_normals<F>(&self, cond: F) -> bool
Iterate all edge normals of the shape, returning true if
any of them satisfy the conditional function provided.
Source§fn visit_normals<F>(&self, plot: F)
fn visit_normals<F>(&self, plot: F)
Walk through every normal of the polygon.
Source§fn visit_edges<F: FnMut(Line<T>)>(&self, plot: F)
fn visit_edges<F: FnMut(Line<T>)>(&self, plot: F)
Walk through every edge of the polygon.
Source§impl<T, S> Shape<T> for S
impl<T, S> Shape<T> for S
Source§fn project_onto_axis(&self, axis: Vec2<T>) -> Projection<T>
fn project_onto_axis(&self, axis: Vec2<T>) -> Projection<T>
Project the shape onto the axis.
Source§fn project_point(&self, p: Vec2<T>) -> Vec2<T>
fn project_point(&self, p: Vec2<T>) -> Vec2<T>
Project a point onto the outside surface of the shape.
Source§fn overlaps_rect(&self, rect: &Rect<T>) -> bool
fn overlaps_rect(&self, rect: &Rect<T>) -> bool
If this shape overlaps the rectangle.
Source§fn overlaps_circ(&self, circ: &Circle<T>) -> bool
fn overlaps_circ(&self, circ: &Circle<T>) -> bool
If this shape overlaps the circle.
Source§fn overlaps_poly<P>(&self, poly: &P) -> boolwhere
P: Polygonal<T>,
fn overlaps_poly<P>(&self, poly: &P) -> boolwhere
P: Polygonal<T>,
If this shape overlaps the polygon.
Source§fn extract_from_circ(&self, circ: &Circle<T>) -> Option<Vec2<T>>
fn extract_from_circ(&self, circ: &Circle<T>) -> Option<Vec2<T>>
If this shape and the circle overlap, return a push-out
vector that can be used to extract them from each other.