Skip to main content

Rect3

Struct Rect3 

Source
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>

Source

pub fn new(x: P, y: P, z: P, w: E, h: E, d: E) -> Rect3<P, E>

Creates a new rectangle from position elements and extent elements.

Source

pub fn position(self) -> Vec3<P>

Gets this rectangle’s position.

Source

pub fn set_position(&mut self, p: Vec3<P>)

Sets this rectangle’s position.

Source

pub fn extent(self) -> Extent3<E>

Gets this rectangle’s extent (size).

Source

pub fn set_extent(&mut self, e: Extent3<E>)

Sets this rectangle’s extent (size).

Source

pub fn position_extent(self) -> (Vec3<P>, Extent3<E>)

Gets this rectangle’s position and extent (size).

Source

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).

Source

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<Output = T>,

Source

pub fn into_aabb(self) -> Aabb<T>

Converts this into the matching axis-aligned bounding shape representation.

Source

pub fn contains_point(self, p: Vec3<T>) -> bool
where T: PartialOrd,

Does this rectangle contain the given point ?

Source

pub fn contains_rect3(self, other: Rect3<T, T>) -> bool
where T: PartialOrd,

Does this rectangle fully contain the given one ?

Source

pub fn collides_with_rect3(self, other: Rect3<T, T>) -> bool
where T: PartialOrd,

Does this rectangle collide with another ?

Source

pub fn center(self) -> Vec3<T>
where T: One + Div<Output = T>,

Gets this rectangle’s center.

Source§

impl<T> Rect3<T, T>
where T: PartialOrd + Sub<Output = T> + Add<Output = T> + Copy,

Source

pub fn expanded_to_contain_point(self, p: Vec3<T>) -> Rect3<T, T>
where T: PartialOrd,

Returns this shape so that it contains the given point.

Source

pub fn expand_to_contain_point(&mut self, p: Vec3<T>)
where T: PartialOrd,

Expands this shape so that it contains the given point.

Source

pub fn union(self, other: Rect3<T, T>) -> Rect3<T, T>

Gets the smallest rectangle that contains both this one and another.

Source

pub fn intersection(self, other: Rect3<T, T>) -> Rect3<T, T>

Gets the largest rectangle contained by both this one and another.

Source

pub fn expand_to_contain(&mut self, other: Rect3<T, T>)

Sets this rectangle to the union of itself with another.

Source

pub fn intersect(&mut self, other: Rect3<T, T>)

Sets this rectangle to the intersection of itself with another.

Source

pub fn collision_vector_with_rect3(self, other: Rect3<T, T>) -> Vec3<T>
where T: One + Div<Output = T>,

Gets a vector that tells how much self penetrates other.

Source

pub fn split_at_x(self, sp: T) -> [Rect3<T, T>; 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.

Source

pub fn split_at_y(self, sp: T) -> [Rect3<T, T>; 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.

Source

pub fn split_at_z(self, sp: T) -> [Rect3<T, T>; 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.

Trait Implementations§

Source§

impl<P, E> Clone for Rect3<P, E>
where P: Clone, E: Clone,

Source§

fn clone(&self) -> Rect3<P, E>

Returns a duplicate 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<P, E> Debug for Rect3<P, E>
where P: Debug, E: Debug,

Source§

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

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

impl<P, E> Default for Rect3<P, E>
where P: Default, E: Default,

Source§

fn default() -> Rect3<P, E>

Returns the “default value” for a type. Read more
Source§

impl<'de, P, E> Deserialize<'de> for Rect3<P, E>
where P: Deserialize<'de>, E: Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Rect3<P, E>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<P, E> From<(Vec3<P>, Extent3<E>)> for Rect3<P, E>

Source§

fn from(t: (Vec3<P>, Extent3<E>)) -> Rect3<P, E>

Converts to this type from the input type.
Source§

impl<T> From<Aabb<T>> for Rect3<T, T>
where T: Copy + Sub<Output = T>,

Source§

fn from(aab: Aabb<T>) -> Rect3<T, T>

Converts to this type from the input type.
Source§

impl<T> From<Rect3<T, T>> for Aabb<T>
where T: Copy + Add<Output = T>,

Source§

fn from(rect: Rect3<T, T>) -> Aabb<T>

Converts to this type from the input type.
Source§

impl<P, E> Hash for Rect3<P, E>
where P: Hash, E: 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<P, E> PartialEq for Rect3<P, E>
where P: PartialEq, E: PartialEq,

Source§

fn eq(&self, other: &Rect3<P, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P, E> Serialize for Rect3<P, E>
where P: Serialize, E: Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<P, E> Copy for Rect3<P, E>
where P: Copy, E: Copy,

Source§

impl<P, E> Eq for Rect3<P, E>
where P: Eq, E: Eq,

Source§

impl<P, E> StructuralPartialEq for Rect3<P, E>

Auto Trait Implementations§

§

impl<P, E> Freeze for Rect3<P, E>
where P: Freeze, E: Freeze,

§

impl<P, E> RefUnwindSafe for Rect3<P, E>

§

impl<P, E> Send for Rect3<P, E>
where P: Send, E: Send,

§

impl<P, E> Sync for Rect3<P, E>
where P: Sync, E: Sync,

§

impl<P, E> Unpin for Rect3<P, E>
where P: Unpin, E: Unpin,

§

impl<P, E> UnsafeUnpin for Rect3<P, E>
where P: UnsafeUnpin, E: UnsafeUnpin,

§

impl<P, E> UnwindSafe for Rect3<P, E>
where P: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

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, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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