Struct Aabb

Source
pub struct Aabb<T, const D: usize>
where T: BHValue,
{ pub min: OPoint<T, Const<D>>, pub max: OPoint<T, Const<D>>, }
Available on crate feature geometry only.
Expand description

Aabb struct.

Fields§

§min: OPoint<T, Const<D>>

Minimum coordinates

§max: OPoint<T, Const<D>>

Maximum coordinates

Implementations§

Source§

impl<T, const D: usize> Aabb<T, D>
where T: BHValue,

Source

pub fn with_bounds( min: OPoint<T, Const<D>>, max: OPoint<T, Const<D>>, ) -> Aabb<T, D>

Creates a new Aabb with the given bounds.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb = Aabb::with_bounds(Point3::new(-1.0,-1.0,-1.0), Point3::new(1.0,1.0,1.0));
assert_eq!(aabb.min.x, -1.0);
assert_eq!(aabb.max.z, 1.0);
Source

pub fn empty() -> Aabb<T, D>

Creates a new empty Aabb.

§Examples
use bvh::aabb::Aabb;

let aabb = Aabb::<f32,3>::empty();
let min = &aabb.min;
let max = &aabb.max;

// For any point
let x = rand::random();
let y = rand::random();
let z = rand::random();

// An empty `Aabb` should not contain it
assert!(x < min.x && y < min.y && z < min.z);
assert!(max.x < x && max.y < y && max.z < z);
Source

pub fn infinite() -> Aabb<T, D>

Creates a new infinite Aabb.

§Examples
use bvh::aabb::Aabb;

let aabb :Aabb<f32,3> = Aabb::infinite();
let min = &aabb.min;
let max = &aabb.max;

// For any point
let x = rand::random();
let y = rand::random();
let z = rand::random();

// An infinite `Aabb` should contain it
assert!(x > min.x && y > min.y && z > min.z);
assert!(max.x > x && max.y > y && max.z > z);
Source

pub fn contains(&self, p: &OPoint<T, Const<D>>) -> bool

Returns true if the Point is inside the Aabb.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb = Aabb::with_bounds(Point3::new(-1.0, -1.0, -1.0), Point3::new(1.0, 1.0, 1.0));
let point_inside = Point3::new(0.125, -0.25, 0.5);
let point_outside = Point3::new(1.0, -2.0, 4.0);

assert!(aabb.contains(&point_inside));
assert!(!aabb.contains(&point_outside));
Source

pub fn approx_contains_eps(&self, p: &OPoint<T, Const<D>>, epsilon: T) -> bool

Returns true if the Point3 is approximately inside the Aabb with respect to some epsilon.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb = Aabb::with_bounds(Point3::new(-1.0, -1.0, -1.0), Point3::new(1.0, 1.0, 1.0));
let point_barely_outside = Point3::new(1.000_000_1, -1.000_000_1, 1.000_000_001);
let point_outside = Point3::new(1.0, -2.0, 4.0);

assert!(aabb.approx_contains_eps(&point_barely_outside, 0.00001));
assert!(!aabb.approx_contains_eps(&point_outside, 0.00001));
Source

pub fn approx_contains_aabb_eps(&self, other: &Aabb<T, D>, epsilon: T) -> bool

Returns true if the other Aabb is approximately inside this Aabb with respect to some epsilon.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb = Aabb::with_bounds(Point3::new(-1.0, -1.0, -1.0), Point3::new(1.0, 1.0, 1.0));
let point_barely_outside = Point3::new(1.000_000_1, 1.000_000_1, 1.000_000_1);
let center = aabb.center();
let inner_aabb = Aabb::with_bounds(center, point_barely_outside);

assert!(aabb.approx_contains_aabb_eps(&inner_aabb, 0.00001));
Source

pub fn intersects_aabb(&self, aabb: &Aabb<T, D>) -> bool

