Cleaned up public exports. Implemented ToComponents for Matrix3. Added tests.
This commit is contained in:
parent
bf257a3e49
commit
45c6fd630d
3 changed files with 61 additions and 32 deletions
|
@ -37,45 +37,30 @@ extern crate rand;
|
|||
|
||||
// Re-exports
|
||||
|
||||
pub use array::{Array1, Array2, FixedArray};
|
||||
pub use array::*;
|
||||
pub use matrix::*;
|
||||
pub use quaternion::*;
|
||||
pub use vector::*;
|
||||
|
||||
pub use matrix::Matrix;
|
||||
pub use matrix::{Matrix2, Matrix3, Matrix4};
|
||||
pub use matrix::{ToMatrix2, ToMatrix3, ToMatrix4};
|
||||
pub use quaternion::{Quaternion, ToQuaternion};
|
||||
pub use vector::{Vector, EuclideanVector};
|
||||
pub use vector::{Vector2, Vector3, Vector4};
|
||||
pub use vector::{dot, vec2, vec3, vec4};
|
||||
|
||||
pub use angle::{rad, deg};
|
||||
pub use angle::{Angle, Rad, Deg};
|
||||
pub use angle::{ToRad, ToDeg};
|
||||
pub use angle::bisect;
|
||||
pub use angle::{sin, cos, tan, sin_cos};
|
||||
pub use angle::{cot, sec, csc};
|
||||
pub use angle::{acos, asin, atan, atan2};
|
||||
pub use angle::*;
|
||||
pub use plane::Plane;
|
||||
pub use point::{Point, Point2, Point3};
|
||||
pub use line::{Line, Line2, Line3};
|
||||
pub use ray::{Ray, Ray2, Ray3};
|
||||
pub use rotation::{Rotation, Rotation2, Rotation3};
|
||||
pub use rotation::{Basis3, Basis2};
|
||||
pub use rotation::{ToBasis2, ToBasis3};
|
||||
pub use transform::{Transform, Transform3};
|
||||
pub use transform::{Decomposed, AffineMatrix3};
|
||||
pub use point::*;
|
||||
pub use line::*;
|
||||
pub use ray::*;
|
||||
pub use rotation::*;
|
||||
pub use transform::*;
|
||||
|
||||
pub use projection::{perspective, frustum, ortho};
|
||||
pub use projection::{Projection, PerspectiveFov, Perspective, Ortho};
|
||||
pub use projection::*;
|
||||
|
||||
pub use aabb::{Aabb, Aabb2, Aabb3};
|
||||
pub use aabb::*;
|
||||
pub use cylinder::Cylinder;
|
||||
pub use frustum::{Frustum, FrustumPoints};
|
||||
pub use intersect::Intersect;
|
||||
pub use obb::{Obb2, Obb3};
|
||||
pub use obb::*;
|
||||
pub use sphere::Sphere;
|
||||
|
||||
pub use approx::ApproxEq;
|
||||
pub use num::{PartialOrd, BaseNum, BaseInt, BaseFloat, One, one, Zero, zero};
|
||||
pub use num::*;
|
||||
|
||||
// Modules
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
use std::fmt;
|
||||
|
||||
use approx::ApproxEq;
|
||||
use matrix::{Matrix, ToMatrix3, Matrix4, ToMatrix4};
|
||||
use matrix::*;
|
||||
use num::{BaseNum, BaseFloat, zero, one};
|
||||
use point::{Point, Point3};
|
||||
use quaternion::*;
|
||||
use ray::Ray;
|
||||
use rotation::{Rotation, Rotation3};
|
||||
use std::marker::PhantomFn;
|
||||
|
@ -230,6 +231,9 @@ pub trait ToComponents<S, V: Vector<S>, P: Point<S, V>> {
|
|||
fn to_scale(&self) -> V;
|
||||
}
|
||||
|
||||
pub trait ToComponents3<S>: ToComponents<S, Vector3<S>, Point3<S>>
|
||||
where Self::Rotation: ToMatrix3<S> {}
|
||||
|
||||
impl<
|
||||
S: BaseFloat,
|
||||
V: Vector<S> + Clone,
|
||||
|
@ -251,5 +255,33 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
pub trait ToComponents3<S>: ToComponents<S, Vector3<S>, Point3<S>>
|
||||
where Self::Rotation: ToMatrix3<S> {}
|
||||
impl<
|
||||
S: BaseFloat,
|
||||
R: Rotation<S, Vector3<S>, Point3<S>> + Clone + ToMatrix3<S>,
|
||||
> ToComponents3<S> for Decomposed<S, Vector3<S>, R> {}
|
||||
|
||||
impl<
|
||||
S: BaseFloat + 'static,
|
||||
> ToComponents<S, Vector3<S>, Point3<S>> for AffineMatrix3<S> {
|
||||
type Rotation = Quaternion<S>;
|
||||
|
||||
fn to_translation(&self) -> Vector3<S> {
|
||||
Vector3::new(self.mat.w.x, self.mat.w.y, self.mat.w.z)
|
||||
}
|
||||
|
||||
fn to_rotation(&self) -> Quaternion<S> {
|
||||
Matrix3::new(
|
||||
self.mat.x.x, self.mat.x.y, self.mat.x.z,
|
||||
self.mat.y.x, self.mat.y.y, self.mat.y.z,
|
||||
self.mat.z.x, self.mat.z.y, self.mat.z.z,
|
||||
).to_quaternion()
|
||||
}
|
||||
|
||||
fn to_scale(&self) -> Vector3<S> {
|
||||
Vector3::new(self.mat.x.x, self.mat.y.y, self.mat.z.z)
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
S: BaseFloat + 'static,
|
||||
> ToComponents3<S> for AffineMatrix3<S> {}
|
||||
|
|
|
@ -41,3 +41,15 @@ fn test_look_at() {
|
|||
let view_point = Point3::new(0.0f64, 1.0f64, 5.0f64);
|
||||
assert!( t.transform_point(&point).approx_eq(&view_point) );
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_components() {
|
||||
let t = Decomposed {
|
||||
scale: 1.5f64,
|
||||
rot: Quaternion::new(0.5f64,0.5,0.5,0.5),
|
||||
disp: Vector3::new(6.0f64,-7.0f64,8.0)
|
||||
};
|
||||
assert_eq!(t.to_translation(), t.disp);
|
||||
assert_eq!(t.to_rotation(), t.rot);
|
||||
assert_eq!(t.to_scale(), Vector::from_value(t.scale));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue