2021-03-01 00:52:14 +08:00
|
|
|
#![cfg(feature = "proptest-support")]
|
2017-02-13 01:17:09 +08:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
use na::{Unit, UnitComplex};
|
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!(
|
2017-02-13 01:17:09 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* From/to rotation matrix.
|
|
|
|
*
|
|
|
|
*/
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn unit_complex_rotation_conversion(c in unit_complex()) {
|
2018-11-07 01:32:20 +08:00
|
|
|
let r = c.to_rotation_matrix();
|
2017-02-13 01:17:09 +08:00
|
|
|
let cc = UnitComplex::from_rotation_matrix(&r);
|
|
|
|
let rr = cc.to_rotation_matrix();
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(c, cc, epsilon = 1.0e-7));
|
|
|
|
prop_assert!(relative_eq!(r, rr, epsilon = 1.0e-7));
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
* Point/Vector transformation.
|
2017-02-13 01:17:09 +08:00
|
|
|
*
|
|
|
|
*/
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn unit_complex_transformation(c in unit_complex(), v in vector2(), p in point2()) {
|
2018-11-07 01:32:20 +08:00
|
|
|
let r = c.to_rotation_matrix();
|
2017-02-13 01:17:09 +08:00
|
|
|
let rv = r * v;
|
|
|
|
let rp = r * p;
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(c * v, rv, epsilon = 1.0e-7)
|
2018-11-07 01:32:20 +08:00
|
|
|
&& relative_eq!(c * &v, rv, epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(&c * v, rv, epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(&c * &v, rv, epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(c * p, rp, epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(c * &p, rp, epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(&c * p, rp, epsilon = 1.0e-7)
|
2021-03-01 00:52:14 +08:00
|
|
|
&& relative_eq!(&c * &p, rp, epsilon = 1.0e-7))
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Inversion.
|
|
|
|
*
|
|
|
|
*/
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn unit_complex_inv(c in unit_complex()) {
|
2017-02-13 01:17:09 +08:00
|
|
|
let iq = c.inverse();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(&iq * &c, UnitComplex::identity(), epsilon = 1.0e-7)
|
2018-11-07 01:32:20 +08:00
|
|
|
&& relative_eq!(iq * &c, UnitComplex::identity(), epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(&iq * c, UnitComplex::identity(), epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(iq * c, UnitComplex::identity(), epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(&c * &iq, UnitComplex::identity(), epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(c * &iq, UnitComplex::identity(), epsilon = 1.0e-7)
|
|
|
|
&& relative_eq!(&c * iq, UnitComplex::identity(), epsilon = 1.0e-7)
|
2021-03-01 00:52:14 +08:00
|
|
|
&& relative_eq!(c * iq, UnitComplex::identity(), epsilon = 1.0e-7))
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2021-03-01 00:52:14 +08:00
|
|
|
* Quaternion * Vector == Rotation * Vector
|
2017-02-13 01:17:09 +08:00
|
|
|
*
|
|
|
|
*/
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn unit_complex_mul_vector(c in unit_complex(), v in vector2(), p in point2()) {
|
2017-02-13 01:17:09 +08:00
|
|
|
let r = c.to_rotation_matrix();
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(c * v, r * v, epsilon = 1.0e-7));
|
|
|
|
prop_assert!(relative_eq!(c * p, r * p, epsilon = 1.0e-7));
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that all operators (incl. all combinations of references) work.
|
|
|
|
// See the top comment on `geometry/quaternion_ops.rs` for details on which operations are
|
|
|
|
// supported.
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
2020-04-06 02:36:26 +08:00
|
|
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
2018-11-07 01:32:20 +08:00
|
|
|
fn all_op_exist(
|
2021-03-01 00:52:14 +08:00
|
|
|
uc in unit_complex(),
|
|
|
|
v in vector2(),
|
|
|
|
p in point2(),
|
|
|
|
r in rotation2()
|
|
|
|
) {
|
2017-02-13 01:17:09 +08:00
|
|
|
let uv = Unit::new_normalize(v);
|
|
|
|
|
|
|
|
let ucMuc = uc * uc;
|
2018-11-07 01:32:20 +08:00
|
|
|
let ucMr = uc * r;
|
|
|
|
let rMuc = r * uc;
|
2017-02-13 01:17:09 +08:00
|
|
|
let ucDuc = uc / uc;
|
2018-11-07 01:32:20 +08:00
|
|
|
let ucDr = uc / r;
|
|
|
|
let rDuc = r / uc;
|
2017-02-13 01:17:09 +08:00
|
|
|
|
2018-11-07 01:32:20 +08:00
|
|
|
let ucMp = uc * p;
|
|
|
|
let ucMv = uc * v;
|
2017-02-13 01:17:09 +08:00
|
|
|
let ucMuv = uc * uv;
|
|
|
|
|
|
|
|
let mut ucMuc1 = uc;
|
|
|
|
let mut ucMuc2 = uc;
|
|
|
|
|
|
|
|
let mut ucMr1 = uc;
|
|
|
|
let mut ucMr2 = uc;
|
|
|
|
|
|
|
|
let mut ucDuc1 = uc;
|
|
|
|
let mut ucDuc2 = uc;
|
|
|
|
|
|
|
|
let mut ucDr1 = uc;
|
|
|
|
let mut ucDr2 = uc;
|
|
|
|
|
|
|
|
ucMuc1 *= uc;
|
|
|
|
ucMuc2 *= &uc;
|
|
|
|
|
|
|
|
ucMr1 *= r;
|
|
|
|
ucMr2 *= &r;
|
|
|
|
|
|
|
|
ucDuc1 /= uc;
|
|
|
|
ucDuc2 /= &uc;
|
|
|
|
|
|
|
|
ucDr1 /= r;
|
|
|
|
ucDr2 /= &r;
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(ucMuc1 == ucMuc
|
2018-11-07 01:32:20 +08:00
|
|
|
&& ucMuc1 == ucMuc2
|
|
|
|
&& ucMr1 == ucMr
|
|
|
|
&& ucMr1 == ucMr2
|
|
|
|
&& ucDuc1 == ucDuc
|
|
|
|
&& ucDuc1 == ucDuc2
|
|
|
|
&& ucDr1 == ucDr
|
|
|
|
&& ucDr1 == ucDr2
|
|
|
|
&& ucMuc == &uc * &uc
|
|
|
|
&& ucMuc == uc * &uc
|
|
|
|
&& ucMuc == &uc * uc
|
|
|
|
&& ucMr == &uc * &r
|
|
|
|
&& ucMr == uc * &r
|
|
|
|
&& ucMr == &uc * r
|
|
|
|
&& rMuc == &r * &uc
|
|
|
|
&& rMuc == r * &uc
|
|
|
|
&& rMuc == &r * uc
|
|
|
|
&& ucDuc == &uc / &uc
|
|
|
|
&& ucDuc == uc / &uc
|
|
|
|
&& ucDuc == &uc / uc
|
|
|
|
&& ucDr == &uc / &r
|
|
|
|
&& ucDr == uc / &r
|
|
|
|
&& ucDr == &uc / r
|
|
|
|
&& rDuc == &r / &uc
|
|
|
|
&& rDuc == r / &uc
|
|
|
|
&& rDuc == &r / uc
|
|
|
|
&& ucMp == &uc * &p
|
|
|
|
&& ucMp == uc * &p
|
|
|
|
&& ucMp == &uc * p
|
|
|
|
&& ucMv == &uc * &v
|
|
|
|
&& ucMv == uc * &v
|
|
|
|
&& ucMv == &uc * v
|
|
|
|
&& ucMuv == &uc * &uv
|
|
|
|
&& ucMuv == uc * &uv
|
2021-03-01 00:52:14 +08:00
|
|
|
&& ucMuv == &uc * uv)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
);
|