Struct Shape

Source
pub struct Shape {
    pub width: u32,
    pub height: u32,
}
Expand description

Represents a rectangular area by its width and height.

Fields§

§width: u32§height: u32

Implementations§

Source§

impl Shape

Constructors

Source

pub fn new(width: u32, height: u32) -> Self

Source

pub fn from_square(side: u32) -> Self

Creates a square shape with equal width and height.

Source

pub fn from_rectangle(width: u32, height: u32) -> Self

Creates a rectangular shape from width and height.

Source

pub fn from_bounds(start: Coordinates, end: Coordinates) -> Self

Creates a shape that covers the area between two coordinates.

Source

pub fn bounding_shape(shapes: &[Self]) -> Self

Computes the smallest shape that can encompass all given shapes.

Source§

impl Shape

Core utilities

Source

pub fn union(&self, other: Shape) -> Self

Computes the union of two shapes by taking the max of each dimension.

Source

pub fn in_bounds(&self, coordinates: Coordinates) -> bool

Checks if the given coordinates fall within the shape.

Source

pub fn delta_in_bounds(&self, delta: Delta) -> bool

Checks if the given delta is within bounds (non-negative and smaller than shape).

Source

pub fn area(&self) -> u32

Returns the area (width * height) of this shape.

Source

pub fn offset_by(&self, offset: Coordinates) -> Self

Returns a new shape offset by the given coordinates.

Source

pub fn expand_to_include(&mut self, offset: Coordinates, other: Shape)

Expands this shape to include another shape placed at an offset.

Source§

impl Shape

Iteration and filtering

Source

pub fn coordinates_in_range( &self, start: Coordinates, end: Coordinates, ) -> Vec<Coordinates>

Iterates through coordinates in a given range clamped by this shape.

Source

pub fn filter_coordinates<F>(&self, filter_fn: F) -> Vec<Coordinates>
where F: FnMut(Coordinates, Shape) -> bool,

Returns coordinates that satisfy a filter predicate.

Trait Implementations§

Source§

impl Add<Coordinates> for Shape

Arithmetic with coordinates

Source§

type Output = Shape

The resulting type after applying the + operator.
Source§

fn add(self, coordinates: Coordinates) -> Shape

Performs the + operation. Read more
Source§

impl Add<Shape> for Coordinates

Source§

fn add(self, shape: Shape) -> Coordinates

Adds a Shape (width, height) to the coordinate.

Source§

type Output = Coordinates

The resulting type after applying the + operator.
Source§

impl Add<u32> for Shape

Arithmetic with scalar values

Source§

type Output = Shape

The resulting type after applying the + operator.
Source§

fn add(self, value: u32) -> Shape

Performs the + operation. Read more
Source§

impl Add for Shape

Arithmetic operations between Shapes

Source§

type Output = Shape

The resulting type after applying the + operator.
Source§

fn add(self, other: Shape) -> Shape

Performs the + operation. Read more
Source§

impl Clone for Shape

Source§

fn clone(&self) -> Shape

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 Shape

Source§

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

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

impl Default for Shape

Source§

fn default() -> Shape

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

impl Div<u32> for Shape

Allows dividing the dimensions of a shape by a scalar.

Source§

type Output = Shape

The resulting type after applying the / operator.
Source§

fn div(self, divisor: u32) -> Shape

Performs the / operation. Read more
Source§

impl PartialEq for Shape

Source§

fn eq(&self, other: &Shape) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<Coordinates> for Shape

Source§

type Output = Shape

The resulting type after applying the - operator.
Source§

fn sub(self, coordinates: Coordinates) -> Shape

Performs the - operation. Read more
Source§

impl Sub<Shape> for Coordinates

Source§

fn sub(self, shape: Shape) -> Coordinates

Subtracts a Shape (width, height) from the coordinate using saturating subtraction.

Source§

type Output = Coordinates

The resulting type after applying the - operator.
Source§

impl Sub<u32> for Shape

Source§

type Output = Shape

The resulting type after applying the - operator.
Source§

fn sub(self, value: u32) -> Shape

Performs the - operation. Read more
Source§

impl Sub for Shape

Source§

type Output = Shape

The resulting type after applying the - operator.
Source§

fn sub(self, other: Shape) -> Shape

Performs the - operation. Read more
Source§

impl Copy for Shape

Source§

impl Eq for Shape

Source§

impl StructuralPartialEq for Shape

Auto Trait Implementations§

§

impl Freeze for Shape

§

impl RefUnwindSafe for Shape

§

impl Send for Shape

§

impl Sync for Shape

§

impl Unpin for Shape

§

impl UnwindSafe for Shape

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.