nalgebra/tests/geometry/projection.rs

47 lines
1.2 KiB
Rust
Raw Normal View History

2018-10-22 13:00:10 +08:00
use na::{Orthographic3, Perspective3};
2017-02-13 01:17:09 +08:00
#[test]
fn perspective_inverse() {
let proj = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0);
2018-10-22 13:00:10 +08:00
let inv = proj.inverse();
2017-02-13 01:17:09 +08:00
let id = inv * proj.unwrap();
assert!(id.is_identity(1.0e-7));
}
#[test]
fn orthographic_inverse() {
let proj = Orthographic3::new(1.0, 2.0, -3.0, -2.5, 10.0, 900.0);
2018-10-22 13:00:10 +08:00
let inv = proj.inverse();
2017-02-13 01:17:09 +08:00
let id = inv * proj.unwrap();
assert!(id.is_identity(1.0e-7));
}
#[cfg(feature = "arbitrary")]
mod quickcheck_tests {
2018-10-22 13:00:10 +08:00
use na::{Orthographic3, Perspective3, Point3};
2017-02-13 01:17:09 +08:00
quickcheck!{
fn perspective_project_unproject(pt: Point3<f64>) -> bool {
let proj = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0);
2017-02-13 01:17:09 +08:00
let projected = proj.project_point(&pt);
let unprojected = proj.unproject_point(&projected);
relative_eq!(pt, unprojected, epsilon = 1.0e-7)
}
2017-02-13 01:17:09 +08:00
fn orthographic_project_unproject(pt: Point3<f64>) -> bool {
let proj = Orthographic3::new(1.0, 2.0, -3.0, -2.5, 10.0, 900.0);
2017-02-13 01:17:09 +08:00
let projected = proj.project_point(&pt);
let unprojected = proj.unproject_point(&projected);
2017-02-13 01:17:09 +08:00
relative_eq!(pt, unprojected, epsilon = 1.0e-7)
}
2017-02-13 01:17:09 +08:00
}
}