Skip to main content

Obb2

Struct Obb2 

Source
pub struct Obb2<Unit: Copy = (), Space: Copy = ()> {
    pub center: Vec2<Unit, Space>,
    pub half_extents: Vec2<Unit, Space>,
    pub axis_x: Vec2<Unit, Space>,
    pub axis_y: Vec2<Unit, Space>,
}
Expand description

A 2D oriented bounding box (OBB).

Stored as a center, half-extents, and an orthonormal basis (axis_x, axis_y).

Fields§

§center: Vec2<Unit, Space>§half_extents: Vec2<Unit, Space>

Half-extents along each local axis. Components should be non-negative.

§axis_x: Vec2<Unit, Space>

Local +X axis (should be unit length).

§axis_y: Vec2<Unit, Space>

Local +Y axis (should be unit length and orthogonal to axis_x).

Implementations§

Source§

impl<Unit: Copy, Space: Copy> Obb2<Unit, Space>

Source

pub const fn from_center_half_extents( center: Vec2<Unit, Space>, half_extents: Vec2<Unit, Space>, ) -> Self

Creates an axis-aligned OBB (equivalent to an AABB expressed as center + half-extents).

Source

pub fn from_center_half_extents_rotation_radians( center: Vec2<Unit, Space>, half_extents: Vec2<Unit, Space>, angle: Radians, ) -> Self

Creates a rotated OBB using a typed angle.

The rotation is counter-clockwise.

Source

pub fn from_center_half_extents_rotation_deg( center: Vec2<Unit, Space>, half_extents: Vec2<Unit, Space>, angle: Degrees, ) -> Self

Creates a rotated OBB using a typed angle in degrees.

Source

pub fn try_from_axes( center: Vec2<Unit, Space>, half_extents: Vec2<Unit, Space>, axis_x: Vec2<Unit, Space>, axis_y: Vec2<Unit, Space>, ) -> Option<Self>

Attempts to create an OBB from basis axes.

Returns None if:

  • half-extents are negative or non-finite
  • axes are not finite
  • axes are not approximately unit length and orthogonal
Source

pub fn contains_point(self, p: Vec2<Unit, Space>) -> bool

Source

pub fn closest_point(self, p: Vec2<Unit, Space>) -> Vec2<Unit, Space>

Source

pub fn corners(self) -> [Vec2<Unit, Space>; 4]

Returns the four corners of the OBB.

Source

pub fn to_aabb(self) -> Aabb2<Unit, Space>

Converts this OBB to the smallest axis-aligned bounding box that contains it.

Trait Implementations§

Source§

impl<Unit: Clone + Copy, Space: Clone + Copy> Clone for Obb2<Unit, Space>

Source§

fn clone(&self) -> Obb2<Unit, Space>

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<Unit: Debug + Copy, Space: Debug + Copy> Debug for Obb2<Unit, Space>

Source§

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

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

impl<'de, Unit, Space> Deserialize<'de> for Obb2<Unit, Space>
where Unit: Deserialize<'de> + Copy, Space: Deserialize<'de> + Copy,

Source§

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

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

impl<Unit: PartialEq + Copy, Space: PartialEq + Copy> PartialEq for Obb2<Unit, Space>

Source§

fn eq(&self, other: &Obb2<Unit, Space>) -> 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<Unit, Space> Serialize for Obb2<Unit, Space>
where Unit: Serialize + Copy, Space: Serialize + Copy,

Source§

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

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

impl<Unit: Copy + Copy, Space: Copy + Copy> Copy for Obb2<Unit, Space>

Source§

impl<Unit: Copy, Space: Copy> StructuralPartialEq for Obb2<Unit, Space>

Auto Trait Implementations§

§

impl<Unit, Space> Freeze for Obb2<Unit, Space>

§

impl<Unit, Space> RefUnwindSafe for Obb2<Unit, Space>
where Unit: RefUnwindSafe, Space: RefUnwindSafe,

§

impl<Unit, Space> Send for Obb2<Unit, Space>
where Unit: Send, Space: Send,

§

impl<Unit, Space> Sync for Obb2<Unit, Space>
where Unit: Sync, Space: Sync,

§

impl<Unit, Space> Unpin for Obb2<Unit, Space>
where Unit: Unpin, Space: Unpin,

§

impl<Unit, Space> UnwindSafe for Obb2<Unit, Space>
where Unit: UnwindSafe, Space: 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> 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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,