use std::mem;
use std::sync::Arc;
use na::{Translate, Point2};
use partitioning::BVT;
use bounding_volume::AABB;
use shape::{Segment, BaseMesh};
use math::{Point, Vector};
pub struct Polyline<P: Point> {
mesh: BaseMesh<P, Point2<usize>, Segment<P>>
}
impl<P: Point> Clone for Polyline<P> {
fn clone(&self) -> Polyline<P> {
Polyline {
mesh: self.mesh.clone()
}
}
}
impl<P> Polyline<P>
where P: Point,
P::Vect: Translate<P> {
pub fn new(vertices: Arc<Vec<P>>,
indices: Arc<Vec<Point2<usize>>>,
uvs: Option<Arc<Vec<Point2<<P::Vect as Vector>::Scalar>>>>,
normals: Option<Arc<Vec<P::Vect>>>) -> Polyline<P> {
Polyline {
mesh: BaseMesh::new(vertices, indices, uvs, normals)
}
}
}
impl<P> Polyline<P>
where P: Point {
#[inline]
pub fn base_mesh(&self) -> &BaseMesh<P, Point2<usize>, Segment<P>> {
&self.mesh
}
#[inline]
pub fn vertices(&self) -> &Arc<Vec<P>> {
self.mesh.vertices()
}
#[inline]
pub fn bounding_volumes(&self) -> &[AABB<P>] {
self.mesh.bounding_volumes()
}
#[inline]
pub fn indices(&self) -> &Arc<Vec<Point2<usize>>> {
unsafe { mem::transmute(self.mesh.indices()) }
}
#[inline]
pub fn uvs(&self) -> &Option<Arc<Vec<Point2<<P::Vect as Vector>::Scalar>>>> {
self.mesh.uvs()
}
#[inline]
pub fn normals(&self) -> &Option<Arc<Vec<P::Vect>>> {
self.mesh.normals()
}
#[inline]
pub fn bvt(&self) -> &BVT<usize, AABB<P>> {
self.mesh.bvt()
}
}
impl<P: Point> Polyline<P> {
#[inline]
pub fn segment_at(&self, i: usize) -> Segment<P> {
self.mesh.element_at(i)
}
}