Struct Rect

Source
pub struct Rect<T> { /* private fields */ }
Expand description

A generic rectangle structure.

Implementations§

Source§

impl<T> Rect<T>
where T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,

Source

pub fn new(left: T, top: T, width: T, height: T) -> Rect<T>

Returns a new rectangle with the supplied position and dimensions.

Source

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.

Source

pub fn width(&self) -> T

Returns the width of the rectangle.

Source

pub fn height(&self) -> T

Returns the height of the rectangle.

Source

pub fn top_left(&self) -> Point<T>

Returns a copy of the top-left point of the rectangle.

Source

pub fn top(&self) -> T

Returns the y coordinate of the top side of the rectangle.

Source

pub fn left(&self) -> T

Returns the x coordinate of the left side of the rectangle.

Source

pub fn bottom_right(&self) -> Point<T>

Returns a copy of the bottom-right point of the rectangle.

Source

pub fn bottom(&self) -> T

Returns the y coordinate of the bottom side of the rectangle.

Source

pub fn right(&self) -> T

Returns the x coordinate of the right side of the rectangle.

Source

pub fn area(&self) -> T

Returns the area of the rectangle.

Source

pub fn contains(&self, point: Point<T>) -> bool

Returns true if the given point lies within the bounds of the rectangle, and false otherwise.

Source

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.

Source

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);
Source

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);
Source

pub fn columns(&self) -> Vec<Rect<T>>

Returns a Vec containing a one-width rectangle for each column of the rectangle.

Source

pub fn rows(&self) -> Vec<Rect<T>>

Returns a Vec containing a one-height rectangle for each row of the rectangle.

Source§

impl<T> Rect<T>
where T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Ord + One + Default + Copy + Clone,

Source

pub 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§

Source§

impl<T: Clone> Clone for Rect<T>

Source§

fn clone(&self) -> Rect<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Rect<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Hash> Hash for Rect<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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,

Source§

type Item = Point<T>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<T>

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for Rect<T>

Source§

fn eq(&self, other: &Rect<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy> Copy for Rect<T>

Source§

impl<T: Eq> Eq for Rect<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.