Struct AABB

Source
pub struct AABB<T> {
    pub x_min: T,
    pub x_max: T,
    pub y_min: T,
    pub y_max: T,
}
Expand description

Axis aligned bounding box.

Fields§

§x_min: T§x_max: T§y_min: T§y_max: T

Implementations§

Source§

impl<T> AABB<T>
where T: UNum,

Source

pub fn bottom_left(&self) -> Vec2<T>

Source

pub fn bottom_right(&self) -> Vec2<T>

Source

pub fn top_left(&self) -> Vec2<T>

Source

pub fn top_right(&self) -> Vec2<T>

Source

pub fn center(&self) -> Vec2<T>

Source

pub fn from_corners(p1: Vec2<T>, p2: Vec2<T>) -> AABB<T>

Source

pub fn pos_size(pos: Vec2<T>, size: Vec2<T>) -> AABB<T>

Source

pub fn map<U, F>(self, f: F) -> AABB<U>
where U: UNum, F: Fn(T) -> U,

Source

pub fn width(&self) -> T

Source

pub fn height(&self) -> T

Get rect’s height.

Source

pub fn size(&self) -> Vec2<T>

Get rect’s size.

Source

pub fn contains(&self, point: Vec2<T>) -> bool

Check if a point is inside the rect.

§Examples
use batbox::*;
let rect = AABB::from_corners(vec2(1, 2), vec2(3, 4));
assert!(rect.contains(vec2(2, 3)));
assert!(!rect.contains(vec2(5, 5)));
Source

pub fn intersects(&self, other: &AABB<T>) -> bool

Source

pub fn translate(self, v: Vec2<T>) -> AABB<T>

Source

pub fn add_padding(self, padding: T) -> AABB<T>

Source

pub fn points(&self) -> impl Iterator<Item = Vec2<T>>
where Range<T>: Iterator<Item = T>,

Source§

impl<T> AABB<T>
where T: Float,

Source

pub fn distance_to(&self, other: &AABB<T>) -> T

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> AABB<T>

Returns a copy 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<T> Debug for AABB<T>
where T: Debug,

Source§

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

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

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

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<AABB<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl<T> PartialEq for AABB<T>
where T: PartialEq,

Source§

fn eq(&self, other: &AABB<T>) -> 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<T> Serialize for AABB<T>
where T: 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<T> Trans for AABB<T>
where T: Trans,

Source§

fn create_schema() -> Schema

Source§

fn write_to(&self, writer: &mut dyn Write) -> Result<(), Error>

Source§

fn read_from(reader: &mut dyn Read) -> Result<AABB<T>, Error>

Source§

impl<T> Copy for AABB<T>
where T: Copy,

Source§

impl<T> Eq for AABB<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for AABB<T>

Auto Trait Implementations§

§

impl<T> Freeze for AABB<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AABB<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for AABB<T>
where T: Unpin,

§

impl<T> UnwindSafe for AABB<T>
where T: 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> 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> Diff for T
where T: Debug + Serialize + for<'de> Deserialize<'de> + Trans + Sync + Send + Copy + PartialEq + 'static,

Source§

type Delta = T

Source§

fn diff(&self, to: &T) -> T

Source§

fn update(&mut self, new_value: &T)

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> Same for T

Source§

type Output = T

Should always be Self
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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Message for T
where T: Debug + Serialize + for<'de> Deserialize<'de> + Send + 'static,