| 1 |
#![allow(clippy::excessive_precision)] |
| 2 |
|
| 3 |
#[macro_use] |
| 4 |
mod support; |
| 5 |
|
| 6 |
macro_rules! impl_quat_tests { |
| 7 |
($t:ident, $new:ident, $mat3:ident, $mat4:ident, $quat:ident, $vec2:ident, $vec3:ident, $vec4:ident) => { |
| 8 |
glam_test!(test_const, { |
| 9 |
const Q0: $quat = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0); |
| 10 |
const Q1: $quat = $quat::from_array([1.0, 2.0, 3.0, 4.0]); |
| 11 |
assert_eq!([1.0, 2.0, 3.0, 4.0], *Q0.as_ref()); |
| 12 |
assert_eq!([1.0, 2.0, 3.0, 4.0], *Q1.as_ref()); |
| 13 |
}); |
| 14 |
|
| 15 |
glam_test!(test_nan, { |
| 16 |
assert!($quat::NAN.is_nan()); |
| 17 |
assert!(!$quat::NAN.is_finite()); |
| 18 |
}); |
| 19 |
|
| 20 |
glam_test!(test_new, { |
| 21 |
let ytheta = deg(45.0); |
| 22 |
let q0 = $quat::from_rotation_y(ytheta); |
| 23 |
|
| 24 |
let v1 = $vec4::new(0.0, (ytheta * 0.5).sin(), 0.0, (ytheta * 0.5).cos()); |
| 25 |
assert_eq!(q0, $quat::from_vec4(v1)); |
| 26 |
let q1 = $quat::from_vec4(v1); |
| 27 |
assert_eq!(v1, q1.into()); |
| 28 |
|
| 29 |
assert_eq!(q0, $new(v1.x, v1.y, v1.z, v1.w)); |
| 30 |
|
| 31 |
let a1: [$t; 4] = q1.into(); |
| 32 |
assert_eq!([v1.x, v1.y, v1.z, v1.w], a1); |
| 33 |
|
| 34 |
assert_eq!(q1, $quat::from_array(a1)); |
| 35 |
|
| 36 |
assert_eq!(a1, *q0.as_ref()); |
| 37 |
}); |
| 38 |
|
| 39 |
glam_test!(test_funcs, { |
| 40 |
let q0 = $quat::from_euler(EulerRot::YXZ, deg(45.0), deg(180.0), deg(90.0)); |
| 41 |
assert!(q0.is_normalized()); |
| 42 |
assert_approx_eq!(q0.length_squared(), 1.0); |
| 43 |
assert_approx_eq!(q0.length(), 1.0); |
| 44 |
assert_approx_eq!(q0.length_recip(), 1.0); |
| 45 |
assert_approx_eq!(q0, q0.normalize()); |
| 46 |
|
| 47 |
assert_approx_eq!(q0.dot(q0), 1.0); |
| 48 |
assert_approx_eq!(q0.dot(q0), 1.0); |
| 49 |
|
| 50 |
let q1 = $quat::from_vec4($vec4::from(q0) * 2.0); |
| 51 |
assert!(!q1.is_normalized()); |
| 52 |
assert_approx_eq!(q1.length_squared(), 4.0, 1.0e-6); |
| 53 |
assert_approx_eq!(q1.length(), 2.0); |
| 54 |
assert_approx_eq!(q1.length_recip(), 0.5); |
| 55 |
assert_approx_eq!(q0, q1.normalize()); |
| 56 |
assert_approx_eq!(q0.dot(q1), 2.0, 1.0e-6); |
| 57 |
|
| 58 |
should_glam_assert!({ ($quat::IDENTITY * 0.0).normalize() }); |
| 59 |
}); |
| 60 |
|
| 61 |
glam_test!(test_rotation, { |
| 62 |
let zero = deg(0.0); |
| 63 |
let yaw = deg(30.0); |
| 64 |
let pitch = deg(60.0); |
| 65 |
let roll = deg(90.0); |
| 66 |
let y0 = $quat::from_rotation_y(yaw); |
| 67 |
assert!(y0.is_normalized()); |
| 68 |
let (axis, angle) = y0.to_axis_angle(); |
| 69 |
assert_approx_eq!(axis, $vec3::Y, 1.0e-6); |
| 70 |
assert_approx_eq!(angle, yaw); |
| 71 |
let y1 = $quat::from_euler(EulerRot::YXZ, yaw, zero, zero); |
| 72 |
assert_approx_eq!(y0, y1); |
| 73 |
let y2 = $quat::from_axis_angle($vec3::Y, yaw); |
| 74 |
assert_approx_eq!(y0, y2); |
| 75 |
let y3 = $quat::from_mat3(&$mat3::from_rotation_y(yaw)); |
| 76 |
assert_approx_eq!(y0, y3); |
| 77 |
let y4 = $quat::from_mat3(&$mat3::from_quat(y0)); |
| 78 |
assert_approx_eq!(y0, y4); |
| 79 |
|
| 80 |
let x0 = $quat::from_rotation_x(pitch); |
| 81 |
assert!(x0.is_normalized()); |
| 82 |
let (axis, angle) = x0.to_axis_angle(); |
| 83 |
assert_approx_eq!(axis, $vec3::X); |
| 84 |
assert_approx_eq!(angle, pitch, 1e-6); |
| 85 |
let x1 = $quat::from_euler(EulerRot::YXZ, zero, pitch, zero); |
| 86 |
assert_approx_eq!(x0, x1); |
| 87 |
let x2 = $quat::from_axis_angle($vec3::X, pitch); |
| 88 |
assert_approx_eq!(x0, x2); |
| 89 |
let x3 = $quat::from_mat4(&$mat4::from_rotation_x(deg(180.0))); |
| 90 |
assert!(x3.is_normalized()); |
| 91 |
assert_approx_eq!($quat::from_rotation_x(deg(180.0)), x3); |
| 92 |
|
| 93 |
let z0 = $quat::from_rotation_z(roll); |
| 94 |
assert!(z0.is_normalized()); |
| 95 |
let (axis, angle) = z0.to_axis_angle(); |
| 96 |
assert_approx_eq!(axis, $vec3::Z); |
| 97 |
assert_approx_eq!(angle, roll); |
| 98 |
let z1 = $quat::from_euler(EulerRot::YXZ, zero, zero, roll); |
| 99 |
assert_approx_eq!(z0, z1); |
| 100 |
let z2 = $quat::from_axis_angle($vec3::Z, roll); |
| 101 |
assert_approx_eq!(z0, z2); |
| 102 |
let z3 = $quat::from_mat4(&$mat4::from_rotation_z(roll)); |
| 103 |
assert_approx_eq!(z0, z3); |
| 104 |
|
| 105 |
let yx0 = y0 * x0; |
| 106 |
assert!(yx0.is_normalized()); |
| 107 |
let yx1 = $quat::from_euler(EulerRot::YXZ, yaw, pitch, zero); |
| 108 |
assert_approx_eq!(yx0, yx1); |
| 109 |
|
| 110 |
let yx0 = &y0 * x0; |
| 111 |
assert_approx_eq!(yx0, yx1); |
| 112 |
let yx0 = y0 * &x0; |
| 113 |
assert_approx_eq!(yx0, yx1); |
| 114 |
let yx0 = &y0 * &x0; |
| 115 |
assert_approx_eq!(yx0, yx1); |
| 116 |
|
| 117 |
let yxz0 = y0 * x0 * z0; |
| 118 |
assert!(yxz0.is_normalized()); |
| 119 |
let yxz1 = $quat::from_euler(EulerRot::YXZ, yaw, pitch, roll); |
| 120 |
assert_approx_eq!(yxz0, yxz1); |
| 121 |
|
| 122 |
// use the conjugate of z0 to remove the rotation from yxz0 |
| 123 |
let yx2 = yxz0 * z0.conjugate(); |
| 124 |
assert_approx_eq!(yx0, yx2); |
| 125 |
assert!((yxz0 * yxz0.conjugate()).is_near_identity()); |
| 126 |
|
| 127 |
// test inverse does the same |
| 128 |
let yx2 = yxz0 * z0.inverse(); |
| 129 |
assert_approx_eq!(yx0, yx2); |
| 130 |
assert!((yxz0 * yxz0.inverse()).is_near_identity()); |
| 131 |
|
| 132 |
let yxz2 = $quat::from_mat4(&$mat4::from_quat(yxz0)); |
| 133 |
assert_approx_eq!(yxz0, yxz2); |
| 134 |
|
| 135 |
// if near identity, just returns x axis and 0 rotation |
| 136 |
let (axis, angle) = $quat::IDENTITY.to_axis_angle(); |
| 137 |
assert_eq!(axis, $vec3::X); |
| 138 |
assert_eq!(angle, rad(0.0)); |
| 139 |
|
| 140 |
let mut x0 = $quat::from_rotation_x(pitch); |
| 141 |
x0 *= x0; |
| 142 |
assert_approx_eq!(x0, $quat::from_rotation_x(pitch * 2.0)); |
| 143 |
|
| 144 |
let mut x0 = $quat::from_rotation_x(pitch); |
| 145 |
x0 *= &x0.clone(); |
| 146 |
assert_approx_eq!(x0, $quat::from_rotation_x(pitch * 2.0)); |
| 147 |
|
| 148 |
should_glam_assert!({ ($quat::IDENTITY * 2.0).inverse() }); |
| 149 |
should_glam_assert!({ $quat::from_axis_angle($vec3::ZERO, 0.0) }); |
| 150 |
}); |
| 151 |
|
| 152 |
glam_test!(test_from_scaled_axis, { |
| 153 |
assert_eq!($quat::from_scaled_axis($vec3::ZERO), $quat::IDENTITY); |
| 154 |
assert_eq!( |
| 155 |
$quat::from_scaled_axis($vec3::Y * 1e-10), |
| 156 |
$quat::from_axis_angle($vec3::Y, 1e-10) |
| 157 |
); |
| 158 |
assert_eq!( |
| 159 |
$quat::from_scaled_axis($vec3::X * 1.0), |
| 160 |
$quat::from_axis_angle($vec3::X, 1.0) |
| 161 |
); |
| 162 |
assert_eq!( |
| 163 |
$quat::from_scaled_axis($vec3::Z * 2.0), |
| 164 |
$quat::from_axis_angle($vec3::Z, 2.0) |
| 165 |
); |
| 166 |
|
| 167 |
assert_eq!( |
| 168 |
$quat::from_scaled_axis($vec3::ZERO).to_scaled_axis(), |
| 169 |
$vec3::ZERO |
| 170 |
); |
| 171 |
for &v in &vec3_float_test_vectors!($vec3) { |
| 172 |
if v.length() < core::$t::consts::PI { |
| 173 |
assert!(($quat::from_scaled_axis(v).to_scaled_axis() - v).length() < 1e-6,); |
| 174 |
} |
| 175 |
} |
| 176 |
}); |
| 177 |
|
| 178 |
glam_test!(test_quat_look_at, { |
| 179 |
let eye = $vec3::new(0.0, 0.0, -5.0); |
| 180 |
let center = $vec3::new(0.0, 0.0, 0.0); |
| 181 |
let up = $vec3::new(1.0, 0.0, 0.0); |
| 182 |
|
| 183 |
let point = $vec3::new(1.0, 0.0, 0.0); |
| 184 |
|
| 185 |
let lh = $quat::look_at_lh(eye, center, up); |
| 186 |
let rh = $quat::look_at_rh(eye, center, up); |
| 187 |
assert_approx_eq!(lh * point, $vec3::new(0.0, 1.0, 0.0)); |
| 188 |
assert_approx_eq!(rh * point, $vec3::new(0.0, 1.0, 0.0)); |
| 189 |
|
| 190 |
let dir = (center - eye).normalize(); |
| 191 |
let lh = $quat::look_to_lh(dir, up); |
| 192 |
let rh = $quat::look_to_rh(dir, up); |
| 193 |
assert_approx_eq!(lh * point, $vec3::new(0.0, 1.0, 0.0)); |
| 194 |
assert_approx_eq!(rh * point, $vec3::new(0.0, 1.0, 0.0)); |
| 195 |
|
| 196 |
should_glam_assert!({ $quat::look_to_lh($vec3::ONE, $vec3::ZERO) }); |
| 197 |
should_glam_assert!({ $quat::look_to_lh($vec3::ZERO, $vec3::ONE) }); |
| 198 |
should_glam_assert!({ $quat::look_to_rh($vec3::ONE, $vec3::ZERO) }); |
| 199 |
should_glam_assert!({ $quat::look_to_rh($vec3::ZERO, $vec3::ONE) }); |
| 200 |
}); |
| 201 |
|
| 202 |
glam_test!(test_mul_vec3, { |
| 203 |
let qrz = $quat::from_rotation_z(deg(90.0)); |
| 204 |
assert_approx_eq!($vec3::Y, qrz * $vec3::X); |
| 205 |
assert_approx_eq!($vec3::Y, qrz.mul_vec3($vec3::X)); |
| 206 |
assert_approx_eq!($vec3::Y, -qrz * $vec3::X); |
| 207 |
assert_approx_eq!($vec3::Y, qrz.neg().mul_vec3($vec3::X)); |
| 208 |
assert_approx_eq!(-$vec3::X, qrz * $vec3::Y); |
| 209 |
assert_approx_eq!(-$vec3::X, qrz.mul_vec3($vec3::Y)); |
| 210 |
assert_approx_eq!(-$vec3::X, -qrz * $vec3::Y); |
| 211 |
assert_approx_eq!(-$vec3::X, qrz.neg().mul_vec3($vec3::Y)); |
| 212 |
|
| 213 |
// check vec3 * mat3 is the same |
| 214 |
let mrz = $mat3::from_quat(qrz); |
| 215 |
assert_approx_eq!($vec3::Y, mrz * $vec3::X); |
| 216 |
assert_approx_eq!($vec3::Y, mrz.mul_vec3($vec3::X)); |
| 217 |
// assert_approx_eq!($vec3::Y, -mrz * $vec3::X); |
| 218 |
assert_approx_eq!(-$vec3::X, mrz * $vec3::Y); |
| 219 |
assert_approx_eq!(-$vec3::X, mrz.mul_vec3($vec3::Y)); |
| 220 |
|
| 221 |
let qrx = $quat::from_rotation_x(deg(90.0)); |
| 222 |
assert_approx_eq!($vec3::X, qrx * $vec3::X); |
| 223 |
assert_approx_eq!($vec3::X, qrx.mul_vec3($vec3::X)); |
| 224 |
assert_approx_eq!($vec3::X, -qrx * $vec3::X); |
| 225 |
assert_approx_eq!($vec3::X, qrx.neg().mul_vec3($vec3::X)); |
| 226 |
assert_approx_eq!($vec3::Z, qrx * $vec3::Y); |
| 227 |
assert_approx_eq!($vec3::Z, qrx.mul_vec3($vec3::Y)); |
| 228 |
assert_approx_eq!($vec3::Z, -qrx * $vec3::Y); |
| 229 |
assert_approx_eq!($vec3::Z, qrx.neg().mul_vec3($vec3::Y)); |
| 230 |
|
| 231 |
// check vec3 * mat3 is the same |
| 232 |
let mrx = $mat3::from_quat(qrx); |
| 233 |
assert_approx_eq!($vec3::X, mrx * $vec3::X); |
| 234 |
assert_approx_eq!($vec3::X, mrx.mul_vec3($vec3::X)); |
| 235 |
assert_approx_eq!($vec3::Z, mrx * $vec3::Y); |
| 236 |
assert_approx_eq!($vec3::Z, mrx.mul_vec3($vec3::Y)); |
| 237 |
|
| 238 |
let qrxz = qrz * qrx; |
| 239 |
assert_approx_eq!($vec3::Y, qrxz * $vec3::X); |
| 240 |
assert_approx_eq!($vec3::Y, qrxz.mul_vec3($vec3::X)); |
| 241 |
assert_approx_eq!($vec3::Z, qrxz * $vec3::Y); |
| 242 |
assert_approx_eq!($vec3::Z, qrxz.mul_vec3($vec3::Y)); |
| 243 |
|
| 244 |
let mrxz = mrz * mrx; |
| 245 |
assert_approx_eq!($vec3::Y, mrxz * $vec3::X); |
| 246 |
assert_approx_eq!($vec3::Y, mrxz.mul_vec3($vec3::X)); |
| 247 |
assert_approx_eq!($vec3::Z, mrxz * $vec3::Y); |
| 248 |
assert_approx_eq!($vec3::Z, mrxz.mul_vec3($vec3::Y)); |
| 249 |
|
| 250 |
let qrzx = qrx * qrz; |
| 251 |
assert_approx_eq!($vec3::Z, qrzx * $vec3::X); |
| 252 |
assert_approx_eq!($vec3::Z, qrzx.mul_vec3($vec3::X)); |
| 253 |
assert_approx_eq!(-$vec3::X, qrzx * $vec3::Y); |
| 254 |
assert_approx_eq!(-$vec3::X, qrzx.mul_vec3($vec3::Y)); |
| 255 |
|
| 256 |
let mrzx = qrx * qrz; |
| 257 |
assert_approx_eq!($vec3::Z, mrzx * $vec3::X); |
| 258 |
assert_approx_eq!($vec3::Z, mrzx.mul_vec3($vec3::X)); |
| 259 |
assert_approx_eq!(-$vec3::X, mrzx * $vec3::Y); |
| 260 |
assert_approx_eq!(-$vec3::X, mrzx.mul_vec3($vec3::Y)); |
| 261 |
|
| 262 |
assert_approx_eq!(-$vec3::X, &mrzx * $vec3::Y); |
| 263 |
assert_approx_eq!(-$vec3::X, mrzx * &$vec3::Y); |
| 264 |
assert_approx_eq!(-$vec3::X, &mrzx * &$vec3::Y); |
| 265 |
|
| 266 |
should_glam_assert!({ ($quat::IDENTITY * 0.5).mul_vec3($vec3::X) }); |
| 267 |
should_glam_assert!({ ($quat::IDENTITY * 0.5) * $vec3::X }); |
| 268 |
}); |
| 269 |
|
| 270 |
glam_test!(test_angle_between, { |
| 271 |
const TAU: $t = 2.0 * core::$t::consts::PI; |
| 272 |
let eps = 10.0 * $t::EPSILON as f32; |
| 273 |
let q1 = $quat::from_euler(EulerRot::YXZ, 0.0, 0.0, 0.0); |
| 274 |
let q2 = $quat::from_euler(EulerRot::YXZ, TAU * 0.25, 0.0, 0.0); |
| 275 |
let q3 = $quat::from_euler(EulerRot::YXZ, TAU * 0.5, 0.0, 0.0); |
| 276 |
let q4 = $quat::from_euler(EulerRot::YXZ, 0.0, 0.0, TAU * 0.25); |
| 277 |
let q5 = $quat::from_axis_angle($vec3::new(1.0, 2.0, 3.0).normalize(), TAU * 0.3718); |
| 278 |
let q6 = $quat::from_axis_angle($vec3::new(-1.0, 5.0, 3.0).normalize(), TAU * 0.94); |
| 279 |
assert_approx_eq!(q1.angle_between(q2), TAU * 0.25, eps); |
| 280 |
assert_approx_eq!(q1.angle_between(q3), TAU * 0.5, eps); |
| 281 |
assert_approx_eq!(q3.angle_between(q3), 0.0, eps); |
| 282 |
assert_approx_eq!(q3.angle_between(-q3), 0.0, eps); |
| 283 |
assert_approx_eq!((q4 * q2 * q2).angle_between(q4 * q2), TAU * 0.25, eps); |
| 284 |
assert_approx_eq!(q1.angle_between(q5), TAU * 0.3718, eps); |
| 285 |
assert_approx_eq!( |
| 286 |
(q5 * q2 * q1).angle_between(q5 * q2 * q5), |
| 287 |
TAU * 0.3718, |
| 288 |
eps |
| 289 |
); |
| 290 |
assert_approx_eq!((q3 * q3).angle_between(q1), 0.0, eps); |
| 291 |
assert_approx_eq!((q3 * q3 * q3).angle_between(q3), 0.0, eps); |
| 292 |
assert_approx_eq!((q3 * q3 * q3 * q3).angle_between(q1), 0.0, eps); |
| 293 |
assert_approx_eq!(q1.angle_between(q6), TAU - TAU * 0.94, eps); |
| 294 |
assert_approx_eq!((q5 * q1).angle_between(q5 * q6), TAU - TAU * 0.94, eps); |
| 295 |
assert_approx_eq!((q1 * q5).angle_between(q6 * q5), TAU - TAU * 0.94, eps); |
| 296 |
}); |
| 297 |
|
| 298 |
glam_test!(test_lerp, { |
| 299 |
let q0 = $quat::from_rotation_y(deg(0.0)); |
| 300 |
assert_approx_eq!(q0, q0.slerp(q0, 0.0)); |
| 301 |
assert_approx_eq!(q0, q0.slerp(q0, 1.0)); |
| 302 |
|
| 303 |
let q1 = $quat::from_rotation_y(deg(90.0)); |
| 304 |
assert_approx_eq!(q0, q0.lerp(q1, 0.0)); |
| 305 |
assert_approx_eq!(q1, q0.lerp(q1, 1.0)); |
| 306 |
assert_approx_eq!($quat::from_rotation_y(deg(45.0)), q0.lerp(q1, 0.5)); |
| 307 |
|
| 308 |
should_glam_assert!({ $quat::lerp($quat::IDENTITY * 2.0, $quat::IDENTITY, 1.0) }); |
| 309 |
should_glam_assert!({ $quat::lerp($quat::IDENTITY, $quat::IDENTITY * 0.5, 1.0) }); |
| 310 |
}); |
| 311 |
|
| 312 |
glam_test!(test_slerp, { |
| 313 |
let q0 = $quat::from_rotation_y(deg(0.0)); |
| 314 |
assert_approx_eq!(q0, q0.slerp(q0, 0.0)); |
| 315 |
assert_approx_eq!(q0, q0.slerp(q0, 1.0)); |
| 316 |
|
| 317 |
let q1 = $quat::from_rotation_y(deg(90.0)); |
| 318 |
assert_approx_eq!(q0, q0.slerp(q1, 0.0), 1.0e-3); |
| 319 |
assert_approx_eq!(q1, q0.slerp(q1, 1.0), 1.0e-3); |
| 320 |
assert_approx_eq!($quat::from_rotation_y(deg(45.0)), q0.slerp(q1, 0.5), 1.0e-3); |
| 321 |
|
| 322 |
should_glam_assert!({ $quat::slerp($quat::IDENTITY * 2.0, $quat::IDENTITY, 1.0) }); |
| 323 |
should_glam_assert!({ $quat::slerp($quat::IDENTITY, $quat::IDENTITY * 0.5, 1.0) }); |
| 324 |
}); |
| 325 |
|
| 326 |
glam_test!(test_slerp_constant_speed, { |
| 327 |
let step = 0.01; |
| 328 |
let mut s = 0.0; |
| 329 |
while s <= 1.0 { |
| 330 |
let q0 = $quat::from_rotation_y(deg(0.0)); |
| 331 |
let q1 = $quat::from_rotation_y(deg(90.0)); |
| 332 |
let result = q0.slerp(q1, s); |
| 333 |
assert_approx_eq!($quat::from_rotation_y(deg(s * 90.0)), result, 1.0e-3); |
| 334 |
assert!(result.is_normalized()); |
| 335 |
s += step; |
| 336 |
} |
| 337 |
}); |
| 338 |
|
| 339 |
glam_test!(test_slerp_tau, { |
| 340 |
let q1 = $quat::IDENTITY; |
| 341 |
let q2 = $quat::from_rotation_x(core::$t::consts::TAU); |
| 342 |
let s = q1.slerp(q2, 1.); |
| 343 |
assert!(s.is_finite()); |
| 344 |
assert!(s.is_normalized()); |
| 345 |
}); |
| 346 |
|
| 347 |
glam_test!(test_slerp_negative_tau, { |
| 348 |
let q1 = $quat::IDENTITY; |
| 349 |
let q2 = $quat::from_rotation_x(-core::$t::consts::TAU); |
| 350 |
let s = q1.slerp(q2, 1.); |
| 351 |
assert!(s.is_finite()); |
| 352 |
assert!(s.is_normalized()); |
| 353 |
}); |
| 354 |
|
| 355 |
glam_test!(test_slerp_pi, { |
| 356 |
let q1 = $quat::IDENTITY; |
| 357 |
let q2 = $quat::from_rotation_x(core::$t::consts::PI); |
| 358 |
let s = q1.slerp(q2, 1.); |
| 359 |
assert!(s.is_finite()); |
| 360 |
assert!(s.is_normalized()); |
| 361 |
}); |
| 362 |
|
| 363 |
glam_test!(test_slerp_negative_pi, { |
| 364 |
let q1 = $quat::IDENTITY; |
| 365 |
let q2 = $quat::from_rotation_x(-core::$t::consts::PI); |
| 366 |
let s = q1.slerp(q2, 1.); |
| 367 |
assert!(s.is_finite()); |
| 368 |
assert!(s.is_normalized()); |
| 369 |
}); |
| 370 |
|
| 371 |
glam_test!(test_rotate_towards, { |
| 372 |
use core::$t::consts::{FRAC_PI_2, FRAC_PI_4}; |
| 373 |
let eps = 10.0 * $t::EPSILON as f32; |
| 374 |
|
| 375 |
// Setup such that `q0` is `PI/2` and `-PI/2` radians away from `q1` and `q2` respectively. |
| 376 |
let q0 = $quat::from_euler(EulerRot::YXZ, 0.0, 0.0, 0.0); |
| 377 |
let q1 = $quat::from_euler(EulerRot::YXZ, FRAC_PI_2, 0.0, 0.0); |
| 378 |
let q2 = $quat::from_euler(EulerRot::YXZ, -FRAC_PI_2, 0.0, 0.0); |
| 379 |
|
| 380 |
// Positive delta |
| 381 |
assert_approx_eq!(q0, q0.rotate_towards(q1, 0.0), eps); |
| 382 |
assert_approx_eq!( |
| 383 |
$quat::from_euler(EulerRot::YXZ, FRAC_PI_4, 0.0, 0.0), |
| 384 |
q0.rotate_towards(q1, FRAC_PI_4), |
| 385 |
eps |
| 386 |
); |
| 387 |
assert_approx_eq!(q1, q0.rotate_towards(q1, FRAC_PI_2), eps); |
| 388 |
assert_approx_eq!(q1, q0.rotate_towards(q1, FRAC_PI_2 * 1.5), eps); |
| 389 |
|
| 390 |
// Negative delta |
| 391 |
assert_approx_eq!( |
| 392 |
$quat::from_euler(EulerRot::YXZ, -FRAC_PI_4, 0.0, 0.0), |
| 393 |
q0.rotate_towards(q1, -FRAC_PI_4), |
| 394 |
eps |
| 395 |
); |
| 396 |
assert_approx_eq!(q2, q0.rotate_towards(q1, -FRAC_PI_2), eps); |
| 397 |
assert_approx_eq!(q2, q0.rotate_towards(q1, -FRAC_PI_2 * 1.5), eps); |
| 398 |
|
| 399 |
// Small angles |
| 400 |
let q0 = $quat::from_euler(EulerRot::YXZ, 0.0, 0.0, 0.0); |
| 401 |
let q1 = $quat::from_euler(EulerRot::YXZ, 1e-4, 0.0, 0.0); |
| 402 |
assert_eq!(q1, q0.rotate_towards(q1, FRAC_PI_2)) |
| 403 |
}); |
| 404 |
|
| 405 |
glam_test!(test_fmt, { |
| 406 |
let a = $quat::IDENTITY; |
| 407 |
assert_eq!( |
| 408 |
format!("{:?}", a), |
| 409 |
format!("{}(0.0, 0.0, 0.0, 1.0)", stringify!($quat)) |
| 410 |
); |
| 411 |
// assert_eq!( |
| 412 |
// format!("{:#?}", a), |
| 413 |
// "$quat(\n 1.0,\n 2.0,\n 3.0,\n 4.0\n)" |
| 414 |
// ); |
| 415 |
assert_eq!(format!("{}", a), "[0, 0, 0, 1]"); |
| 416 |
assert_eq!(format!("{:.2}", a), "[0.00, 0.00, 0.00, 1.00]"); |
| 417 |
}); |
| 418 |
|
| 419 |
glam_test!(test_identity, { |
| 420 |
let identity = $quat::IDENTITY; |
| 421 |
assert!(identity.is_near_identity()); |
| 422 |
assert!(identity.is_normalized()); |
| 423 |
assert_eq!(identity, $quat::from_xyzw(0.0, 0.0, 0.0, 1.0)); |
| 424 |
assert_eq!(identity, identity * identity); |
| 425 |
let q = $quat::from_euler(EulerRot::YXZ, deg(10.0), deg(-10.0), deg(45.0)); |
| 426 |
assert_eq!(q, q * identity); |
| 427 |
assert_eq!(q, identity * q); |
| 428 |
assert_eq!(identity, $quat::default()); |
| 429 |
}); |
| 430 |
|
| 431 |
glam_test!(test_slice, { |
| 432 |
let a: [$t; 4] = |
| 433 |
$quat::from_euler(EulerRot::YXZ, deg(30.0), deg(60.0), deg(90.0)).into(); |
| 434 |
let b = $quat::from_slice(&a); |
| 435 |
let c: [$t; 4] = b.into(); |
| 436 |
assert_eq!(a, c); |
| 437 |
let mut d = [0.0, 0.0, 0.0, 0.0]; |
| 438 |
b.write_to_slice(&mut d[..]); |
| 439 |
assert_eq!(a, d); |
| 440 |
|
| 441 |
should_panic!({ $quat::IDENTITY.write_to_slice(&mut [0 as $t; 3]) }); |
| 442 |
should_panic!({ $quat::from_slice(&[0 as $t; 3]) }); |
| 443 |
}); |
| 444 |
|
| 445 |
glam_test!(test_elements, { |
| 446 |
let x = 1.0; |
| 447 |
let y = 2.0; |
| 448 |
let z = 3.0; |
| 449 |
let w = 4.0; |
| 450 |
|
| 451 |
let a = $quat::from_xyzw(x, y, z, w); |
| 452 |
assert!(a.x == x); |
| 453 |
assert!(a.y == y); |
| 454 |
assert!(a.z == z); |
| 455 |
assert!(a.w == w); |
| 456 |
|
| 457 |
assert_eq!($vec3::new(1.0, 2.0, 3.0), a.xyz()); |
| 458 |
}); |
| 459 |
|
| 460 |
glam_test!(test_addition, { |
| 461 |
let a = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0); |
| 462 |
let b = $quat::from_xyzw(5.0, 6.0, 7.0, -9.0); |
| 463 |
let result = $quat::from_xyzw(6.0, 8.0, 10.0, -5.0); |
| 464 |
assert_eq!(a + b, result); |
| 465 |
assert_eq!(&a + b, result); |
| 466 |
assert_eq!(a + &b, result); |
| 467 |
assert_eq!(&a + &b, result); |
| 468 |
|
| 469 |
let mut c = a; |
| 470 |
c += b; |
| 471 |
assert_eq!(c, result); |
| 472 |
|
| 473 |
let mut c = a; |
| 474 |
c += &b; |
| 475 |
assert_eq!(c, result); |
| 476 |
}); |
| 477 |
|
| 478 |
glam_test!(test_subtraction, { |
| 479 |
let a = $quat::from_xyzw(6.0, 8.0, 10.0, -5.0); |
| 480 |
let b = $quat::from_xyzw(5.0, 6.0, 7.0, -9.0); |
| 481 |
let result = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0); |
| 482 |
assert_eq!(a - b, result); |
| 483 |
assert_eq!(&a - b, result); |
| 484 |
assert_eq!(a - &b, result); |
| 485 |
assert_eq!(&a - &b, result); |
| 486 |
|
| 487 |
let mut c = a; |
| 488 |
c -= b; |
| 489 |
assert_eq!(c, result); |
| 490 |
|
| 491 |
let mut c = a; |
| 492 |
c -= &b; |
| 493 |
assert_eq!(c, result); |
| 494 |
}); |
| 495 |
|
| 496 |
glam_test!(test_scalar_multiplication, { |
| 497 |
let a = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0); |
| 498 |
let result = $quat::from_xyzw(2.0, 4.0, 6.0, 8.0); |
| 499 |
assert_eq!(a * 2.0, result); |
| 500 |
assert_eq!(&a * 2.0, result); |
| 501 |
assert_eq!(a * &2.0, result); |
| 502 |
assert_eq!(&a * &2.0, result); |
| 503 |
|
| 504 |
let mut b = a; |
| 505 |
b *= 2.0; |
| 506 |
assert_eq!(b, result); |
| 507 |
|
| 508 |
let mut b = a; |
| 509 |
b *= &2.0; |
| 510 |
assert_eq!(b, result); |
| 511 |
}); |
| 512 |
|
| 513 |
glam_test!(test_scalar_division, { |
| 514 |
let a = $quat::from_xyzw(2.0, 4.0, 6.0, 8.0); |
| 515 |
let result = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0); |
| 516 |
assert_eq!(a / 2.0, result); |
| 517 |
assert_eq!(&a / 2.0, result); |
| 518 |
assert_eq!(a / &2.0, result); |
| 519 |
assert_eq!(&a / &2.0, result); |
| 520 |
|
| 521 |
let mut b = a; |
| 522 |
b /= 2.0; |
| 523 |
assert_eq!(b, result); |
| 524 |
|
| 525 |
let mut b = a; |
| 526 |
b /= &2.0; |
| 527 |
assert_eq!(b, result); |
| 528 |
}); |
| 529 |
|
| 530 |
glam_test!(test_sum, { |
| 531 |
let two = $new(2.0, 2.0, 2.0, 2.0); |
| 532 |
assert_eq!([two, two].iter().sum::<$quat>(), two + two); |
| 533 |
assert_eq!([two, two].into_iter().sum::<$quat>(), two + two); |
| 534 |
}); |
| 535 |
|
| 536 |
glam_test!(test_product, { |
| 537 |
let two = $new(2.0, 2.0, 2.0, 2.0).normalize(); |
| 538 |
assert_eq!([two, two].iter().product::<$quat>(), two * two); |
| 539 |
assert_eq!([two, two].into_iter().product::<$quat>(), two * two); |
| 540 |
}); |
| 541 |
|
| 542 |
glam_test!(test_is_finite, { |
| 543 |
assert!($quat::from_xyzw(0.0, 0.0, 0.0, 0.0).is_finite()); |
| 544 |
assert!($quat::from_xyzw(-1e-10, 1.0, 1e10, 42.0).is_finite()); |
| 545 |
assert!(!$quat::from_xyzw($t::INFINITY, 0.0, 0.0, 0.0).is_finite()); |
| 546 |
assert!(!$quat::from_xyzw(0.0, $t::NAN, 0.0, 0.0).is_finite()); |
| 547 |
assert!(!$quat::from_xyzw(0.0, 0.0, $t::NEG_INFINITY, 0.0).is_finite()); |
| 548 |
assert!(!$quat::from_xyzw(0.0, 0.0, 0.0, $t::NAN).is_finite()); |
| 549 |
}); |
| 550 |
|
| 551 |
glam_test!(test_rotation_arc, { |
| 552 |
let eps = 2.0 * $t::EPSILON.sqrt(); |
| 553 |
|
| 554 |
for &from in &vec3_float_test_vectors!($vec3) { |
| 555 |
let from = from.normalize(); |
| 556 |
|
| 557 |
{ |
| 558 |
let q = $quat::from_rotation_arc(from, from); |
| 559 |
assert!(q.is_near_identity(), "from: {}, q: {}", from, q); |
| 560 |
} |
| 561 |
|
| 562 |
{ |
| 563 |
let q = $quat::from_rotation_arc_colinear(from, from); |
| 564 |
assert!(q.is_near_identity(), "from: {}, q: {}", from, q); |
| 565 |
} |
| 566 |
|
| 567 |
{ |
| 568 |
let to = -from; |
| 569 |
let q = $quat::from_rotation_arc(from, to); |
| 570 |
assert!(q.is_normalized()); |
| 571 |
assert!((q * from - to).length() < eps); |
| 572 |
} |
| 573 |
|
| 574 |
{ |
| 575 |
let to = -from; |
| 576 |
let q = $quat::from_rotation_arc_colinear(from, to); |
| 577 |
assert!(q.is_near_identity(), "from: {}, q: {}", from, q); |
| 578 |
} |
| 579 |
|
| 580 |
for &to in &vec3_float_test_vectors!($vec3) { |
| 581 |
let to = to.normalize(); |
| 582 |
|
| 583 |
let q = $quat::from_rotation_arc(from, to); |
| 584 |
assert!(q.is_normalized()); |
| 585 |
assert!((q * from - to).length() < eps); |
| 586 |
|
| 587 |
let q = $quat::from_rotation_arc_colinear(from, to); |
| 588 |
assert!(q.is_normalized()); |
| 589 |
let transformed = q * from; |
| 590 |
assert!( |
| 591 |
(transformed - to).length() < eps || (-transformed - to).length() < eps |
| 592 |
); |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
for &from in &vec2_float_test_vectors!($vec2) { |
| 597 |
let from = from.normalize(); |
| 598 |
|
| 599 |
{ |
| 600 |
let q = $quat::from_rotation_arc_2d(from, from); |
| 601 |
assert!(q.is_near_identity(), "from: {}, q: {}", from, q); |
| 602 |
} |
| 603 |
|
| 604 |
{ |
| 605 |
let to = -from; |
| 606 |
let q = $quat::from_rotation_arc_2d(from, to); |
| 607 |
assert!(q.is_normalized()); |
| 608 |
assert!((q * from.extend(0.0) - to.extend(0.0)).length() < eps); |
| 609 |
} |
| 610 |
|
| 611 |
for &to in &vec2_float_test_vectors!($vec2) { |
| 612 |
let to = to.normalize(); |
| 613 |
|
| 614 |
let q = $quat::from_rotation_arc_2d(from, to); |
| 615 |
assert!(q.is_normalized()); |
| 616 |
assert!((q * from.extend(0.0) - to.extend(0.0)).length() < eps); |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
should_glam_assert!({ $quat::from_rotation_arc($vec3::ZERO, $vec3::X) }); |
| 621 |
should_glam_assert!({ $quat::from_rotation_arc($vec3::X, $vec3::ZERO) }); |
| 622 |
should_glam_assert!({ $quat::from_rotation_arc_colinear($vec3::ZERO, $vec3::X) }); |
| 623 |
should_glam_assert!({ $quat::from_rotation_arc_colinear($vec3::X, $vec3::ZERO) }); |
| 624 |
|
| 625 |
should_glam_assert!({ $quat::from_rotation_arc_2d($vec2::ZERO, $vec2::X) }); |
| 626 |
should_glam_assert!({ $quat::from_rotation_arc_2d($vec2::X, $vec2::ZERO) }); |
| 627 |
}); |
| 628 |
|
| 629 |
glam_test!(test_to_array, { |
| 630 |
assert!($new(1.0, 2.0, 3.0, 4.0).to_array() == [1.0, 2.0, 3.0, 4.0]); |
| 631 |
}); |
| 632 |
|
| 633 |
glam_test!(test_to_axis_angle, { |
| 634 |
{ |
| 635 |
let q = $quat::from_xyzw( |
| 636 |
5.28124762e-08, |
| 637 |
-5.12559303e-03, |
| 638 |
8.29266140e-08, |
| 639 |
9.99986828e-01, |
| 640 |
); |
| 641 |
assert!(q.is_normalized()); |
| 642 |
let (axis, angle) = q.to_axis_angle(); |
| 643 |
assert!(axis.is_normalized()); |
| 644 |
let q2 = $quat::from_axis_angle(axis, angle); |
| 645 |
assert!((q.dot(q2) - 1.0).abs() < 1e-6); |
| 646 |
} |
| 647 |
{ |
| 648 |
let q = $quat::IDENTITY; |
| 649 |
let (axis, angle) = q.to_axis_angle(); |
| 650 |
assert!(axis.is_normalized()); |
| 651 |
let q2 = $quat::from_axis_angle(axis, angle); |
| 652 |
assert!((q.dot(q2) - 1.0).abs() < 1e-6); |
| 653 |
} |
| 654 |
{ |
| 655 |
let q = $quat::from_xyzw(0.0, 1.0, 0.0, 0.0); |
| 656 |
assert!(q.is_normalized()); |
| 657 |
let (axis, angle) = q.to_axis_angle(); |
| 658 |
assert!(axis.is_normalized()); |
| 659 |
let q2 = $quat::from_axis_angle(axis, angle); |
| 660 |
assert!((q.dot(q2) - 1.0).abs() < 1e-6); |
| 661 |
} |
| 662 |
{ |
| 663 |
let axis = $vec3::Z; |
| 664 |
let angle = core::$t::consts::PI * 0.25; |
| 665 |
let q = $quat::from_axis_angle(axis, angle); |
| 666 |
assert!(q.is_normalized()); |
| 667 |
let (axis2, angle2) = q.to_axis_angle(); |
| 668 |
assert!(axis.is_normalized()); |
| 669 |
assert_approx_eq!(axis, axis2); |
| 670 |
assert_approx_eq!(angle, angle2); |
| 671 |
} |
| 672 |
}); |
| 673 |
|
| 674 |
glam_test!(test_add_assign, { |
| 675 |
{ |
| 676 |
// Normalization not needed for this test. |
| 677 |
let q = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0); |
| 678 |
let p = $quat::from_xyzw(5.0, 6.0, 7.0, 8.0); |
| 679 |
|
| 680 |
let mut pq = p; |
| 681 |
pq += q; |
| 682 |
assert_eq!(p + q, pq); |
| 683 |
|
| 684 |
let mut pq = p; |
| 685 |
pq += &q; |
| 686 |
assert_eq!(p + q, pq); |
| 687 |
} |
| 688 |
}); |
| 689 |
|
| 690 |
glam_test!(test_sub_assign, { |
| 691 |
{ |
| 692 |
// Normalization not needed for this test. |
| 693 |
let q = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0); |
| 694 |
let p = $quat::from_xyzw(5.0, 6.0, 7.0, 8.0); |
| 695 |
|
| 696 |
let mut pq = p; |
| 697 |
pq -= q; |
| 698 |
assert_eq!(p - q, pq); |
| 699 |
|
| 700 |
let mut pq = p; |
| 701 |
pq -= &q; |
| 702 |
assert_eq!(p - q, pq); |
| 703 |
} |
| 704 |
}); |
| 705 |
}; |
| 706 |
} |
| 707 |
|
| 708 |
mod quat { |
| 709 |
use crate::support::{deg, rad}; |
| 710 |
use core::ops::Neg; |
| 711 |
use glam::{quat, EulerRot, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A, Vec4}; |
| 712 |
|
| 713 |
glam_test!(test_align, { |
| 714 |
use std::mem; |
| 715 |
assert_eq!(16, mem::size_of::<Quat>()); |
| 716 |
if cfg!(feature = "scalar-math") { |
| 717 |
assert_eq!(4, mem::align_of::<Quat>()); |
| 718 |
} else { |
| 719 |
assert_eq!(16, mem::align_of::<Quat>()); |
| 720 |
} |
| 721 |
}); |
| 722 |
|
| 723 |
glam_test!(test_mul_vec3a, { |
| 724 |
let qrz = Quat::from_rotation_z(deg(90.0)); |
| 725 |
assert_approx_eq!(Vec3A::Y, qrz * Vec3A::X); |
| 726 |
assert_approx_eq!(Vec3A::Y, qrz.mul_vec3a(Vec3A::X)); |
| 727 |
assert_approx_eq!(Vec3A::Y, -qrz * Vec3A::X); |
| 728 |
assert_approx_eq!(Vec3A::Y, qrz.neg().mul_vec3a(Vec3A::X)); |
| 729 |
assert_approx_eq!(-Vec3A::X, qrz * Vec3A::Y); |
| 730 |
assert_approx_eq!(-Vec3A::X, qrz.mul_vec3a(Vec3A::Y)); |
| 731 |
assert_approx_eq!(-Vec3A::X, -qrz * Vec3A::Y); |
| 732 |
assert_approx_eq!(-Vec3A::X, qrz.neg().mul_vec3a(Vec3A::Y)); |
| 733 |
|
| 734 |
// check vec3 * mat3 is the same |
| 735 |
let mrz = Mat3::from_quat(qrz); |
| 736 |
assert_approx_eq!(Vec3A::Y, mrz * Vec3A::X); |
| 737 |
assert_approx_eq!(Vec3A::Y, mrz.mul_vec3a(Vec3A::X)); |
| 738 |
// assert_approx_eq!(Vec3A::Y, -mrz * Vec3A::X); |
| 739 |
assert_approx_eq!(-Vec3A::X, mrz * Vec3A::Y); |
| 740 |
assert_approx_eq!(-Vec3A::X, mrz.mul_vec3a(Vec3A::Y)); |
| 741 |
|
| 742 |
let qrx = Quat::from_rotation_x(deg(90.0)); |
| 743 |
assert_approx_eq!(Vec3A::X, qrx * Vec3A::X); |
| 744 |
assert_approx_eq!(Vec3A::X, qrx.mul_vec3a(Vec3A::X)); |
| 745 |
assert_approx_eq!(Vec3A::X, -qrx * Vec3A::X); |
| 746 |
assert_approx_eq!(Vec3A::X, qrx.neg().mul_vec3a(Vec3A::X)); |
| 747 |
assert_approx_eq!(Vec3A::Z, qrx * Vec3A::Y); |
| 748 |
assert_approx_eq!(Vec3A::Z, qrx.mul_vec3a(Vec3A::Y)); |
| 749 |
assert_approx_eq!(Vec3A::Z, -qrx * Vec3A::Y); |
| 750 |
assert_approx_eq!(Vec3A::Z, qrx.neg().mul_vec3a(Vec3A::Y)); |
| 751 |
|
| 752 |
// check vec3 * mat3 is the same |
| 753 |
let mrx = Mat3::from_quat(qrx); |
| 754 |
assert_approx_eq!(Vec3A::X, mrx * Vec3A::X); |
| 755 |
assert_approx_eq!(Vec3A::X, mrx.mul_vec3a(Vec3A::X)); |
| 756 |
assert_approx_eq!(Vec3A::Z, mrx * Vec3A::Y); |
| 757 |
assert_approx_eq!(Vec3A::Z, mrx.mul_vec3a(Vec3A::Y)); |
| 758 |
|
| 759 |
let qrxz = qrz * qrx; |
| 760 |
assert_approx_eq!(Vec3A::Y, qrxz * Vec3A::X); |
| 761 |
assert_approx_eq!(Vec3A::Y, qrxz.mul_vec3a(Vec3A::X)); |
| 762 |
assert_approx_eq!(Vec3A::Z, qrxz * Vec3A::Y); |
| 763 |
assert_approx_eq!(Vec3A::Z, qrxz.mul_vec3a(Vec3A::Y)); |
| 764 |
|
| 765 |
let mrxz = mrz * mrx; |
| 766 |
assert_approx_eq!(Vec3A::Y, mrxz * Vec3A::X); |
| 767 |
assert_approx_eq!(Vec3A::Y, mrxz.mul_vec3a(Vec3A::X)); |
| 768 |
assert_approx_eq!(Vec3A::Z, mrxz * Vec3A::Y); |
| 769 |
assert_approx_eq!(Vec3A::Z, mrxz.mul_vec3a(Vec3A::Y)); |
| 770 |
|
| 771 |
let qrzx = qrx * qrz; |
| 772 |
assert_approx_eq!(Vec3A::Z, qrzx * Vec3A::X); |
| 773 |
assert_approx_eq!(Vec3A::Z, qrzx.mul_vec3a(Vec3A::X)); |
| 774 |
assert_approx_eq!(-Vec3A::X, qrzx * Vec3A::Y); |
| 775 |
assert_approx_eq!(-Vec3A::X, qrzx.mul_vec3a(Vec3A::Y)); |
| 776 |
|
| 777 |
let mrzx = qrx * qrz; |
| 778 |
assert_approx_eq!(Vec3A::Z, mrzx * Vec3A::X); |
| 779 |
assert_approx_eq!(Vec3A::Z, mrzx.mul_vec3a(Vec3A::X)); |
| 780 |
assert_approx_eq!(-Vec3A::X, mrzx * Vec3A::Y); |
| 781 |
assert_approx_eq!(-Vec3A::X, mrzx.mul_vec3a(Vec3A::Y)); |
| 782 |
}); |
| 783 |
|
| 784 |
glam_test!(test_from_mat3a, { |
| 785 |
use glam::Mat3A; |
| 786 |
let yaw = deg(30.0); |
| 787 |
let y0 = Quat::from_rotation_y(yaw); |
| 788 |
let y1 = Quat::from_mat3a(&Mat3A::from_rotation_y(yaw)); |
| 789 |
assert_approx_eq!(y0, y1); |
| 790 |
let y2 = Quat::from_mat3a(&Mat3A::from_quat(y0)); |
| 791 |
assert_approx_eq!(y0, y2); |
| 792 |
}); |
| 793 |
|
| 794 |
glam_test!(test_as, { |
| 795 |
use glam::DQuat; |
| 796 |
assert_approx_eq!( |
| 797 |
DQuat::from_euler(EulerRot::YXZ, 1.0, 2.0, 3.0), |
| 798 |
Quat::from_euler(EulerRot::YXZ, 1.0, 2.0, 3.0).as_dquat() |
| 799 |
); |
| 800 |
assert_approx_eq!( |
| 801 |
Quat::from_euler(EulerRot::YXZ, 1.0, 2.0, 3.0), |
| 802 |
DQuat::from_euler(EulerRot::YXZ, 1.0, 2.0, 3.0).as_quat() |
| 803 |
); |
| 804 |
}); |
| 805 |
|
| 806 |
impl_quat_tests!(f32, quat, Mat3, Mat4, Quat, Vec2, Vec3, Vec4); |
| 807 |
} |
| 808 |
|
| 809 |
mod dquat { |
| 810 |
use crate::support::{deg, rad}; |
| 811 |
use core::ops::Neg; |
| 812 |
use glam::{dquat, DMat3, DMat4, DQuat, DVec2, DVec3, DVec4, EulerRot}; |
| 813 |
|
| 814 |
glam_test!(test_align, { |
| 815 |
use std::mem; |
| 816 |
assert_eq!(32, mem::size_of::<DQuat>()); |
| 817 |
assert_eq!(mem::align_of::<f64>(), mem::align_of::<DQuat>()); |
| 818 |
}); |
| 819 |
|
| 820 |
impl_quat_tests!(f64, dquat, DMat3, DMat4, DQuat, DVec2, DVec3, DVec4); |
| 821 |
} |