From 42e38017152a60ba666f37007b0d4ec6b453af3a Mon Sep 17 00:00:00 2001 From: kvark Date: Sat, 2 Nov 2013 11:16:18 -0400 Subject: [PATCH] Implemented missing rotation functions (rotate_point, rotate_ray) --- src/cgmath/rotation.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/cgmath/rotation.rs b/src/cgmath/rotation.rs index 6eba8fc..91fdb47 100644 --- a/src/cgmath/rotation.rs +++ b/src/cgmath/rotation.rs @@ -20,7 +20,7 @@ use matrix::{Mat2, ToMat2}; use matrix::{Mat3, ToMat3}; use point::{Point, Point2, Point3}; use quaternion::{Quat, ToQuat}; -use ray::{Ray, Ray2, Ray3}; +use ray::Ray; use vector::{Vector, Vec2, Vec3}; /// A trait for generic rotation @@ -35,9 +35,13 @@ pub trait Rotation + ApproxEq { fn identity() -> Self; - fn rotate_point(&self, point: &P) -> P; fn rotate_vec(&self, vec: &V) -> V; + #[inline] + fn rotate_point(&self, point: &P) -> P { + Point::from_vec( &self.rotate_vec( &point.to_vec() ) ) + } + #[inline] fn rotate_ray(&self, ray: &Ray) -> Ray { Ray::new( //FIXME: use clone derived from Array @@ -115,15 +119,9 @@ impl Rotation, Point2> for Basis2 { #[inline] fn identity() -> Basis2 { Basis2{ mat: Mat2::identity() } } - #[inline] - fn rotate_point(&self, _point: &Point2) -> Point2 { fail!("Not yet implemented") } - #[inline] fn rotate_vec(&self, vec: &Vec2) -> Vec2 { self.mat.mul_v(vec) } - #[inline] - fn rotate_ray(&self, _ray: &Ray2) -> Ray2 { fail!("Not yet implemented") } - #[inline] fn concat(&self, other: &Basis2) -> Basis2 { Basis2 { mat: self.mat.mul_m(&other.mat) } } @@ -236,15 +234,9 @@ impl Rotation, Point3> for Basis3 { #[inline] fn identity() -> Basis3 { Basis3{ mat: Mat3::identity() } } - #[inline] - fn rotate_point(&self, _point: &Point3) -> Point3 { fail!("Not yet implemented") } - #[inline] fn rotate_vec(&self, vec: &Vec3) -> Vec3 { self.mat.mul_v(vec) } - #[inline] - fn rotate_ray(&self, _ray: &Ray3) -> Ray3 { fail!("Not yet implemented") } - #[inline] fn concat(&self, other: &Basis3) -> Basis3 { Basis3 { mat: self.mat.mul_m(&other.mat) } } @@ -298,15 +290,9 @@ impl Rotation, Point3> for Quat { #[inline] fn identity() -> Quat { Quat::identity() } - #[inline] - fn rotate_point(&self, _point: &Point3) -> Point3 { fail!("Not yet implemented") } - #[inline] fn rotate_vec(&self, vec: &Vec3) -> Vec3 { self.mul_v(vec) } - #[inline] - fn rotate_ray(&self, _ray: &Ray3) -> Ray3 { fail!("Not yet implemented") } - #[inline] fn concat(&self, other: &Quat) -> Quat { self.mul_q(other) }