Returns true if this Aabb touches the other Aabb.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb1 = Aabb::with_bounds(Point3::new(-1.0, -1.0, -1.0), Point3::new(1.0, 1.0, 1.0));
let aabb2 = Aabb::with_bounds(Point3::new(0.5, -0.1, -0.1), Point3::new(1.5, 0.1, 0.1));

assert!(aabb1.intersects_aabb(&aabb2));
Source

pub fn relative_eq(&self, other: &Aabb<T, D>, epsilon: T) -> bool

Returns true if the other Aabb is approximately equal to this Aabb with respect to some epsilon.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb = Aabb::with_bounds(Point3::new(-1.0, -1.0, -1.0), Point3::new(1.0, 1.0, 1.0));
let point_barely_outside_min = Point3::new(-1.000_000_1, -1.000_000_1, -1.000_000_1);
let point_barely_outside_max = Point3::new(1.000_000_1, 1.000_000_1, 1.000_000_1);
let other = Aabb::with_bounds(point_barely_outside_min, point_barely_outside_max);

assert!(aabb.relative_eq(&other, 0.00001));
Source

pub fn join(&self, other: &Aabb<T, D>) -> Aabb<T, D>

Returns a new minimal Aabb which contains both this Aabb and other. The result is the convex hull of the both Aabbs.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb1 = Aabb::with_bounds(Point3::new(-101.0, 0.0, 0.0), Point3::new(-100.0, 1.0, 1.0));
let aabb2 = Aabb::with_bounds(Point3::new(100.0, 0.0, 0.0), Point3::new(101.0, 1.0, 1.0));
let joint = aabb1.join(&aabb2);

let point_inside_aabb1 = Point3::new(-100.5, 0.5, 0.5);
let point_inside_aabb2 = Point3::new(100.5, 0.5, 0.5);
let point_inside_joint = Point3::new(0.0, 0.5, 0.5);


assert!(joint.contains(&point_inside_aabb1));
assert!(joint.contains(&point_inside_aabb2));
assert!(joint.contains(&point_inside_joint));
Source

pub fn join_mut(&mut self, other: &Aabb<T, D>)

Mutable version of Aabb::join.

§Examples
use bvh::aabb::Aabb;
use nalgebra::{Point3, Vector3};

let size = Vector3::new(1.0, 1.0, 1.0);
let aabb_pos = Point3::new(-101.0, 0.0, 0.0);
let mut aabb = Aabb::with_bounds(aabb_pos, aabb_pos + size);

let other_pos = Point3::new(100.0, 0.0, 0.0);
let other = Aabb::with_bounds(other_pos, other_pos + size);

let point_inside_aabb = aabb_pos + size / 2.0;
let point_inside_other = other_pos + size / 2.0;
let point_inside_joint = Point3::new(0.0, 0.0, 0.0) + size / 2.0;


aabb.join_mut(&other);

assert!(aabb.contains(&point_inside_aabb));
assert!(aabb.contains(&point_inside_other));
assert!(aabb.contains(&point_inside_joint));
Source

pub fn grow(&self, other: &OPoint<T, Const<D>>) -> Aabb<T, D>

Returns a new minimal Aabb which contains both this Aabb and the Point3 other.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let point1 = Point3::new(0.0, 0.0, 0.0);
let point2 = Point3::new(1.0, 1.0, 1.0);
let point3 = Point3::new(2.0, 2.0, 2.0);

let aabb = Aabb::empty();
assert!(!aabb.contains(&point1));

let aabb1 = aabb.grow(&point1);
assert!(aabb1.contains(&point1));

let aabb2 = aabb.grow(&point2);
assert!(aabb2.contains(&point2));
assert!(!aabb2.contains(&point3));
Source

pub fn grow_mut(&mut self, other: &OPoint<T, Const<D>>)

Mutable version of Aabb::grow.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let point1 = Point3::new(0.0, 0.0, 0.0);
let point2 = Point3::new(1.0, 1.0, 1.0);
let point3 = Point3::new(2.0, 2.0, 2.0);

