logo
pub trait Intersection<T> {
    type Output;

    fn intersection(&self, other: &T) -> Option<Self::Output>;
}
Expand description

Intersection of geometric objects.

Determines if a pair of objects intersects and produces data describing the intersection. Each set of objects produces its own intersection data as the Output type.

A symmetrical implementation is provided for heterogeneous pairs:

// These queries are equivalent.
if let Some(LinePlane::TimeOfImpact(t)) = line.intersection(&plane) { /* ... */ }
if let Some(LinePlane::TimeOfImpact(t)) = plane.intersection(&line) { /* ... */ }

Examples

Testing for intersection of an axis-aligned bounding box and a ray:

use nalgebra::Point2;
use theon::query::{Aabb, Intersection, Ray, Unit};
use theon::space::{EuclideanSpace, VectorSpace};

type E2 = Point2<f64>;

let aabb = Aabb::<E2> {
    origin: EuclideanSpace::from_xy(1.0, -1.0),
    extent: VectorSpace::from_xy(2.0, 2.0),
};
let ray = Ray::<E2> {
    origin: EuclideanSpace::origin(),
    direction: Unit::x(),
};
if let Some((min, max)) = ray.intersection(&aabb) {
    // ...
}

Required Associated Types

Required Methods

Implementors

Intersection of axis-aligned bounding boxes.

Symmetrical intersection.

Symmetrical intersection.

Intersection of lines in two dimensions.

Symmetrical intersection.

Intersection of a line and a plane.

Symmetrical intersection.

Intersection of an axis-aligned bounding box and a ray.

Intersection of a plane and a ray.

Intersection of an axis-aligned bounding box and a point.