Update formatting

This commit is contained in:
Brendan Zabarauskas 2014-04-14 11:41:29 +10:00
parent 64ae5fbd9a
commit 7c11ec250a
7 changed files with 170 additions and 173 deletions

View file

@ -26,9 +26,9 @@ pub mod matrix2 {
type float = f32;
pub static A: Matrix2<f32> = Matrix2 { x: Vector2 { x: 1.0, y: 3.0 },
y: Vector2 { x: 2.0, y: 4.0 } };
y: Vector2 { x: 2.0, y: 4.0 } };
pub static B: Matrix2<f32> = Matrix2 { x: Vector2 { x: 2.0, y: 4.0 },
y: Vector2 { x: 3.0, y: 5.0 } };
y: Vector2 { x: 3.0, y: 5.0 } };
}
pub mod matrix3 {
@ -37,11 +37,11 @@ pub mod matrix3 {
type float = f32;
pub static A: Matrix3<f32> = Matrix3 { x: Vector3 { x: 1.0, y: 4.0, z: 7.0 },
y: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
z: Vector3 { x: 3.0, y: 6.0, z: 9.0 } };
y: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
z: Vector3 { x: 3.0, y: 6.0, z: 9.0 } };
pub static B: Matrix3<f32> = Matrix3 { x: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
y: Vector3 { x: 3.0, y: 6.0, z: 9.0 },
z: Vector3 { x: 4.0, y: 7.0, z: 10.0 } };
y: Vector3 { x: 3.0, y: 6.0, z: 9.0 },
z: Vector3 { x: 4.0, y: 7.0, z: 10.0 } };
}
pub mod matrix4 {
@ -50,13 +50,13 @@ pub mod matrix4 {
type float = f32;
pub static A: Matrix4<f32> = Matrix4 { x: Vector4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 },
y: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
z: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
w: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } };
y: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
z: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
w: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } };
pub static B: Matrix4<f32> = Matrix4 { x: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
y: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
z: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 },
w: Vector4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } };
y: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
z: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 },
w: Vector4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } };
}
#[bench]

View file

