DynShape

Enum DynShape 

Source
pub enum DynShape<T> {
    Circle(Circle<T>),
    Triangle(Triangle<T>),
    Rect(Rect<T>),
    Quad(Quad<T>),
    Polygon(Polygon<T>),
}
Expand description

A circle, triangle, rect, quad, or polygon.

This itself implements Shape<T> and defers to each variant’s implementation of the trait’s methods.

This is convenient when you want lists of shapes that can be one of any of the variants, rather than all being the same. For example, colliders for entities in a core engine.

Variants§

§

Circle(Circle<T>)

§

Triangle(Triangle<T>)

§

Rect(Rect<T>)

§

Quad(Quad<T>)

§

Polygon(Polygon<T>)

Implementations§

Source§

impl<T: Float> DynShape<T>

Source

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

Returns true if this shape overlaps the other.

Source

pub fn extract_from(&self, other: &Self) -> Option<Vec2<T>>

If this shape overlaps the other, returns a push-out vector that can be used to translate it so they no longer overlap.

Source

pub fn hull_points(&self, circle_seg_len: T, plot: impl FnMut(Vec2<T>))

Plot the vertices of the shape. For polygons, it will be the vertices of the polygon, and for circles it will be CAP points distributed evenly along the circle’s radius.

Source

pub fn hull_points_n(&self, circle_count: T, plot: impl FnMut(Vec2<T>))

Plot the vertices of the shape.

Source

pub fn hull_edges(&self, circle_seg_len: T, plot: impl FnMut(Line<T>))

Plot the edges of the shape. For polygons, it will be the edges of the polygon, and for circles it will be CAP edgds distributed evenly along the circle’s radius.

Source

pub fn hull_edges_n(&self, circle_count: T, plot: impl FnMut(Line<T>))

Plot the edges of the shape. For polygons, it will be the edges of the polygon, and for circles it will be CAP edgds distributed evenly along the circle’s radius.

Source

pub fn transform_into( &self, into: &mut Self, circle_out: CircleOut<T>, rect_out: RectOut, f: impl FnMut(Vec2<T>) -> Vec2<T>, )

Trait Implementations§

Source§

impl<T: Clone> Clone for DynShape<T>

Source§

fn clone(&self) -> DynShape<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for DynShape<T>

Source§

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

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

impl<T> From<Circle<T>> for DynShape<T>

Source§

fn from(value: Circle<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Polygon<T>> for DynShape<T>

Source§

fn from(value: Polygon<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Quad<T>> for DynShape<T>

Source§

fn from(value: Quad<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Rect<T>> for DynShape<T>

Source§

fn from(value: Rect<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Triangle<T>> for DynShape<T>

Source§

fn from(value: Triangle<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> Shape<T> for DynShape<T>

Source§

fn centroid(&self) -> Vec2<T>

Centroid of the shape.
Source§

fn contains(&self, p: Vec2<T>) -> bool

If the point is contained within the shape.
Source§

fn bounds(&self) -> Rect<T>

Rectangular bounds of the shape.
Source§

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>

Project a point onto the outside surface of the shape.
Source§

fn rayhit(&self, ray: &Ray<T>) -> bool

Check if a ray intersects this shape.
Source§

fn raycast(&self, ray: &Ray<T>) -> Option<RayHit<T>>

Raycast against the shape.
Source§

fn overlaps_rect(&self, rect: &Rect<T>) -> bool

If this shape overlaps the rectangle.
Source§

fn overlaps_circ(&self, circ: &Circle<T>) -> bool

If this shape overlaps the circle.
Source§

fn overlaps_poly<P: Polygonal<T>>(&self, poly: &P) -> bool

If this shape overlaps the polygon.
Source§

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.
Source§

fn extract_from_poly<P: Polygonal<T>>(&self, poly: &P) -> Option<Vec2<T>>

If this shape and the polygon overlap, return a push-out vector that can be used to extract them from each other.
Source§

fn is_convex(&self) -> bool

If this shape is convex.

Auto Trait Implementations§

§

impl<T> Freeze for DynShape<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for DynShape<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for DynShape<T>
where T: Unpin,

§

impl<T> UnwindSafe for DynShape<T>
where T: UnwindSafe,

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.