diff --git a/src/bound.rs b/src/bound.rs index 33a20b9..753ae1a 100644 --- a/src/bound.rs +++ b/src/bound.rs @@ -19,6 +19,7 @@ use aabb::{Aabb, Aabb3}; use num::BaseNum; use plane::Plane; use point::{Point, Point3}; +use sphere::Sphere; /// Spatial relation between two objects. pub enum Relation { @@ -58,3 +59,16 @@ impl Bound for Aabb3 { } } } + +impl Bound for Sphere { + fn relate(&self, plane: &Plane) -> Relation { + let dist = self.center.dot(&plane.n) - plane.d; + if dist > self.radius { + Relation::In + }else if dist < - self.radius { + Relation::Out + }else { + Relation::Cross + } + } +}