@ -45,7 +45,7 @@ impl<S: Primitive> Matrix2<S> {
pub fn new(c0r0: S, c0r1: S,
c1r0: S, c1r1: S) -> Matrix2<S> {
Matrix2::from_cols(Vector2::new(c0r0, c0r1),
Vector2::new(c1r0, c1r1))
Vector2::new(c1r0, c1r1))
}
#[inline]
@ -56,7 +56,7 @@ impl<S: Primitive> Matrix2<S> {
#[inline]
pub fn from_value(value: S) -> Matrix2<S> {
Matrix2::new(value.clone(), zero(),
zero(), value.clone())
zero(), value.clone())
}
#[inline]
@ -81,8 +81,8 @@ impl<S: PartOrdFloat<S>> Matrix2<S> {
let cos_theta = cos(theta.clone());
let sin_theta = sin(theta.clone());
Matrix2::new(cos_theta.clone(), -sin_theta.clone(),
sin_theta.clone(), cos_theta.clone())
Matrix2::new(cos_theta.clone(), -sin_theta.clone(),
sin_theta.clone(), cos_theta.clone())
}
}
@ -92,8 +92,8 @@ impl<S: Primitive> Matrix3<S> {
c1r0:S, c1r1:S, c1r2:S,
c2r0:S, c2r1:S, c2r2:S) -> Matrix3<S> {
Matrix3::from_cols(Vector3::new(c0r0, c0r1, c0r2),
Vector3::new(c1r0, c1r1, c1r2),
Vector3::new(c2r0, c2r1, c2r2))
Vector3::new(c1r0, c1r1, c1r2),
Vector3::new(c2r0, c2r1, c2r2))
}
#[inline]
@ -104,8 +104,8 @@ impl<S: Primitive> Matrix3<S> {
#[inline]
pub fn from_value(value: S) -> Matrix3<S> {
Matrix3::new(value.clone(), zero(), zero(),
zero(), value.clone(), zero(),
zero(), zero(), value.clone())
zero(), value.clone(), zero(),
zero(), zero(), value.clone())
}
#[inline]
@ -133,9 +133,9 @@ Matrix3<S> {
pub fn from_angle_x(theta: Rad<S>) -> Matrix3<S> {
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
let (s, c) = sin_cos(theta);
Matrix3::new(one(), zero(), zero(),
zero(), c.clone(), s.clone(),
zero(), -s.clone(), c.clone())
Matrix3::new( one(), zero(), zero(),
zero(), c.clone(), s.clone(),
zero(), -s.clone(), c.clone())
}
/// Create a matrix from a rotation around the `y` axis (yaw).
@ -143,17 +143,17 @@ Matrix3<S> {
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
let (s, c) = sin_cos(theta);
Matrix3::new(c.clone(), zero(), -s.clone(),
zero(), one(), zero(),
s.clone(), zero(), c.clone())
zero(), one(), zero(),
s.clone(), zero(), c.clone())
}
/// Create a matrix from a rotation around the `z` axis (roll).
pub fn from_angle_z(theta: Rad<S>) -> Matrix3<S> {
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
let (s, c) = sin_cos(theta);
Matrix3::new(c.clone(), s.clone(), zero(),
-s.clone(), c.clone(), zero(),
zero(), zero(), one())
Matrix3::new( c.clone(), s.clone(), zero(),
-s.clone(), c.clone(), zero(),
zero(), zero(), one())
}
/// Create a matrix from a set of euler angles.
@ -169,9 +169,9 @@ Matrix3<S> {
let (sy, cy) = sin_cos(y);
let (sz, cz) = sin_cos(z);
Matrix3::new(cy * cz, cy * sz, -sy,
-cx * sz + sx * sy * cz, cx * cz + sx * sy * sz, sx * cy,
sx * sz + cx * sy * cz, -sx * cz + cx * sy * sz, cx * cy)
Matrix3::new( cy * cz, cy * sz, -sy,
-cx * sz + sx * sy * cz, cx * cz + sx * sy * sz, sx * cy,
sx * sz + cx * sy * cz, -sx * cz + cx * sy * sz, cx * cy)
}
/// Create a matrix from a rotation around an arbitrary axis
@ -180,16 +180,16 @@ Matrix3<S> {
let _1subc = one::<S>() - c;
Matrix3::new(_1subc * axis.x * axis.x + c,
_1subc * axis.x * axis.y + s * axis.z,
_1subc * axis.x * axis.z - s * axis.y,
_1subc * axis.x * axis.y + s * axis.z,
_1subc * axis.x * axis.z - s * axis.y,
_1subc * axis.x * axis.y - s * axis.z,
_1subc * axis.y * axis.y + c,
_1subc * axis.y * axis.z + s * axis.x,
_1subc * axis.x * axis.y - s * axis.z,
_1subc * axis.y * axis.y + c,
_1subc * axis.y * axis.z + s * axis.x,
_1subc * axis.x * axis.z + s * axis.y,
_1subc * axis.y * axis.z - s * axis.x,
_1subc * axis.z * axis.z + c)
_1subc * axis.x * axis.z + s * axis.y,
_1subc * axis.y * axis.z - s * axis.x,
_1subc * axis.z * axis.z + c)
}
}
@ -200,9 +200,9 @@ impl<S: Primitive> Matrix4<S> {
c2r0: S, c2r1: S, c2r2: S, c2r3: S,
c3r0: S, c3r1: S, c3r2: S, c3r3: S) -> Matrix4<S> {
Matrix4::from_cols(Vector4::new(c0r0, c0r1, c0r2, c0r3),
Vector4::new(c1r0, c1r1, c1r2, c1r3),
Vector4::new(c2r0, c2r1, c2r2, c2r3),
Vector4::new(c3r0, c3r1, c3r2, c3r3))
Vector4::new(c1r0, c1r1, c1r2, c1r3),
Vector4::new(c2r0, c2r1, c2r2, c2r3),
Vector4::new(c3r0, c3r1, c3r2, c3r3))
}
#[inline]
@ -212,10 +212,10 @@ impl<S: Primitive> Matrix4<S> {
#[inline]
pub fn from_value(value: S) -> Matrix4<S> {
Matrix4::new(value.clone(), zero(), zero(), zero(),
zero(), value.clone(), zero(), zero(),
zero(), zero(), value.clone(), zero(),
zero(), zero(), zero(), value.clone())
Matrix4::new(value.clone(), zero(), zero(), zero(),
zero(), value.clone(), zero(), zero(),
zero(), zero(), value.clone(), zero(),
zero(), zero(), zero(), value.clone())
}
#[inline]
@ -236,10 +236,10 @@ Matrix4<S> {
let s = f.cross(up).normalize();
let u = s.cross(&f);
Matrix4::new(s.x.clone(), u.x.clone(), -f.x.clone(), zero(),
s.y.clone(), u.y.clone(), -f.y.clone(), zero(),
s.z.clone(), u.z.clone(), -f.z.clone(), zero(),
-eye.dot(&s), -eye.dot(&u), eye.dot(&f), one())
Matrix4::new( s.x.clone(), u.x.clone(), -f.x.clone(), zero(),
s.y.clone(), u.y.clone(), -f.y.clone(), zero(),
s.z.clone(), u.z.clone(), -f.z.clone(), zero(),
-eye.dot(&s), -eye.dot(&u), eye.dot(&f), one())
}
}
@ -391,12 +391,12 @@ for Matrix2<S>
{
fn mul_m(&self, other: &Matrix2<S>) -> Matrix2<S> {
Matrix2::new(self.r(0).dot(other.c(0)), self.r(1).dot(other.c(0)),
self.r(0).dot(other.c(1)), self.r(1).dot(other.c(1)))
self.r(0).dot(other.c(1)), self.r(1).dot(other.c(1)))
}
fn transpose(&self) -> Matrix2<S> {
Matrix2::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(),
self.cr(0, 1).clone(), self.cr(1, 1).clone())
self.cr(0, 1).clone(), self.cr(1, 1).clone())
}
#[inline]
@ -416,7 +416,7 @@ for Matrix2<S>
None
} else {
Some(Matrix2::new( *self.cr(1, 1) / det, -*self.cr(0, 1) / det,
-*self.cr(1, 0) / det, *self.cr(0, 0) / det))
-*self.cr(1, 0) / det, *self.cr(0, 0) / det))
}
}
@ -440,14 +440,14 @@ for Matrix3<S>
{
fn mul_m(&self, other: &Matrix3<S>) -> Matrix3<S> {
Matrix3::new(self.r(0).dot(other.c(0)),self.r(1).dot(other.c(0)),self.r(2).dot(other.c(0)),
self.r(0).dot(other.c(1)),self.r(1).dot(other.c(1)),self.r(2).dot(other.c(1)),
self.r(0).dot(other.c(2)),self.r(1).dot(other.c(2)),self.r(2).dot(other.c(2)))
self.r(0).dot(other.c(1)),self.r(1).dot(other.c(1)),self.r(2).dot(other.c(1)),
self.r(0).dot(other.c(2)),self.r(1).dot(other.c(2)),self.r(2).dot(other.c(2)))
}
fn transpose(&self) -> Matrix3<S> {
Matrix3::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), self.cr(2, 0).clone(),
self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(),
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone())
self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(),
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone())
}
#[inline]
@ -467,8 +467,8 @@ for Matrix3<S>
let det = self.determinant();
if det.approx_eq(&zero()) { None } else {
Some(Matrix3::from_cols(self.c(1).cross(self.c(2)).div_s(det.clone()),
self.c(2).cross(self.c(0)).div_s(det.clone()),
self.c(0).cross(self.c(1)).div_s(det.clone())).transpose())
self.c(2).cross(self.c(0)).div_s(det.clone()),
self.c(0).cross(self.c(1)).div_s(det.clone())).transpose())
}
}
@ -513,16 +513,16 @@ for Matrix4<S>
{
fn mul_m(&self, other: &Matrix4<S>) -> Matrix4<S> {
Matrix4::new(dot_matrix4!(self, other, 0, 0), dot_matrix4!(self, other, 1, 0), dot_matrix4!(self, other, 2, 0), dot_matrix4!(self, other, 3, 0),
dot_matrix4!(self, other, 0, 1), dot_matrix4!(self, other, 1, 1), dot_matrix4!(self, other, 2, 1), dot_matrix4!(self, other, 3, 1),
dot_matrix4!(self, other, 0, 2), dot_matrix4!(self, other, 1, 2), dot_matrix4!(self, other, 2, 2), dot_matrix4!(self, other, 3, 2),
dot_matrix4!(self, other, 0, 3), dot_matrix4!(self, other, 1, 3), dot_matrix4!(self, other, 2, 3), dot_matrix4!(self, other, 3, 3))
dot_matrix4!(self, other, 0, 1), dot_matrix4!(self, other, 1, 1), dot_matrix4!(self, other, 2, 1), dot_matrix4!(self, other, 3, 1),
dot_matrix4!(self, other, 0, 2), dot_matrix4!(self, other, 1, 2), dot_matrix4!(self, other, 2, 2), dot_matrix4!(self, other, 3, 2),
dot_matrix4!(self, other, 0, 3), dot_matrix4!(self, other, 1, 3), dot_matrix4!(self, other, 2, 3), dot_matrix4!(self, other, 3, 3))
}
fn transpose(&self) -> Matrix4<S> {
Matrix4::new(self.cr(0, 0).clone(), self.cr(1, 0).clone(), self.cr(2, 0).clone(), self.cr(3, 0).clone(),
self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(),
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(),
self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone())
self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(),
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(),
self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone())
}
fn transpose_self(&mut self) {
@ -536,17 +536,17 @@ for Matrix4<S>
fn determinant(&self) -> S {
let m0 = Matrix3::new(self.cr(1, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(),
self.cr(1, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(),
self.cr(1, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone());
self.cr(1, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(),
self.cr(1, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone());
let m1 = Matrix3::new(self.cr(0, 1).clone(), self.cr(2, 1).clone(), self.cr(3, 1).clone(),
self.cr(0, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(),
self.cr(0, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone());
self.cr(0, 2).clone(), self.cr(2, 2).clone(), self.cr(3, 2).clone(),
self.cr(0, 3).clone(), self.cr(2, 3).clone(), self.cr(3, 3).clone());
let m2 = Matrix3::new(self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(3, 1).clone(),
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(3, 2).clone(),
self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(3, 3).clone());
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(3, 2).clone(),
self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(3, 3).clone());
let m3 = Matrix3::new(self.cr(0, 1).clone(), self.cr(1, 1).clone(), self.cr(2, 1).clone(),
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone(),
self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(2, 3).clone());
self.cr(0, 2).clone(), self.cr(1, 2).clone(), self.cr(2, 2).clone(),
self.cr(0, 3).clone(), self.cr(1, 3).clone(), self.cr(2, 3).clone());
*self.cr(0, 0) * m0.determinant() -
*self.cr(1, 0) * m1.determinant() +
@ -646,8 +646,8 @@ ToMatrix3<S> for Matrix2<S> {
/// 3-dimensional identity matrix.
fn to_matrix3(&self) -> Matrix3<S> {
Matrix3::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero(),
self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero(),
zero(), zero(), one())
self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero(),
zero(), zero(), one())
}
}
@ -657,9 +657,9 @@ ToMatrix4<S> for Matrix2<S> {
/// 4-dimensional identity matrix.
fn to_matrix4(&self) -> Matrix4<S> {
Matrix4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), zero(), zero(),
self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero(), zero(),
zero(), zero(), one(), zero(),
zero(), zero(), zero(), one())
self.cr(1, 0).clone(), self.cr(1, 1).clone(), zero(), zero(),
zero(), zero(), one(), zero(),
zero(), zero(), zero(), one())
}
}
@ -669,9 +669,9 @@ ToMatrix4<S> for Matrix3<S> {
/// 4-dimensional identity matrix.
fn to_matrix4(&self) -> Matrix4<S> {
Matrix4::new(self.cr(0, 0).clone(), self.cr(0, 1).clone(), self.cr(0, 2).clone(), zero(),
self.cr(1, 0).clone(), self.cr(1, 1).clone(), self.cr(1, 2).clone(), zero(),
self.cr(2, 0).clone(), self.cr(2, 1).clone(), self.cr(2, 2).clone(), zero(),
zero(), zero(), zero(), one())
self.cr(1, 0).clone(), self.cr(1, 1).clone(), self.cr(1, 2).clone(), zero(),
self.cr(2, 0).clone(), self.cr(2, 1).clone(), self.cr(2, 2).clone(), zero(),
zero(), zero(), zero(), one())
}
}

