[][src]Struct bvh::aabb::AABB

pub struct AABB {
    pub min: Point3<f32>,
    pub max: Point3<f32>,
}

AABB struct.

Fields

min: Point3<f32>

Minimum coordinates

max: Point3<f32>

Maximum coordinates

Methods

impl AABB[src]

pub fn with_bounds(min: Point3<f32>, max: Point3<f32>) -> AABB[src]

Creates a new AABB with the given bounds.

Examples

use bvh::aabb::AABB;
use bvh::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);

pub fn empty() -> AABB[src]

Creates a new empty AABB.

Examples

use bvh::aabb::AABB;

let aabb = AABB::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);

pub fn contains(&self, p: &Point3<f32>) -> bool[src]

Returns true if the Point3 is inside the AABB.

Examples

use bvh::aabb::AABB;
use bvh::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));

pub fn approx_contains_eps(&self, p: &Point3<f32>, epsilon: f32) -> bool[src]

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

Examples

use bvh::EPSILON;
use bvh::aabb::AABB;
use bvh::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, EPSILON));
assert!(!aabb.approx_contains_eps(&point_outside, EPSILON));

pub fn approx_contains_aabb_eps(&self, other: &AABB, epsilon: f32) -> bool[src]

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

Examples

use bvh::EPSILON;
use bvh::aabb::AABB;
use bvh::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, EPSILON));

pub fn relative_eq(&self, other: &AABB, epsilon: f32) -> bool[src]

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

Examples

use bvh::EPSILON;
use bvh::aabb::AABB;
use bvh::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, EPSILON));

pub fn join(&self, other: &AABB) -> AABB[src]

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 bvh::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));

pub fn join_mut(&mut self, other: &AABB)[src]

Mutable version of AABB::join.

Examples

use bvh::aabb::AABB;
use bvh::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));

pub fn grow(&self, other: &Point3<f32>) -> AABB[src]

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

Examples

use bvh::aabb::AABB;
use bvh::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));

pub fn grow_mut(&mut self, other: &Point3<f32>)[src]

Mutable version of AABB::grow.

Examples

use bvh::aabb::AABB;
use bvh::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));

pub fn join_bounded<T: Bounded>(&self, other: &T) -> AABB[src]

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

Examples

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

struct Something;

impl Bounded for Something {
    fn aabb(&self) -> AABB {
        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));

pub fn size(&self) -> Vector3<f32>[src]

Returns the size of this AABB in all three dimensions.

Examples

use bvh::aabb::AABB;
use bvh::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);

pub fn center(&self) -> Point3<f32>[src]

Returns the center Point3 of the AABB.

Examples

use bvh::aabb::AABB;
use bvh::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);

pub fn is_empty(&self) -> bool[src]

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 bvh::nalgebra::Point3;

let empty_aabb = 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());

pub fn surface_area(&self) -> f32[src]

Returns the total surface area of this AABB.

Examples

use bvh::aabb::AABB;
use bvh::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);

pub fn volume(&self) -> f32[src]

Returns the volume of this AABB.

Examples

use bvh::aabb::AABB;
use bvh::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);

pub fn largest_axis(&self) -> Axis[src]

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

Examples

use bvh::aabb::AABB;
use bvh::axis::Axis;
use bvh::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 == Axis::X);

Trait Implementations

impl Bounded for AABB[src]

Implementation of Bounded for AABB.

Examples

use bvh::aabb::{AABB, Bounded};
use bvh::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);

impl Default for AABB[src]

Default instance for AABBs. Returns an AABB which is empty().

impl Copy for AABB[src]

impl Clone for AABB[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for AABB[src]

impl Display for AABB[src]

impl Index<usize> for AABB[src]

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 bvh::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);

type Output = Point3<f32>

The returned type after indexing.

Auto Trait Implementations

impl Send for AABB

impl Sync for AABB

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Same for T

type Output = T

Should always be Self

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