pub struct Rect3<P, E> {
pub x: P,
pub y: P,
pub z: P,
pub w: E,
pub h: E,
pub d: E,
}
Expand description
A Rect
extended to 3D.
This would have been named Box
, but it was “taken” by the standard library already.
You should probably use Aabb
because it is less confusing.
See also Rect
for a short discussion on the topic.
Fields§
§x: P
X position of the bottom-left-near corner.
y: P
Y position of the bottom-left-near corner.
z: P
Z position of the bottom-left-near corner.
w: E
Width.
h: E
Height, with Y axis going upwards.
d: E
Depth, with Z axis going forwards.
Implementations§
source§impl<P, E> Rect3<P, E>
impl<P, E> Rect3<P, E>
sourcepub fn new(x: P, y: P, z: P, w: E, h: E, d: E) -> Self
pub fn new(x: P, y: P, z: P, w: E, h: E, d: E) -> Self
Creates a new rectangle from position elements and extent elements.
sourcepub fn position_extent(self) -> (Vec3<P>, Extent3<E>)
pub fn position_extent(self) -> (Vec3<P>, Extent3<E>)
Gets this rectangle’s position and extent (size).
sourcepub fn map<DP, DE, PF, EF>(self, pf: PF, ef: EF) -> Rect3<DP, DE>where
PF: FnMut(P) -> DP,
EF: FnMut(E) -> DE,
pub fn map<DP, DE, PF, EF>(self, pf: PF, ef: EF) -> Rect3<DP, DE>where
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).
sourcepub fn as_<DP, DE>(self) -> Rect3<DP, DE>where
P: AsPrimitive<DP>,
DP: 'static + Copy,
E: AsPrimitive<DE>,
DE: 'static + Copy,
pub fn as_<DP, DE>(self) -> Rect3<DP, DE>where
P: AsPrimitive<DP>,
DP: 'static + Copy,
E: AsPrimitive<DE>,
DE: 'static + Copy,
Converts this rectangle to a rectangle of another type, using the as
conversion.
source§impl<T> Rect3<T, T>where
T: Copy + Add<T, Output = T>,
impl<T> Rect3<T, T>where
T: Copy + Add<T, Output = T>,
sourcepub fn into_aabb(self) -> Aabb<T>
pub fn into_aabb(self) -> Aabb<T>
Converts this into the matching axis-aligned bounding shape representation.
sourcepub fn contains_point(self, p: Vec3<T>) -> boolwhere
T: PartialOrd,
pub fn contains_point(self, p: Vec3<T>) -> boolwhere
T: PartialOrd,
Does this rectangle contain the given point ?
sourcepub fn contains_rect3(self, other: Self) -> boolwhere
T: PartialOrd,
pub fn contains_rect3(self, other: Self) -> boolwhere
T: PartialOrd,
Does this rectangle fully contain the given one ?
sourcepub fn collides_with_rect3(self, other: Self) -> boolwhere
T: PartialOrd,
pub fn collides_with_rect3(self, other: Self) -> boolwhere
T: PartialOrd,
Does this rectangle collide with another ?
source§impl<T> Rect3<T, T>where
T: Copy + PartialOrd + Sub<T, Output = T> + Add<T, Output = T>,
impl<T> Rect3<T, T>where
T: Copy + PartialOrd + Sub<T, Output = T> + Add<T, Output = T>,
sourcepub fn expanded_to_contain_point(self, p: Vec3<T>) -> Selfwhere
T: PartialOrd,
pub fn expanded_to_contain_point(self, p: Vec3<T>) -> Selfwhere
T: PartialOrd,
Returns this shape so that it contains the given point.
sourcepub fn expand_to_contain_point(&mut self, p: Vec3<T>)where
T: PartialOrd,
pub fn expand_to_contain_point(&mut self, p: Vec3<T>)where
T: PartialOrd,
Expands this shape so that it contains the given point.
sourcepub fn union(self, other: Self) -> Self
pub fn union(self, other: Self) -> Self
Gets the smallest rectangle that contains both this one and another.
sourcepub fn intersection(self, other: Self) -> Self
pub fn intersection(self, other: Self) -> Self
Gets the largest rectangle contained by both this one and another.
sourcepub fn expand_to_contain(&mut self, other: Self)
pub fn expand_to_contain(&mut self, other: Self)
Sets this rectangle to the union of itself with another.
sourcepub fn intersect(&mut self, other: Self)
pub fn intersect(&mut self, other: Self)
Sets this rectangle to the intersection of itself with another.
sourcepub fn collision_vector_with_rect3(self, other: Self) -> Vec3<T>where
T: One + Div<T, Output = T>,
pub fn collision_vector_with_rect3(self, other: Self) -> Vec3<T>where
T: One + Div<T, Output = T>,
Gets a vector that tells how much self
penetrates other
.
sourcepub fn split_at_x(self, sp: T) -> [Self; 2]
pub fn split_at_x(self, sp: T) -> [Self; 2]
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.
sourcepub fn split_at_y(self, sp: T) -> [Self; 2]
pub fn split_at_y(self, sp: T) -> [Self; 2]
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.
sourcepub fn split_at_z(self, sp: T) -> [Self; 2]
pub fn split_at_z(self, sp: T) -> [Self; 2]
Splits this shape in two, by a straight plane along the
z
axis.
The returned tuple is (low, high)
.
Panics
sp
is assumed to be a position along the
z
axis that is within this shape’s bounds.