Add conversions from points to homogenous coordinates
This commit is contained in:
parent
de649c3b50
commit
290861f952
1 changed files with 24 additions and 1 deletions
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
use std::cast;
|
use std::cast;
|
||||||
|
|
||||||
use core::{Mat2, Mat3, Quat, Vec2, Vec3};
|
use core::{Mat2, Mat3, Quat, Vec2, Vec3, Vec4};
|
||||||
|
|
||||||
#[path = "../num_macros.rs"]
|
#[path = "../num_macros.rs"]
|
||||||
mod num_macros;
|
mod num_macros;
|
||||||
|
@ -65,6 +65,17 @@ impl<T:Num> Point2<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T:Clone + Num> Point2<T> {
|
||||||
|
/// Converts the point to a three-dimensional homogeneous vector:
|
||||||
|
/// `[x, y] -> [x, y, 1]`
|
||||||
|
#[inline]
|
||||||
|
pub fn to_vec3(&self) -> Vec3<T> {
|
||||||
|
Vec3::new((*self).x.clone(),
|
||||||
|
(*self).y.clone(),
|
||||||
|
one!(T))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T:Clone + Float> Point2<T> {
|
impl<T:Clone + Float> Point2<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rotate_t(&self, radians: &T) -> Point2<T> {
|
pub fn rotate_t(&self, radians: &T) -> Point2<T> {
|
||||||
|
@ -191,6 +202,18 @@ impl<T:Num> Point3<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T:Clone + Num> Point3<T> {
|
||||||
|
/// Converts the point to a four-dimensional homogeneous vector:
|
||||||
|
/// `[x, y, z] -> [x, y, z, 1]`
|
||||||
|
#[inline]
|
||||||
|
pub fn to_vec4(&self) -> Vec4<T> {
|
||||||
|
Vec4::new((*self).x.clone(),
|
||||||
|
(*self).y.clone(),
|
||||||
|
(*self).z.clone(),
|
||||||
|
one!(T))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T:Clone + Float> Point3<T> {
|
impl<T:Clone + Float> Point3<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rotate_q(&self, quat: &Quat<T>) -> Point3<T> {
|
pub fn rotate_q(&self, quat: &Quat<T>) -> Point3<T> {
|
||||||
|
|
Loading…
Reference in a new issue