Struct vek::geom::repr_c::Rect [−][src]
pub struct Rect<P, E> { pub x: P, pub y: P, pub w: E, pub h: E, }
Expand description
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
Expand description
X position of the bottom-left corner.
y: P
Expand description
Y position of the bottom-left corner.
w: E
Expand description
Width.
h: E
Expand description
Height, with Y axis going upwards.
Implementations
impl<P, E> Rect<P, E>
[src]
impl<P, E> Rect<P, E>
[src]pub fn new(x: P, y: P, w: E, h: E) -> Self
[src]
pub fn new(x: P, y: P, w: E, h: E) -> Self
[src]Creates a new rectangle from position elements and extent elements.
pub fn position_extent(self) -> (Vec2<P>, Extent2<E>)
[src]
pub fn position_extent(self) -> (Vec2<P>, Extent2<E>)
[src]Gets this rectangle’s position and extent (size).
pub fn map<DP, DE, PF, EF>(self, pf: PF, ef: EF) -> Rect<DP, DE> where
PF: FnMut(P) -> DP,
EF: FnMut(E) -> DE,
[src]
pub fn map<DP, DE, PF, EF>(self, pf: PF, ef: EF) -> Rect<DP, DE> where
PF: FnMut(P) -> DP,
EF: FnMut(E) -> DE,
[src]Returns this rectangle, converted with the given closures (one for position elements, the other for extent elements).
pub fn as_<DP, DE>(self) -> Rect<DP, DE> where
P: AsPrimitive<DP>,
DP: 'static + Copy,
E: AsPrimitive<DE>,
DE: 'static + Copy,
[src]
pub fn as_<DP, DE>(self) -> Rect<DP, DE> where
P: AsPrimitive<DP>,
DP: 'static + Copy,
E: AsPrimitive<DE>,
DE: 'static + Copy,
[src]Converts this rectangle to a rectangle of another type, using the as
conversion.
impl<T> Rect<T, T> where
T: Copy + Add<T, Output = T>,
[src]
impl<T> Rect<T, T> where
T: Copy + Add<T, Output = T>,
[src]pub fn into_aabr(self) -> Aabr<T>
[src]
pub fn into_aabr(self) -> Aabr<T>
[src]Converts this into the matching axis-aligned bounding shape representation.
pub fn contains_point(self, p: Vec2<T>) -> bool where
T: PartialOrd,
[src]
pub fn contains_point(self, p: Vec2<T>) -> bool where
T: PartialOrd,
[src]Does this rectangle contain the given point ?
pub fn contains_rect(self, other: Self) -> bool where
T: PartialOrd,
[src]
pub fn contains_rect(self, other: Self) -> bool where
T: PartialOrd,
[src]Does this rectangle fully contain the given one ?
pub fn collides_with_rect(self, other: Self) -> bool where
T: PartialOrd,
[src]
pub fn collides_with_rect(self, other: Self) -> bool where
T: PartialOrd,
[src]Does this rectangle collide with another ?
impl<T> Rect<T, T> where
T: Copy + PartialOrd + Sub<T, Output = T> + Add<T, Output = T>,
[src]
impl<T> Rect<T, T> where
T: Copy + PartialOrd + Sub<T, Output = T> + Add<T, Output = T>,
[src]pub fn expanded_to_contain_point(self, p: Vec2<T>) -> Self where
T: PartialOrd,
[src]
pub fn expanded_to_contain_point(self, p: Vec2<T>) -> Self where
T: PartialOrd,
[src]Returns this shape so that it contains the given point.
pub fn expand_to_contain_point(&mut self, p: Vec2<T>) where
T: PartialOrd,
[src]
pub fn expand_to_contain_point(&mut self, p: Vec2<T>) where
T: PartialOrd,
[src]Expands this shape so that it contains the given point.
pub fn union(self, other: Self) -> Self
[src]
pub fn union(self, other: Self) -> Self
[src]Gets the smallest rectangle that contains both this one and another.
pub fn intersection(self, other: Self) -> Self
[src]
pub fn intersection(self, other: Self) -> Self
[src]Gets the largest rectangle contained by both this one and another.
pub fn expand_to_contain(&mut self, other: Self)
[src]
pub fn expand_to_contain(&mut self, other: Self)
[src]Sets this rectangle to the union of itself with another.
pub fn intersect(&mut self, other: Self)
[src]
pub fn intersect(&mut self, other: Self)
[src]Sets this rectangle to the intersection of itself with another.
pub fn collision_vector_with_rect(self, other: Self) -> Vec2<T> where
T: One + Div<T, Output = T>,
[src]
pub fn collision_vector_with_rect(self, other: Self) -> Vec2<T> where
T: One + Div<T, Output = T>,
[src]Gets a vector that tells how much self
penetrates other
.
pub fn split_at_x(self, sp: T) -> [Self; 2]
[src]
pub fn split_at_x(self, sp: T) -> [Self; 2]
[src]Splits this shape in two, by a straight plane along the
x
axis.
The returned tuple is (low, high)
.
Panics
sp
is assumed to be a position along the
x
axis that is within this shape’s bounds.
pub fn split_at_y(self, sp: T) -> [Self; 2]
[src]
pub fn split_at_y(self, sp: T) -> [Self; 2]
[src]Splits this shape in two, by a straight plane along the
y
axis.
The returned tuple is (low, high)
.
Panics
sp
is assumed to be a position along the
y
axis that is within this shape’s bounds.
Trait Implementations
impl<'de, P, E> Deserialize<'de> for Rect<P, E> where
P: Deserialize<'de>,
E: Deserialize<'de>,
[src]
impl<'de, P, E> Deserialize<'de> for Rect<P, E> where
P: Deserialize<'de>,
E: Deserialize<'de>,
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl<P: Copy, E: Copy> Copy for Rect<P, E>
[src]
impl<P: Eq, E: Eq> Eq for Rect<P, E>
[src]
impl<P, E> StructuralEq for Rect<P, E>
[src]
impl<P, E> StructuralPartialEq for Rect<P, E>
[src]
Auto Trait Implementations
impl<P, E> RefUnwindSafe for Rect<P, E> where
E: RefUnwindSafe,
P: RefUnwindSafe,
E: RefUnwindSafe,
P: RefUnwindSafe,
impl<P, E> Send for Rect<P, E> where
E: Send,
P: Send,
E: Send,
P: Send,
impl<P, E> Sync for Rect<P, E> where
E: Sync,
P: Sync,
E: Sync,
P: Sync,
impl<P, E> Unpin for Rect<P, E> where
E: Unpin,
P: Unpin,
E: Unpin,
P: Unpin,
impl<P, E> UnwindSafe for Rect<P, E> where
E: UnwindSafe,
P: UnwindSafe,
E: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,