ncollide_entities 0.5.1

DEPRECATED: use ncollide2d or ncollide3d insead.
//! Definition of the triangle shape.

use na::{Dimension, Point3};
use na;
use shape::BaseMeshElement;


/// A triangle shape.
#[derive(PartialEq, Debug, Clone, RustcEncodable, RustcDecodable)]
pub struct Triangle<P> {
    a: P,
    b: P,
    c: P
}

impl<P: Dimension> Triangle<P> {
    /// Creates a triangle from three points.
    #[inline]
    pub fn new(a: P, b: P, c: P) -> Triangle<P> {
        assert!(na::dimension::<P>() > 1);

        Triangle {
            a: a,
            b: b,
            c: c
        }
    }
}

impl<P> Triangle<P> {
    /// The fist point of this triangle.
    #[inline]
    pub fn a(&self) -> &P {
        &self.a
    }

    /// The second point of this triangle.
    #[inline]
    pub fn b(&self) -> &P {
        &self.b
    }

    /// The third point of this triangle.
    #[inline]
    pub fn c(&self) -> &P {
        &self.c
    }
}

impl<P: Copy + Dimension> BaseMeshElement<Point3<usize>, P> for Triangle<P> {
    #[inline]
    fn new_with_vertices_and_indices(vs: &[P], is: &Point3<usize>) -> Triangle<P> {
        Triangle::new(vs[is.x], vs[is.y], vs[is.z])
    }
}