pub struct Rect<T = i32>(/* private fields */);
Expand description
A Rectangle
positioned at (x, y)
with width
and height
. A square is a Rectangle
where
width
and height
are equal.
Please see the module-level documentation for examples.
Implementations§
Source§impl<T: Copy> Rect<T>
impl<T: Copy> Rect<T>
Sourcepub fn coords(&self) -> [T; 4]
pub fn coords(&self) -> [T; 4]
Returns Rect
coordinates as [x, y, width, height]
.
§Example
let r = rect!(5, 10, 100, 100);
assert_eq!(r.coords(), [5, 10, 100, 100]);
Sourcepub fn coords_mut(&mut self) -> &mut [T; 4]
pub fn coords_mut(&mut self) -> &mut [T; 4]
Returns Rect
coordinates as a mutable slice &mut [x, y, width, height]
.
§Example
let mut r = rect!(5, 10, 100, 100);
for p in r.coords_mut() {
*p += 5;
}
assert_eq!(r.coords(), [10, 15, 105, 105]);
Sourcepub fn set_height(&mut self, height: T)
pub fn set_height(&mut self, height: T)
Sets the height
of the rectangle.
Source§impl<T: Num> Rect<T>
impl<T: Num> Rect<T>
Sourcepub fn with_position<P: Into<Point<T>>>(p: P, width: T, height: T) -> Self
pub fn with_position<P: Into<Point<T>>>(p: P, width: T, height: T) -> Self
Constructs a Rect
at position Point with width
and height
.
Sourcepub fn square_with_position<P: Into<Point<T>>>(p: P, size: T) -> Self
pub fn square_with_position<P: Into<Point<T>>>(p: P, size: T) -> Self
Constructs a square Rect
at position Point with size
.
Sourcepub fn with_points<P: Into<Point<T>>>(p1: P, p2: P) -> Self
pub fn with_points<P: Into<Point<T>>>(p1: P, p2: P) -> Self
Sourcepub fn from_center<P: Into<Point<T>>>(p: P, width: T, height: T) -> Self
pub fn from_center<P: Into<Point<T>>>(p: P, width: T, height: T) -> Self
Constructs a Rect
centered at position (x, y)
with width
and height
.
§Example
let r = Rect::from_center([50, 50], 100, 100);
assert_eq!(r.coords(), [0, 0, 100, 100]);
Sourcepub fn square_from_center<P: Into<Point<T>>>(p: P, size: T) -> Self
pub fn square_from_center<P: Into<Point<T>>>(p: P, size: T) -> Self
Constructs a square Rect
centered at position (x, y)
with size
.
§Example
let s = Rect::square_from_center([50, 50], 100);
assert_eq!(s.coords(), [0, 0, 100, 100]);
Sourcepub fn reposition(&self, x: T, y: T) -> Self
pub fn reposition(&self, x: T, y: T) -> Self
Reposition the the rectangle.
Sourcepub fn offset<P>(&self, offsets: P) -> Self
pub fn offset<P>(&self, offsets: P) -> Self
Offsets a rectangle by shifting coordinates by given amount.
Sourcepub fn offset_size<P>(&self, offsets: P) -> Self
pub fn offset_size<P>(&self, offsets: P) -> Self
Offsets a rectangle’s size by shifting coordinates by given amount.
Sourcepub fn set_bottom(&mut self, bottom: T)
pub fn set_bottom(&mut self, bottom: T)
Set the vertical position of the bottom edge.
Sourcepub fn bottom_left(&self) -> Point<T>
pub fn bottom_left(&self) -> Point<T>
Returns the bottom-left position as Point.
Sourcepub fn bottom_right(&self) -> Point<T>
pub fn bottom_right(&self) -> Point<T>
Returns the bottom-right position as Point.
Source§impl<T> Rect<T>
impl<T> Rect<T>
Sourcepub fn as_<U>(&self) -> Rect<U>where
U: 'static + Copy,
T: AsPrimitive<U>,
pub fn as_<U>(&self) -> Rect<U>where
U: 'static + Copy,
T: AsPrimitive<U>,
Converts Rect < T > to Rect < U >.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Rect<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Rect<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: Default> FromIterator<T> for Rect<T>
impl<T: Default> FromIterator<T> for Rect<T>
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Source§impl<'a, T> IntoIterator for &'a Rect<T>
impl<'a, T> IntoIterator for &'a Rect<T>
Source§impl<'a, T> IntoIterator for &'a mut Rect<T>
impl<'a, T> IntoIterator for &'a mut Rect<T>
Source§impl<T> IntoIterator for Rect<T>
impl<T> IntoIterator for Rect<T>
impl<T: Copy> Copy for Rect<T>
impl<T: Eq> Eq for Rect<T>
impl<T> StructuralPartialEq for Rect<T>
Auto Trait Implementations§
impl<T> Freeze for Rect<T>where
T: Freeze,
impl<T> RefUnwindSafe for Rect<T>where
T: RefUnwindSafe,
impl<T> Send for Rect<T>where
T: Send,
impl<T> Sync for Rect<T>where
T: Sync,
impl<T> Unpin for Rect<T>where
T: Unpin,
impl<T> UnwindSafe for Rect<T>where
T: UnwindSafe,
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.