2018-01-17 23:48:47 +08:00
|
|
|
#![cfg(feature = "arbitrary")]
|
2017-02-13 01:17:09 +08:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
2018-10-21 04:26:44 +08:00
|
|
|
use na::{Point2, Rotation2, Unit, UnitComplex, Vector2};
|
2017-02-13 01:17:09 +08:00
|
|
|
|
|
|
|
quickcheck!(
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* From/to rotation matrix.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
fn unit_complex_rotation_conversion(c: UnitComplex<f64>) -> bool {
|
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();
|
|
|
|
|
2018-11-07 01:32:20 +08:00
|
|
|
relative_eq!(c, cc, epsilon = 1.0e-7) && 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
fn unit_complex_transformation(c: UnitComplex<f64>, v: Vector2<f64>, p: Point2<f64>) -> bool {
|
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;
|
|
|
|
|
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 * &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)
|
|
|
|
&& relative_eq!(&c * &p, rp, epsilon = 1.0e-7)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Inversion.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
fn unit_complex_inv(c: UnitComplex<f64>) -> bool {
|
|
|
|
let iq = c.inverse();
|
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!(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)
|
|
|
|
&& relative_eq!(c * iq, UnitComplex::identity(), epsilon = 1.0e-7)
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
2017-08-16 01:36:38 +08:00
|
|
|
* Quaterion * Vector == Rotation * Vector
|
2017-02-13 01:17:09 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
fn unit_complex_mul_vector(c: UnitComplex<f64>, v: Vector2<f64>, p: Point2<f64>) -> bool {
|
|
|
|
let r = c.to_rotation_matrix();
|
|
|
|
|
2018-11-07 01:32:20 +08:00
|
|
|
relative_eq!(c * v, r * v, epsilon = 1.0e-7) && 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.
|
2018-11-07 01:32:20 +08:00
|
|
|
fn all_op_exist(
|
|
|
|
uc: UnitComplex<f64>,
|
|
|
|
v: Vector2<f64>,
|
|
|
|
p: Point2<f64>,
|
2020-04-06 00:49:48 +08:00
|
|
|
r: Rotation2<f64>,
|
|
|
|
) -> bool {
|
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;
|
|
|
|
|
2018-11-07 01:32:20 +08:00
|
|
|
ucMuc1 == ucMuc
|
|
|
|
&& 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
|
|
|
|
&& ucMuv == &uc * uv
|
2017-02-13 01:17:09 +08:00
|
|
|
}
|
|
|
|
);
|