Add point conversion methods for vec2 and vec3 types

This commit is contained in:
Brendan Zabarauskas 2013-07-10 14:18:44 +10:00
parent e12f561930
commit 053586c8e2

View file

@ -13,7 +13,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(geom)]
use std::cast;
use core::Dimensional;
#[cfg(geom)]
use geom::{Point2, Point3};
#[path = "../num_macros.rs"]
mod num_macros;
@ -56,6 +61,24 @@ impl<T> Vec2<T> {
}
}
#[cfg(geom)]
impl<T> Vec2<T> {
#[inline]
pub fn from_point(point: Point2<T>) -> Vec2<T> {
unsafe { cast::transmute(point) }
}
#[inline]
pub fn as_point<'a>(&'a self) -> &'a Point2<T> {
unsafe { cast::transmute(self) }
}
#[inline]
pub fn as_mut_point<'a>(&'a mut self) -> &'a mut Point2<T> {
unsafe { cast::transmute(self) }
}
}
impl<T:Clone> Vec2<T> {
#[inline]
pub fn from_value(value: T) -> Vec2<T> {
@ -561,6 +584,24 @@ impl<T> Vec3<T> {
}
}
#[cfg(geom)]
impl<T> Vec3<T> {
#[inline]
pub fn from_point(point: Point3<T>) -> Vec3<T> {
unsafe { cast::transmute(point) }
}
#[inline]
pub fn as_point<'a>(&'a self) -> &'a Point3<T> {
unsafe { cast::transmute(self) }
}
#[inline]
pub fn as_mut_point<'a>(&'a mut self) -> &'a mut Point3<T> {
unsafe { cast::transmute(self) }
}
}
impl<T:Clone> Vec3<T> {
#[inline]
pub fn from_value(value: T) -> Vec3<T> {