Implemented Bound for Sphere

This commit is contained in:
Dzmitry Malyshau 2015-03-12 23:02:39 +03:00
parent e71887a848
commit 2722815d84

View file

@ -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<S: BaseNum> Bound<S> for Aabb3<S> {
}
}
}
impl<S: BaseNum> Bound<S> for Sphere<S> {
fn relate(&self, plane: &Plane<S>) -> 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
}
}
}