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
impl Shape
Constructors
pub fn new(width: u32, height: u32) -> Self
Sourcepub fn from_square(side: u32) -> Self
pub fn from_square(side: u32) -> Self
Creates a square shape with equal width and height.
Sourcepub fn from_rectangle(width: u32, height: u32) -> Self
pub fn from_rectangle(width: u32, height: u32) -> Self
Creates a rectangular shape from width and height.
Sourcepub fn from_bounds(start: Coordinates, end: Coordinates) -> Self
pub fn from_bounds(start: Coordinates, end: Coordinates) -> Self
Creates a shape that covers the area between two coordinates.
Sourcepub fn bounding_shape(shapes: &[Self]) -> Self
pub fn bounding_shape(shapes: &[Self]) -> Self
Computes the smallest shape that can encompass all given shapes.
Source§impl Shape
Core utilities
impl Shape
Core utilities
Sourcepub fn union(&self, other: Shape) -> Self
pub fn union(&self, other: Shape) -> Self
Computes the union of two shapes by taking the max of each dimension.
Sourcepub fn in_bounds(&self, coordinates: Coordinates) -> bool
pub fn in_bounds(&self, coordinates: Coordinates) -> bool
Checks if the given coordinates fall within the shape.
Sourcepub fn delta_in_bounds(&self, delta: Delta) -> bool
pub fn delta_in_bounds(&self, delta: Delta) -> bool
Checks if the given delta is within bounds (non-negative and smaller than shape).
Sourcepub fn offset_by(&self, offset: Coordinates) -> Self
pub fn offset_by(&self, offset: Coordinates) -> Self
Returns a new shape offset by the given coordinates.
Sourcepub fn expand_to_include(&mut self, offset: Coordinates, other: Shape)
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
impl Shape
Iteration and filtering
Sourcepub fn coordinates_in_range(
&self,
start: Coordinates,
end: Coordinates,
) -> Vec<Coordinates>
pub fn coordinates_in_range( &self, start: Coordinates, end: Coordinates, ) -> Vec<Coordinates>
Iterates through coordinates in a given range clamped by this shape.
Sourcepub fn filter_coordinates<F>(&self, filter_fn: F) -> Vec<Coordinates>
pub fn filter_coordinates<F>(&self, filter_fn: F) -> Vec<Coordinates>
Returns coordinates that satisfy a filter predicate.
Trait Implementations§
Source§impl Add<Coordinates> for Shape
Arithmetic with coordinates
impl Add<Coordinates> for Shape
Arithmetic with coordinates
Source§impl Add<Shape> for Coordinates
impl Add<Shape> for Coordinates
Source§fn add(self, shape: Shape) -> Coordinates
fn add(self, shape: Shape) -> Coordinates
Adds a Shape
(width, height) to the coordinate.
Source§type Output = Coordinates
type Output = Coordinates
+
operator.Source§impl Sub<Coordinates> for Shape
impl Sub<Coordinates> for Shape
Source§impl Sub<Shape> for Coordinates
impl Sub<Shape> for Coordinates
Source§fn sub(self, shape: Shape) -> Coordinates
fn sub(self, shape: Shape) -> Coordinates
Subtracts a Shape
(width, height) from the coordinate using saturating subtraction.
Source§type Output = Coordinates
type Output = Coordinates
-
operator.impl Copy for Shape
impl Eq for Shape
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.