pub struct Rect { /* private fields */ }
Expand description
A non-empty rectangle on the 2D grid.
Implementations
sourceimpl Rect
impl Rect
sourcepub fn from_point<T>(point: T) -> Rectwhere
T: Into<XY<usize>>,
pub fn from_point<T>(point: T) -> Rectwhere
T: Into<XY<usize>>,
Creates a new Rect
around a single point.
The size will be (1, 1)
.
sourcepub fn from_size<U, V>(top_left: U, size: V) -> Rectwhere
U: Into<XY<usize>>,
V: Into<XY<usize>>,
pub fn from_size<U, V>(top_left: U, size: V) -> Rectwhere
U: Into<XY<usize>>,
V: Into<XY<usize>>,
Creates a new Rect
with the given position and size.
The minimum size will (1, 1)
.
sourcepub fn from_corners<U, V>(a: U, b: V) -> Rectwhere
U: Into<XY<usize>>,
V: Into<XY<usize>>,
pub fn from_corners<U, V>(a: U, b: V) -> Rectwhere
U: Into<XY<usize>>,
V: Into<XY<usize>>,
Creates a new Rect
from two corners.
It can be any two opposite corners.
sourcepub fn expand_to<R>(&mut self, other: R)where
R: Into<Rect>,
pub fn expand_to<R>(&mut self, other: R)where
R: Into<Rect>,
Grow this rectangle if necessary to include other
.
sourcepub fn expanded_to<R>(self, other: R) -> Rectwhere
R: Into<Rect>,
pub fn expanded_to<R>(self, other: R) -> Rectwhere
R: Into<Rect>,
Returns a new rectangle that includes both self
and other
.
sourcepub fn side(self, orientation: Orientation) -> (usize, usize)
pub fn side(self, orientation: Orientation) -> (usize, usize)
Returns the start and end coordinate of one side of this rectangle.
Both start and end are inclusive.
sourcepub fn edge(self, side: Absolute) -> usize
pub fn edge(self, side: Absolute) -> usize
Returns the coordinate of the given edge.
All edges are inclusive.
sourcepub fn offset<V>(&mut self, offset: V)where
V: Into<XY<usize>>,
pub fn offset<V>(&mut self, offset: V)where
V: Into<XY<usize>>,
Adds the given offset to this rectangle.
sourcepub fn bottom_right(self) -> XY<usize>
pub fn bottom_right(self) -> XY<usize>
Returns the bottom-right corner.
This is inclusive.
sourcepub fn bottom_left(self) -> XY<usize>
pub fn bottom_left(self) -> XY<usize>
Returns the bottom-left corner.
This is inclusive.
sourcepub fn top(self) -> usize
pub fn top(self) -> usize
Returns the Y value of the top edge of the rectangle.
This is inclusive.
sourcepub fn left(self) -> usize
pub fn left(self) -> usize
Returns the X value of the left edge of the rectangle.
This is inclusive.
sourcepub fn right(self) -> usize
pub fn right(self) -> usize
Returns the X value of the right edge of the rectangle.
This is inclusive.
Trait Implementations
sourceimpl PartialEq<Rect> for Rect
impl PartialEq<Rect> for Rect
impl Copy for Rect
impl Eq for Rect
impl StructuralEq for Rect
impl StructuralPartialEq for Rect
Auto Trait Implementations
impl RefUnwindSafe for Rect
impl Send for Rect
impl Sync for Rect
impl Unpin for Rect
impl UnwindSafe for Rect
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more