//! Definition of the segment shape. use std::mem; use na::{self, Point2}; use shape::{BaseMeshElement, SupportMap}; use math::{Isometry, Point}; /// A segment shape. #[derive(PartialEq, Debug, Clone)] pub struct Segment

{ a: P, b: P, } impl Segment

{ /// Creates a new segment from two points. #[inline] pub fn new(a: P, b: P) -> Segment

{ assert!(na::dimension::() > 1); Segment { a, b } } /// Creates the reference to a segment from the reference to an array of two points. pub fn from_array(arr: &[P; 2]) -> &Segment

{ unsafe { mem::transmute(arr) } } pub(crate) fn from_array3(arr: &[P; 3]) -> &Segment

{ unsafe { mem::transmute(arr) } } pub(crate) fn from_array4(arr: &[P; 4]) -> &Segment

{ unsafe { mem::transmute(arr) } } } impl

Segment

{ /// The first point of this segment. #[inline] pub fn a(&self) -> &P { &self.a } /// The second point of this segment. #[inline] pub fn b(&self) -> &P { &self.b } } impl BaseMeshElement, P> for Segment

{ #[inline] fn new_with_vertices_and_indices(vs: &[P], is: &Point2) -> Segment

{ Segment::new(vs[is.x], vs[is.y]) } } impl> SupportMap for Segment

{ #[inline] fn support_point(&self, m: &M, dir: &P::Vector) -> P { let local_dir = m.inverse_transform_vector(dir); if na::dot(&self.a().coordinates(), &local_dir) > na::dot(&self.b().coordinates(), &local_dir) { m.transform_point(self.a()) } else { m.transform_point(self.b()) } } }