[−][src]Trait vector2math::Rectangle
Trait for manipulating axis-aligned rectangles
Because the primary expected use for this crate is in 2D graphics and alignment implementations, a coordinate system where the positive Y direction is "down" is assumed.
Note
Methods of the form abs_
account for the case where the size if negative.
If the size is not negative, they are identical to their non-abs_
counterparts.
use vector2math::*; let pos_size = [1, 2, 3, 4]; assert_eq!(pos_size.right(), pos_size.abs_right()); let neg_size = [1, 2, -3, -4]; assert_ne!(neg_size.right(), neg_size.abs_right());
Associated Types
Loading content...Required methods
fn new(top_left: Self::Vector, size: Self::Vector) -> Self
Create a new rectangle from a top-left corner position and a size
fn top_left(self) -> Self::Vector
Get the top-left corner position
fn size(self) -> Self::Vector
Get the size
Provided methods
fn square(top_left: Self::Vector, side_length: Self::Scalar) -> Self
Create a new square from a top-left corner position and a side length
fn centered(center: Self::Vector, size: Self::Vector) -> Self
Create a new rectangle from a center position and a size
fn square_centered(center: Self::Vector, side_length: Self::Scalar) -> Self
Create a new square from a top-left corner position and a side length
fn map<R>(self) -> R where
R: Rectangle,
R::Scalar: From<Self::Scalar>,
R: Rectangle,
R::Scalar: From<Self::Scalar>,
Map this rectangle to a rectangle of another type
fn map_with<R, F>(self, f: F) -> R where
R: Rectangle,
F: FnMut(Self::Scalar) -> <<R as Rectangle>::Vector as Vector2>::Scalar,
R: Rectangle,
F: FnMut(Self::Scalar) -> <<R as Rectangle>::Vector as Vector2>::Scalar,
Map this rectangle to a rectangle of another type using a function
fn abs_size(self) -> Self::Vector
Get the absolute size
fn top_right(self) -> Self::Vector
Get the top-right corner position
fn bottom_left(self) -> Self::Vector
Get the bottom-left corner position
fn bottom_right(self) -> Self::Vector
Get the bottom-right corner position
fn abs_top_left(self) -> Self::Vector
Get the absolute top-left corner position
fn abs_top_right(self) -> Self::Vector
Get the absolute top-right corner position
fn abs_bottom_left(self) -> Self::Vector
Get the absolute bottom-left corner position
fn abs_bottom_right(self) -> Self::Vector
Get the absolute bottom-right corner position
fn top(self) -> Self::Scalar
Get the top y
fn bottom(self) -> Self::Scalar
Get the bottom y
fn left(self) -> Self::Scalar
Get the left x
fn right(self) -> Self::Scalar
Get the right x
fn abs_top(self) -> Self::Scalar
Get the absolute top y
fn abs_bottom(self) -> Self::Scalar
Get the absolute bottom y
fn abs_left(self) -> Self::Scalar
Get the absolute left x
fn abs_right(self) -> Self::Scalar
Get the absolute right x
fn width(self) -> Self::Scalar
Get the width
fn height(self) -> Self::Scalar
Get the height
fn abs_width(self) -> Self::Scalar
Get the absolute width
fn abs_height(self) -> Self::Scalar
Get the absolute height
fn center(self) -> Self::Vector
Get the position of the center
fn with_top_left(self, top_left: Self::Vector) -> Self
Transform the rectangle into one with a different top-left corner position
fn with_center(self, center: Self::Vector) -> Self
Transform the rectangle into one with a different center position
fn with_size(self, size: Self::Vector) -> Self
Transform the rectangle into one with a different size
fn perimeter(self) -> Self::Scalar
Get the perimeter
fn area(self) -> Self::Scalar
Get the area
fn translated(self, offset: Self::Vector) -> Self
Get the rectangle that is this one translated by some vector
fn scaled(self, scale: Self::Scalar) -> Self
Get the rectangle that is this one with a scalar-scaled size
fn scaled2(self, scale: Self::Vector) -> Self
Get the rectangle that is this one with a vector-scaled size
fn corners(self) -> IntoIter<Self::Vector>
Get an iterator over the rectangle's four corners
fn contains(self, point: Self::Vector) -> bool
Check that the rectangle contains the given point
fn contains_all<I>(self, points: I) -> bool where
I: IntoIterator<Item = Self::Vector>,
I: IntoIterator<Item = Self::Vector>,
Check that the rectangle contains all points
fn contains_any<I>(self, points: I) -> bool where
I: IntoIterator<Item = Self::Vector>,
I: IntoIterator<Item = Self::Vector>,
Check that the rectangle contains any point
Implementors
impl<P> Rectangle for P where
P: Pair + Copy,
P::Item: Vector2,
[src]
P: Pair + Copy,
P::Item: Vector2,
type Scalar = <P::Item as Vector2>::Scalar
type Vector = P::Item
fn new(top_left: Self::Vector, size: Self::Vector) -> Self
[src]
fn top_left(self) -> Self::Vector
[src]
fn size(self) -> Self::Vector
[src]
fn square(top_left: Self::Vector, side_length: Self::Scalar) -> Self
[src]
fn centered(center: Self::Vector, size: Self::Vector) -> Self
[src]
fn square_centered(center: Self::Vector, side_length: Self::Scalar) -> Self
[src]
fn map<R>(self) -> R where
R: Rectangle,
R::Scalar: From<Self::Scalar>,
[src]
R: Rectangle,
R::Scalar: From<Self::Scalar>,
fn map_with<R, F>(self, f: F) -> R where
R: Rectangle,
F: FnMut(Self::Scalar) -> <<R as Rectangle>::Vector as Vector2>::Scalar,
[src]
R: Rectangle,
F: FnMut(Self::Scalar) -> <<R as Rectangle>::Vector as Vector2>::Scalar,
fn abs_size(self) -> Self::Vector
[src]
fn top_right(self) -> Self::Vector
[src]
fn bottom_left(self) -> Self::Vector
[src]
fn bottom_right(self) -> Self::Vector
[src]
fn abs_top_left(self) -> Self::Vector
[src]
fn abs_top_right(self) -> Self::Vector
[src]
fn abs_bottom_left(self) -> Self::Vector
[src]
fn abs_bottom_right(self) -> Self::Vector
[src]
fn top(self) -> Self::Scalar
[src]
fn bottom(self) -> Self::Scalar
[src]
fn left(self) -> Self::Scalar
[src]
fn right(self) -> Self::Scalar
[src]
fn abs_top(self) -> Self::Scalar
[src]
fn abs_bottom(self) -> Self::Scalar
[src]
fn abs_left(self) -> Self::Scalar
[src]
fn abs_right(self) -> Self::Scalar
[src]
fn width(self) -> Self::Scalar
[src]
fn height(self) -> Self::Scalar
[src]
fn abs_width(self) -> Self::Scalar
[src]
fn abs_height(self) -> Self::Scalar
[src]
fn center(self) -> Self::Vector
[src]
fn with_top_left(self, top_left: Self::Vector) -> Self
[src]
fn with_center(self, center: Self::Vector) -> Self
[src]
fn with_size(self, size: Self::Vector) -> Self
[src]
fn perimeter(self) -> Self::Scalar
[src]
fn area(self) -> Self::Scalar
[src]
fn translated(self, offset: Self::Vector) -> Self
[src]
fn scaled(self, scale: Self::Scalar) -> Self
[src]
fn scaled2(self, scale: Self::Vector) -> Self
[src]
fn corners(self) -> IntoIter<Self::Vector>
[src]
fn contains(self, point: Self::Vector) -> bool
[src]
fn contains_all<I>(self, points: I) -> bool where
I: IntoIterator<Item = Self::Vector>,
[src]
I: IntoIterator<Item = Self::Vector>,
fn contains_any<I>(self, points: I) -> bool where
I: IntoIterator<Item = Self::Vector>,
[src]
I: IntoIterator<Item = Self::Vector>,