Struct geom::rect::Rect
[−]
[src]
pub struct Rect<T> { /* fields omitted */ }
A generic rectangle structure.
Methods
impl<T> Rect<T> where
T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,
[src]
T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,
fn new(left: T, top: T, width: T, height: T) -> Rect<T>
Returns a new rectangle with the supplied position and dimensions.
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.
fn width(&self) -> T
Returns the width of the rectangle.
fn height(&self) -> T
Returns the height of the rectangle.
fn top_left(&self) -> Point<T>
Returns a copy of the top-left point of the rectangle.
fn top(&self) -> T
Returns the y
coordinate of the top side of the rectangle.
fn left(&self) -> T
Returns the x
coordinate of the left side of the rectangle.
fn bottom_right(&self) -> Point<T>
Returns a copy of the bottom-right point of the rectangle.
fn bottom(&self) -> T
Returns the y
coordinate of the bottom side of the rectangle.
fn right(&self) -> T
Returns the x
coordinate of the right side of the rectangle.
fn area(&self) -> T
Returns the area of the rectangle.
fn contains(&self, point: Point<T>) -> bool
Returns true
if the given point lies within the bounds of the rectangle,
and false
otherwise.
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.
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);
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);
fn columns(&self) -> Vec<Rect<T>>
Returns a Vec
containing a one-width rectangle for each column of the rectangle.
fn rows(&self) -> Vec<Rect<T>>
Returns a Vec
containing a one-height rectangle for each row of the rectangle.
impl<T> Rect<T> where
T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,
[src]
T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,
fn iter(&self) -> Iter<T>
Returns an iterator over each point in the rectangle, going from left-to-right and top-to-bottom.
Trait Implementations
impl<T: PartialEq> PartialEq for Rect<T>
[src]
fn eq(&self, __arg_0: &Rect<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Rect<T>) -> bool
This method tests for !=
.
impl<T: Eq> Eq for Rect<T>
[src]
impl<T: Copy> Copy for Rect<T>
[src]
impl<T: Clone> Clone for Rect<T>
[src]
fn clone(&self) -> Rect<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Debug> Debug for Rect<T>
[src]
impl<T: Hash> Hash for Rect<T>
[src]
fn hash<__HT: Hasher>(&self, __arg_0: &mut __HT)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> IntoIterator for Rect<T> where
T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,
[src]
T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,