View file

@ -125,9 +125,6 @@ ApproxEq<S> for Plane<S> {
impl<S: Clone + fmt::Float> fmt::Show for Plane<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "{:f}x + {:f}y + {:f}z - {:f} = 0",
self.n.x,
self.n.y,
self.n.z,
self.d)
self.n.x, self.n.y, self.n.z, self.d)
}
}

View file

@ -137,9 +137,9 @@ impl<S: Float, A: Angle<S>> ToMatrix4<S> for PerspectiveFov<S, A> {
let c3r3 = zero();
Matrix4::new(c0r0, c0r1, c0r2, c0r3,
c1r0, c1r1, c1r2, c1r3,
c2r0, c2r1, c2r2, c2r3,
c3r0, c3r1, c3r2, c3r3)
c1r0, c1r1, c1r2, c1r3,
c2r0, c2r1, c2r2, c2r3,
c3r0, c3r1, c3r2, c3r3)
}
}
@ -188,9 +188,9 @@ impl<S: Float> ToMatrix4<S> for Perspective<S> {
let c3r3 = zero();
Matrix4::new(c0r0, c0r1, c0r2, c0r3,
c1r0, c1r1, c1r2, c1r3,
c2r0, c2r1, c2r2, c2r3,
c3r0, c3r1, c3r2, c3r3)
c1r0, c1r1, c1r2, c1r3,
c2r0, c2r1, c2r2, c2r3,
c3r0, c3r1, c3r2, c3r3)
}
}
@ -245,8 +245,8 @@ impl<S: Float> ToMatrix4<S> for Ortho<S> {
let c3r3 = one::<S>();
Matrix4::new(c0r0, c0r1, c0r2, c0r3,
c1r0, c1r1, c1r2, c1r3,
c2r0, c2r1, c2r2, c2r3,
c3r0, c3r1, c3r2, c3r3)
c1r0, c1r1, c1r2, c1r3,
c2r0, c2r1, c2r2, c2r3,
c3r0, c3r1, c3r2, c3r3)
}
}

