pub struct Rectangle {
pub coordinate: Coordinate,
pub dimensions: Dimensions,
}Expand description
Rectangle defined by inclusive minimum and maximum coordinates.
let rectangle = Rectangle::from (((1, 2).into(), (5, 3).into()));
assert_eq!(rectangle.height(), 5);
assert_eq!(rectangle.width(), 3);
assert_eq!(rectangle.height(), rectangle.dimensions.rows);
assert_eq!(rectangle.width(), rectangle.dimensions.columns);
assert_eq!(rectangle.contains ((0, 0).into()), false);
assert_eq!(rectangle.contains ((4, 3).into()), true);Fields§
§coordinate: Coordinate§dimensions: DimensionsImplementations§
Source§impl Rectangle
impl Rectangle
pub const fn width(&self) -> usize
pub const fn height(&self) -> usize
pub const fn min(&self) -> Coordinate
Sourcepub const fn max(&self) -> Coordinate
pub const fn max(&self) -> Coordinate
Max is inclusive: this is the lower right corner element of the rectangle
pub const fn upper_left(&self) -> Coordinate
pub const fn upper_right(&self) -> Coordinate
pub const fn lower_right(&self) -> Coordinate
pub const fn lower_left(&self) -> Coordinate
pub fn row(&self, row: usize) -> Option<Self>
pub fn column(&self, column: usize) -> Option<Self>
Sourcepub fn contains(&self, _: Coordinate) -> bool
pub fn contains(&self, _: Coordinate) -> bool
Return true if the coordinate is between min and max (inclusive)
pub fn contains_rc(&self, row: usize, column: usize) -> bool
pub fn iter(&self) -> impl Iterator<Item = Coordinate>
Trait Implementations§
Source§impl From<(Coordinate, Dimensions)> for Rectangle
impl From<(Coordinate, Dimensions)> for Rectangle
Source§fn from((coordinate, dimensions): (Coordinate, Dimensions)) -> Self
fn from((coordinate, dimensions): (Coordinate, Dimensions)) -> Self
Converts to this type from the input type.
Source§impl From<Dimensions> for Rectangle
impl From<Dimensions> for Rectangle
Source§fn from(dimensions: Dimensions) -> Self
fn from(dimensions: Dimensions) -> Self
Converts to this type from the input type.
impl Eq for Rectangle
impl StructuralPartialEq for Rectangle
Auto Trait Implementations§
impl Freeze for Rectangle
impl RefUnwindSafe for Rectangle
impl Send for Rectangle
impl Sync for Rectangle
impl Unpin for Rectangle
impl UnwindSafe for Rectangle
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
Mutably borrows from an owned value. Read more