diff --git a/src/cgmath/ray.rs b/src/cgmath/ray.rs index 3b1096c..f9d4125 100644 --- a/src/cgmath/ray.rs +++ b/src/cgmath/ray.rs @@ -13,9 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use point::{Point,Point2, Point3}; -use vector::{Vector,Vec2, Vec3}; +use point::{Point, Point2, Point3}; +use vector::{Vector, Vec2, Vec3}; +/// A generic ray #[deriving(Clone, Eq)] pub struct Ray
{
diff --git a/src/cgmath/rotation.rs b/src/cgmath/rotation.rs
index 28dc015..4da5b96 100644
--- a/src/cgmath/rotation.rs
+++ b/src/cgmath/rotation.rs
@@ -17,49 +17,65 @@ use angle::Rad;
use matrix::Matrix;
use matrix::{Mat2, ToMat2};
use matrix::{Mat3, ToMat3};
-use point::{Point2, Point3};
+use point::{Point, Point2, Point3};
use quaternion::{Quat, ToQuat};
-use ray::{Ray2, Ray3};
+use ray::{Ray, Ray2, Ray3};
use vector::{Vector, Vec2, Vec3};
+/// A trait for generic rotation
+pub trait Rotation
+<
+ S: Primitive + Clone,
+ Slice,
+ V: Vector,
+ P: Point + Clone
+>
+: Eq
++ ApproxEq
+{
+ fn rotate_point(&self, point: &P) -> P;
+ fn rotate_vec(&self, vec: &V) -> V;
+
+ #[inline]
+ fn rotate_ray(&self, ray: &Ray
) -> Ray
{
+ Ray::new( ray.origin.clone(), self.rotate_vec(&ray.direction) )
+ }
+
+ fn concat(&self, other: &Self) -> Self;
+ fn invert(&self) -> Self;
+
+ #[inline]
+ fn concat_self(&mut self, other: &Self) {
+ *self = self.concat(other);
+ }
+
+ #[inline]
+ fn invert_self(&mut self) {
+ *self = self.invert();
+ }
+}
+
/// A two-dimensional rotation
pub trait Rotation2
<
S
>
-: Eq
-+ ApproxEq
+: Rotation, Point2>
+ ToMat2
+ ToBasis2
-{
- fn rotate_point2(&self, point: &Point2) -> Point2;
- fn rotate_vec2(&self, vec: &Vec2) -> Vec2;
- fn rotate_ray2(&self, ray: &Ray2) -> Ray2;
- fn concat(&self, other: &Self) -> Self;
- fn concat_self(&mut self, other: &Self);
- fn invert(&self) -> Self;
- fn invert_self(&mut self);
-}
+{}
/// A three-dimensional rotation
pub trait Rotation3
<
S
>
-: Eq
-+ ApproxEq
+: Rotation, Point3>
+ ToMat3
+ ToBasis3
+ ToQuat
-{
- fn rotate_point3(&self, point: &Point3) -> Point3;
- fn rotate_vec3(&self, vec: &Vec3) -> Vec3;
- fn rotate_ray3(&self, ray: &Ray3) -> Ray3;
- fn concat(&self, other: &Self) -> Self;
- fn concat_self(&mut self, other: &Self);
- fn invert(&self) -> Self;
- fn invert_self(&mut self);
-}
+{}
+
/// A two-dimensional rotation matrix.
///
@@ -91,15 +107,15 @@ impl for Basis2 {
fn to_mat2(&self) -> Mat2 { self.mat.clone() }
}
-impl for Basis2 {
+impl, Point2> for Basis2 {
#[inline]
- fn rotate_point2(&self, _point: &Point2) -> Point2 { fail!("Not yet implemented") }
+ fn rotate_point(&self, _point: &Point2) -> Point2 { fail!("Not yet implemented") }
#[inline]
- fn rotate_vec2(&self, vec: &Vec2) -> Vec2 { self.mat.mul_v(vec) }
+ fn rotate_vec(&self, vec: &Vec2) -> Vec2 { self.mat.mul_v(vec) }
#[inline]
- fn rotate_ray2(&self, _ray: &Ray2) -> Ray2 { fail!("Not yet implemented") }
+ 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) } }
@@ -136,6 +152,8 @@ impl for Basis2 {
}
}
+impl for Basis2 {}
+
/// A three-dimensional rotation matrix.
///
/// The matrix is guaranteed to be orthogonal, so some operations, specifically
@@ -207,15 +225,15 @@ impl for Basis3 {
fn to_quat(&self) -> Quat { self.mat.to_quat() }
}
-impl for Basis3 {
+impl, Point3> for Basis3 {
#[inline]
- fn rotate_point3(&self, _point: &Point3) -> Point3 { fail!("Not yet implemented") }
+ fn rotate_point(&self, _point: &Point3) -> Point3 { fail!("Not yet implemented") }
#[inline]
- fn rotate_vec3(&self, vec: &Vec3) -> Vec3 { self.mat.mul_v(vec) }
+ fn rotate_vec(&self, vec: &Vec3) -> Vec3 { self.mat.mul_v(vec) }
#[inline]
- fn rotate_ray3(&self, _ray: &Ray3) -> Ray3 { fail!("Not yet implemented") }
+ 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) } }
@@ -252,6 +270,8 @@ impl for Basis3 {
}
}
+impl for Basis3 {}
+
// Quaternion Rotation impls
impl for Quat {
@@ -264,15 +284,15 @@ impl for Quat {
fn to_quat(&self) -> Quat { self.clone() }
}
-impl for Quat {
+impl, Point3> for Quat {
#[inline]
- fn rotate_point3(&self, _point: &Point3) -> Point3 { fail!("Not yet implemented") }
+ fn rotate_point(&self, _point: &Point3) -> Point3 { fail!("Not yet implemented") }
#[inline]
- fn rotate_vec3(&self, vec: &Vec3) -> Vec3 { self.mul_v(vec) }
+ fn rotate_vec(&self, vec: &Vec3) -> Vec3 { self.mul_v(vec) }
#[inline]
- fn rotate_ray3(&self, _ray: &Ray3) -> Ray3 { fail!("Not yet implemented") }
+ fn rotate_ray(&self, _ray: &Ray3) -> Ray3 { fail!("Not yet implemented") }
#[inline]
fn concat(&self, other: &Quat) -> Quat { self.mul_q(other) }
@@ -286,3 +306,5 @@ impl for Quat {
#[inline]
fn invert_self(&mut self) { *self = self.invert() }
}
+
+impl for Quat {}
\ No newline at end of file
diff --git a/src/cgmath/transform.rs b/src/cgmath/transform.rs
index 2eefb44..08ae398 100644
--- a/src/cgmath/transform.rs
+++ b/src/cgmath/transform.rs
@@ -14,10 +14,10 @@
// limitations under the License.
use matrix::Mat4;
-use point::{Point,Point3};
+use point::{Point, Point3};
use ray::Ray;
use rotation::Rotation3;
-use vector::{Vector,Vec3};
+use vector::{Vector, Vec3};
/// A trait of affine transformation, that can be applied to points or vectors
pub trait Transform
@@ -60,11 +60,11 @@ impl {
impl , Point3> for Transform3 {
#[inline]
fn transform_vec(&self, vec: &Vec3) -> Vec3 {
- self.rot.rotate_vec3( &vec.mul_s( self.scale.clone() ))
+ self.rot.rotate_vec( &vec.mul_s( self.scale.clone() ))
}
#[inline]
fn transform_point(&self, point: &Point3) -> Point3 {
- self.rot.rotate_point3( &point.mul_s( self.scale.clone() )).add_v( &self.disp )
+ self.rot.rotate_point( &point.mul_s( self.scale.clone() )).add_v( &self.disp )
}
}