//! 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 {
/// Creates a new segment from two points.
#[inline]
pub fn new(a: P, b: P) -> Segment {
assert!(na::dimension:: {
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 {
#[inline]
fn new_with_vertices_and_indices(vs: &[P], is: &Point2 {
Segment::new(vs[is.x], vs[is.y])
}
}
impl 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())
}
}
}