Rename Rot->Basis

This commit is contained in:
Brendan Zabarauskas 2013-10-13 11:00:07 +11:00
parent 70d48ed37b
commit 77aeff0785

View file

@ -30,7 +30,7 @@ pub trait Rotation2
: Eq : Eq
+ ApproxEq<S> + ApproxEq<S>
+ ToMat2<S> + ToMat2<S>
+ ToRot2<S> + ToBasis2<S>
{ {
fn rotate_point2(&self, point: &Point2<S>) -> Point2<S>; fn rotate_point2(&self, point: &Point2<S>) -> Point2<S>;
fn rotate_vec2(&self, vec: &Vec2<S>) -> Vec2<S>; fn rotate_vec2(&self, vec: &Vec2<S>) -> Vec2<S>;
@ -49,7 +49,7 @@ pub trait Rotation3
: Eq : Eq
+ ApproxEq<S> + ApproxEq<S>
+ ToMat3<S> + ToMat3<S>
+ ToRot3<S> + ToBasis3<S>
+ ToQuat<S> + ToQuat<S>
{ {
fn rotate_point3(&self, point: &Point3<S>) -> Point3<S>; fn rotate_point3(&self, point: &Point3<S>) -> Point3<S>;
@ -68,30 +68,30 @@ pub trait Rotation3
/// enforce orthogonality at the type level the operations have been restricted /// enforce orthogonality at the type level the operations have been restricted
/// to a subeset of those implemented on `Mat2`. /// to a subeset of those implemented on `Mat2`.
#[deriving(Eq, Clone)] #[deriving(Eq, Clone)]
pub struct Rot2<S> { pub struct Basis2<S> {
priv mat: Mat2<S> priv mat: Mat2<S>
} }
impl<S: Float> Rot2<S> { impl<S: Float> Basis2<S> {
#[inline] #[inline]
pub fn as_mat2<'a>(&'a self) -> &'a Mat2<S> { &'a self.mat } pub fn as_mat2<'a>(&'a self) -> &'a Mat2<S> { &'a self.mat }
} }
pub trait ToRot2<S: Float> { pub trait ToBasis2<S: Float> {
fn to_rot2(&self) -> Rot2<S>; fn to_rot2(&self) -> Basis2<S>;
} }
impl<S: Float> ToRot2<S> for Rot2<S> { impl<S: Float> ToBasis2<S> for Basis2<S> {
#[inline] #[inline]
fn to_rot2(&self) -> Rot2<S> { self.clone() } fn to_rot2(&self) -> Basis2<S> { self.clone() }
} }
impl<S: Float> ToMat2<S> for Rot2<S> { impl<S: Float> ToMat2<S> for Basis2<S> {
#[inline] #[inline]
fn to_mat2(&self) -> Mat2<S> { self.mat.clone() } fn to_mat2(&self) -> Mat2<S> { self.mat.clone() }
} }
impl<S: Float> Rotation2<S> for Rot2<S> { impl<S: Float> Rotation2<S> for Basis2<S> {
#[inline] #[inline]
fn rotate_point2(&self, _point: &Point2<S>) -> Point2<S> { fail!("Not yet implemented") } fn rotate_point2(&self, _point: &Point2<S>) -> Point2<S> { fail!("Not yet implemented") }
@ -102,15 +102,15 @@ impl<S: Float> Rotation2<S> for Rot2<S> {
fn rotate_ray2(&self, _ray: &Ray2<S>) -> Ray2<S> { fail!("Not yet implemented") } fn rotate_ray2(&self, _ray: &Ray2<S>) -> Ray2<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn concat(&self, other: &Rot2<S>) -> Rot2<S> { Rot2 { mat: self.mat.mul_m(&other.mat) } } fn concat(&self, other: &Basis2<S>) -> Basis2<S> { Basis2 { mat: self.mat.mul_m(&other.mat) } }
#[inline] #[inline]
fn concat_self(&mut self, other: &Rot2<S>) { self.mat.mul_self_m(&other.mat); } fn concat_self(&mut self, other: &Basis2<S>) { self.mat.mul_self_m(&other.mat); }
// TODO: we know the matrix is orthogonal, so this could be re-written // TODO: we know the matrix is orthogonal, so this could be re-written
// to be faster // to be faster
#[inline] #[inline]
fn invert(&self) -> Rot2<S> { Rot2 { mat: self.mat.invert().unwrap() } } fn invert(&self) -> Basis2<S> { Basis2 { mat: self.mat.invert().unwrap() } }
// TODO: we know the matrix is orthogonal, so this could be re-written // TODO: we know the matrix is orthogonal, so this could be re-written
// to be faster // to be faster
@ -118,7 +118,7 @@ impl<S: Float> Rotation2<S> for Rot2<S> {
fn invert_self(&mut self) { self.mat.invert_self(); } fn invert_self(&mut self) { self.mat.invert_self(); }
} }
impl<S: Float> ApproxEq<S> for Rot2<S> { impl<S: Float> ApproxEq<S> for Basis2<S> {
#[inline] #[inline]
fn approx_epsilon() -> S { fn approx_epsilon() -> S {
// TODO: fix this after static methods are fixed in rustc // TODO: fix this after static methods are fixed in rustc
@ -126,12 +126,12 @@ impl<S: Float> ApproxEq<S> for Rot2<S> {
} }
#[inline] #[inline]
fn approx_eq(&self, other: &Rot2<S>) -> bool { fn approx_eq(&self, other: &Basis2<S>) -> bool {
self.mat.approx_eq(&other.mat) self.mat.approx_eq(&other.mat)
} }
#[inline] #[inline]
fn approx_eq_eps(&self, other: &Rot2<S>, approx_epsilon: &S) -> bool { fn approx_eq_eps(&self, other: &Basis2<S>, approx_epsilon: &S) -> bool {
self.mat.approx_eq_eps(&other.mat, approx_epsilon) self.mat.approx_eq_eps(&other.mat, approx_epsilon)
} }
} }
@ -143,29 +143,29 @@ impl<S: Float> ApproxEq<S> for Rot2<S> {
/// `math::Mat3`. To ensure orthogonality is maintained, the operations have /// `math::Mat3`. To ensure orthogonality is maintained, the operations have
/// been restricted to a subeset of those implemented on `Mat3`. /// been restricted to a subeset of those implemented on `Mat3`.
#[deriving(Eq, Clone)] #[deriving(Eq, Clone)]
pub struct Rot3<S> { pub struct Basis3<S> {
priv mat: Mat3<S> priv mat: Mat3<S>
} }
impl<S: Float> Rot3<S> { impl<S: Float> Basis3<S> {
#[inline] #[inline]
pub fn look_at(dir: &Vec3<S>, up: &Vec3<S>) -> Rot3<S> { pub fn look_at(dir: &Vec3<S>, up: &Vec3<S>) -> Basis3<S> {
Rot3 { mat: Mat3::look_at(dir, up) } Basis3 { mat: Mat3::look_at(dir, up) }
} }
/// Create a rotation matrix from a rotation around the `x` axis (pitch). /// Create a rotation matrix from a rotation around the `x` axis (pitch).
pub fn from_angle_x(theta: Rad<S>) -> Rot3<S> { pub fn from_angle_x(theta: Rad<S>) -> Basis3<S> {
Rot3 { mat: Mat3::from_angle_x(theta) } Basis3 { mat: Mat3::from_angle_x(theta) }
} }
/// Create a rotation matrix from a rotation around the `y` axis (yaw). /// Create a rotation matrix from a rotation around the `y` axis (yaw).
pub fn from_angle_y(theta: Rad<S>) -> Rot3<S> { pub fn from_angle_y(theta: Rad<S>) -> Basis3<S> {
Rot3 { mat: Mat3::from_angle_y(theta) } Basis3 { mat: Mat3::from_angle_y(theta) }
} }
/// Create a rotation matrix from a rotation around the `z` axis (roll). /// Create a rotation matrix from a rotation around the `z` axis (roll).
pub fn from_angle_z(theta: Rad<S>) -> Rot3<S> { pub fn from_angle_z(theta: Rad<S>) -> Basis3<S> {
Rot3 { mat: Mat3::from_angle_z(theta) } Basis3 { mat: Mat3::from_angle_z(theta) }
} }
/// Create a rotation matrix from a set of euler angles. /// Create a rotation matrix from a set of euler angles.
@ -175,39 +175,39 @@ impl<S: Float> Rot3<S> {
/// - `x`: the angular rotation around the `x` axis (pitch). /// - `x`: the angular rotation around the `x` axis (pitch).
/// - `y`: the angular rotation around the `y` axis (yaw). /// - `y`: the angular rotation around the `y` axis (yaw).
/// - `z`: the angular rotation around the `z` axis (roll). /// - `z`: the angular rotation around the `z` axis (roll).
pub fn from_euler(x: Rad<S>, y: Rad<S>, z: Rad<S>) -> Rot3<S> { pub fn from_euler(x: Rad<S>, y: Rad<S>, z: Rad<S>) -> Basis3<S> {
Rot3 { mat: Mat3::from_euler(x, y ,z) } Basis3 { mat: Mat3::from_euler(x, y ,z) }
} }
/// Create a rotation matrix from a rotation around an arbitrary axis. /// Create a rotation matrix from a rotation around an arbitrary axis.
pub fn from_axis_angle(axis: &Vec3<S>, angle: Rad<S>) -> Rot3<S> { pub fn from_axis_angle(axis: &Vec3<S>, angle: Rad<S>) -> Basis3<S> {
Rot3 { mat: Mat3::from_axis_angle(axis, angle) } Basis3 { mat: Mat3::from_axis_angle(axis, angle) }
} }
#[inline] #[inline]
pub fn as_mat3<'a>(&'a self) -> &'a Mat3<S> { &'a self.mat } pub fn as_mat3<'a>(&'a self) -> &'a Mat3<S> { &'a self.mat }
} }
pub trait ToRot3<S: Float> { pub trait ToBasis3<S: Float> {
fn to_rot3(&self) -> Rot3<S>; fn to_rot3(&self) -> Basis3<S>;
} }
impl<S: Float> ToRot3<S> for Rot3<S> { impl<S: Float> ToBasis3<S> for Basis3<S> {
#[inline] #[inline]
fn to_rot3(&self) -> Rot3<S> { self.clone() } fn to_rot3(&self) -> Basis3<S> { self.clone() }
} }
impl<S: Float> ToMat3<S> for Rot3<S> { impl<S: Float> ToMat3<S> for Basis3<S> {
#[inline] #[inline]
fn to_mat3(&self) -> Mat3<S> { self.mat.clone() } fn to_mat3(&self) -> Mat3<S> { self.mat.clone() }
} }
impl<S: Float> ToQuat<S> for Rot3<S> { impl<S: Float> ToQuat<S> for Basis3<S> {
#[inline] #[inline]
fn to_quat(&self) -> Quat<S> { self.mat.to_quat() } fn to_quat(&self) -> Quat<S> { self.mat.to_quat() }
} }
impl<S: Float> Rotation3<S> for Rot3<S> { impl<S: Float> Rotation3<S> for Basis3<S> {
#[inline] #[inline]
fn rotate_point3(&self, _point: &Point3<S>) -> Point3<S> { fail!("Not yet implemented") } fn rotate_point3(&self, _point: &Point3<S>) -> Point3<S> { fail!("Not yet implemented") }
@ -218,15 +218,15 @@ impl<S: Float> Rotation3<S> for Rot3<S> {
fn rotate_ray3(&self, _ray: &Ray3<S>) -> Ray3<S> { fail!("Not yet implemented") } fn rotate_ray3(&self, _ray: &Ray3<S>) -> Ray3<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn concat(&self, other: &Rot3<S>) -> Rot3<S> { Rot3 { mat: self.mat.mul_m(&other.mat) } } fn concat(&self, other: &Basis3<S>) -> Basis3<S> { Basis3 { mat: self.mat.mul_m(&other.mat) } }
#[inline] #[inline]
fn concat_self(&mut self, other: &Rot3<S>) { self.mat.mul_self_m(&other.mat); } fn concat_self(&mut self, other: &Basis3<S>) { self.mat.mul_self_m(&other.mat); }
// TODO: we know the matrix is orthogonal, so this could be re-written // TODO: we know the matrix is orthogonal, so this could be re-written
// to be faster // to be faster
#[inline] #[inline]
fn invert(&self) -> Rot3<S> { Rot3 { mat: self.mat.invert().unwrap() } } fn invert(&self) -> Basis3<S> { Basis3 { mat: self.mat.invert().unwrap() } }
// TODO: we know the matrix is orthogonal, so this could be re-written // TODO: we know the matrix is orthogonal, so this could be re-written
// to be faster // to be faster
@ -234,7 +234,7 @@ impl<S: Float> Rotation3<S> for Rot3<S> {
fn invert_self(&mut self) { self.mat.invert_self(); } fn invert_self(&mut self) { self.mat.invert_self(); }
} }
impl<S: Float> ApproxEq<S> for Rot3<S> { impl<S: Float> ApproxEq<S> for Basis3<S> {
#[inline] #[inline]
fn approx_epsilon() -> S { fn approx_epsilon() -> S {
// TODO: fix this after static methods are fixed in rustc // TODO: fix this after static methods are fixed in rustc
@ -242,21 +242,21 @@ impl<S: Float> ApproxEq<S> for Rot3<S> {
} }
#[inline] #[inline]
fn approx_eq(&self, other: &Rot3<S>) -> bool { fn approx_eq(&self, other: &Basis3<S>) -> bool {
self.mat.approx_eq(&other.mat) self.mat.approx_eq(&other.mat)
} }
#[inline] #[inline]
fn approx_eq_eps(&self, other: &Rot3<S>, approx_epsilon: &S) -> bool { fn approx_eq_eps(&self, other: &Basis3<S>, approx_epsilon: &S) -> bool {
self.mat.approx_eq_eps(&other.mat, approx_epsilon) self.mat.approx_eq_eps(&other.mat, approx_epsilon)
} }
} }
// Quaternion Rotation impls // Quaternion Rotation impls
impl<S: Float> ToRot3<S> for Quat<S> { impl<S: Float> ToBasis3<S> for Quat<S> {
#[inline] #[inline]
fn to_rot3(&self) -> Rot3<S> { Rot3 { mat: self.to_mat3() } } fn to_rot3(&self) -> Basis3<S> { Basis3 { mat: self.to_mat3() } }
} }
impl<S: Float> ToQuat<S> for Quat<S> { impl<S: Float> ToQuat<S> for Quat<S> {