Struct vek::geom::repr_c::Rect
[−]
[src]
pub struct Rect<P, E> { pub x: P, pub y: P, pub w: E, pub h: E, }
2D rectangle, represented by a bottom-left position, and 2D extents.
Most operations on a Rect
are better done by converting it to
Aabr
form. In fact, most existing code in the wild implicitly does this
and so does this crate.
Aabr
structs are often more convenient, faster and probably less confusing.
The Rect
type is provided because it exists for a lot of APIs (including
some system APIs, OpenGL, and others).
Please note that in most APIs in the wild (but NOT in vek
), the Y axis
is treated as pointing downwards because it's the one of window space.
Keeping the Y axis upwards is a lot more convenient implementation-wise, and still matches the convention used in 3D spaces.
Fields
x: P
X position of the bottom-left corner.
y: P
Y position of the bottom-left corner.
w: E
Width.
h: E
Height, with Y axis going upwards.
Methods
impl<P, E> Rect<P, E>
[src]
fn new(x: P, y: P, w: E, h: E) -> Self
[src]
Creates a new rectangle from position elements and extent elements.
fn position(self) -> Vec2<P>
[src]
Gets this rectangle's position.
fn extent(self) -> Extent2<E>
[src]
Gets this rectangle's extent (size).
fn position_extent(self) -> (Vec2<P>, Extent2<E>)
[src]
Gets this rectangle's position and extent (size).
fn map<DP, DE, PF, EF>(self, pf: PF, ef: EF) -> Rect<DP, DE> where
PF: FnMut(P) -> DP,
EF: FnMut(E) -> DE,
[src]
PF: FnMut(P) -> DP,
EF: FnMut(E) -> DE,
Returns this rectangle, converted with the given closures (one for position elements, the other for extent elements).
impl<T> Rect<T, T> where
T: Copy + Add<T, Output = T>,
[src]
T: Copy + Add<T, Output = T>,
fn into_aabr(self) -> Aabr<T>
[src]
Converts this into the matching axis-aligned bounding shape representation.
fn contains_point(self, p: Vec2<T>) -> bool where
T: PartialOrd,
[src]
T: PartialOrd,
Does this rectangle contain the given point ?
fn contains_rect(self, other: Self) -> bool where
T: PartialOrd,
[src]
T: PartialOrd,
Does this rectangle fully contain the given one ?
fn collides_with_rect(self, other: Self) -> bool where
T: PartialOrd,
[src]
T: PartialOrd,
Does this rectangle collide with another ?
fn center(self) -> Vec2<T> where
T: One + Div<T, Output = T>,
[src]
T: One + Div<T, Output = T>,
Gets this rectangle's center.
impl<T> Rect<T, T> where
T: Copy + PartialOrd + Sub<T, Output = T> + Add<T, Output = T>,
[src]
T: Copy + PartialOrd + Sub<T, Output = T> + Add<T, Output = T>,
fn expanded_to_contain_point(self, p: Vec2<T>) -> Self where
T: PartialOrd,
[src]
T: PartialOrd,
Returns this shape so that it contains the given point.
fn expand_to_contain_point(&mut self, p: Vec2<T>) where
T: PartialOrd,
[src]
T: PartialOrd,
Expands this shape so that it contains the given point.
fn union(self, other: Self) -> Self
[src]
Gets the smallest rectangle that contains both this one and another.
fn intersection(self, other: Self) -> Self
[src]
Gets the largest rectangle contained by both this one and another.
fn expand_to_contain(&mut self, other: Self)
[src]
Sets this rectangle to the union of itself with another.
fn intersect(&mut self, other: Self)
[src]
Sets this rectangle to the intersection of itself with another.
fn collision_vector_with_rect(self, other: Self) -> Vec2<T> where
T: One + Div<T, Output = T>,
[src]
T: One + Div<T, Output = T>,
Gets a vector that tells how much self
penetrates other
.
fn split_at_x(self, sp: T) -> (Self, Self)
[src]
Splits this shape in two, by a straight plane along the
axis.
The returned tuple is (low, high)
.
Panics
sp
is assumed to be a position along the
axis that is within this shape's bounds.
fn split_at_y(self, sp: T) -> (Self, Self)
[src]
Splits this shape in two, by a straight plane along the
axis.
The returned tuple is (low, high)
.
Panics
sp
is assumed to be a position along the
axis that is within this shape's bounds.
Trait Implementations
impl<P: Debug, E: Debug> Debug for Rect<P, E>
[src]
impl<P: Default, E: Default> Default for Rect<P, E>
[src]
impl<P: Clone, E: Clone> Clone for Rect<P, E>
[src]
fn clone(&self) -> Rect<P, E>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<P: Copy, E: Copy> Copy for Rect<P, E>
[src]
impl<P: Hash, E: Hash> Hash for Rect<P, E>
[src]
fn hash<__HPE: Hasher>(&self, __arg_0: &mut __HPE)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<P: Eq, E: Eq> Eq for Rect<P, E>
[src]
impl<P: PartialEq, E: PartialEq> PartialEq for Rect<P, E>
[src]
fn eq(&self, __arg_0: &Rect<P, E>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Rect<P, E>) -> bool
[src]
This method tests for !=
.
impl<P, E> From<(Vec2<P>, Extent2<E>)> for Rect<P, E>
[src]
impl<T> From<Aabr<T>> for Rect<T, T> where
T: Copy + Sub<T, Output = T>,
[src]
T: Copy + Sub<T, Output = T>,