pub struct Rect<T> { /* private fields */ }Expand description
A generic rectangle structure.
Implementations§
Source§impl<T> Rect<T>
 
impl<T> Rect<T>
Sourcepub fn new(left: T, top: T, width: T, height: T) -> Rect<T>
 
pub fn new(left: T, top: T, width: T, height: T) -> Rect<T>
Returns a new rectangle with the supplied position and dimensions.
Sourcepub fn from_points(top_left: Point<T>, bottom_right: Point<T>) -> Rect<T>
 
pub fn from_points(top_left: Point<T>, bottom_right: Point<T>) -> Rect<T>
Returns a new rectangle with the given top-left and bottom-right points.
Sourcepub fn bottom_right(&self) -> Point<T>
 
pub fn bottom_right(&self) -> Point<T>
Returns a copy of the bottom-right point of the rectangle.
Sourcepub fn contains(&self, point: Point<T>) -> bool
 
pub fn contains(&self, point: Point<T>) -> bool
Returns true if the given point lies within the bounds of the rectangle,
and false otherwise.
Sourcepub fn intersect(&self, other: &Rect<T>) -> Option<Rect<T>>
 
pub fn intersect(&self, other: &Rect<T>) -> Option<Rect<T>>
If self and other intersect, then the intersection of the two rectangles
is returned as a new rectangle, otherwise None is returned.
Sourcepub fn split_column_mut(&mut self, col: T) -> Rect<T>
 
pub fn split_column_mut(&mut self, col: T) -> Rect<T>
Splits the rectangle at the given column col. The right side of the left part
of the resulting split will be at col - 1, and the left side of the right part
will be at col. The current rectangle will be modified in-place to be the left
part, and the right part will be returned as a new rectangle.
§Examples
use geom::Rect;
let mut r = Rect::new(0, 0, 10, 10);
let s = r.split_column_mut(5);
assert_eq!(r.top(), 0);
assert_eq!(r.left(), 0);
assert_eq!(r.bottom(), 9);
assert_eq!(r.right(), 4);
assert_eq!(s.top(), 0);
assert_eq!(s.left(), 5);
assert_eq!(s.bottom(), 9);
assert_eq!(s.right(), 9);Sourcepub fn split_row_mut(&mut self, row: T) -> Rect<T>
 
pub fn split_row_mut(&mut self, row: T) -> Rect<T>
Splits the rectangle at the given row row. The bottom side of the top part
of the resulting split will be at row - 1, and the top side of the bottom part
will be at row. The current rectangle will be modified in-place to be the top
part, and the bottom part will be returned as a new rectangle.
§Examples
use geom::Rect;
let mut r = Rect::new(0, 0, 10, 10);
let s = r.split_row_mut(5);
assert_eq!(r.top(), 0);
assert_eq!(r.left(), 0);
assert_eq!(r.bottom(), 4);
assert_eq!(r.right(), 9);
assert_eq!(s.top(), 5);
assert_eq!(s.left(), 0);
assert_eq!(s.bottom(), 9);
assert_eq!(s.right(), 9);