Skip to main content

FixedRing

Struct FixedRing 

Source
pub struct FixedRing<const N: usize> { /* private fields */ }
Expand description

A fixed-capacity closed ring backed by an inline array.

The ring is implicitly closed: the edge from vertices[len-1] back to vertices[0] is always present when the ring has 3+ vertices.

Implementations§

Source§

impl<const N: usize> FixedRing<N>

Source

pub fn new() -> Self

Creates an empty FixedRing.

Source

pub fn push(&mut self, p: Point2D) -> Result<(), NoAllocError>

Attempts to append a vertex. Returns Ok(()) on success or Err(NoAllocError::CapacityExceeded) if the ring is full.

Source

pub fn len(&self) -> usize

Returns the number of vertices.

Source

pub fn is_empty(&self) -> bool

Returns true if the ring has no vertices.

Source

pub fn vertices(&self) -> &[Point2D]

Returns a slice of the current vertices.

Source

pub fn get(&self, index: usize) -> Option<&Point2D>

Returns the vertex at the given index, or None if out of bounds.

Source

pub fn signed_area(&self) -> f64

Computes the signed area using the shoelace formula.

Positive for counter-clockwise winding, negative for clockwise. Returns 0.0 if the ring has fewer than 3 vertices.

Source

pub fn area(&self) -> f64

Computes the absolute area using the shoelace formula.

Source

pub fn is_counter_clockwise(&self) -> bool

Returns true if the ring’s vertices are ordered counter-clockwise.

A ring with fewer than 3 vertices is considered neither CW nor CCW and returns false.

Source

pub fn is_clockwise(&self) -> bool

Returns true if the ring’s vertices are ordered clockwise.

Source

pub fn contains_point(&self, p: Point2D) -> bool

Tests whether a point lies inside or on the boundary of the ring using the ray-casting algorithm.

A horizontal ray from the point toward +X is tested against each edge of the ring. An odd number of crossings means the point is inside.

Returns false for rings with fewer than 3 vertices.

Source

pub fn perimeter(&self) -> f64

Computes the perimeter (sum of edge lengths including the closing edge).

Returns 0.0 for rings with fewer than 2 vertices.

Source

pub const fn capacity(&self) -> usize

Returns the capacity of this ring.

Source

pub fn clear(&mut self)

Clears all vertices, resetting the length to zero.

Trait Implementations§

Source§

impl<const N: usize> Default for FixedRing<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for FixedRing<N>

§

impl<const N: usize> RefUnwindSafe for FixedRing<N>

§

impl<const N: usize> Send for FixedRing<N>

§

impl<const N: usize> Sync for FixedRing<N>

§

impl<const N: usize> Unpin for FixedRing<N>

§

impl<const N: usize> UnsafeUnpin for FixedRing<N>

§

impl<const N: usize> UnwindSafe for FixedRing<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> 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, 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.