diff --git a/src/geom/point.rs b/src/geom/point.rs index 940509c..83d4052 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -22,7 +22,7 @@ use std::cast; -use core::{Mat2, Mat3, Quat, Vec2, Vec3}; +use core::{Mat2, Mat3, Quat, Vec2, Vec3, Vec4}; #[path = "../num_macros.rs"] mod num_macros; @@ -65,6 +65,17 @@ impl Point2 { } } +impl Point2 { + /// Converts the point to a three-dimensional homogeneous vector: + /// `[x, y] -> [x, y, 1]` + #[inline] + pub fn to_vec3(&self) -> Vec3 { + Vec3::new((*self).x.clone(), + (*self).y.clone(), + one!(T)) + } +} + impl Point2 { #[inline] pub fn rotate_t(&self, radians: &T) -> Point2 { @@ -191,6 +202,18 @@ impl Point3 { } } +impl Point3 { + /// Converts the point to a four-dimensional homogeneous vector: + /// `[x, y, z] -> [x, y, z, 1]` + #[inline] + pub fn to_vec4(&self) -> Vec4 { + Vec4::new((*self).x.clone(), + (*self).y.clone(), + (*self).z.clone(), + one!(T)) + } +} + impl Point3 { #[inline] pub fn rotate_q(&self, quat: &Quat) -> Point3 {