orbtk_utils

Struct Rectangle

Source
pub struct Rectangle { /* private fields */ }
Expand description

A Rectangle is normally expressed as a top-left corner and a size

§Examples

let rectangle = Rectangle::new((0., 5.),(10., 7.));

assert_eq!(rectangle.x(), 0.);
assert_eq!(rectangle.y(), 5.);
assert_eq!(rectangle.width(), 10.);
assert_eq!(rectangle.height(), 7.);

Implementations§

Source§

impl Rectangle

Source

pub fn new(position: impl Into<Point>, size: impl Into<Size>) -> Self

Create a new rectangle with the given parameters.

Source

pub fn x(&self) -> f64

Gets x coordiante.

Source

pub fn set_x(&mut self, x: impl Into<f64>)

Sets x coordinate.

Source

pub fn y(&self) -> f64

Gets y coordinate.

Source

pub fn set_y(&mut self, y: impl Into<f64>)

Sets y coordinate.

Source

pub fn position(&self) -> Point

Gets position as Point.

Source

pub fn set_position(&mut self, position: impl Into<Point>)

Sets position.

Source

pub fn width(&self) -> f64

Gets the width.

Source

pub fn set_width(&mut self, width: impl Into<f64>)

Sets the width.

Source

pub fn height(&self) -> f64

Gets the height.

Source

pub fn set_height(&mut self, height: impl Into<f64>)

Sets the height.

Source

pub fn size(&self) -> Size

Gets the size with width and height.

Source

pub fn set_size(&mut self, width: impl Into<f64>, height: impl Into<f64>)

Sets the size with width and height.

Source

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

Checks if this rect contains the given point.

Source

pub fn contains_rect(&self, rect: &Rectangle) -> bool

Checks if this rect contains the given rect.

Source

pub fn intersects(&self, rect: &Rectangle) -> bool

Checks if this rect intersects with the given rect.

Source

pub fn join_with_rectangle(&mut self, other: &Rectangle)

Joins this rectangle with another one, the result is a rectangle in which the two parents fit.

Source

pub fn join_with_point(&mut self, point: &Point)

Extends this rectangle to cover the given point.

Source

pub fn box_into(&mut self, container: Rectangle)

Box itself inside another rectangle

Trait Implementations§

Source§

impl Clone for Rectangle

Source§

fn clone(&self) -> Rectangle

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 Rectangle

Source§

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

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

impl Default for Rectangle

Source§

fn default() -> Rectangle

Returns the “default value” for a type. Read more
Source§

impl From<(Point, Size)> for Rectangle

Source§

fn from(t: (Point, Size)) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(t: (f64, f64, f64, f64)) -> Self

Converts to this type from the input type.
Source§

impl From<(i32, i32, i32, i32)> for Rectangle

Source§

fn from(t: (i32, i32, i32, i32)) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Rectangle

Source§

fn eq(&self, other: &Rectangle) -> 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 Copy for Rectangle

Source§

impl StructuralPartialEq for Rectangle

Auto Trait Implementations§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.