use std::mem; use std::any::{Any, TypeId}; use math::{Point, Vector, Isometry}; use shape::{Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, Triangle}; use support_map::SupportMap; use inspection::{Repr, ReprDesc}; /// Gets the id associated with the `SupportMap` trait. pub fn support_map_repr_id() -> TypeId { TypeId::of::<&SupportMap>() } /// Converts a shape descriptor to a support map if possible. #[inline] pub fn maybe_repr_desc_as_support_map<'a, P: Any, M: Any>(desc: ReprDesc<'a, P, M>) -> Option<&'a (SupportMap + 'a)> { if desc.repr_id() == support_map_repr_id::() { Some(unsafe { mem::transmute(desc.repr()) }) } else { None } } /// Converts a shape to a support map if possible. #[inline] pub fn maybe_as_support_map(g: &G) -> Option<&SupportMap> where P: Any, M: Any, G: Repr { maybe_repr_desc_as_support_map(g.repr()) } macro_rules! impl_support_map_repr( ($t: ty) => { impl Repr for $t where P: Point, M: Isometry { #[inline(always)] fn repr(&self) -> ReprDesc { unsafe { ReprDesc::new( TypeId::of::<$t>(), TypeId::of::<&SupportMap>(), mem::transmute(self as &SupportMap) ) } } } } ); impl_support_map_repr!(Ball<::Scalar>); impl_support_map_repr!(Capsule<::Scalar>); impl_support_map_repr!(Cone<::Scalar>); impl_support_map_repr!(ConvexHull

); impl_support_map_repr!(Cuboid); impl_support_map_repr!(Cylinder<::Scalar>); impl_support_map_repr!(Segment

); impl_support_map_repr!(Triangle

);