Struct tree_layout::Rectangle

source ·
pub struct Rectangle<T> {
    pub min: Point<T>,
    pub max: Point<T>,
}
Expand description

A non-rotated rectangle, used to represent AABB collision boxes.

Notice

The constructor will not check the legality of the parameters, it is possible that two points coincide, or the side length is negative

Examples

let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);

Fields§

§min: Point<T>

origin x points of the rectangle

§max: Point<T>

origin y points of the rectangle

Implementations§

source§

impl<T> Rectangle<T>

Constructors for rectangle_2d

source

pub fn new(x: T, y: T, width: T, height: T) -> Rectangle<T>where T: Clone + Add<Output = T>,

Create a rectangle_2d from 4 properties

Notice

The constructor will not check the legality of the parameters, call [is_valid] to ensure that the rectangle_2d is legal.

Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
source

pub fn from_anchor<P>(origin: P, width: T, height: T) -> Rectangle<T>where T: Clone + Add<Output = T>, P: Into<Point<T>>,

Create a [Rectangle] from anchor (top left point) and 2 properties

Notice

The constructor will not check the legality of the parameters, call [is_valid] to ensure that the rectangle_2d is legal.

Examples
let rect = Rectangle::from_anchor((0.0, 0.0), 1.0, 1.0);
source

pub fn from_center<P>(center: P, width: T, height: T) -> Rectangle<T>where T: Clone + One + Add<Output = T> + Sub<Output = T> + Div<Output = T>, P: Into<Point<T>>,

Create a rectangle_2d from center and 2 properties

Notice

The constructor will not check the legality of the parameters, call [is_valid] to ensure that the rectangle_2d is legal.

Examples
let rect = Rectangle::from_center((0.0, 0.0), 1.0, 1.0);
source

pub fn from_origin(width: T, height: T) -> Rectangle<T>where T: Clone + Zero<Output = T> + One + Add + Sub<Output = T> + Div<Output = T>,

source

pub fn from_min_max<P1, P2>(min: P1, max: P2) -> Rectangle<T>where P1: Into<Point<T>>, P2: Into<Point<T>>,

Create a rectangle_2d from two diagonal points.

Notice

The constructor will not check the legality of the parameters, it is possible that two points coincide, or the side length is negative

Examples
let rect = Rectangle::from_min_max((0.0, 0.0), (1.0, 1.0));
source§

impl<T> Rectangle<T>

source

pub fn width(&self) -> Twhere T: Clone + Sub<Output = T>,

Get the width of the rectangle

Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert_eq!(rect.width(), 1.0);
source

pub fn height(&self) -> Twhere T: Clone + Sub<Output = T>,

Get the height of the rectangle

Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert_eq!(rect.height(), 1.0);
source

pub fn origin(&self) -> Point<T>where T: Clone,

Get the origin of the rectangle

Examples
let rect = Rectangle::from_center((0.0, 0.0), 1.0,1.0);
assert_eq!(rect.origin(), -Point::new(0.5, 0.5));
source

pub fn center(&self) -> Point<T>where T: Clone + One + Add<Output = T> + Sub<Output = T> + Div<Output = T>,

Get the center point of the rectangle

Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert_eq!(rect.center(), Point::new(0.5, 0.5));
source

pub fn ref_inner(&self) -> Rectangle<&T>

Move reference to the inner value

source

pub fn contains(&self, point: &Point<T>) -> boolwhere T: Clone + PartialOrd,

source

pub fn overlaps(&self, other: &Rectangle<T>) -> boolwhere T: Clone + PartialOrd,

Check if two rectangle had overlapped

source

pub fn area(&self) -> Twhere T: Clone + Mul<Output = T> + Sub<Output = T>,

Get the area of the rectangle

Examples
let rect = Rectangle::new(0.0, 0.0, 2.0, 2.0);
assert_eq!(rect.area(), 4.0);

Trait Implementations§

source§

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

source§

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

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<T> Debug for Rectangle<T>where T: Debug,

source§

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

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

impl<T> Display for Rectangle<T>where T: Display,

source§

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

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

impl<T> Hash for Rectangle<T>where T: Hash,

source§

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

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> PartialEq for Rectangle<T>where T: PartialEq,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Shape2D for Rectangle<T>where T: Signed + Clone + PartialOrd,

source§

fn is_valid(&self) -> bool

A valid rectangle means it has a positive area.

Examples
let rect = Rectangle::new(0.0, 0.0, 1.0, 1.0);
assert!(rect.is_valid());
source§

fn boundary(&self) -> Rectangle<<Rectangle<T> as Shape2D>::Value>

SAFETY

It may return a zero area rectangle if shape is not valid.

It never returns a rectangle with negative area.

Examples
let rect = Rectangle::new(0.0, 0.0, -1.0, -1.0);
assert_eq!(rect.boundary(), Rectangle::new(0.0,0.0, 1.0,1.0));
source§

fn vertices<'a>( &'a self, _: usize ) -> <Rectangle<T> as Shape2D>::VertexIterator<'a>

Returns four vertices counterclockwise in the ↑Y coordinate system

source§

fn edges<'a>(&'a self, _: usize) -> <Rectangle<T> as Shape2D>::LineIterator<'a>

Returns four edges counterclockwise in the ↑Y coordinate system

§

type Value = T

The value type of the shape.
§

type VertexIterator<'a> = IntoIter<Point<T>> where T: 'a

The value type of the shape.
§

type LineIterator<'a> = IntoIter<Line<T>> where T: 'a

The value type of the shape.
source§

fn normalize(&mut self) -> bool

Returns true if the shape successfully normalized.
source§

impl<T> Copy for Rectangle<T>where T: Copy,

source§

impl<T> Eq for Rectangle<T>where T: Eq,

source§

impl<T> StructuralEq for Rectangle<T>

source§

impl<T> StructuralPartialEq for Rectangle<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Rectangle<T>where T: RefUnwindSafe,

§

impl<T> Send for Rectangle<T>where T: Send,

§

impl<T> Sync for Rectangle<T>where T: Sync,

§

impl<T> Unpin for Rectangle<T>where T: Unpin,

§

impl<T> UnwindSafe for Rectangle<T>where T: UnwindSafe,

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.