use na::Transform; use na; use entities::shape::Triangle; use point::PointQuery; use math::{Point, Vector}; impl
PointQuery
for Triangle
where P: Point, M: Transform
{ #[inline] fn project_point(&self, m: &M, pt: &P, solid: bool) -> P { /* * This comes from the book `Real Time Collision Detection`. * This is a trivial Voronoï region based approach, except that great care has been taken * to avoid cross products (which is good for the genericity here). * * We keep the original (somehow, obscure) notations for future reference. */ let a = self.a().clone(); let b = self.b().clone(); let c = self.c().clone(); let p = m.inverse_transform(pt); let ab = b - a; let ac = c - a; let ap = p - a; let d1 = na::dot(&ab, &ap); let d2 = na::dot(&ac, &ap); if d1 <= na::zero() && d2 <= na::zero() { // Voronoï region of `a`. return m.transform(&a); } let bp = p - b; let d3 = na::dot(&ab, &bp); let d4 = na::dot(&ac, &bp); if d3 >= na::zero() && d4 <= d3 { // Voronoï region of `b`. return m.transform(&b); } let vc = d1 * d4 - d3 * d2; if vc <= na::zero() && d1 >= na::zero() && d3 <= na::zero() { // Voronoï region of `ab`. let v = d1 / (d1 - d3); return m.transform(&(a + ab * v)); } let cp = p - c; let d5 = na::dot(&ab, &cp); let d6 = na::dot(&ac, &cp); if d6 >= na::zero() && d5 <= d6 { // Voronoï region of `c`. return m.transform(&c); } let vb = d5 * d2 - d1 * d6; if vb <= na::zero() && d2 >= na::zero() && d6 <= na::zero() { // Voronoï region of `ac`. let w = d2 / (d2 - d6); return m.transform(&(a + ac * w)); } let va = d3 * d6 - d5 * d4; if va <= na::zero() && d4 - d3 >= na::zero() && d5 - d6 >= na::zero() { // Voronoï region of `bc`. let w = (d4 - d3) / ((d4 - d3) + (d5 - d6)); return m.transform(&(b + (c - b) * w)); } // Voronoï region of the face. if na::dimension::
() != 2 {
let denom = na::one::<