let mut aabb = Aabb::empty();
assert!(!aabb.contains(&point1));

aabb.grow_mut(&point1);
assert!(aabb.contains(&point1));
assert!(!aabb.contains(&point2));

aabb.grow_mut(&point2);
assert!(aabb.contains(&point2));
assert!(!aabb.contains(&point3));
Source

pub fn join_bounded<B>(&self, other: &B) -> Aabb<T, D>
where B: Bounded<T, D>,

Returns a new minimal Aabb which contains both this Aabb and the Bounded other.

§Examples
use bvh::aabb::{Aabb, Bounded};
use nalgebra::Point3;

struct Something;

impl Bounded<f32,3> for Something {
    fn aabb(&self) -> Aabb<f32,3> {
        let point1 = Point3::new(0.0,0.0,0.0);
        let point2 = Point3::new(1.0,1.0,1.0);
        Aabb::with_bounds(point1, point2)
    }
}

let aabb = Aabb::empty();
let something = Something;
let aabb1 = aabb.join_bounded(&something);

let center = something.aabb().center();
assert!(aabb1.contains(&center));
Source

pub fn size(&self) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>

Returns the size of this Aabb in all three dimensions.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb = Aabb::with_bounds(Point3::new(-1.0,-1.0,-1.0), Point3::new(1.0,1.0,1.0));
let size = aabb.size();
assert!(size.x == 2.0 && size.y == 2.0 && size.z == 2.0);
Source

pub fn half_size(&self) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>

Returns the half size of this Aabb in all three dimensions. This can be interpreted as the distance from the center to the edges

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let aabb = Aabb::with_bounds(Point3::new(0.0,0.0,0.0), Point3::new(2.0,2.0,2.0));
let half_size = aabb.half_size();
assert!(half_size.x == 1.0 && half_size.y == 1.0 && half_size.z == 1.0);
Source

pub fn center(&self) -> OPoint<T, Const<D>>

Returns the center Point3 of the Aabb.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let min = Point3::new(41.0,41.0,41.0);
let max = Point3::new(43.0,43.0,43.0);

let aabb = Aabb::with_bounds(min, max);
let center = aabb.center();
assert!(center.x == 42.0 && center.y == 42.0 && center.z == 42.0);
Source

pub fn is_empty(&self) -> bool

An empty Aabb is an Aabb where the lower bound is greater than the upper bound in at least one component

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let empty_aabb: Aabb<f32,3> = Aabb::empty();
assert!(empty_aabb.is_empty());

let min = Point3::new(41.0,41.0,41.0);
let max = Point3::new(43.0,43.0,43.0);

let aabb = Aabb::with_bounds(min, max);
assert!(!aabb.is_empty());
Source

pub fn surface_area(&self) -> T

Returns the total surface area of this Aabb.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let min = Point3::new(41.0,41.0,41.0);
let max = Point3::new(43.0,43.0,43.0);

let aabb = Aabb::with_bounds(min, max);
let surface_area = aabb.surface_area();
assert!(surface_area == 24.0);
Source

pub fn volume(&self) -> T

Returns the volume of this Aabb.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let min = Point3::new(41.0,41.0,41.0);
let max = Point3::new(43.0,43.0,43.0);

let aabb = Aabb::with_bounds(min, max);
let volume = aabb.volume();
assert!(volume == 8.0);
Source

pub fn largest_axis(&self) -> usize

Returns the axis along which the Aabb is stretched the most.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let min = Point3::new(-100.0,0.0,0.0);
let max = Point3::new(100.0,0.0,0.0);

let aabb = Aabb::with_bounds(min, max);
let axis = aabb.largest_axis();
assert!(axis == 0);
Source

pub fn min_distance_squared(&self, point: OPoint<T, Const<D>>) -> T

Returns the minimum distance squared to the Aabb. The minimum distance is the distance to the closest point on the box, or 0 if the point is inside the box.

