commit
74af5626ba
4 changed files with 78 additions and 77 deletions
|
@ -20,61 +20,61 @@ pub mod mat2 {
|
||||||
use cgmath::matrix::*;
|
use cgmath::matrix::*;
|
||||||
use cgmath::vector::*;
|
use cgmath::vector::*;
|
||||||
|
|
||||||
pub static A: Mat2<float> = Mat2 { x: Vec2 { x: 1.0, y: 3.0 },
|
pub static A: Mat2<f64> = Mat2 { x: Vec2 { x: 1.0, y: 3.0 },
|
||||||
y: Vec2 { x: 2.0, y: 4.0 } };
|
y: Vec2 { x: 2.0, y: 4.0 } };
|
||||||
pub static B: Mat2<float> = Mat2 { x: Vec2 { x: 2.0, y: 4.0 },
|
pub static B: Mat2<f64> = Mat2 { x: Vec2 { x: 2.0, y: 4.0 },
|
||||||
y: Vec2 { x: 3.0, y: 5.0 } };
|
y: Vec2 { x: 3.0, y: 5.0 } };
|
||||||
pub static C: Mat2<float> = Mat2 { x: Vec2 { x: 2.0, y: 1.0 },
|
pub static C: Mat2<f64> = Mat2 { x: Vec2 { x: 2.0, y: 1.0 },
|
||||||
y: Vec2 { x: 1.0, y: 2.0 } };
|
y: Vec2 { x: 1.0, y: 2.0 } };
|
||||||
|
|
||||||
pub static V: Vec2<float> = Vec2 { x: 1.0, y: 2.0 };
|
pub static V: Vec2<f64> = Vec2 { x: 1.0, y: 2.0 };
|
||||||
pub static F: float = 0.5;
|
pub static F: f64 = 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod mat3 {
|
pub mod mat3 {
|
||||||
use cgmath::matrix::*;
|
use cgmath::matrix::*;
|
||||||
use cgmath::vector::*;
|
use cgmath::vector::*;
|
||||||
|
|
||||||
pub static A: Mat3<float> = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 },
|
pub static A: Mat3<f64> = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 },
|
||||||
y: Vec3 { x: 2.0, y: 5.0, z: 8.0 },
|
y: Vec3 { x: 2.0, y: 5.0, z: 8.0 },
|
||||||
z: Vec3 { x: 3.0, y: 6.0, z: 9.0 } };
|
z: Vec3 { x: 3.0, y: 6.0, z: 9.0 } };
|
||||||
pub static B: Mat3<float> = Mat3 { x: Vec3 { x: 2.0, y: 5.0, z: 8.0 },
|
pub static B: Mat3<f64> = Mat3 { x: Vec3 { x: 2.0, y: 5.0, z: 8.0 },
|
||||||
y: Vec3 { x: 3.0, y: 6.0, z: 9.0 },
|
y: Vec3 { x: 3.0, y: 6.0, z: 9.0 },
|
||||||
z: Vec3 { x: 4.0, y: 7.0, z: 10.0 } };
|
z: Vec3 { x: 4.0, y: 7.0, z: 10.0 } };
|
||||||
pub static C: Mat3<float> = Mat3 { x: Vec3 { x: 2.0, y: 4.0, z: 6.0 },
|
pub static C: Mat3<f64> = Mat3 { x: Vec3 { x: 2.0, y: 4.0, z: 6.0 },
|
||||||
y: Vec3 { x: 0.0, y: 2.0, z: 4.0 },
|
y: Vec3 { x: 0.0, y: 2.0, z: 4.0 },
|
||||||
z: Vec3 { x: 0.0, y: 0.0, z: 1.0 } };
|
z: Vec3 { x: 0.0, y: 0.0, z: 1.0 } };
|
||||||
pub static D: Mat3<float> = Mat3 { x: Vec3 { x: 3.0, y: 2.0, z: 1.0 },
|
pub static D: Mat3<f64> = Mat3 { x: Vec3 { x: 3.0, y: 2.0, z: 1.0 },
|
||||||
y: Vec3 { x: 2.0, y: 3.0, z: 2.0 },
|
y: Vec3 { x: 2.0, y: 3.0, z: 2.0 },
|
||||||
z: Vec3 { x: 1.0, y: 2.0, z: 3.0 } };
|
z: Vec3 { x: 1.0, y: 2.0, z: 3.0 } };
|
||||||
|
|
||||||
pub static V: Vec3<float> = Vec3 { x: 1.0, y: 2.0, z: 3.0 };
|
pub static V: Vec3<f64> = Vec3 { x: 1.0, y: 2.0, z: 3.0 };
|
||||||
pub static F: float = 0.5;
|
pub static F: f64 = 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod mat4 {
|
pub mod mat4 {
|
||||||
use cgmath::matrix::*;
|
use cgmath::matrix::*;
|
||||||
use cgmath::vector::*;
|
use cgmath::vector::*;
|
||||||
|
|
||||||
pub static A: Mat4<float> = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 },
|
pub static A: Mat4<f64> = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 },
|
||||||
y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
||||||
z: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
|
z: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
|
||||||
w: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } };
|
w: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 } };
|
||||||
pub static B: Mat4<float> = Mat4 { x: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
pub static B: Mat4<f64> = Mat4 { x: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },
|
||||||
y: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
|
y: Vec4 { x: 3.0, y: 7.0, z: 11.0, w: 15.0 },
|
||||||
z: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 },
|
z: Vec4 { x: 4.0, y: 8.0, z: 12.0, w: 16.0 },
|
||||||
w: Vec4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } };
|
w: Vec4 { x: 5.0, y: 9.0, z: 13.0, w: 17.0 } };
|
||||||
pub static C: Mat4<float> = Mat4 { x: Vec4 { x: 3.0, y: 2.0, z: 1.0, w: 1.0 },
|
pub static C: Mat4<f64> = Mat4 { x: Vec4 { x: 3.0, y: 2.0, z: 1.0, w: 1.0 },
|
||||||
y: Vec4 { x: 2.0, y: 3.0, z: 2.0, w: 2.0 },
|
y: Vec4 { x: 2.0, y: 3.0, z: 2.0, w: 2.0 },
|
||||||
z: Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 3.0 },
|
z: Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 3.0 },
|
||||||
w: Vec4 { x: 0.0, y: 1.0, z: 1.0, w: 0.0 } };
|
w: Vec4 { x: 0.0, y: 1.0, z: 1.0, w: 0.0 } };
|
||||||
pub static D: Mat4<float> = Mat4 { x: Vec4 { x: 4.0, y: 3.0, z: 2.0, w: 1.0 },
|
pub static D: Mat4<f64> = Mat4 { x: Vec4 { x: 4.0, y: 3.0, z: 2.0, w: 1.0 },
|
||||||
y: Vec4 { x: 3.0, y: 4.0, z: 3.0, w: 2.0 },
|
y: Vec4 { x: 3.0, y: 4.0, z: 3.0, w: 2.0 },
|
||||||
z: Vec4 { x: 2.0, y: 3.0, z: 4.0, w: 3.0 },
|
z: Vec4 { x: 2.0, y: 3.0, z: 4.0, w: 3.0 },
|
||||||
w: Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 } };
|
w: Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 } };
|
||||||
|
|
||||||
pub static V: Vec4<float> = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
|
pub static V: Vec4<f64> = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
|
||||||
pub static F: float = 0.5;
|
pub static F: f64 = 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -227,7 +227,7 @@ fn test_trace() {
|
||||||
fn test_transpose() {
|
fn test_transpose() {
|
||||||
// Mat2
|
// Mat2
|
||||||
assert_eq!(mat2::A.transpose(),
|
assert_eq!(mat2::A.transpose(),
|
||||||
Mat2::<float>::new(1.0, 2.0,
|
Mat2::<f64>::new(1.0, 2.0,
|
||||||
3.0, 4.0));
|
3.0, 4.0));
|
||||||
let mut mut_a = mat2::A;
|
let mut mut_a = mat2::A;
|
||||||
mut_a.transpose_self();
|
mut_a.transpose_self();
|
||||||
|
@ -235,7 +235,7 @@ fn test_transpose() {
|
||||||
|
|
||||||
// Mat3
|
// Mat3
|
||||||
assert_eq!(mat3::A.transpose(),
|
assert_eq!(mat3::A.transpose(),
|
||||||
Mat3::<float>::new(1.0, 2.0, 3.0,
|
Mat3::<f64>::new(1.0, 2.0, 3.0,
|
||||||
4.0, 5.0, 6.0,
|
4.0, 5.0, 6.0,
|
||||||
7.0, 8.0, 9.0));
|
7.0, 8.0, 9.0));
|
||||||
let mut mut_a = mat3::A;
|
let mut mut_a = mat3::A;
|
||||||
|
@ -244,7 +244,7 @@ fn test_transpose() {
|
||||||
|
|
||||||
// Mat4
|
// Mat4
|
||||||
assert_eq!(mat4::A.transpose(),
|
assert_eq!(mat4::A.transpose(),
|
||||||
Mat4::<float>::new( 1.0, 2.0, 3.0, 4.0,
|
Mat4::<f64>::new( 1.0, 2.0, 3.0, 4.0,
|
||||||
5.0, 6.0, 7.0, 8.0,
|
5.0, 6.0, 7.0, 8.0,
|
||||||
9.0, 10.0, 11.0, 12.0,
|
9.0, 10.0, 11.0, 12.0,
|
||||||
13.0, 14.0, 15.0, 16.0));
|
13.0, 14.0, 15.0, 16.0));
|
||||||
|
@ -256,7 +256,7 @@ fn test_transpose() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invert() {
|
fn test_invert() {
|
||||||
// Mat2
|
// Mat2
|
||||||
assert!(Mat2::<float>::identity().invert().unwrap().is_identity());
|
assert!(Mat2::<f64>::identity().invert().unwrap().is_identity());
|
||||||
|
|
||||||
assert_eq!(mat2::A.invert().unwrap(),
|
assert_eq!(mat2::A.invert().unwrap(),
|
||||||
Mat2::new(-2.0, 1.5,
|
Mat2::new(-2.0, 1.5,
|
||||||
|
@ -268,7 +268,7 @@ fn test_invert() {
|
||||||
assert_eq!(mut_a, mat2::A.invert().unwrap());
|
assert_eq!(mut_a, mat2::A.invert().unwrap());
|
||||||
|
|
||||||
// Mat3
|
// Mat3
|
||||||
assert!(Mat3::<float>::identity().invert().unwrap().is_identity());
|
assert!(Mat3::<f64>::identity().invert().unwrap().is_identity());
|
||||||
|
|
||||||
assert_eq!(mat3::A.invert(), None);
|
assert_eq!(mat3::A.invert(), None);
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ fn test_invert() {
|
||||||
assert_eq!(mut_c, mat3::C.invert().unwrap());
|
assert_eq!(mut_c, mat3::C.invert().unwrap());
|
||||||
|
|
||||||
// Mat4
|
// Mat4
|
||||||
assert!(Mat4::<float>::identity().invert().unwrap().is_identity());
|
assert!(Mat4::<f64>::identity().invert().unwrap().is_identity());
|
||||||
|
|
||||||
assert_approx_eq!(mat4::C.invert().unwrap(),
|
assert_approx_eq!(mat4::C.invert().unwrap(),
|
||||||
Mat4::new( 5.0, -4.0, 1.0, 0.0,
|
Mat4::new( 5.0, -4.0, 1.0, 0.0,
|
||||||
|
@ -297,11 +297,11 @@ fn test_invert() {
|
||||||
fn test_predicates() {
|
fn test_predicates() {
|
||||||
// Mat2
|
// Mat2
|
||||||
|
|
||||||
assert!(Mat2::<float>::identity().is_identity());
|
assert!(Mat2::<f64>::identity().is_identity());
|
||||||
assert!(Mat2::<float>::identity().is_symmetric());
|
assert!(Mat2::<f64>::identity().is_symmetric());
|
||||||
assert!(Mat2::<float>::identity().is_diagonal());
|
assert!(Mat2::<f64>::identity().is_diagonal());
|
||||||
assert!(!Mat2::<float>::identity().is_rotated());
|
assert!(!Mat2::<f64>::identity().is_rotated());
|
||||||
assert!(Mat2::<float>::identity().is_invertible());
|
assert!(Mat2::<f64>::identity().is_invertible());
|
||||||
|
|
||||||
assert!(!mat2::A.is_identity());
|
assert!(!mat2::A.is_identity());
|
||||||
assert!(!mat2::A.is_symmetric());
|
assert!(!mat2::A.is_symmetric());
|
||||||
|
@ -319,11 +319,11 @@ fn test_predicates() {
|
||||||
|
|
||||||
// Mat3
|
// Mat3
|
||||||
|
|
||||||
assert!(Mat3::<float>::identity().is_identity());
|
assert!(Mat3::<f64>::identity().is_identity());
|
||||||
assert!(Mat3::<float>::identity().is_symmetric());
|
assert!(Mat3::<f64>::identity().is_symmetric());
|
||||||
assert!(Mat3::<float>::identity().is_diagonal());
|
assert!(Mat3::<f64>::identity().is_diagonal());
|
||||||
assert!(!Mat3::<float>::identity().is_rotated());
|
assert!(!Mat3::<f64>::identity().is_rotated());
|
||||||
assert!(Mat3::<float>::identity().is_invertible());
|
assert!(Mat3::<f64>::identity().is_invertible());
|
||||||
|
|
||||||
assert!(!mat3::A.is_identity());
|
assert!(!mat3::A.is_identity());
|
||||||
assert!(!mat3::A.is_symmetric());
|
assert!(!mat3::A.is_symmetric());
|
||||||
|
@ -341,11 +341,11 @@ fn test_predicates() {
|
||||||
|
|
||||||
// Mat4
|
// Mat4
|
||||||
|
|
||||||
assert!(Mat4::<float>::identity().is_identity());
|
assert!(Mat4::<f64>::identity().is_identity());
|
||||||
assert!(Mat4::<float>::identity().is_symmetric());
|
assert!(Mat4::<f64>::identity().is_symmetric());
|
||||||
assert!(Mat4::<float>::identity().is_diagonal());
|
assert!(Mat4::<f64>::identity().is_diagonal());
|
||||||
assert!(!Mat4::<float>::identity().is_rotated());
|
assert!(!Mat4::<f64>::identity().is_rotated());
|
||||||
assert!(Mat4::<float>::identity().is_invertible());
|
assert!(Mat4::<f64>::identity().is_invertible());
|
||||||
|
|
||||||
assert!(!mat4::A.is_identity());
|
assert!(!mat4::A.is_identity());
|
||||||
assert!(!mat4::A.is_symmetric());
|
assert!(!mat4::A.is_symmetric());
|
||||||
|
|
|
@ -18,11 +18,11 @@ use cgmath::point::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_points() {
|
fn test_from_points() {
|
||||||
assert_eq!(Plane::from_points(Point3::new(5f, 0f, 5f),
|
assert_eq!(Plane::from_points(Point3::new(5f64, 0f64, 5f64),
|
||||||
Point3::new(5f, 5f, 5f),
|
Point3::new(5f64, 5f64, 5f64),
|
||||||
Point3::new(5f, 0f, -1f)), Some(Plane::from_abcd(-1f, 0f, 0f, 5f)));
|
Point3::new(5f64, 0f64, -1f64)), Some(Plane::from_abcd(-1f64, 0f64, 0f64, 5f64)));
|
||||||
|
|
||||||
assert_eq!(Plane::from_points(Point3::new(0f, 5f, -5f),
|
assert_eq!(Plane::from_points(Point3::new(0f64, 5f64, -5f64),
|
||||||
Point3::new(0f, 5f, 0f),
|
Point3::new(0f64, 5f64, 0f64),
|
||||||
Point3::new(0f, 5f, 5f)), None); // The points are parallel
|
Point3::new(0f64, 5f64, 5f64)), None); // The points are parallel
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
#[feature(globs)];
|
||||||
|
|
||||||
extern mod cgmath;
|
extern mod cgmath;
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ fn test_comp_add() {
|
||||||
assert_eq!(Vec3::new(1, 2, 3).comp_add(), 6);
|
assert_eq!(Vec3::new(1, 2, 3).comp_add(), 6);
|
||||||
assert_eq!(Vec4::new(1, 2, 3, 4).comp_add(), 10);
|
assert_eq!(Vec4::new(1, 2, 3, 4).comp_add(), 10);
|
||||||
|
|
||||||
assert_eq!(Vec2::new(3f, 4f).comp_add(), 7f);
|
assert_eq!(Vec2::new(3f64, 4f64).comp_add(), 7f64);
|
||||||
assert_eq!(Vec3::new(4f, 5f, 6f).comp_add(), 15f);
|
assert_eq!(Vec3::new(4f64, 5f64, 6f64).comp_add(), 15f64);
|
||||||
assert_eq!(Vec4::new(5f, 6f, 7f, 8f).comp_add(), 26f);
|
assert_eq!(Vec4::new(5f64, 6f64, 7f64, 8f64).comp_add(), 26f64);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -47,9 +47,9 @@ fn test_comp_mul() {
|
||||||
assert_eq!(Vec3::new(1, 2, 3).comp_mul(), 6);
|
assert_eq!(Vec3::new(1, 2, 3).comp_mul(), 6);
|
||||||
assert_eq!(Vec4::new(1, 2, 3, 4).comp_mul(), 24);
|
assert_eq!(Vec4::new(1, 2, 3, 4).comp_mul(), 24);
|
||||||
|
|
||||||
assert_eq!(Vec2::new(3f, 4f).comp_mul(), 12f);
|
assert_eq!(Vec2::new(3f64, 4f64).comp_mul(), 12f64);
|
||||||
assert_eq!(Vec3::new(4f, 5f, 6f).comp_mul(), 120f);
|
assert_eq!(Vec3::new(4f64, 5f64, 6f64).comp_mul(), 120f64);
|
||||||
assert_eq!(Vec4::new(5f, 6f, 7f, 8f).comp_mul(), 1680f);
|
assert_eq!(Vec4::new(5f64, 6f64, 7f64, 8f64).comp_mul(), 1680f64);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -58,9 +58,9 @@ fn test_comp_min() {
|
||||||
assert_eq!(Vec3::new(1, 2, 3).comp_min(), 1);
|
assert_eq!(Vec3::new(1, 2, 3).comp_min(), 1);
|
||||||
assert_eq!(Vec4::new(1, 2, 3, 4).comp_min(), 1);
|
assert_eq!(Vec4::new(1, 2, 3, 4).comp_min(), 1);
|
||||||
|
|
||||||
assert_eq!(Vec2::new(3f, 4f).comp_min(), 3f);
|
assert_eq!(Vec2::new(3f64, 4f64).comp_min(), 3f64);
|
||||||
assert_eq!(Vec3::new(4f, 5f, 6f).comp_min(), 4f);
|
assert_eq!(Vec3::new(4f64, 5f64, 6f64).comp_min(), 4f64);
|
||||||
assert_eq!(Vec4::new(5f, 6f, 7f, 8f).comp_min(), 5f);
|
assert_eq!(Vec4::new(5f64, 6f64, 7f64, 8f64).comp_min(), 5f64);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -69,9 +69,9 @@ fn test_comp_max() {
|
||||||
assert_eq!(Vec3::new(1, 2, 3).comp_max(), 3);
|
assert_eq!(Vec3::new(1, 2, 3).comp_max(), 3);
|
||||||
assert_eq!(Vec4::new(1, 2, 3, 4).comp_max(), 4);
|
assert_eq!(Vec4::new(1, 2, 3, 4).comp_max(), 4);
|
||||||
|
|
||||||
assert_eq!(Vec2::new(3f, 4f).comp_max(), 4f);
|
assert_eq!(Vec2::new(3f64, 4f64).comp_max(), 4f64);
|
||||||
assert_eq!(Vec3::new(4f, 5f, 6f).comp_max(), 6f);
|
assert_eq!(Vec3::new(4f64, 5f64, 6f64).comp_max(), 6f64);
|
||||||
assert_eq!(Vec4::new(5f, 6f, 7f, 8f).comp_max(), 8f);
|
assert_eq!(Vec4::new(5f64, 6f64, 7f64, 8f64).comp_max(), 8f64);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -88,9 +88,9 @@ fn test_cross() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_perpendicular() {
|
fn test_is_perpendicular() {
|
||||||
assert!(Vec2::new(1f, 0f).is_perpendicular(&Vec2::new(0f, 1f)));
|
assert!(Vec2::new(1f64, 0f64).is_perpendicular(&Vec2::new(0f64, 1f64)));
|
||||||
assert!(Vec3::new(0f, 1f, 0f).is_perpendicular(&Vec3::new(0f, 0f, 1f)));
|
assert!(Vec3::new(0f64, 1f64, 0f64).is_perpendicular(&Vec3::new(0f64, 0f64, 1f64)));
|
||||||
assert!(Vec4::new(1f, 0f, 0f, 0f).is_perpendicular(&Vec4::new(0f, 0f, 0f, 1f)));
|
assert!(Vec4::new(1f64, 0f64, 0f64, 0f64).is_perpendicular(&Vec4::new(0f64, 0f64, 0f64, 1f64)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -99,8 +99,8 @@ mod test_length {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec2(){
|
fn test_vec2(){
|
||||||
let (a, a_res) = (Vec2::new(3f, 4f), 5f); // (3, 4, 5) Pythagorean triple
|
let (a, a_res) = (Vec2::new(3f64, 4f64), 5f64); // (3, 4, 5) Pythagorean triple
|
||||||
let (b, b_res) = (Vec2::new(5f, 12f), 13f); // (5, 12, 13) Pythagorean triple
|
let (b, b_res) = (Vec2::new(5f64, 12f64), 13f64); // (5, 12, 13) Pythagorean triple
|
||||||
|
|
||||||
assert_eq!(a.length2(), a_res * a_res);
|
assert_eq!(a.length2(), a_res * a_res);
|
||||||
assert_eq!(b.length2(), b_res * b_res);
|
assert_eq!(b.length2(), b_res * b_res);
|
||||||
|
@ -111,8 +111,8 @@ mod test_length {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec3(){
|
fn test_vec3(){
|
||||||
let (a, a_res) = (Vec3::new(2f, 3f, 6f), 7f); // (2, 3, 6, 7) Pythagorean quadruple
|
let (a, a_res) = (Vec3::new(2f64, 3f64, 6f64), 7f64); // (2, 3, 6, 7) Pythagorean quadruple
|
||||||
let (b, b_res) = (Vec3::new(1f, 4f, 8f), 9f); // (1, 4, 8, 9) Pythagorean quadruple
|
let (b, b_res) = (Vec3::new(1f64, 4f64, 8f64), 9f64); // (1, 4, 8, 9) Pythagorean quadruple
|
||||||
|
|
||||||
assert_eq!(a.length2(), a_res * a_res);
|
assert_eq!(a.length2(), a_res * a_res);
|
||||||
assert_eq!(b.length2(), b_res * b_res);
|
assert_eq!(b.length2(), b_res * b_res);
|
||||||
|
@ -123,8 +123,8 @@ mod test_length {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec4(){
|
fn test_vec4(){
|
||||||
let (a, a_res) = (Vec4::new(1f, 2f, 4f, 10f), 11f); // (1, 2, 4, 10, 11) Pythagorean quintuple
|
let (a, a_res) = (Vec4::new(1f64, 2f64, 4f64, 10f64), 11f64); // (1, 2, 4, 10, 11) Pythagorean quintuple
|
||||||
let (b, b_res) = (Vec4::new(1f, 2f, 8f, 10f), 13f); // (1, 2, 8, 10, 13) Pythagorean quintuple
|
let (b, b_res) = (Vec4::new(1f64, 2f64, 8f64, 10f64), 13f64); // (1, 2, 8, 10, 13) Pythagorean quintuple
|
||||||
|
|
||||||
assert_eq!(a.length2(), a_res * a_res);
|
assert_eq!(a.length2(), a_res * a_res);
|
||||||
assert_eq!(b.length2(), b_res * b_res);
|
assert_eq!(b.length2(), b_res * b_res);
|
||||||
|
@ -136,23 +136,23 @@ mod test_length {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_angle() {
|
fn test_angle() {
|
||||||
assert_approx_eq!(Vec2::new(1f, 0f).angle(&Vec2::new(0f, 1f)), rad(Real::frac_pi_2()));
|
assert_approx_eq!(Vec2::new(1f64, 0f64).angle(&Vec2::new(0f64, 1f64)), rad(Real::frac_pi_2()));
|
||||||
assert_approx_eq!(Vec2::new(10f, 0f).angle(&Vec2::new(0f, 5f)), rad(Real::frac_pi_2()));
|
assert_approx_eq!(Vec2::new(10f64, 0f64).angle(&Vec2::new(0f64, 5f64)), rad(Real::frac_pi_2()));
|
||||||
assert_approx_eq!(Vec2::new(-1f, 0f).angle(&Vec2::new(0f, 1f)), -rad(Real::frac_pi_2()));
|
assert_approx_eq!(Vec2::new(-1f64, 0f64).angle(&Vec2::new(0f64, 1f64)), -rad(Real::frac_pi_2()));
|
||||||
|
|
||||||
assert_approx_eq!(Vec3::new(1f, 0f, 1f).angle(&Vec3::new(1f, 1f, 0f)), rad(Real::frac_pi_3()));
|
assert_approx_eq!(Vec3::new(1f64, 0f64, 1f64).angle(&Vec3::new(1f64, 1f64, 0f64)), rad(Real::frac_pi_3()));
|
||||||
assert_approx_eq!(Vec3::new(10f, 0f, 10f).angle(&Vec3::new(5f, 5f, 0f)), rad(Real::frac_pi_3()));
|
assert_approx_eq!(Vec3::new(10f64, 0f64, 10f64).angle(&Vec3::new(5f64, 5f64, 0f64)), rad(Real::frac_pi_3()));
|
||||||
assert_approx_eq!(Vec3::new(-1f, 0f, -1f).angle(&Vec3::new(1f, -1f, 0f)), rad(2f * Real::frac_pi_3()));
|
assert_approx_eq!(Vec3::new(-1f64, 0f64, -1f64).angle(&Vec3::new(1f64, -1f64, 0f64)), rad(2f64 * Real::frac_pi_3()));
|
||||||
|
|
||||||
assert_approx_eq!(Vec4::new(1f, 0f, 1f, 0f).angle(&Vec4::new(0f, 1f, 0f, 1f)), rad(Real::frac_pi_2()));
|
assert_approx_eq!(Vec4::new(1f64, 0f64, 1f64, 0f64).angle(&Vec4::new(0f64, 1f64, 0f64, 1f64)), rad(Real::frac_pi_2()));
|
||||||
assert_approx_eq!(Vec4::new(10f, 0f, 10f, 0f).angle(&Vec4::new(0f, 5f, 0f, 5f)), rad(Real::frac_pi_2()));
|
assert_approx_eq!(Vec4::new(10f64, 0f64, 10f64, 0f64).angle(&Vec4::new(0f64, 5f64, 0f64, 5f64)), rad(Real::frac_pi_2()));
|
||||||
assert_approx_eq!(Vec4::new(-1f, 0f, -1f, 0f).angle(&Vec4::new(0f, 1f, 0f, 1f)), rad(Real::frac_pi_2()));
|
assert_approx_eq!(Vec4::new(-1f64, 0f64, -1f64, 0f64).angle(&Vec4::new(0f64, 1f64, 0f64, 1f64)), rad(Real::frac_pi_2()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_normalize() {
|
fn test_normalize() {
|
||||||
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||||
assert_approx_eq!(Vec2::new(3f, 4f).normalize(), Vec2::new(3f/5f, 4f/5f));
|
assert_approx_eq!(Vec2::new(3f64, 4f64).normalize(), Vec2::new(3f64/5f64, 4f64/5f64));
|
||||||
assert_approx_eq!(Vec3::new(2f, 3f, 6f).normalize(), Vec3::new(2f/7f, 3f/7f, 6f/7f));
|
assert_approx_eq!(Vec3::new(2f64, 3f64, 6f64).normalize(), Vec3::new(2f64/7f64, 3f64/7f64, 6f64/7f64));
|
||||||
assert_approx_eq!(Vec4::new(1f, 2f, 4f, 10f).normalize(), Vec4::new(1f/11f, 2f/11f, 4f/11f, 10f/11f));
|
assert_approx_eq!(Vec4::new(1f64, 2f64, 4f64, 10f64).normalize(), Vec4::new(1f64/11f64, 2f64/11f64, 4f64/11f64, 10f64/11f64));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue