2018-01-17 22:47:28 +08:00
|
|
|
#![cfg(feature = "arbitrary")]
|
2016-12-05 05:44:42 +08:00
|
|
|
use na::{Point3, Vector3, Vector4};
|
2018-10-22 13:00:10 +08:00
|
|
|
use num::Zero;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn point_ops() {
|
|
|
|
let a = Point3::new(1.0, 2.0, 3.0);
|
|
|
|
let b = Point3::new(1.0, 2.0, 3.0);
|
|
|
|
let c = Vector3::new(1.0, 2.0, 3.0);
|
|
|
|
|
2018-10-22 13:00:10 +08:00
|
|
|
assert_eq!(a - b, Vector3::zero());
|
2016-12-05 05:44:42 +08:00
|
|
|
assert_eq!(&a - &b, Vector3::zero());
|
2018-10-22 13:00:10 +08:00
|
|
|
assert_eq!(a - &b, Vector3::zero());
|
|
|
|
assert_eq!(&a - b, Vector3::zero());
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2018-10-22 13:00:10 +08:00
|
|
|
assert_eq!(b - c, Point3::origin());
|
2016-12-05 05:44:42 +08:00
|
|
|
assert_eq!(&b - &c, Point3::origin());
|
2018-10-22 13:00:10 +08:00
|
|
|
assert_eq!(b - &c, Point3::origin());
|
|
|
|
assert_eq!(&b - c, Point3::origin());
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2018-10-22 13:00:10 +08:00
|
|
|
assert_eq!(b + c, 2.0 * a);
|
2016-12-05 05:44:42 +08:00
|
|
|
assert_eq!(&b + &c, 2.0 * a);
|
2018-10-22 13:00:10 +08:00
|
|
|
assert_eq!(b + &c, 2.0 * a);
|
|
|
|
assert_eq!(&b + c, 2.0 * a);
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
let mut a1 = a;
|
|
|
|
let mut a2 = a;
|
|
|
|
let mut a3 = a;
|
|
|
|
let mut a4 = a;
|
|
|
|
|
|
|
|
a1 -= c;
|
|
|
|
a2 -= &c;
|
|
|
|
a3 += c;
|
|
|
|
a4 += &c;
|
|
|
|
|
|
|
|
assert_eq!(a1, Point3::origin());
|
|
|
|
assert_eq!(a2, Point3::origin());
|
|
|
|
assert_eq!(a3, 2.0 * a);
|
|
|
|
assert_eq!(a4, 2.0 * a);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn point_coordinates() {
|
|
|
|
let mut pt = Point3::origin();
|
|
|
|
|
|
|
|
assert_eq!(pt.x, 0);
|
|
|
|
assert_eq!(pt.y, 0);
|
|
|
|
assert_eq!(pt.z, 0);
|
|
|
|
|
|
|
|
pt.x = 1;
|
|
|
|
pt.y = 2;
|
|
|
|
pt.z = 3;
|
|
|
|
|
|
|
|
assert_eq!(pt.x, 1);
|
|
|
|
assert_eq!(pt.y, 2);
|
|
|
|
assert_eq!(pt.z, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn point_scale() {
|
2018-10-22 13:00:10 +08:00
|
|
|
let pt = Point3::new(1, 2, 3);
|
2016-12-05 05:44:42 +08:00
|
|
|
let expected = Point3::new(10, 20, 30);
|
|
|
|
|
|
|
|
assert_eq!(pt * 10, expected);
|
|
|
|
assert_eq!(&pt * 10, expected);
|
|
|
|
assert_eq!(10 * pt, expected);
|
|
|
|
assert_eq!(10 * &pt, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn point_vector_sum() {
|
2018-10-22 13:00:10 +08:00
|
|
|
let pt = Point3::new(1, 2, 3);
|
|
|
|
let vec = Vector3::new(10, 20, 30);
|
2016-12-05 05:44:42 +08:00
|
|
|
let expected = Point3::new(11, 22, 33);
|
|
|
|
|
|
|
|
assert_eq!(&pt + &vec, expected);
|
|
|
|
assert_eq!(pt + &vec, expected);
|
|
|
|
assert_eq!(&pt + vec, expected);
|
|
|
|
assert_eq!(pt + vec, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_homogeneous() {
|
2018-10-22 13:00:10 +08:00
|
|
|
let a = Point3::new(1.0, 2.0, 3.0);
|
2016-12-05 05:44:42 +08:00
|
|
|
let expected = Vector4::new(1.0, 2.0, 3.0, 1.0);
|
|
|
|
|
|
|
|
assert_eq!(a.to_homogeneous(), expected);
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:00:10 +08:00
|
|
|
quickcheck!(fn point_sub(pt1: Point3<f64>, pt2: Point3<f64>) -> bool {
|
|
|
|
let dpt = &pt2 - &pt1;
|
|
|
|
relative_eq!(pt2, pt1 + dpt, epsilon = 1.0e-7)
|
|
|
|
});
|