View file

@ -96,9 +96,9 @@ Quaternion<S> {
/// The the result of multipliplying the quaternion by `other`
pub fn mul_q(&self, other: &Quaternion<S>) -> Quaternion<S> {
Quaternion::new(self.s * other.s - self.v.x * other.v.x - self.v.y * other.v.y - self.v.z * other.v.z,
self.s * other.v.x + self.v.x * other.s + self.v.y * other.v.z - self.v.z * other.v.y,
self.s * other.v.y + self.v.y * other.s + self.v.z * other.v.x - self.v.x * other.v.z,
self.s * other.v.z + self.v.z * other.s + self.v.x * other.v.y - self.v.y * other.v.x)
self.s * other.v.x + self.v.x * other.s + self.v.y * other.v.z - self.v.z * other.v.y,
self.s * other.v.y + self.v.y * other.s + self.v.z * other.v.x - self.v.x * other.v.z,
self.s * other.v.z + self.v.z * other.s + self.v.x * other.v.y - self.v.y * other.v.x)
}
#[inline]
@ -248,8 +248,8 @@ ToMatrix3<S> for Quaternion<S> {
let sx2 = x2 * self.s;
Matrix3::new(one::<S>() - yy2 - zz2, xy2 + sz2, xz2 - sy2,
xy2 - sz2, one::<S>() - xx2 - zz2, yz2 + sx2,
xz2 + sy2, yz2 - sx2, one::<S>() - xx2 - yy2)
xy2 - sz2, one::<S>() - xx2 - zz2, yz2 + sx2,
xz2 + sy2, yz2 - sx2, one::<S>() - xx2 - yy2)
}
}
@ -274,9 +274,9 @@ ToMatrix4<S> for Quaternion<S> {
let sx2 = x2 * self.s;
Matrix4::new(one::<S>() - yy2 - zz2, xy2 + sz2, xz2 - sy2, zero::<S>(),
xy2 - sz2, one::<S>() - xx2 - zz2, yz2 + sx2, zero::<S>(),
xz2 + sy2, yz2 - sx2, one::<S>() - xx2 - yy2, zero::<S>(),
zero::<S>(), zero::<S>(), zero::<S>(), one::<S>())
xy2 - sz2, one::<S>() - xx2 - zz2, yz2 + sx2, zero::<S>(),
xz2 + sy2, yz2 - sx2, one::<S>() - xx2 - yy2, zero::<S>(),
zero::<S>(), zero::<S>(), zero::<S>(), one::<S>())
}
}
@ -360,8 +360,8 @@ Rotation3<S> for Quaternion<S>
let (sz2, cz2) = sin_cos(z.mul_s(cast(0.5).unwrap()));
Quaternion::new(cz2 * cx2 * cy2 + sz2 * sx2 * sy2,
sz2 * cx2 * cy2 - cz2 * sx2 * sy2,
cz2 * sx2 * cy2 + sz2 * cx2 * sy2,
cz2 * cx2 * sy2 - sz2 * sx2 * cy2)
sz2 * cx2 * cy2 - cz2 * sx2 * sy2,
cz2 * sx2 * cy2 + sz2 * cx2 * sy2,
cz2 * cx2 * sy2 - sz2 * sx2 * cy2)
}
}

