Struct shapes::Rect

source ·
pub struct Rect {
    pub pos: Point,
    pub size: Size,
}
Expand description

A rectangle.

Fields§

§pos: Point

The position of the top left corner of the rectangle.

§size: Size

The width and height of the rectangle.

Implementations§

source§

impl Rect

source

pub fn bottom(&self) -> Scalar

Returns the position of the bottom side of the rectangle.

source

pub fn centered(self) -> Rect

Computes a rectangle with quadruple the surface area of self and with center (self.x, self.y).

source

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

Compute whether or not the point is inside the rectangle.

source

pub fn new_circle<T: Into<Point>>(center: T, radius: Scalar) -> Rect

Create a rectangle that circumscribes the given circle.

source

pub fn new_square<T: Into<Point>>(pos: T, len: Scalar) -> Rect

Create a square rectangle with sides of length len and top left corner at pos.

source

pub fn left(&self) -> Scalar

Returns the position of the left side of the rectangle.

source

pub fn margin(self, m: Scalar) -> Rect

Computes a rectangle whose perimeter forms the inside edge of margin with size m for self.

source

pub fn relative<T: Into<Point>>(self, v: T) -> Rect

Computes a rectangle translated (slid) in the direction of the vector a distance relative to the size of the rectangle. For example, self.relative([1.0, 1.0]) returns a rectangle one rectangle to the right and down from the original.

source

pub fn right(&self) -> Scalar

Returns the position of the right side of the rectangle.

source

pub fn scaled<T: Into<Size>>(self, v: T) -> Rect

Computes a scaled rectangle with the same position as self.

source

pub fn top(&self) -> Scalar

Returns the position of the top side of the rectangle.

Trait Implementations§

source§

impl Clone for Rect

source§

fn clone(&self) -> Rect

Returns a copy 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 Debug for Rect

source§

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

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

impl From<[f64; 4]> for Rect

source§

fn from(v: [Scalar; 4]) -> Rect

Creates a rectangle from an array.

source§

impl<P: Into<Point>, S: Into<Size>> From<(P, S)> for Rect

source§

fn from((pos, size): (P, S)) -> Rect

Creates a rectangle from the position of its top left corner and its size.

source§

impl From<(f64, f64, f64, f64)> for Rect

source§

fn from((x, y, w, h): (Scalar, Scalar, Scalar, Scalar)) -> Rect

Converts to this type from the input type.
source§

impl From<Rect> for [Scalar; 4]

source§

fn from(rect: Rect) -> [Scalar; 4]

Converts to this type from the input type.
source§

impl Copy 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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.