2019-08-27 20:30:20 +08:00
|
|
|
use na::{Orthographic3, Perspective3, Point3};
|
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
|
|
|
|
2018-12-10 04:38:02 +08:00
|
|
|
let id = inv * proj.into_inner();
|
2017-02-13 01:17:09 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-12-10 04:32:35 +08:00
|
|
|
let id = inv * proj.into_inner();
|
2017-02-13 01:17:09 +08:00
|
|
|
|
|
|
|
assert!(id.is_identity(1.0e-7));
|
|
|
|
}
|
|
|
|
|
2019-08-27 20:30:20 +08:00
|
|
|
#[test]
|
|
|
|
fn perspective_matrix_point_transformation() {
|
2021-01-29 20:33:37 +08:00
|
|
|
// https://github.com/dimforge/nalgebra/issues/640
|
2019-08-27 20:30:20 +08:00
|
|
|
let proj = Perspective3::new(4.0 / 3.0, 90.0, 0.1, 100.0);
|
|
|
|
let perspective_inv = proj.as_matrix().try_inverse().unwrap();
|
|
|
|
let some_point = Point3::new(1.0, 2.0, 0.0);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
perspective_inv.transform_point(&some_point),
|
|
|
|
Point3::from_homogeneous(perspective_inv * some_point.coords.push(1.0)).unwrap()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[cfg(feature = "proptest-support")]
|
|
|
|
mod proptest_tests {
|
|
|
|
use na::{Orthographic3, Perspective3};
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
use crate::proptest::*;
|
|
|
|
use proptest::{prop_assert, proptest};
|
|
|
|
|
|
|
|
proptest! {
|
|
|
|
#[test]
|
|
|
|
fn perspective_project_unproject(pt in point3()) {
|
2018-01-17 23:48:47 +08:00
|
|
|
let proj = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0);
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2018-01-17 23:48:47 +08:00
|
|
|
let projected = proj.project_point(&pt);
|
|
|
|
let unprojected = proj.unproject_point(&projected);
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(pt, unprojected, epsilon = 1.0e-7))
|
2018-01-17 23:48:47 +08:00
|
|
|
}
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn orthographic_project_unproject(pt in point3()) {
|
2018-01-17 23:48:47 +08:00
|
|
|
let proj = Orthographic3::new(1.0, 2.0, -3.0, -2.5, 10.0, 900.0);
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2018-01-17 23:48:47 +08:00
|
|
|
let projected = proj.project_point(&pt);
|
|
|
|
let unprojected = proj.unproject_point(&projected);
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(pt, unprojected, epsilon = 1.0e-7))
|
2018-01-17 23:48:47 +08:00
|
|
|
}
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
}
|