§Examples
use bvh::aabb::Aabb;
use nalgebra::Point3;

let min = Point3::new(0.0,0.0,0.0);
let max = Point3::new(10.0,10.0,10.0);

let aabb = Aabb::with_bounds(min, max);
let query = Point3::new(20.0, 0.0, 0.0);
let min_dist = aabb.min_distance_squared(query);
assert_eq!((min_dist as f32).sqrt(), 10.0);

Trait Implementations§

Source§

impl<T, const D: usize> Bounded<T, D> for Aabb<T, D>
where T: BHValue,

Implementation of Bounded for Aabb.

§Examples

use bvh::aabb::{Aabb, Bounded};
use nalgebra::Point3;

let point_a = Point3::new(3.0,4.0,5.0);
let point_b = Point3::new(17.0,18.0,19.0);
let aabb = Aabb::empty().grow(&point_a).grow(&point_b);

let aabb_aabb = aabb.aabb();

assert_eq!(aabb_aabb.min, aabb.min);
assert_eq!(aabb_aabb.max, aabb.max);
Source§

fn aabb(&self) -> Aabb<T, D>

Returns the geometric bounds of this object in the form of an Aabb. Read more
Source§

impl<T, const D: usize> Clone for Aabb<T, D>
where T: Clone + BHValue,

Source§

fn clone(&self) -> Aabb<T, D>

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, const D: usize> Debug for Aabb<T, D>
where T: Debug + BHValue,

Source§

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

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

impl<T, const D: usize> Default for Aabb<T, D>
where T: BHValue,

Default instance for Aabbs. Returns an Aabb which is empty().

Source§

fn default() -> Aabb<T, D>

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

impl<T, const D: usize> Display for Aabb<T, D>
where T: BHValue + Display,

Source§

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

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

impl<T, const D: usize> Index<usize> for Aabb<T, D>
where T: BHValue,

Make Aabbs indexable. aabb[0] gives a reference to the minimum bound. All other indices return a reference to the maximum bound.

§Examples

use bvh::aabb::Aabb;
use nalgebra::Point3;

let min = Point3::new(3.0,4.0,5.0);
let max = Point3::new(123.0,123.0,123.0);

let aabb = Aabb::with_bounds(min, max);
assert_eq!(aabb[0], min);
assert_eq!(aabb[1], max);
Source§

type Output = OPoint<T, Const<D>>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &OPoint<T, Const<D>>

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const D: usize> IntersectsAabb<T, D> for Aabb<T, D>
where T: BHValue,

Source§

fn intersects_aabb(&self, aabb: &Aabb<T, D>) -> bool

Returns whether this object intersects an Aabb. For the purpose of intersection, the Aabb is a solid with area/volume. As a result, intersecting an Aabb implies intersecting any Aabb that contains that Aabb. Read more
Source§

impl<T, const D: usize> PartialEq for Aabb<T, D>
where T: PartialEq + BHValue,

Source§

fn eq(&self, other: &Aabb<T, D>) -> 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, const D: usize> Copy for Aabb<T, D>
where T: Copy + BHValue,

Source§

impl<T, const D: usize> StructuralPartialEq for Aabb<T, D>
where T: BHValue,

Auto Trait Implementations§

§

impl<T, const D: usize> Freeze for Aabb<T, D>
where T: Freeze,

§

impl<T, const D: usize> RefUnwindSafe for Aabb<T, D>
where T: RefUnwindSafe,

§

impl<T, const D: usize> Send for Aabb<T, D>
where T: Send,

§

impl<T, const D: usize> Sync for Aabb<T, D>
where T: Sync,

§

impl<T, const D: usize> Unpin for Aabb<T, D>
where T: Unpin,

§

impl<T, const D: usize> UnwindSafe for Aabb<T, D>
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, dst: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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> 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> Scalar for T
where T: 'static + Clone + PartialEq + Debug,