View file

@ -22,11 +22,11 @@ pub mod matrix2 {
use cgmath::vector::*;
pub static A: Matrix2<f64> = Matrix2 { x: Vector2 { x: 1.0, y: 3.0 },
y: Vector2 { x: 2.0, y: 4.0 } };
y: Vector2 { x: 2.0, y: 4.0 } };
pub static B: Matrix2<f64> = Matrix2 { x: Vector2 { x: 2.0, y: 4.0 },
y: Vector2 { x: 3.0, y: 5.0 } };
y: Vector2 { x: 3.0, y: 5.0 } };
pub static C: Matrix2<f64> = Matrix2 { x: Vector2 { x: 2.0, y: 1.0 },
y: Vector2 { x: 1.0, y: 2.0 } };
y: Vector2 { x: 1.0, y: 2.0 } };
pub static V: Vector2<f64> = Vector2 { x: 1.0, y: 2.0 };
pub static F: f64 = 0.5;
@ -37,17 +37,17 @@ pub mod matrix3 {
use cgmath::vector::*;
pub static A: Matrix3<f64> = Matrix3 { x: Vector3 { x: 1.0, y: 4.0, z: 7.0 },
y: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
z: Vector3 { x: 3.0, y: 6.0, z: 9.0 } };
y: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
z: Vector3 { x: 3.0, y: 6.0, z: 9.0 } };
pub static B: Matrix3<f64> = Matrix3 { x: Vector3 { x: 2.0, y: 5.0, z: 8.0 },
y: Vector3 { x: 3.0, y: 6.0, z: 9.0 },
z: Vector3 { x: 4.0, y: 7.0, z: 10.0 } };
y: Vector3 { x: 3.0, y: 6.0, z: 9.0 },
z: Vector3 { x: 4.0, y: 7.0, z: 10.0 } };
pub static C: Matrix3<f64> = Matrix3 { x: Vector3 { x: 2.0, y: 4.0, z: 6.0 },
y: Vector3 { x: 0.0, y: 2.0, z: 4.0 },
z: Vector3 { x: 0.0, y: 0.0, z: 1.0 } };
y: Vector3 { x: 0.0, y: 2.0, z: 4.0 },
z: Vector3 { x: 0.0, y: 0.0, z: 1.0 } };
pub static D: Matrix3<f64> = Matrix3 { x: Vector3 { x: 3.0, y: 2.0, z: 1.0 },
y: Vector3 { x: 2.0, y: 3.0, z: 2.0 },
z: Vector3 { x: 1.0, y: 2.0, z: 3.0 } };
y: Vector3 { x: 2.0, y: 3.0, z: 2.0 },
z: Vector3 { x: 1.0, y: 2.0, z: 3.0 } };
pub static V: Vector3<f64> = Vector3 { x: 1.0, y: 2.0, z: 3.0 };
pub static F: f64 = 0.5;
@ -58,21 +58,21 @@ pub mod matrix4 {
use cgmath::vector::*;
pub static A: Matrix4<f64> = Matrix4 { x: Vector4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 },
y: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
z: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
w: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } };
y: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
z: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
w: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } };
pub static B: Matrix4<f64> = Matrix4 { x: Vector4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
y: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
z: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 },
w: Vector4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } };
y: Vector4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
z: Vector4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 },
w: Vector4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } };
pub static C: Matrix4<f64> = Matrix4 { x: Vector4 { x: 3.0, y: 2.0, z: 1.0, w: 1.0 },
y: Vector4 { x: 2.0, y: 3.0, z: 2.0, w: 2.0 },
z: Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 3.0 },
w: Vector4 { x: 0.0, y: 1.0, z: 1.0, w: 0.0 } };
y: Vector4 { x: 2.0, y: 3.0, z: 2.0, w: 2.0 },
z: Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 3.0 },
w: Vector4 { x: 0.0, y: 1.0, z: 1.0, w: 0.0 } };
pub static D: Matrix4<f64> = Matrix4 { x: Vector4 { x: 4.0, y: 3.0, z: 2.0, w: 1.0 },
y: Vector4 { x: 3.0, y: 4.0, z: 3.0, w: 2.0 },
z: Vector4 { x: 2.0, y: 3.0, z: 4.0, w: 3.0 },
w: Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 } };
y: Vector4 { x: 3.0, y: 4.0, z: 3.0, w: 2.0 },
z: Vector4 { x: 2.0, y: 3.0, z: 4.0, w: 3.0 },
w: Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 } };
pub static V: Vector4<f64> = Vector4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
pub static F: f64 = 0.5;
@ -83,18 +83,18 @@ fn test_neg() {
// Matrix2
assert_eq!(-matrix2::A,
Matrix2::new(-1.0, -3.0,
-2.0, -4.0));
-2.0, -4.0));
// Matrix3
assert_eq!(-matrix3::A,
Matrix3::new(-1.0, -4.0, -7.0,
-2.0, -5.0, -8.0,
-3.0, -6.0, -9.0));
-2.0, -5.0, -8.0,
-3.0, -6.0, -9.0));
// Matrix4
assert_eq!(-matrix4::A,
Matrix4::new(-1.0, -5.0, -9.0, -13.0,
-2.0, -6.0, -10.0, -14.0,
-3.0, -7.0, -11.0, -15.0,
-4.0, -8.0, -12.0, -16.0));
-2.0, -6.0, -10.0, -14.0,
-3.0, -7.0, -11.0, -15.0,
-4.0, -8.0, -12.0, -16.0));
}
#[test]
@ -102,7 +102,7 @@ fn test_mul_s() {
// Matrix2
assert_eq!(matrix2::A.mul_s(matrix2::F),
Matrix2::new(0.5, 1.5,
1.0, 2.0));
1.0, 2.0));
let mut mut_a = matrix2::A;
mut_a.mul_self_s(matrix2::F);
assert_eq!(mut_a, matrix2::A.mul_s(matrix2::F));
@ -110,8 +110,8 @@ fn test_mul_s() {
// Matrix3
assert_eq!(matrix3::A.mul_s(matrix3::F),
Matrix3::new(0.5, 2.0, 3.5,
1.0, 2.5, 4.0,
1.5, 3.0, 4.5));
1.0, 2.5, 4.0,
1.5, 3.0, 4.5));
let mut mut_a = matrix3::A;
mut_a.mul_self_s(matrix3::F);
assert_eq!(mut_a, matrix3::A.mul_s(matrix3::F));
@ -119,9 +119,9 @@ fn test_mul_s() {
// Matrix4
assert_eq!(matrix4::A.mul_s(matrix4::F),
Matrix4::new(0.5, 2.5, 4.5, 6.5,
1.0, 3.0, 5.0, 7.0,
1.5, 3.5, 5.5, 7.5,
2.0, 4.0, 6.0, 8.0));
1.0, 3.0, 5.0, 7.0,
1.5, 3.5, 5.5, 7.5,
2.0, 4.0, 6.0, 8.0));
let mut mut_a = matrix4::A;
mut_a.mul_self_s(matrix4::F);
assert_eq!(mut_a, matrix4::A.mul_s(matrix4::F));
@ -132,7 +132,7 @@ fn test_add_m() {
// Matrix2
assert_eq!(matrix2::A.add_m(&matrix2::B),
Matrix2::new(3.0, 7.0,
5.0, 9.0));
5.0, 9.0));
let mut mut_a = matrix2::A;
mut_a.add_self_m(&matrix2::B);
assert_eq!(mut_a, matrix2::A.add_m(&matrix2::B));
@ -140,8 +140,8 @@ fn test_add_m() {
// Matrix3
assert_eq!(matrix3::A.add_m(&matrix3::B),
Matrix3::new(3.0, 9.0, 15.0,
5.0, 11.0, 17.0,
7.0, 13.0, 19.0));
5.0, 11.0, 17.0,
7.0, 13.0, 19.0));
let mut mut_a = matrix3::A;
mut_a.add_self_m(&matrix3::B);
assert_eq!(mut_a, matrix3::A.add_m(&matrix3::B));
@ -149,9 +149,9 @@ fn test_add_m() {
// Matrix4
assert_eq!(matrix4::A.add_m(&matrix4::B),
Matrix4::new(3.0, 11.0, 19.0, 27.0,
5.0, 13.0, 21.0, 29.0,
7.0, 15.0, 23.0, 31.0,
9.0, 17.0, 25.0, 33.0));
5.0, 13.0, 21.0, 29.0,
7.0, 15.0, 23.0, 31.0,
9.0, 17.0, 25.0, 33.0));
let mut mut_a = matrix4::A;
mut_a.add_self_m(&matrix4::B);
assert_eq!(mut_a, matrix4::A.add_m(&matrix4::B));
@ -162,7 +162,7 @@ fn test_sub_m() {
// Matrix2
assert_eq!(matrix2::A.sub_m(&matrix2::B),
Matrix2::new(-1.0, -1.0,
-1.0, -1.0));
-1.0, -1.0));
let mut mut_a = matrix2::A;
mut_a.sub_self_m(&matrix2::B);
assert_eq!(mut_a, matrix2::A.sub_m(&matrix2::B));
@ -170,8 +170,8 @@ fn test_sub_m() {
// Matrix3
assert_eq!(matrix3::A.sub_m(&matrix3::B),
Matrix3::new(-1.0, -1.0, -1.0,
-1.0, -1.0, -1.0,
-1.0, -1.0, -1.0));
-1.0, -1.0, -1.0,
-1.0, -1.0, -1.0));
let mut mut_a = matrix3::A;
mut_a.sub_self_m(&matrix3::B);
assert_eq!(mut_a, matrix3::A.sub_m(&matrix3::B));
@ -179,9 +179,9 @@ fn test_sub_m() {
// Matrix4
assert_eq!(matrix4::A.sub_m(&matrix4::B),
Matrix4::new(-1.0, -1.0, -1.0, -1.0,
-1.0, -1.0, -1.0, -1.0,
-1.0, -1.0, -1.0, -1.0,
-1.0, -1.0, -1.0, -1.0));
-1.0, -1.0, -1.0, -1.0,
-1.0, -1.0, -1.0, -1.0,
-1.0, -1.0, -1.0, -1.0));
let mut mut_a = matrix4::A;
mut_a.sub_self_m(&matrix4::B);
assert_eq!(mut_a, matrix4::A.sub_m(&matrix4::B));
@ -198,16 +198,16 @@ fn test_mul_v() {
fn test_mul_m() {
assert_eq!(matrix2::A.mul_m(&matrix2::B),
Matrix2::new(10.0, 22.0,
13.0, 29.0));
13.0, 29.0));
assert_eq!(matrix3::A.mul_m(&matrix3::B),
Matrix3::new(36.0, 81.0, 126.0,
42.0, 96.0, 150.0,
48.0, 111.0, 174.0));
42.0, 96.0, 150.0,
48.0, 111.0, 174.0));
assert_eq!(matrix4::A.mul_m(&matrix4::B),
Matrix4::new(100.0, 228.0, 356.0, 484.0,
110.0, 254.0, 398.0, 542.0,
120.0, 280.0, 440.0, 600.0,
130.0, 306.0, 482.0, 658.0));
110.0, 254.0, 398.0, 542.0,
120.0, 280.0, 440.0, 600.0,
130.0, 306.0, 482.0, 658.0));
}
#[test]
@ -229,7 +229,7 @@ fn test_transpose() {
// Matrix2
assert_eq!(matrix2::A.transpose(),
Matrix2::<f64>::new(1.0, 2.0,
3.0, 4.0));
3.0, 4.0));
let mut mut_a = matrix2::A;
mut_a.transpose_self();
assert_eq!(mut_a, matrix2::A.transpose());
@ -237,8 +237,8 @@ fn test_transpose() {
// Matrix3
assert_eq!(matrix3::A.transpose(),
Matrix3::<f64>::new(1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0));
4.0, 5.0, 6.0,
7.0, 8.0, 9.0));
let mut mut_a = matrix3::A;
mut_a.transpose_self();
assert_eq!(mut_a, matrix3::A.transpose());
@ -246,9 +246,9 @@ fn test_transpose() {
// Matrix4
assert_eq!(matrix4::A.transpose(),
Matrix4::<f64>::new( 1.0, 2.0, 3.0, 4.0,
5.0, 6.0, 7.0, 8.0,
9.0, 10.0, 11.0, 12.0,
13.0, 14.0, 15.0, 16.0));
5.0, 6.0, 7.0, 8.0,
9.0, 10.0, 11.0, 12.0,
13.0, 14.0, 15.0, 16.0));
let mut mut_a = matrix4::A;
mut_a.transpose_self();
assert_eq!(mut_a, matrix4::A.transpose());
@ -261,9 +261,9 @@ fn test_invert() {
assert_eq!(matrix2::A.invert().unwrap(),
Matrix2::new(-2.0, 1.5,
1.0, -0.5));
1.0, -0.5));
assert!(Matrix2::new(0.0, 2.0,
0.0, 5.0).invert().is_none());
0.0, 5.0).invert().is_none());
let mut mut_a = matrix2::A;
mut_a.invert_self();
assert_eq!(mut_a, matrix2::A.invert().unwrap());
@ -275,8 +275,8 @@ fn test_invert() {
assert_eq!(matrix3::C.invert().unwrap(),
Matrix3::new(0.5, -1.0, 1.0,
0.0, 0.5, -2.0,
0.0, 0.0, 1.0));
0.0, 0.5, -2.0,
0.0, 0.0, 1.0));
let mut mut_c = matrix3::C;
mut_c.invert_self();
assert_eq!(mut_c, matrix3::C.invert().unwrap());
@ -286,9 +286,9 @@ fn test_invert() {
assert!(matrix4::C.invert().unwrap().approx_eq(&
Matrix4::new( 5.0, -4.0, 1.0, 0.0,
-4.0, 8.0, -4.0, 0.0,
4.0, -8.0, 4.0, 8.0,
-3.0, 4.0, 1.0, -8.0).mul_s(0.125)));
-4.0, 8.0, -4.0, 0.0,
4.0, -8.0, 4.0, 8.0,
-3.0, 4.0, 1.0, -8.0).mul_s(0.125)));
let mut mut_c = matrix4::C;
mut_c.invert_self();
assert_eq!(mut_c, matrix4::C.invert().unwrap());

View file

@ -39,8 +39,8 @@ fn test_ray_intersection() {
assert_eq!((p0, r0).intersection(), Some(Point3::new(7f64, 8f64, 9f64)));
let p1 = Plane::from_points(Point3::new(5f64, 0f64, 5f64),
Point3::new(5f64, 5f64, 5f64),
Point3::new(5f64, 0f64, -1f64)).unwrap();
Point3::new(5f64, 5f64, 5f64),
Point3::new(5f64, 0f64, -1f64)).unwrap();
let r1: Ray3<f64> = Ray::new(Point3::new(0f64, 0f64, 0f64), Vector3::new(-1f64, 0f64, 0f64).normalize());
assert_eq!((p1, r1).intersection(), None); // r1 points away from p1
}