| 1 |
#[macro_use] |
| 2 |
mod support; |
| 3 |
|
| 4 |
macro_rules! impl_mat3_tests { |
| 5 |
($t:ident, $const_new:ident, $newmat3:ident, $mat3:ident, $mat2:ident, $mat4:ident, $quat:ident, $newvec3:ident, $vec3:ident, $vec2:ident) => { |
| 6 |
use core::$t::INFINITY; |
| 7 |
use core::$t::NAN; |
| 8 |
use core::$t::NEG_INFINITY; |
| 9 |
|
| 10 |
const IDENTITY: [[$t; 3]; 3] = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]; |
| 11 |
|
| 12 |
const MATRIX: [[$t; 3]; 3] = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]; |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn test_const() { |
| 16 |
const M0: $mat3 = $const_new!([0.0; 9]); |
| 17 |
const M1: $mat3 = $const_new!([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]); |
| 18 |
const M2: $mat3 = $const_new!([1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]); |
| 19 |
assert_eq!($mat3::ZERO, M0); |
| 20 |
assert_eq!( |
| 21 |
$mat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]), |
| 22 |
M1 |
| 23 |
); |
| 24 |
assert_eq!( |
| 25 |
$mat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]), |
| 26 |
M2 |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
#[test] |
| 31 |
fn test_mat3_identity() { |
| 32 |
assert_eq!( |
| 33 |
$mat3::IDENTITY, |
| 34 |
$mat3::from_cols_array(&[ |
| 35 |
1., 0., 0., // |
| 36 |
0., 1., 0., // |
| 37 |
0., 0., 1., // |
| 38 |
]) |
| 39 |
); |
| 40 |
let identity = $mat3::IDENTITY; |
| 41 |
assert_eq!(IDENTITY, identity.to_cols_array_2d()); |
| 42 |
assert_eq!($mat3::from_cols_array_2d(&IDENTITY), identity); |
| 43 |
assert_eq!(identity, identity * identity); |
| 44 |
assert_eq!(identity, $mat3::default()); |
| 45 |
} |
| 46 |
|
| 47 |
#[test] |
| 48 |
fn test_mat3_zero() { |
| 49 |
assert_eq!( |
| 50 |
$mat3::ZERO, |
| 51 |
$mat3::from_cols_array(&[0., 0., 0., 0., 0., 0., 0., 0., 0.]) |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
#[test] |
| 56 |
fn test_mat3_accessors() { |
| 57 |
let mut m = $mat3::ZERO; |
| 58 |
m.x_axis = $newvec3(1.0, 2.0, 3.0); |
| 59 |
m.y_axis = $newvec3(4.0, 5.0, 6.0); |
| 60 |
m.z_axis = $newvec3(7.0, 8.0, 9.0); |
| 61 |
assert_eq!($mat3::from_cols_array_2d(&MATRIX), m); |
| 62 |
assert_eq!($newvec3(1.0, 2.0, 3.0), m.x_axis); |
| 63 |
assert_eq!($newvec3(4.0, 5.0, 6.0), m.y_axis); |
| 64 |
assert_eq!($newvec3(7.0, 8.0, 9.0), m.z_axis); |
| 65 |
|
| 66 |
assert_eq!($newvec3(1.0, 2.0, 3.0), m.col(0)); |
| 67 |
assert_eq!($newvec3(4.0, 5.0, 6.0), m.col(1)); |
| 68 |
assert_eq!($newvec3(7.0, 8.0, 9.0), m.col(2)); |
| 69 |
|
| 70 |
assert_eq!($newvec3(1.0, 4.0, 7.0), m.row(0)); |
| 71 |
assert_eq!($newvec3(2.0, 5.0, 8.0), m.row(1)); |
| 72 |
assert_eq!($newvec3(3.0, 6.0, 9.0), m.row(2)); |
| 73 |
|
| 74 |
*m.col_mut(0) = m.col(0).zyx(); |
| 75 |
*m.col_mut(1) = m.col(1).zyx(); |
| 76 |
*m.col_mut(2) = m.col(2).zyx(); |
| 77 |
assert_eq!($newvec3(3.0, 2.0, 1.0), m.col(0)); |
| 78 |
assert_eq!($newvec3(6.0, 5.0, 4.0), m.col(1)); |
| 79 |
assert_eq!($newvec3(9.0, 8.0, 7.0), m.col(2)); |
| 80 |
|
| 81 |
should_panic!({ $mat3::ZERO.col(3) }); |
| 82 |
should_panic!({ |
| 83 |
let mut m = $mat3::ZERO; |
| 84 |
m.col_mut(3); |
| 85 |
}); |
| 86 |
should_panic!({ $mat3::ZERO.row(3) }); |
| 87 |
} |
| 88 |
|
| 89 |
#[test] |
| 90 |
fn test_mat3_from_axes() { |
| 91 |
let a = $mat3::from_cols_array_2d(&[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]); |
| 92 |
assert_eq!(MATRIX, a.to_cols_array_2d()); |
| 93 |
let b = $mat3::from_cols( |
| 94 |
$newvec3(1.0, 2.0, 3.0), |
| 95 |
$newvec3(4.0, 5.0, 6.0), |
| 96 |
$newvec3(7.0, 8.0, 9.0), |
| 97 |
); |
| 98 |
assert_eq!(a, b); |
| 99 |
let c = $newmat3( |
| 100 |
$newvec3(1.0, 2.0, 3.0), |
| 101 |
$newvec3(4.0, 5.0, 6.0), |
| 102 |
$newvec3(7.0, 8.0, 9.0), |
| 103 |
); |
| 104 |
assert_eq!(a, c); |
| 105 |
let d = b.to_cols_array(); |
| 106 |
let f = $mat3::from_cols_array(&d); |
| 107 |
assert_eq!(b, f); |
| 108 |
} |
| 109 |
|
| 110 |
#[test] |
| 111 |
fn test_from_rotation() { |
| 112 |
let rot_x1 = $mat3::from_rotation_x(deg(180.0)); |
| 113 |
let rot_x2 = $mat3::from_axis_angle($vec3::X, deg(180.0)); |
| 114 |
assert_approx_eq!(rot_x1, rot_x2); |
| 115 |
let rot_x3 = $mat3::from_quat($quat::from_rotation_x(deg(180.0))); |
| 116 |
assert_approx_eq!(rot_x1, rot_x3); |
| 117 |
|
| 118 |
let rot_y1 = $mat3::from_rotation_y(deg(180.0)); |
| 119 |
let rot_y2 = $mat3::from_axis_angle($vec3::Y, deg(180.0)); |
| 120 |
assert_approx_eq!(rot_y1, rot_y2); |
| 121 |
let rot_y3 = $mat3::from_quat($quat::from_rotation_y(deg(180.0))); |
| 122 |
assert_approx_eq!(rot_y1, rot_y3); |
| 123 |
|
| 124 |
let rot_z1 = $mat3::from_rotation_z(deg(180.0)); |
| 125 |
let rot_z2 = $mat3::from_axis_angle($vec3::Z, deg(180.0)); |
| 126 |
assert_approx_eq!(rot_z1, rot_z2); |
| 127 |
let rot_z3 = $mat3::from_quat($quat::from_rotation_z(deg(180.0))); |
| 128 |
assert_approx_eq!(rot_z1, rot_z3); |
| 129 |
|
| 130 |
should_glam_assert!({ $mat3::from_axis_angle($vec3::ZERO, 0.0) }); |
| 131 |
should_glam_assert!({ $mat3::from_quat($quat::from_xyzw(0.0, 0.0, 0.0, 0.0)) }); |
| 132 |
} |
| 133 |
|
| 134 |
#[test] |
| 135 |
fn test_mat3_mul() { |
| 136 |
let mat_a = $mat3::from_axis_angle($vec3::Z, deg(90.0)); |
| 137 |
assert_approx_eq!($newvec3(-1.0, 0.0, 0.0), mat_a * $newvec3(0.0, 1.0, 0.0)); |
| 138 |
assert_approx_eq!( |
| 139 |
$vec3::new(-1.0, 0.0, 0.0), |
| 140 |
mat_a.mul_vec3($vec3::new(0.0, 1.0, 0.0)) |
| 141 |
); |
| 142 |
} |
| 143 |
|
| 144 |
#[test] |
| 145 |
fn test_mat3_transform2d() { |
| 146 |
let m = $mat3::from_translation($vec2::new(2.0, 4.0)); |
| 147 |
assert_eq!($vec2::ZERO, m.transform_vector2($vec2::ZERO)); |
| 148 |
assert_eq!($vec2::new(2.0, 4.0), m.transform_point2($vec2::ZERO)); |
| 149 |
assert_eq!($vec2::ZERO, m.transform_point2($vec2::new(-2.0, -4.0))); |
| 150 |
|
| 151 |
let m = $mat3::from_angle($t::to_radians(90.0)); |
| 152 |
assert_approx_eq!($vec2::Y, m.transform_vector2($vec2::X), 1e-7); |
| 153 |
assert_approx_eq!($vec2::Y, m.transform_point2($vec2::X), 1e-7); |
| 154 |
|
| 155 |
let m = $mat3::from_scale($vec2::new(2.0, 4.0)); |
| 156 |
assert_eq!($vec2::new(2.0, 0.0), m.transform_vector2($vec2::X)); |
| 157 |
assert_eq!($vec2::new(0.0, 4.0), m.transform_vector2($vec2::Y)); |
| 158 |
assert_eq!($vec2::new(2.0, 0.0), m.transform_point2($vec2::X)); |
| 159 |
assert_eq!($vec2::new(0.0, 4.0), m.transform_point2($vec2::Y)); |
| 160 |
|
| 161 |
should_glam_assert!({ $mat3::from_scale($vec2::ZERO) }); |
| 162 |
|
| 163 |
let m = $mat3::from_scale_angle_translation( |
| 164 |
$vec2::new(0.5, 1.5), |
| 165 |
$t::to_radians(90.0), |
| 166 |
$vec2::new(1.0, 2.0), |
| 167 |
); |
| 168 |
let result2 = m.transform_vector2($vec2::Y); |
| 169 |
assert_approx_eq!($vec2::new(-1.5, 0.0), result2, 1.0e-6); |
| 170 |
assert_approx_eq!(result2, (m * $vec2::Y.extend(0.0)).truncate()); |
| 171 |
|
| 172 |
let result2 = m.transform_point2($vec2::Y); |
| 173 |
assert_approx_eq!($vec2::new(-0.5, 2.0), result2, 1.0e-6); |
| 174 |
assert_approx_eq!(result2, (m * $vec2::Y.extend(1.0)).truncate()); |
| 175 |
} |
| 176 |
|
| 177 |
#[test] |
| 178 |
fn test_from_ypr() { |
| 179 |
use glam::EulerRot; |
| 180 |
let zero = deg(0.0); |
| 181 |
let yaw = deg(30.0); |
| 182 |
let pitch = deg(60.0); |
| 183 |
let roll = deg(90.0); |
| 184 |
let y0 = $mat3::from_rotation_y(yaw); |
| 185 |
let y1 = $mat3::from_euler(EulerRot::YXZ, yaw, zero, zero); |
| 186 |
assert_approx_eq!(y0, y1); |
| 187 |
|
| 188 |
let x0 = $mat3::from_rotation_x(pitch); |
| 189 |
let x1 = $mat3::from_euler(EulerRot::YXZ, zero, pitch, zero); |
| 190 |
assert_approx_eq!(x0, x1); |
| 191 |
|
| 192 |
let z0 = $mat3::from_rotation_z(roll); |
| 193 |
let z1 = $mat3::from_euler(EulerRot::YXZ, zero, zero, roll); |
| 194 |
assert_approx_eq!(z0, z1); |
| 195 |
|
| 196 |
let yx0 = y0 * x0; |
| 197 |
let yx1 = $mat3::from_euler(EulerRot::YXZ, yaw, pitch, zero); |
| 198 |
assert_approx_eq!(yx0, yx1); |
| 199 |
|
| 200 |
let yxz0 = y0 * x0 * z0; |
| 201 |
let yxz1 = $mat3::from_euler(EulerRot::YXZ, yaw, pitch, roll); |
| 202 |
assert_approx_eq!(yxz0, yxz1, 1e-6); |
| 203 |
} |
| 204 |
|
| 205 |
#[test] |
| 206 |
fn test_from_diagonal() { |
| 207 |
let m = $mat3::from_diagonal($vec3::new(2.0, 4.0, 8.0)); |
| 208 |
assert_approx_eq!(m * $vec3::new(1.0, 1.0, 1.0), $vec3::new(2.0, 4.0, 8.0)); |
| 209 |
assert_approx_eq!($newvec3(2.0, 0.0, 0.0), m.x_axis); |
| 210 |
assert_approx_eq!($newvec3(0.0, 4.0, 0.0), m.y_axis); |
| 211 |
assert_approx_eq!($newvec3(0.0, 0.0, 8.0), m.z_axis); |
| 212 |
} |
| 213 |
|
| 214 |
#[test] |
| 215 |
fn test_from_mat2() { |
| 216 |
let m2 = $mat2::from_cols_array_2d(&[[1.0, 2.0], [3.0, 4.0]]); |
| 217 |
let m3 = $mat3::from_mat2(m2); |
| 218 |
assert_eq!( |
| 219 |
$mat3::from_cols_array_2d(&[[1.0, 2.0, 0.0], [3.0, 4.0, 0.0], [0.0, 0.0, 1.0]]), |
| 220 |
m3 |
| 221 |
); |
| 222 |
} |
| 223 |
#[test] |
| 224 |
fn test_from_mat4() { |
| 225 |
let m4 = $mat4::from_cols_array_2d(&[ |
| 226 |
[1.0, 2.0, 3.0, 4.0], |
| 227 |
[5.0, 6.0, 7.0, 8.0], |
| 228 |
[9.0, 10.0, 11.0, 12.0], |
| 229 |
[13.0, 14.0, 15.0, 16.0], |
| 230 |
]); |
| 231 |
let m3 = $mat3::from_mat4(m4); |
| 232 |
assert_eq!( |
| 233 |
$mat3::from_cols_array_2d(&[[1.0, 2.0, 3.0], [5.0, 6.0, 7.0], [9.0, 10.0, 11.0]]), |
| 234 |
m3 |
| 235 |
); |
| 236 |
} |
| 237 |
|
| 238 |
#[test] |
| 239 |
fn test_mat3_transpose() { |
| 240 |
let m = $newmat3( |
| 241 |
$newvec3(1.0, 2.0, 3.0), |
| 242 |
$newvec3(4.0, 5.0, 6.0), |
| 243 |
$newvec3(7.0, 8.0, 9.0), |
| 244 |
); |
| 245 |
let mt = m.transpose(); |
| 246 |
assert_eq!($newvec3(1.0, 4.0, 7.0), mt.x_axis); |
| 247 |
assert_eq!($newvec3(2.0, 5.0, 8.0), mt.y_axis); |
| 248 |
assert_eq!($newvec3(3.0, 6.0, 9.0), mt.z_axis); |
| 249 |
} |
| 250 |
|
| 251 |
#[test] |
| 252 |
fn test_mat3_det() { |
| 253 |
assert_eq!(0.0, $mat3::ZERO.determinant()); |
| 254 |
assert_eq!(1.0, $mat3::IDENTITY.determinant()); |
| 255 |
assert_eq!(1.0, $mat3::from_rotation_x(deg(90.0)).determinant()); |
| 256 |
assert_eq!(1.0, $mat3::from_rotation_y(deg(180.0)).determinant()); |
| 257 |
assert_eq!(1.0, $mat3::from_rotation_z(deg(270.0)).determinant()); |
| 258 |
assert_eq!( |
| 259 |
2.0 * 2.0 * 2.0, |
| 260 |
$mat3::from_diagonal($vec3::new(2.0, 2.0, 2.0)).determinant() |
| 261 |
); |
| 262 |
} |
| 263 |
|
| 264 |
#[test] |
| 265 |
fn test_mat3_inverse() { |
| 266 |
// assert_eq!(None, $mat3::ZERO.inverse()); |
| 267 |
let inv = $mat3::IDENTITY.inverse(); |
| 268 |
// assert_ne!(None, inv); |
| 269 |
assert_approx_eq!($mat3::IDENTITY, inv); |
| 270 |
|
| 271 |
let rotz = $mat3::from_rotation_z(deg(90.0)); |
| 272 |
let rotz_inv = rotz.inverse(); |
| 273 |
// assert_ne!(None, rotz_inv); |
| 274 |
// let rotz_inv = rotz_inv.unwrap(); |
| 275 |
assert_approx_eq!($mat3::IDENTITY, rotz * rotz_inv); |
| 276 |
assert_approx_eq!($mat3::IDENTITY, rotz_inv * rotz); |
| 277 |
|
| 278 |
let scale = $mat3::from_diagonal($vec3::new(4.0, 5.0, 6.0)); |
| 279 |
let scale_inv = scale.inverse(); |
| 280 |
// assert_ne!(None, scale_inv); |
| 281 |
// let scale_inv = scale_inv.unwrap(); |
| 282 |
assert_approx_eq!($mat3::IDENTITY, scale * scale_inv); |
| 283 |
assert_approx_eq!($mat3::IDENTITY, scale_inv * scale); |
| 284 |
|
| 285 |
let m = scale * rotz; |
| 286 |
let m_inv = m.inverse(); |
| 287 |
// assert_ne!(None, m_inv); |
| 288 |
// let m_inv = m_inv.unwrap(); |
| 289 |
assert_approx_eq!($mat3::IDENTITY, m * m_inv); |
| 290 |
assert_approx_eq!($mat3::IDENTITY, m_inv * m); |
| 291 |
assert_approx_eq!(m_inv, rotz_inv * scale_inv); |
| 292 |
|
| 293 |
should_glam_assert!({ $mat3::ZERO.inverse() }); |
| 294 |
} |
| 295 |
|
| 296 |
#[test] |
| 297 |
fn test_mat3_ops() { |
| 298 |
let m0 = $mat3::from_cols_array_2d(&MATRIX); |
| 299 |
let m0x2 = $mat3::from_cols_array_2d(&[ |
| 300 |
[2.0, 4.0, 6.0], |
| 301 |
[8.0, 10.0, 12.0], |
| 302 |
[14.0, 16.0, 18.0], |
| 303 |
]); |
| 304 |
assert_eq!(m0x2, m0 * 2.0); |
| 305 |
assert_eq!(m0x2, 2.0 * m0); |
| 306 |
assert_eq!(m0x2, m0 + m0); |
| 307 |
assert_eq!($mat3::ZERO, m0 - m0); |
| 308 |
assert_approx_eq!(m0, m0 * $mat3::IDENTITY); |
| 309 |
assert_approx_eq!(m0, $mat3::IDENTITY * m0); |
| 310 |
|
| 311 |
let mut m1 = m0; |
| 312 |
m1 *= 2.0; |
| 313 |
assert_eq!(m0x2, m1); |
| 314 |
|
| 315 |
let mut m1 = m0; |
| 316 |
m1 += m0; |
| 317 |
assert_eq!(m0x2, m1); |
| 318 |
|
| 319 |
let mut m1 = m0; |
| 320 |
m1 -= m0; |
| 321 |
assert_eq!($mat3::ZERO, m1); |
| 322 |
|
| 323 |
let mut m1 = $mat3::IDENTITY; |
| 324 |
m1 *= m0; |
| 325 |
assert_approx_eq!(m0, m1); |
| 326 |
} |
| 327 |
|
| 328 |
#[test] |
| 329 |
fn test_mat3_fmt() { |
| 330 |
let a = $mat3::from_cols_array_2d(&MATRIX); |
| 331 |
assert_eq!(format!("{}", a), "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"); |
| 332 |
} |
| 333 |
|
| 334 |
#[test] |
| 335 |
fn test_mat3_to_from_slice() { |
| 336 |
const MATRIX1D: [$t; 9] = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]; |
| 337 |
let m = $mat3::from_cols_slice(&MATRIX1D); |
| 338 |
assert_eq!($mat3::from_cols_array(&MATRIX1D), m); |
| 339 |
let mut out: [$t; 9] = Default::default(); |
| 340 |
m.write_cols_to_slice(&mut out); |
| 341 |
assert_eq!(MATRIX1D, out); |
| 342 |
|
| 343 |
should_panic!({ $mat3::from_cols_slice(&[0.0; 8]) }); |
| 344 |
should_panic!({ $mat3::IDENTITY.write_cols_to_slice(&mut [0.0; 8]) }); |
| 345 |
} |
| 346 |
|
| 347 |
#[cfg(feature = "std")] |
| 348 |
#[test] |
| 349 |
fn test_sum() { |
| 350 |
let id = $mat3::IDENTITY; |
| 351 |
assert_eq!(vec![id, id].iter().sum::<$mat3>(), id + id); |
| 352 |
} |
| 353 |
|
| 354 |
#[cfg(feature = "std")] |
| 355 |
#[test] |
| 356 |
fn test_product() { |
| 357 |
let two = $mat3::IDENTITY + $mat3::IDENTITY; |
| 358 |
assert_eq!(vec![two, two].iter().product::<$mat3>(), two * two); |
| 359 |
} |
| 360 |
|
| 361 |
#[test] |
| 362 |
fn test_mat3_is_finite() { |
| 363 |
assert!($mat3::IDENTITY.is_finite()); |
| 364 |
assert!(!($mat3::IDENTITY * INFINITY).is_finite()); |
| 365 |
assert!(!($mat3::IDENTITY * NEG_INFINITY).is_finite()); |
| 366 |
assert!(!($mat3::IDENTITY * NAN).is_finite()); |
| 367 |
} |
| 368 |
}; |
| 369 |
} |
| 370 |
|
| 371 |
mod mat3 { |
| 372 |
use super::support::deg; |
| 373 |
use glam::{ |
| 374 |
const_mat3, mat3, swizzles::*, vec3, vec3a, Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec3A, |
| 375 |
}; |
| 376 |
|
| 377 |
#[test] |
| 378 |
fn test_align() { |
| 379 |
use std::mem; |
| 380 |
assert_eq!(36, mem::size_of::<Mat3>()); |
| 381 |
assert_eq!(4, mem::align_of::<Mat3>()); |
| 382 |
} |
| 383 |
|
| 384 |
#[test] |
| 385 |
fn test_mul_vec3a() { |
| 386 |
let mat_a = Mat3::from_axis_angle(Vec3::Z, deg(90.0)); |
| 387 |
assert_approx_eq!(vec3a(-1.0, 0.0, 0.0), mat_a * Vec3A::Y); |
| 388 |
assert_approx_eq!(vec3a(-1.0, 0.0, 0.0), mat_a.mul_vec3a(Vec3A::Y)); |
| 389 |
} |
| 390 |
|
| 391 |
#[test] |
| 392 |
fn test_as() { |
| 393 |
use glam::DMat3; |
| 394 |
assert_eq!( |
| 395 |
DMat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]), |
| 396 |
Mat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]).as_f64() |
| 397 |
); |
| 398 |
assert_eq!( |
| 399 |
Mat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]), |
| 400 |
DMat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]).as_f32() |
| 401 |
); |
| 402 |
} |
| 403 |
|
| 404 |
impl_mat3_tests!(f32, const_mat3, mat3, Mat3, Mat2, Mat4, Quat, vec3, Vec3, Vec2); |
| 405 |
} |
| 406 |
|
| 407 |
mod mat3a { |
| 408 |
use super::support::deg; |
| 409 |
use glam::{ |
| 410 |
const_mat3a, mat3a, swizzles::*, vec3a, Mat2, Mat3A, Mat4, Quat, Vec2, Vec3, Vec3A, |
| 411 |
}; |
| 412 |
|
| 413 |
#[test] |
| 414 |
fn test_align() { |
| 415 |
use std::mem; |
| 416 |
assert_eq!(48, mem::size_of::<Mat3A>()); |
| 417 |
assert_eq!(16, mem::align_of::<Mat3A>()); |
| 418 |
} |
| 419 |
|
| 420 |
#[test] |
| 421 |
fn test_mul_vec3a() { |
| 422 |
let mat_a = Mat3A::from_axis_angle(Vec3::Z, deg(90.0)); |
| 423 |
assert_approx_eq!(vec3a(-1.0, 0.0, 0.0), mat_a * Vec3A::Y); |
| 424 |
assert_approx_eq!(vec3a(-1.0, 0.0, 0.0), mat_a.mul_vec3a(Vec3A::Y)); |
| 425 |
} |
| 426 |
|
| 427 |
#[test] |
| 428 |
fn test_as() { |
| 429 |
use glam::DMat3; |
| 430 |
assert_eq!( |
| 431 |
DMat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]), |
| 432 |
Mat3A::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]).as_f64() |
| 433 |
); |
| 434 |
} |
| 435 |
|
| 436 |
impl_mat3_tests!( |
| 437 |
f32, |
| 438 |
const_mat3a, |
| 439 |
mat3a, |
| 440 |
Mat3A, |
| 441 |
Mat2, |
| 442 |
Mat4, |
| 443 |
Quat, |
| 444 |
vec3a, |
| 445 |
Vec3, |
| 446 |
Vec2 |
| 447 |
); |
| 448 |
} |
| 449 |
|
| 450 |
mod dmat3 { |
| 451 |
use super::support::deg; |
| 452 |
use glam::{const_dmat3, dmat3, dvec3, swizzles::*, DMat2, DMat3, DMat4, DQuat, DVec2, DVec3}; |
| 453 |
|
| 454 |
#[test] |
| 455 |
fn test_align() { |
| 456 |
use std::mem; |
| 457 |
assert_eq!(72, mem::size_of::<DMat3>()); |
| 458 |
assert_eq!(mem::align_of::<f64>(), mem::align_of::<DMat3>()); |
| 459 |
} |
| 460 |
|
| 461 |
impl_mat3_tests!( |
| 462 |
f64, |
| 463 |
const_dmat3, |
| 464 |
dmat3, |
| 465 |
DMat3, |
| 466 |
DMat2, |
| 467 |
DMat4, |
| 468 |
DQuat, |
| 469 |
dvec3, |
| 470 |
DVec3, |
| 471 |
DVec2 |
| 472 |
); |
| 473 |
} |