RKTK API Docs RKTK Home Repo

Shape2d

Enum Shape2d 

Source
pub enum Shape2d {
    Point(Vec2),
    Line {
        start: Vec2,
        end: Vec2,
        pixel_count: usize,
    },
    Grid {
        start: Vec2,
        horizontal_end: Vec2,
        vertical_end: Vec2,
        horizontal_pixel_count: usize,
        vertical_pixel_count: usize,
        serpentine: bool,
    },
    Arc {
        center: Vec2,
        axis_u: Vec2,
        axis_v: Vec2,
        start_angle_in_radians: f32,
        end_angle_in_radians: f32,
        pixel_count: usize,
    },
}
Expand description

Enumeration of two-dimensional shape primitives.

Each variant represents a different type of 2D arrangement of LEDs.

Variants§

§

Point(Vec2)

A single point at the specified location.

§

Line

A line of LEDs from start to end with pixel_count LEDs.

Fields

§start: Vec2

Starting point of the line

§end: Vec2

Ending point of the line

§pixel_count: usize

Number of LEDs along the line

§

Grid

A grid of LEDs defined by three corners and dimensions.

Fields

§start: Vec2

Starting point (origin) of the grid

§horizontal_end: Vec2

Ending point for first horizontal row (defines the horizontal axis)

§vertical_end: Vec2

Ending point for first vertical column (defines the vertical axis)

§horizontal_pixel_count: usize

Number of LEDs along each horizontal row

§vertical_pixel_count: usize

Number of LEDs along each vertical column

§serpentine: bool

Whether horizontal rows of LEDs are wired in a zigzag pattern

§

Arc

A circular or elliptical arc in 2D.

Parametric form:

point(theta) = center + cos(theta) * axis_u + sin(theta) * axis_v

Angle and direction:

  • Theta = 0 lies along axis_u (i.e. center + axis_u)
    • As theta increases, the point moves towards axis_v (counter-clockwise in the XY plane).
  • The arc is traced for theta in [start_angle_in_radians, end_angle_in_radians].
    • If end < start, the arc goes clockwise.
  • Positive angles are counter-clockwise.
  • To make a full ellipse, set end = start + TAU.

How to choose axis_u / axis_v:

  • Axis-aligned circle with with radius r:
    • axis_u = (r, 0)
    • axis_v = (0, r)
  • Axis-aligned ellipse with radii (rx, ry):
    • axis_u = (rx, 0)
    • axis_v = (0, ry)
  • Rotated by phi:
    • axis_u = ( rx * cos(phi), rx * sin(phi))
    • axis_v = ( -ry * sin(phi), ry * cos(phi))

Notes:

  • axis_u and axis_v must not both be zero.
  • axis_u and axis_v need not be unit length of perpendicular.
  • The points returned by shape::points() of a Shape2d::Arc:
    • Will have uniform density if a circular arc
    • Will not have uniform density if an elliptical arc, as the points correspond to theta.

Fields

§center: Vec2

Center of the ellipse

§axis_u: Vec2

Cosine-axis vector

§axis_v: Vec2

Sine-axis vector

§start_angle_in_radians: f32

Start angle in radians

§end_angle_in_radians: f32

End angle in radians

§pixel_count: usize

Number of LEDs

Implementations§

Source§

impl Shape2d

Source

pub const fn pixel_count(&self) -> usize

Returns the total number of pixels (LEDs) in this shape.

Source

pub fn points(&self) -> Shape2dPointsIterator

Returns an iterator over all points (LED positions) in this shape.

Trait Implementations§

Source§

impl Clone for Shape2d

Source§

fn clone(&self) -> Shape2d

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 Debug for Shape2d

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> FromColor<T> for T

Source§

fn from_color(color: T) -> T

Converts from the source color type
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> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Converts into the target color type
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
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.