| 1 |
#![allow(clippy::excessive_precision)] |
| 2 |
|
| 3 |
#[macro_use] |
| 4 |
mod support; |
| 5 |
|
| 6 |
macro_rules! impl_vec3_tests { |
| 7 |
($t:ident, $new:ident, $vec3:ident, $mask:ident) => { |
| 8 |
glam_test!(test_const, { |
| 9 |
const V0: $vec3 = $vec3::splat(1 as $t); |
| 10 |
const V1: $vec3 = $vec3::new(1 as $t, 2 as $t, 3 as $t); |
| 11 |
const V2: $vec3 = $vec3::from_array([1 as $t, 2 as $t, 3 as $t]); |
| 12 |
assert_eq!([1 as $t, 1 as $t, 1 as $t], *V0.as_ref()); |
| 13 |
assert_eq!([1 as $t, 2 as $t, 3 as $t], *V1.as_ref()); |
| 14 |
assert_eq!([1 as $t, 2 as $t, 3 as $t], *V2.as_ref()); |
| 15 |
}); |
| 16 |
|
| 17 |
glam_test!(test_vec3_consts, { |
| 18 |
assert_eq!($vec3::ZERO, $new(0 as $t, 0 as $t, 0 as $t)); |
| 19 |
assert_eq!($vec3::ONE, $new(1 as $t, 1 as $t, 1 as $t)); |
| 20 |
assert_eq!($vec3::X, $new(1 as $t, 0 as $t, 0 as $t)); |
| 21 |
assert_eq!($vec3::Y, $new(0 as $t, 1 as $t, 0 as $t)); |
| 22 |
assert_eq!($vec3::Z, $new(0 as $t, 0 as $t, 1 as $t)); |
| 23 |
assert_eq!($vec3::MIN, $new($t::MIN, $t::MIN, $t::MIN)); |
| 24 |
assert_eq!($vec3::MAX, $new($t::MAX, $t::MAX, $t::MAX)); |
| 25 |
}); |
| 26 |
|
| 27 |
glam_test!(test_new, { |
| 28 |
let v = $new(1 as $t, 2 as $t, 3 as $t); |
| 29 |
|
| 30 |
assert_eq!(v.x, 1 as $t); |
| 31 |
assert_eq!(v.y, 2 as $t); |
| 32 |
assert_eq!(v.z, 3 as $t); |
| 33 |
|
| 34 |
let t = (1 as $t, 2 as $t, 3 as $t); |
| 35 |
let v = $vec3::from(t); |
| 36 |
assert_eq!(t, v.into()); |
| 37 |
|
| 38 |
let a = [1 as $t, 2 as $t, 3 as $t]; |
| 39 |
let v = $vec3::from(a); |
| 40 |
let a1: [$t; 3] = v.into(); |
| 41 |
assert_eq!(a, a1); |
| 42 |
|
| 43 |
assert_eq!(a, v.to_array()); |
| 44 |
assert_eq!(a, *v.as_ref()); |
| 45 |
|
| 46 |
let mut v2 = $vec3::default(); |
| 47 |
*v2.as_mut() = a; |
| 48 |
assert_eq!(a, v2.to_array()); |
| 49 |
|
| 50 |
let v = $vec3::new(t.0, t.1, t.2); |
| 51 |
assert_eq!(t, v.into()); |
| 52 |
|
| 53 |
assert_eq!($vec3::new(1 as $t, 0 as $t, 0 as $t), $vec3::X); |
| 54 |
assert_eq!($vec3::new(0 as $t, 1 as $t, 0 as $t), $vec3::Y); |
| 55 |
assert_eq!($vec3::new(0 as $t, 0 as $t, 1 as $t), $vec3::Z); |
| 56 |
}); |
| 57 |
|
| 58 |
glam_test!(test_fmt, { |
| 59 |
let a = $vec3::new(1 as $t, 2 as $t, 3 as $t); |
| 60 |
assert_eq!( |
| 61 |
format!("{:?}", a), |
| 62 |
format!("{}({:?}, {:?}, {:?})", stringify!($vec3), a.x, a.y, a.z) |
| 63 |
); |
| 64 |
assert_eq!( |
| 65 |
format!("{:#?}", a), |
| 66 |
format!( |
| 67 |
"{}(\n {:#?},\n {:#?},\n {:#?},\n)", |
| 68 |
stringify!($vec3), |
| 69 |
a.x, |
| 70 |
a.y, |
| 71 |
a.z |
| 72 |
) |
| 73 |
); |
| 74 |
assert_eq!(format!("{}", a), "[1, 2, 3]"); |
| 75 |
}); |
| 76 |
|
| 77 |
glam_test!(test_zero, { |
| 78 |
let v = $vec3::ZERO; |
| 79 |
assert_eq!((0 as $t, 0 as $t, 0 as $t), v.into()); |
| 80 |
assert_eq!(v, $vec3::default()); |
| 81 |
}); |
| 82 |
|
| 83 |
glam_test!(test_splat, { |
| 84 |
let v = $vec3::splat(1 as $t); |
| 85 |
assert_eq!($vec3::ONE, v); |
| 86 |
}); |
| 87 |
|
| 88 |
glam_test!(test_accessors, { |
| 89 |
let mut a = $vec3::ZERO; |
| 90 |
a.x = 1 as $t; |
| 91 |
a.y = 2 as $t; |
| 92 |
a.z = 3 as $t; |
| 93 |
assert_eq!(1 as $t, a.x); |
| 94 |
assert_eq!(2 as $t, a.y); |
| 95 |
assert_eq!(3 as $t, a.z); |
| 96 |
assert_eq!((1 as $t, 2 as $t, 3 as $t), a.into()); |
| 97 |
|
| 98 |
let mut a = $vec3::ZERO; |
| 99 |
a[0] = 1 as $t; |
| 100 |
a[1] = 2 as $t; |
| 101 |
a[2] = 3 as $t; |
| 102 |
assert_eq!(1 as $t, a[0]); |
| 103 |
assert_eq!(2 as $t, a[1]); |
| 104 |
assert_eq!(3 as $t, a[2]); |
| 105 |
assert_eq!((1 as $t, 2 as $t, 3 as $t), a.into()); |
| 106 |
}); |
| 107 |
|
| 108 |
glam_test!(test_dot_unsigned, { |
| 109 |
let x = $new(1 as $t, 0 as $t, 0 as $t); |
| 110 |
let y = $new(0 as $t, 1 as $t, 0 as $t); |
| 111 |
assert_eq!(1 as $t, x.dot(x)); |
| 112 |
assert_eq!(0 as $t, x.dot(y)); |
| 113 |
|
| 114 |
assert_eq!( |
| 115 |
$new(14 as $t, 14 as $t, 14 as $t), |
| 116 |
$new(0 as $t, 4 as $t, 6 as $t).dot_into_vec($new(3 as $t, 2 as $t, 1 as $t)) |
| 117 |
); |
| 118 |
}); |
| 119 |
|
| 120 |
glam_test!(test_length_squared_unsigned, { |
| 121 |
let x = $new(1 as $t, 0 as $t, 0 as $t); |
| 122 |
let z = $new(0 as $t, 0 as $t, 1 as $t); |
| 123 |
assert_eq!(4 as $t, (2 as $t * x).length_squared()); |
| 124 |
assert_eq!(16 as $t, (4 as $t * z).length_squared()); |
| 125 |
}); |
| 126 |
|
| 127 |
glam_test!(test_cross, { |
| 128 |
let x = $new(1 as $t, 0 as $t, 0 as $t); |
| 129 |
let y = $new(0 as $t, 1 as $t, 0 as $t); |
| 130 |
let z = $new(0 as $t, 0 as $t, 1 as $t); |
| 131 |
assert_eq!(y, z.cross(x)); |
| 132 |
assert_eq!(z, x.cross(y)); |
| 133 |
}); |
| 134 |
|
| 135 |
glam_test!(test_ops, { |
| 136 |
let a = $new(2 as $t, 4 as $t, 8 as $t); |
| 137 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t), a + a); |
| 138 |
assert_eq!($new(2 as $t, 4 as $t, 8 as $t), 0 as $t + a); |
| 139 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t), a - a); |
| 140 |
assert_eq!($new(14 as $t, 12 as $t, 8 as $t), 16 as $t - a); |
| 141 |
assert_eq!($new(4 as $t, 16 as $t, 64 as $t), a * a); |
| 142 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t), a * 2 as $t); |
| 143 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t), 2 as $t * a); |
| 144 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t), a / a); |
| 145 |
assert_eq!($new(1 as $t, 2 as $t, 4 as $t), a / 2 as $t); |
| 146 |
assert_eq!($new(4 as $t, 2 as $t, 1 as $t), 8 as $t / a); |
| 147 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t), a % a); |
| 148 |
assert_eq!($new(0 as $t, 1 as $t, 1 as $t), a % (a - 1 as $t)); |
| 149 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t), a % 1 as $t); |
| 150 |
assert_eq!($new(2 as $t, 1 as $t, 2 as $t), a % 3 as $t); |
| 151 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t), 17 as $t % a); |
| 152 |
assert_eq!($new(2 as $t, 4 as $t, 0 as $t), a % 8 as $t); |
| 153 |
}); |
| 154 |
|
| 155 |
glam_test!(test_assign_ops, { |
| 156 |
let a = $new(1 as $t, 2 as $t, 3 as $t); |
| 157 |
let mut b = a; |
| 158 |
|
| 159 |
b += 2 as $t; |
| 160 |
assert_eq!($new(3 as $t, 4 as $t, 5 as $t), b); |
| 161 |
b -= 2 as $t; |
| 162 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t), b); |
| 163 |
b *= 2 as $t; |
| 164 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t), b); |
| 165 |
b /= 2 as $t; |
| 166 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t), b); |
| 167 |
b %= 2 as $t; |
| 168 |
assert_eq!($new(1 as $t, 0 as $t, 1 as $t), b); |
| 169 |
|
| 170 |
b = a; |
| 171 |
b += a; |
| 172 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t), b); |
| 173 |
b -= a; |
| 174 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t), b); |
| 175 |
b *= a; |
| 176 |
assert_eq!($new(1 as $t, 4 as $t, 9 as $t), b); |
| 177 |
b /= a; |
| 178 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t), b); |
| 179 |
b *= 2 as $t; |
| 180 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t), b); |
| 181 |
b /= 2 as $t; |
| 182 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t), b); |
| 183 |
b %= (b + 1 as $t); |
| 184 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t), b); |
| 185 |
b %= b; |
| 186 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t), b); |
| 187 |
}); |
| 188 |
|
| 189 |
glam_test!(test_min_max, { |
| 190 |
let a = $new(3 as $t, 5 as $t, 1 as $t); |
| 191 |
let b = $new(4 as $t, 2 as $t, 6 as $t); |
| 192 |
assert_eq!((3 as $t, 2 as $t, 1 as $t), a.min(b).into()); |
| 193 |
assert_eq!((3 as $t, 2 as $t, 1 as $t), b.min(a).into()); |
| 194 |
assert_eq!((4 as $t, 5 as $t, 6 as $t), a.max(b).into()); |
| 195 |
assert_eq!((4 as $t, 5 as $t, 6 as $t), b.max(a).into()); |
| 196 |
}); |
| 197 |
|
| 198 |
glam_test!(test_clamp, { |
| 199 |
fn vec(x: i32, y: i32, z: i32) -> $vec3 { |
| 200 |
$vec3::new(x as $t, y as $t, z as $t) |
| 201 |
} |
| 202 |
let min = vec(1, 3, 3); |
| 203 |
let max = vec(6, 8, 8); |
| 204 |
assert_eq!(vec(0, 0, 0).clamp(min, max), vec(1, 3, 3)); |
| 205 |
assert_eq!(vec(2, 2, 2).clamp(min, max), vec(2, 3, 3)); |
| 206 |
assert_eq!(vec(4, 5, 5).clamp(min, max), vec(4, 5, 5)); |
| 207 |
assert_eq!(vec(6, 6, 6).clamp(min, max), vec(6, 6, 6)); |
| 208 |
assert_eq!(vec(7, 7, 7).clamp(min, max), vec(6, 7, 7)); |
| 209 |
assert_eq!(vec(9, 9, 9).clamp(min, max), vec(6, 8, 8)); |
| 210 |
|
| 211 |
should_glam_assert!({ $vec3::clamp($vec3::ZERO, $vec3::ONE, $vec3::ZERO) }); |
| 212 |
}); |
| 213 |
|
| 214 |
glam_test!(test_hmin_hmax, { |
| 215 |
assert_eq!(1 as $t, $new(1 as $t, 2 as $t, 3 as $t).min_element()); |
| 216 |
assert_eq!(1 as $t, $new(3 as $t, 1 as $t, 2 as $t).min_element()); |
| 217 |
assert_eq!(1 as $t, $new(2 as $t, 3 as $t, 1 as $t).min_element()); |
| 218 |
assert_eq!(3 as $t, $new(1 as $t, 2 as $t, 3 as $t).max_element()); |
| 219 |
assert_eq!(3 as $t, $new(3 as $t, 1 as $t, 2 as $t).max_element()); |
| 220 |
assert_eq!(3 as $t, $new(2 as $t, 3 as $t, 1 as $t).max_element()); |
| 221 |
}); |
| 222 |
|
| 223 |
glam_test!(test_eq, { |
| 224 |
let a = $new(1 as $t, 1 as $t, 1 as $t); |
| 225 |
let b = $new(1 as $t, 2 as $t, 3 as $t); |
| 226 |
assert!(a.cmpeq(a).all()); |
| 227 |
assert!(b.cmpeq(b).all()); |
| 228 |
assert!(a.cmpne(b).any()); |
| 229 |
assert!(b.cmpne(a).any()); |
| 230 |
assert!(b.cmpeq(a).any()); |
| 231 |
}); |
| 232 |
|
| 233 |
glam_test!(test_cmp, { |
| 234 |
assert!(!$mask::default().any()); |
| 235 |
assert!(!$mask::default().all()); |
| 236 |
assert_eq!($mask::default().bitmask(), 0x0); |
| 237 |
let a = $new(1 as $t, 1 as $t, 1 as $t); |
| 238 |
let b = $new(2 as $t, 2 as $t, 2 as $t); |
| 239 |
let c = $new(1 as $t, 1 as $t, 2 as $t); |
| 240 |
let d = $new(2 as $t, 1 as $t, 1 as $t); |
| 241 |
assert_eq!(a.cmplt(a).bitmask(), 0x0); |
| 242 |
assert_eq!(a.cmplt(b).bitmask(), 0x7); |
| 243 |
assert_eq!(a.cmplt(c).bitmask(), 0x4); |
| 244 |
assert_eq!(c.cmple(a).bitmask(), 0x3); |
| 245 |
assert_eq!(a.cmplt(d).bitmask(), 0x1); |
| 246 |
assert!(a.cmplt(b).all()); |
| 247 |
assert!(a.cmplt(c).any()); |
| 248 |
assert!(a.cmple(b).all()); |
| 249 |
assert!(a.cmple(a).all()); |
| 250 |
assert!(b.cmpgt(a).all()); |
| 251 |
assert!(b.cmpge(a).all()); |
| 252 |
assert!(b.cmpge(b).all()); |
| 253 |
assert!(!(a.cmpge(c).all())); |
| 254 |
assert!(c.cmple(c).all()); |
| 255 |
assert!(c.cmpge(c).all()); |
| 256 |
assert!(a == a); |
| 257 |
}); |
| 258 |
|
| 259 |
glam_test!(test_extend_truncate, { |
| 260 |
let a = $new(1 as $t, 2 as $t, 3 as $t); |
| 261 |
let b = a.extend(4 as $t); |
| 262 |
assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), b.into()); |
| 263 |
let c = $vec3::from(b.truncate()); |
| 264 |
assert_eq!(a, c); |
| 265 |
}); |
| 266 |
|
| 267 |
glam_test!(test_mask, { |
| 268 |
let mut a = $vec3::ZERO; |
| 269 |
a.x = 1 as $t; |
| 270 |
a.y = 1 as $t; |
| 271 |
a.z = 1 as $t; |
| 272 |
assert!(!a.cmpeq($vec3::ZERO).any()); |
| 273 |
assert!(a.cmpeq($vec3::ONE).all()); |
| 274 |
}); |
| 275 |
|
| 276 |
glam_test!(test_mask_into_array_u32, { |
| 277 |
assert_eq!( |
| 278 |
Into::<[u32; 3]>::into($mask::new(false, false, false)), |
| 279 |
[0, 0, 0] |
| 280 |
); |
| 281 |
assert_eq!( |
| 282 |
Into::<[u32; 3]>::into($mask::new(true, false, false)), |
| 283 |
[!0, 0, 0] |
| 284 |
); |
| 285 |
assert_eq!( |
| 286 |
Into::<[u32; 3]>::into($mask::new(false, true, true)), |
| 287 |
[0, !0, !0] |
| 288 |
); |
| 289 |
assert_eq!( |
| 290 |
Into::<[u32; 3]>::into($mask::new(false, true, false)), |
| 291 |
[0, !0, 0] |
| 292 |
); |
| 293 |
assert_eq!( |
| 294 |
Into::<[u32; 3]>::into($mask::new(true, false, true)), |
| 295 |
[!0, 0, !0] |
| 296 |
); |
| 297 |
assert_eq!( |
| 298 |
Into::<[u32; 3]>::into($mask::new(true, true, true)), |
| 299 |
[!0, !0, !0] |
| 300 |
); |
| 301 |
}); |
| 302 |
|
| 303 |
glam_test!(test_mask_into_array_bool, { |
| 304 |
assert_eq!( |
| 305 |
Into::<[bool; 3]>::into($mask::new(false, false, false)), |
| 306 |
[false, false, false] |
| 307 |
); |
| 308 |
assert_eq!( |
| 309 |
Into::<[bool; 3]>::into($mask::new(true, false, false)), |
| 310 |
[true, false, false] |
| 311 |
); |
| 312 |
assert_eq!( |
| 313 |
Into::<[bool; 3]>::into($mask::new(false, true, true)), |
| 314 |
[false, true, true] |
| 315 |
); |
| 316 |
assert_eq!( |
| 317 |
Into::<[bool; 3]>::into($mask::new(false, true, false)), |
| 318 |
[false, true, false] |
| 319 |
); |
| 320 |
assert_eq!( |
| 321 |
Into::<[bool; 3]>::into($mask::new(true, false, true)), |
| 322 |
[true, false, true] |
| 323 |
); |
| 324 |
assert_eq!( |
| 325 |
Into::<[u32; 3]>::into($mask::new(true, true, true)), |
| 326 |
[!0, !0, !0] |
| 327 |
); |
| 328 |
}); |
| 329 |
|
| 330 |
glam_test!(test_mask_splat, { |
| 331 |
assert_eq!($mask::splat(false), $mask::new(false, false, false)); |
| 332 |
assert_eq!($mask::splat(true), $mask::new(true, true, true)); |
| 333 |
}); |
| 334 |
|
| 335 |
glam_test!(test_mask_bitmask, { |
| 336 |
assert_eq!($mask::new(false, false, false).bitmask(), 0b000); |
| 337 |
assert_eq!($mask::new(true, false, false).bitmask(), 0b001); |
| 338 |
assert_eq!($mask::new(false, true, true).bitmask(), 0b110); |
| 339 |
assert_eq!($mask::new(false, true, false).bitmask(), 0b010); |
| 340 |
assert_eq!($mask::new(true, false, true).bitmask(), 0b101); |
| 341 |
assert_eq!($mask::new(true, true, true).bitmask(), 0b111); |
| 342 |
}); |
| 343 |
|
| 344 |
glam_test!(test_mask_any, { |
| 345 |
assert_eq!($mask::new(false, false, false).any(), false); |
| 346 |
assert_eq!($mask::new(true, false, false).any(), true); |
| 347 |
assert_eq!($mask::new(false, true, false).any(), true); |
| 348 |
assert_eq!($mask::new(false, false, true).any(), true); |
| 349 |
}); |
| 350 |
|
| 351 |
glam_test!(test_mask_all, { |
| 352 |
assert_eq!($mask::new(true, true, true).all(), true); |
| 353 |
assert_eq!($mask::new(false, true, true).all(), false); |
| 354 |
assert_eq!($mask::new(true, false, true).all(), false); |
| 355 |
assert_eq!($mask::new(true, true, false).all(), false); |
| 356 |
}); |
| 357 |
|
| 358 |
glam_test!(test_mask_select, { |
| 359 |
let a = $vec3::new(1 as $t, 2 as $t, 3 as $t); |
| 360 |
let b = $vec3::new(4 as $t, 5 as $t, 6 as $t); |
| 361 |
assert_eq!( |
| 362 |
$vec3::select($mask::new(true, true, true), a, b), |
| 363 |
$vec3::new(1 as $t, 2 as $t, 3 as $t), |
| 364 |
); |
| 365 |
assert_eq!( |
| 366 |
$vec3::select($mask::new(true, false, true), a, b), |
| 367 |
$vec3::new(1 as $t, 5 as $t, 3 as $t), |
| 368 |
); |
| 369 |
assert_eq!( |
| 370 |
$vec3::select($mask::new(false, true, false), a, b), |
| 371 |
$vec3::new(4 as $t, 2 as $t, 6 as $t), |
| 372 |
); |
| 373 |
assert_eq!( |
| 374 |
$vec3::select($mask::new(false, false, false), a, b), |
| 375 |
$vec3::new(4 as $t, 5 as $t, 6 as $t), |
| 376 |
); |
| 377 |
}); |
| 378 |
|
| 379 |
glam_test!(test_mask_and, { |
| 380 |
assert_eq!( |
| 381 |
($mask::new(false, false, false) & $mask::new(false, false, false)).bitmask(), |
| 382 |
0b000, |
| 383 |
); |
| 384 |
assert_eq!( |
| 385 |
($mask::new(true, true, true) & $mask::new(true, true, true)).bitmask(), |
| 386 |
0b111, |
| 387 |
); |
| 388 |
assert_eq!( |
| 389 |
($mask::new(true, false, true) & $mask::new(false, true, false)).bitmask(), |
| 390 |
0b000, |
| 391 |
); |
| 392 |
assert_eq!( |
| 393 |
($mask::new(true, false, true) & $mask::new(true, true, true)).bitmask(), |
| 394 |
0b101, |
| 395 |
); |
| 396 |
|
| 397 |
let mut mask = $mask::new(true, true, false); |
| 398 |
mask &= $mask::new(true, false, false); |
| 399 |
assert_eq!(mask.bitmask(), 0b001); |
| 400 |
}); |
| 401 |
|
| 402 |
glam_test!(test_mask_or, { |
| 403 |
assert_eq!( |
| 404 |
($mask::new(false, false, false) | $mask::new(false, false, false)).bitmask(), |
| 405 |
0b000, |
| 406 |
); |
| 407 |
assert_eq!( |
| 408 |
($mask::new(true, true, true) | $mask::new(true, true, true)).bitmask(), |
| 409 |
0b111, |
| 410 |
); |
| 411 |
assert_eq!( |
| 412 |
($mask::new(true, false, true) | $mask::new(false, true, false)).bitmask(), |
| 413 |
0b111, |
| 414 |
); |
| 415 |
assert_eq!( |
| 416 |
($mask::new(true, false, true) | $mask::new(true, false, true)).bitmask(), |
| 417 |
0b101, |
| 418 |
); |
| 419 |
|
| 420 |
let mut mask = $mask::new(true, true, false); |
| 421 |
mask |= $mask::new(true, false, false); |
| 422 |
assert_eq!(mask.bitmask(), 0b011); |
| 423 |
}); |
| 424 |
|
| 425 |
glam_test!(test_mask_xor, { |
| 426 |
assert_eq!( |
| 427 |
($mask::new(false, false, false) ^ $mask::new(false, false, false)).bitmask(), |
| 428 |
0b000, |
| 429 |
); |
| 430 |
assert_eq!( |
| 431 |
($mask::new(true, true, true) ^ $mask::new(true, true, true)).bitmask(), |
| 432 |
0b000, |
| 433 |
); |
| 434 |
assert_eq!( |
| 435 |
($mask::new(true, false, true) ^ $mask::new(false, true, false)).bitmask(), |
| 436 |
0b111, |
| 437 |
); |
| 438 |
assert_eq!( |
| 439 |
($mask::new(true, false, true) ^ $mask::new(true, false, true)).bitmask(), |
| 440 |
0b000, |
| 441 |
); |
| 442 |
|
| 443 |
let mut mask = $mask::new(true, true, false); |
| 444 |
mask ^= $mask::new(true, false, false); |
| 445 |
assert_eq!(mask.bitmask(), 0b010); |
| 446 |
}); |
| 447 |
|
| 448 |
glam_test!(test_mask_not, { |
| 449 |
assert_eq!((!$mask::new(false, false, false)).bitmask(), 0b111); |
| 450 |
assert_eq!((!$mask::new(true, true, true)).bitmask(), 0b000); |
| 451 |
assert_eq!((!$mask::new(true, false, true)).bitmask(), 0b010); |
| 452 |
assert_eq!((!$mask::new(false, true, false)).bitmask(), 0b101); |
| 453 |
}); |
| 454 |
|
| 455 |
glam_test!(test_mask_fmt, { |
| 456 |
let a = $mask::new(true, false, false); |
| 457 |
|
| 458 |
// debug fmt |
| 459 |
assert_eq!( |
| 460 |
format!("{:?}", a), |
| 461 |
format!("{}(0xffffffff, 0x0, 0x0)", stringify!($mask)) |
| 462 |
); |
| 463 |
|
| 464 |
// display fmt |
| 465 |
assert_eq!(format!("{}", a), "[true, false, false]"); |
| 466 |
}); |
| 467 |
|
| 468 |
glam_test!(test_mask_eq, { |
| 469 |
let a = $mask::new(true, false, true); |
| 470 |
let b = $mask::new(true, false, true); |
| 471 |
let c = $mask::new(false, true, true); |
| 472 |
|
| 473 |
assert_eq!(a, b); |
| 474 |
assert_eq!(b, a); |
| 475 |
assert_ne!(a, c); |
| 476 |
assert_ne!(b, c); |
| 477 |
}); |
| 478 |
|
| 479 |
glam_test!(test_mask_test, { |
| 480 |
let a = $mask::new(true, false, true); |
| 481 |
assert_eq!(a.test(0), true); |
| 482 |
assert_eq!(a.test(1), false); |
| 483 |
assert_eq!(a.test(2), true); |
| 484 |
|
| 485 |
let b = $mask::new(false, true, false); |
| 486 |
assert_eq!(b.test(0), false); |
| 487 |
assert_eq!(b.test(1), true); |
| 488 |
assert_eq!(b.test(2), false); |
| 489 |
}); |
| 490 |
|
| 491 |
glam_test!(test_mask_set, { |
| 492 |
let mut a = $mask::new(false, true, false); |
| 493 |
a.set(0, true); |
| 494 |
assert_eq!(a.test(0), true); |
| 495 |
a.set(1, false); |
| 496 |
assert_eq!(a.test(1), false); |
| 497 |
a.set(2, true); |
| 498 |
assert_eq!(a.test(2), true); |
| 499 |
|
| 500 |
let mut b = $mask::new(true, false, true); |
| 501 |
b.set(0, false); |
| 502 |
assert_eq!(b.test(0), false); |
| 503 |
b.set(1, true); |
| 504 |
assert_eq!(b.test(1), true); |
| 505 |
b.set(2, false); |
| 506 |
assert_eq!(b.test(2), false); |
| 507 |
}); |
| 508 |
|
| 509 |
glam_test!(test_mask_hash, { |
| 510 |
use std::collections::hash_map::DefaultHasher; |
| 511 |
use std::hash::Hash; |
| 512 |
use std::hash::Hasher; |
| 513 |
|
| 514 |
let a = $mask::new(true, false, true); |
| 515 |
let b = $mask::new(true, false, true); |
| 516 |
let c = $mask::new(false, true, true); |
| 517 |
|
| 518 |
let mut hasher = DefaultHasher::new(); |
| 519 |
a.hash(&mut hasher); |
| 520 |
let a_hashed = hasher.finish(); |
| 521 |
|
| 522 |
let mut hasher = DefaultHasher::new(); |
| 523 |
b.hash(&mut hasher); |
| 524 |
let b_hashed = hasher.finish(); |
| 525 |
|
| 526 |
let mut hasher = DefaultHasher::new(); |
| 527 |
c.hash(&mut hasher); |
| 528 |
let c_hashed = hasher.finish(); |
| 529 |
|
| 530 |
assert_eq!(a, b); |
| 531 |
assert_eq!(a_hashed, b_hashed); |
| 532 |
assert_ne!(a, c); |
| 533 |
assert_ne!(a_hashed, c_hashed); |
| 534 |
}); |
| 535 |
|
| 536 |
glam_test!(test_to_from_slice, { |
| 537 |
let v = $vec3::new(1 as $t, 2 as $t, 3 as $t); |
| 538 |
let mut a = [0 as $t, 0 as $t, 0 as $t]; |
| 539 |
v.write_to_slice(&mut a); |
| 540 |
assert_eq!(v, $vec3::from_slice(&a)); |
| 541 |
|
| 542 |
should_panic!({ $vec3::ONE.write_to_slice(&mut [0 as $t; 2]) }); |
| 543 |
should_panic!({ $vec3::from_slice(&[0 as $t; 2]) }); |
| 544 |
}); |
| 545 |
|
| 546 |
glam_test!(test_sum, { |
| 547 |
let one = $vec3::ONE; |
| 548 |
assert_eq!([one, one].iter().sum::<$vec3>(), one + one); |
| 549 |
assert_eq!([one, one].into_iter().sum::<$vec3>(), one + one); |
| 550 |
}); |
| 551 |
|
| 552 |
glam_test!(test_product, { |
| 553 |
let two = $vec3::new(2 as $t, 2 as $t, 2 as $t); |
| 554 |
assert_eq!([two, two].iter().product::<$vec3>(), two * two); |
| 555 |
assert_eq!([two, two].into_iter().product::<$vec3>(), two * two); |
| 556 |
}); |
| 557 |
}; |
| 558 |
} |
| 559 |
|
| 560 |
macro_rules! impl_vec3_signed_tests { |
| 561 |
($t:ident, $new:ident, $vec3:ident, $mask:ident) => { |
| 562 |
impl_vec3_tests!($t, $new, $vec3, $mask); |
| 563 |
|
| 564 |
glam_test!(test_neg, { |
| 565 |
let a = $new(1 as $t, 2 as $t, 3 as $t); |
| 566 |
assert_eq!((-1 as $t, -2 as $t, -3 as $t), (-a).into()); |
| 567 |
assert_eq!( |
| 568 |
$new(-0.0 as $t, -0.0 as $t, -0.0 as $t), |
| 569 |
-$new(0.0 as $t, 0.0 as $t, 0.0 as $t) |
| 570 |
); |
| 571 |
assert_eq!( |
| 572 |
$new(0.0 as $t, -0.0 as $t, -0.0 as $t), |
| 573 |
-$new(-0.0 as $t, 0.0 as $t, 0.0 as $t) |
| 574 |
); |
| 575 |
}); |
| 576 |
|
| 577 |
glam_test!(test_is_negative_bitmask, { |
| 578 |
assert_eq!($vec3::ZERO.is_negative_bitmask(), 0b000); |
| 579 |
assert_eq!($vec3::ONE.is_negative_bitmask(), 0b000); |
| 580 |
assert_eq!((-$vec3::ONE).is_negative_bitmask(), 0b111); |
| 581 |
assert_eq!( |
| 582 |
$vec3::new(-1 as $t, 2 as $t, 3 as $t).is_negative_bitmask(), |
| 583 |
0b001 |
| 584 |
); |
| 585 |
assert_eq!( |
| 586 |
$vec3::new(8 as $t, 3 as $t, 1 as $t).is_negative_bitmask(), |
| 587 |
0b000 |
| 588 |
); |
| 589 |
assert_eq!( |
| 590 |
$vec3::new(1 as $t, 5 as $t, -3 as $t).is_negative_bitmask(), |
| 591 |
0b100 |
| 592 |
); |
| 593 |
assert_eq!( |
| 594 |
$vec3::new(3 as $t, -4 as $t, 1 as $t).is_negative_bitmask(), |
| 595 |
0b010 |
| 596 |
); |
| 597 |
assert_eq!( |
| 598 |
$vec3::new(-2 as $t, 6 as $t, -5 as $t).is_negative_bitmask(), |
| 599 |
0b101 |
| 600 |
); |
| 601 |
}); |
| 602 |
|
| 603 |
glam_test!(test_abs, { |
| 604 |
assert_eq!($vec3::ZERO.abs(), $vec3::ZERO); |
| 605 |
assert_eq!($vec3::ONE.abs(), $vec3::ONE); |
| 606 |
assert_eq!((-$vec3::ONE).abs(), $vec3::ONE); |
| 607 |
}); |
| 608 |
|
| 609 |
glam_test!(test_dot_signed, { |
| 610 |
let x = $new(1 as $t, 0 as $t, 0 as $t); |
| 611 |
let y = $new(0 as $t, 1 as $t, 0 as $t); |
| 612 |
let z = $new(0 as $t, 0 as $t, 1 as $t); |
| 613 |
assert_eq!(1 as $t, x.dot(x)); |
| 614 |
assert_eq!(0 as $t, x.dot(y)); |
| 615 |
assert_eq!(-1 as $t, z.dot(-z)); |
| 616 |
}); |
| 617 |
|
| 618 |
glam_test!(test_length_squared_signed, { |
| 619 |
let x = $new(1 as $t, 0 as $t, 0 as $t); |
| 620 |
let y = $new(0 as $t, 1 as $t, 0 as $t); |
| 621 |
let z = $new(0 as $t, 0 as $t, 1 as $t); |
| 622 |
assert_eq!(9 as $t, (-3 as $t * y).length_squared()); |
| 623 |
assert_eq!( |
| 624 |
2 as $t * 2 as $t + 3 as $t * 3 as $t + 4 as $t * 4 as $t, |
| 625 |
$new(2 as $t, 3 as $t, 4 as $t).length_squared() |
| 626 |
); |
| 627 |
assert_eq!(2 as $t, x.distance_squared(y)); |
| 628 |
assert_eq!(13 as $t, (2 as $t * x).distance_squared(-3 as $t * z)); |
| 629 |
}); |
| 630 |
|
| 631 |
glam_test!(test_div_euclid, { |
| 632 |
let one = $vec3::ONE; |
| 633 |
let two = one + one; |
| 634 |
let three = two + one; |
| 635 |
assert_eq!(three.div_euclid(two), one); |
| 636 |
assert_eq!((-three).div_euclid(two), -two); |
| 637 |
assert_eq!(three.div_euclid(-two), -one); |
| 638 |
assert_eq!((-three).div_euclid(-two), two); |
| 639 |
}); |
| 640 |
|
| 641 |
glam_test!(test_rem_euclid, { |
| 642 |
let one = $vec3::ONE; |
| 643 |
let two = one + one; |
| 644 |
let three = two + one; |
| 645 |
let four = three + one; |
| 646 |
assert_eq!(four.rem_euclid(three), one); |
| 647 |
assert_eq!((-four).rem_euclid(three), two); |
| 648 |
assert_eq!(four.rem_euclid(-three), one); |
| 649 |
assert_eq!((-four).rem_euclid(-three), two); |
| 650 |
}); |
| 651 |
}; |
| 652 |
} |
| 653 |
|
| 654 |
macro_rules! impl_vec3_signed_integer_tests { |
| 655 |
($t:ident, $new:ident, $vec3:ident, $mask:ident) => { |
| 656 |
impl_vec3_signed_tests!($t, $new, $vec3, $mask); |
| 657 |
|
| 658 |
glam_test!(test_signum, { |
| 659 |
assert_eq!($vec3::ZERO.signum(), $vec3::ZERO); |
| 660 |
assert_eq!($vec3::ONE.signum(), $vec3::ONE); |
| 661 |
assert_eq!((-$vec3::ONE).signum(), -$vec3::ONE); |
| 662 |
}); |
| 663 |
}; |
| 664 |
} |
| 665 |
|
| 666 |
macro_rules! impl_vec3_eq_hash_tests { |
| 667 |
($t:ident, $new:ident) => { |
| 668 |
glam_test!(test_vec3_hash, { |
| 669 |
use std::collections::hash_map::DefaultHasher; |
| 670 |
use std::hash::Hash; |
| 671 |
use std::hash::Hasher; |
| 672 |
|
| 673 |
let a = $new(1 as $t, 2 as $t, 3 as $t); |
| 674 |
let b = $new(1 as $t, 2 as $t, 3 as $t); |
| 675 |
let c = $new(3 as $t, 2 as $t, 1 as $t); |
| 676 |
|
| 677 |
let mut hasher = DefaultHasher::new(); |
| 678 |
a.hash(&mut hasher); |
| 679 |
let a_hashed = hasher.finish(); |
| 680 |
|
| 681 |
let mut hasher = DefaultHasher::new(); |
| 682 |
b.hash(&mut hasher); |
| 683 |
let b_hashed = hasher.finish(); |
| 684 |
|
| 685 |
let mut hasher = DefaultHasher::new(); |
| 686 |
c.hash(&mut hasher); |
| 687 |
let c_hashed = hasher.finish(); |
| 688 |
|
| 689 |
assert_eq!(a, b); |
| 690 |
assert_eq!(a_hashed, b_hashed); |
| 691 |
assert_ne!(a, c); |
| 692 |
assert_ne!(a_hashed, c_hashed); |
| 693 |
}); |
| 694 |
}; |
| 695 |
} |
| 696 |
|
| 697 |
macro_rules! impl_vec3_float_tests { |
| 698 |
($t:ident, $new:ident, $vec3:ident, $mask:ident) => { |
| 699 |
impl_vec3_signed_tests!($t, $new, $vec3, $mask); |
| 700 |
impl_vec_float_normalize_tests!($t, $vec3); |
| 701 |
|
| 702 |
use core::$t::INFINITY; |
| 703 |
use core::$t::NAN; |
| 704 |
use core::$t::NEG_INFINITY; |
| 705 |
|
| 706 |
glam_test!(test_nan, { |
| 707 |
assert!($vec3::NAN.is_nan()); |
| 708 |
assert!(!$vec3::NAN.is_finite()); |
| 709 |
}); |
| 710 |
|
| 711 |
glam_test!(test_funcs, { |
| 712 |
let x = $new(1.0, 0.0, 0.0); |
| 713 |
let y = $new(0.0, 1.0, 0.0); |
| 714 |
let z = $new(0.0, 0.0, 1.0); |
| 715 |
assert_eq!(y, z.cross(x)); |
| 716 |
assert_eq!(z, x.cross(y)); |
| 717 |
assert_eq!(2.0, (-2.0 * x).length()); |
| 718 |
assert_eq!(3.0, (3.0 * y).length()); |
| 719 |
assert_eq!(4.0, (-4.0 * z).length()); |
| 720 |
assert_eq!((2.0 as $t).sqrt(), x.distance(y)); |
| 721 |
assert_eq!(5.0, (3.0 * x).distance(-4.0 * y)); |
| 722 |
assert_eq!(13.0, (-5.0 * z).distance(12.0 * y)); |
| 723 |
assert_eq!(x, (2.0 * x).normalize()); |
| 724 |
assert_eq!( |
| 725 |
1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0, |
| 726 |
$new(1.0, 2.0, 3.0).dot($new(4.0, 5.0, 6.0)) |
| 727 |
); |
| 728 |
assert_eq!( |
| 729 |
(2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0).sqrt(), |
| 730 |
$new(2.0, 3.0, 4.0).length() |
| 731 |
); |
| 732 |
assert_eq!( |
| 733 |
1.0 / (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0).sqrt(), |
| 734 |
$new(2.0, 3.0, 4.0).length_recip() |
| 735 |
); |
| 736 |
assert!($new(2.0, 3.0, 4.0).normalize().is_normalized()); |
| 737 |
assert_approx_eq!( |
| 738 |
$new(2.0, 3.0, 4.0) / (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0).sqrt(), |
| 739 |
$new(2.0, 3.0, 4.0).normalize() |
| 740 |
); |
| 741 |
assert_eq!($new(0.5, 0.25, 0.125), $new(2.0, 4.0, 8.0).recip()); |
| 742 |
}); |
| 743 |
|
| 744 |
glam_test!(test_project_reject, { |
| 745 |
assert_eq!( |
| 746 |
$new(0.0, 0.0, 1.0), |
| 747 |
$new(1.0, 0.0, 1.0).project_onto($new(0.0, 0.0, 2.0)) |
| 748 |
); |
| 749 |
assert_eq!( |
| 750 |
$new(1.0, 0.0, 0.0), |
| 751 |
$new(1.0, 0.0, 1.0).reject_from($new(0.0, 0.0, 2.0)) |
| 752 |
); |
| 753 |
assert_eq!( |
| 754 |
$new(0.0, 0.0, 1.0), |
| 755 |
$new(1.0, 0.0, 1.0).project_onto_normalized($new(0.0, 0.0, 1.0)) |
| 756 |
); |
| 757 |
assert_eq!( |
| 758 |
$new(1.0, 0.0, 0.0), |
| 759 |
$new(1.0, 0.0, 1.0).reject_from_normalized($new(0.0, 0.0, 1.0)) |
| 760 |
); |
| 761 |
should_glam_assert!({ $vec3::ONE.project_onto($vec3::ZERO) }); |
| 762 |
should_glam_assert!({ $vec3::ONE.reject_from($vec3::ZERO) }); |
| 763 |
should_glam_assert!({ $vec3::ONE.project_onto_normalized($vec3::ONE) }); |
| 764 |
should_glam_assert!({ $vec3::ONE.reject_from_normalized($vec3::ONE) }); |
| 765 |
}); |
| 766 |
|
| 767 |
glam_test!(test_signum, { |
| 768 |
assert_eq!($vec3::ZERO.signum(), $vec3::ONE); |
| 769 |
assert_eq!((-$vec3::ZERO).signum(), -$vec3::ONE); |
| 770 |
assert_eq!($vec3::ONE.signum(), $vec3::ONE); |
| 771 |
assert_eq!((-$vec3::ONE).signum(), -$vec3::ONE); |
| 772 |
assert_eq!($vec3::INFINITY.signum(), $vec3::ONE); |
| 773 |
assert_eq!($vec3::NEG_INFINITY.signum(), -$vec3::ONE); |
| 774 |
assert!($vec3::NAN.signum().is_nan_mask().all()); |
| 775 |
}); |
| 776 |
|
| 777 |
glam_test!(test_copysign, { |
| 778 |
assert_eq!($vec3::ZERO.copysign(-$vec3::ZERO), -$vec3::ZERO); |
| 779 |
assert_eq!((-$vec3::ZERO).copysign(-$vec3::ZERO), -$vec3::ZERO); |
| 780 |
assert_eq!($vec3::ZERO.copysign($vec3::ZERO), $vec3::ZERO); |
| 781 |
assert_eq!((-$vec3::ZERO).copysign($vec3::ZERO), $vec3::ZERO); |
| 782 |
assert_eq!($vec3::ONE.copysign(-$vec3::ZERO), -$vec3::ONE); |
| 783 |
assert_eq!((-$vec3::ONE).copysign(-$vec3::ZERO), -$vec3::ONE); |
| 784 |
assert_eq!($vec3::ONE.copysign($vec3::ZERO), $vec3::ONE); |
| 785 |
assert_eq!((-$vec3::ONE).copysign($vec3::ZERO), $vec3::ONE); |
| 786 |
assert_eq!($vec3::ZERO.copysign(-$vec3::ONE), -$vec3::ZERO); |
| 787 |
assert_eq!((-$vec3::ZERO).copysign(-$vec3::ONE), -$vec3::ZERO); |
| 788 |
assert_eq!($vec3::ZERO.copysign($vec3::ONE), $vec3::ZERO); |
| 789 |
assert_eq!((-$vec3::ZERO).copysign($vec3::ONE), $vec3::ZERO); |
| 790 |
assert_eq!($vec3::ONE.copysign(-$vec3::ONE), -$vec3::ONE); |
| 791 |
assert_eq!((-$vec3::ONE).copysign(-$vec3::ONE), -$vec3::ONE); |
| 792 |
assert_eq!($vec3::ONE.copysign($vec3::ONE), $vec3::ONE); |
| 793 |
assert_eq!((-$vec3::ONE).copysign($vec3::ONE), $vec3::ONE); |
| 794 |
assert_eq!($vec3::INFINITY.copysign($vec3::ONE), $vec3::INFINITY); |
| 795 |
assert_eq!($vec3::INFINITY.copysign(-$vec3::ONE), $vec3::NEG_INFINITY); |
| 796 |
assert_eq!($vec3::NEG_INFINITY.copysign($vec3::ONE), $vec3::INFINITY); |
| 797 |
assert_eq!( |
| 798 |
$vec3::NEG_INFINITY.copysign(-$vec3::ONE), |
| 799 |
$vec3::NEG_INFINITY |
| 800 |
); |
| 801 |
assert!($vec3::NAN.copysign($vec3::ONE).is_nan_mask().all()); |
| 802 |
assert!($vec3::NAN.copysign(-$vec3::ONE).is_nan_mask().all()); |
| 803 |
}); |
| 804 |
|
| 805 |
glam_test!(test_float_is_negative_bitmask, { |
| 806 |
assert_eq!($vec3::ZERO.is_negative_bitmask(), 0b000); |
| 807 |
assert_eq!((-$vec3::ZERO).is_negative_bitmask(), 0b111); |
| 808 |
assert_eq!($vec3::ONE.is_negative_bitmask(), 0b000); |
| 809 |
assert_eq!((-$vec3::ONE).is_negative_bitmask(), 0b111); |
| 810 |
assert_eq!($vec3::new(-1.0, 2.0, 3.0).is_negative_bitmask(), 0b001); |
| 811 |
assert_eq!($vec3::new(8.0, 3.0, 1.0).is_negative_bitmask(), 0b000); |
| 812 |
assert_eq!($vec3::new(1.0, 5.0, -3.0).is_negative_bitmask(), 0b100); |
| 813 |
assert_eq!($vec3::new(3.0, -4.0, 1.0).is_negative_bitmask(), 0b010); |
| 814 |
assert_eq!($vec3::new(-2.0, 6.0, -5.0).is_negative_bitmask(), 0b101); |
| 815 |
}); |
| 816 |
|
| 817 |
glam_test!(test_round, { |
| 818 |
assert_eq!($vec3::new(1.35, 0.0, 0.0).round().x, 1.0); |
| 819 |
assert_eq!($vec3::new(0.0, 1.5, 0.0).round().y, 2.0); |
| 820 |
assert_eq!($vec3::new(0.0, 0.0, -15.5).round().z, -16.0); |
| 821 |
assert_eq!($vec3::new(0.0, 0.0, 0.0).round().z, 0.0); |
| 822 |
assert_eq!($vec3::new(0.0, 21.1, 0.0).round().y, 21.0); |
| 823 |
assert_eq!($vec3::new(0.0, 11.123, 0.0).round().y, 11.0); |
| 824 |
assert_eq!($vec3::new(0.0, 11.499, 0.0).round().y, 11.0); |
| 825 |
assert_eq!( |
| 826 |
$vec3::new(NEG_INFINITY, INFINITY, 0.0).round(), |
| 827 |
$vec3::new(NEG_INFINITY, INFINITY, 0.0) |
| 828 |
); |
| 829 |
assert!($vec3::new(NAN, 0.0, 0.0).round().x.is_nan()); |
| 830 |
}); |
| 831 |
|
| 832 |
glam_test!(test_floor, { |
| 833 |
assert_eq!( |
| 834 |
$vec3::new(1.35, 1.5, -1.5).floor(), |
| 835 |
$vec3::new(1.0, 1.0, -2.0) |
| 836 |
); |
| 837 |
assert_eq!( |
| 838 |
$vec3::new(INFINITY, NEG_INFINITY, 0.0).floor(), |
| 839 |
$vec3::new(INFINITY, NEG_INFINITY, 0.0) |
| 840 |
); |
| 841 |
assert!($vec3::new(NAN, 0.0, 0.0).floor().x.is_nan()); |
| 842 |
assert_eq!( |
| 843 |
$vec3::new(-2000000.123, 10000000.123, 1000.9).floor(), |
| 844 |
$vec3::new(-2000001.0, 10000000.0, 1000.0) |
| 845 |
); |
| 846 |
}); |
| 847 |
|
| 848 |
glam_test!(test_fract, { |
| 849 |
assert_approx_eq!( |
| 850 |
$vec3::new(1.35, 1.5, -1.5).fract(), |
| 851 |
$vec3::new(0.35, 0.5, 0.5) |
| 852 |
); |
| 853 |
assert_approx_eq!( |
| 854 |
$vec3::new(-200000.123, 1000000.123, 1000.9).fract(), |
| 855 |
$vec3::new(0.877, 0.123, 0.9), |
| 856 |
0.002 |
| 857 |
); |
| 858 |
}); |
| 859 |
|
| 860 |
glam_test!(test_ceil, { |
| 861 |
assert_eq!( |
| 862 |
$vec3::new(1.35, 1.5, -1.5).ceil(), |
| 863 |
$vec3::new(2.0, 2.0, -1.0) |
| 864 |
); |
| 865 |
assert_eq!( |
| 866 |
$vec3::new(INFINITY, NEG_INFINITY, 0.0).ceil(), |
| 867 |
$vec3::new(INFINITY, NEG_INFINITY, 0.0) |
| 868 |
); |
| 869 |
assert!($vec3::new(NAN, 0.0, 0.0).ceil().x.is_nan()); |
| 870 |
assert_eq!( |
| 871 |
$vec3::new(-2000000.123, 1000000.123, 1000.9).ceil(), |
| 872 |
$vec3::new(-2000000.0, 1000001.0, 1001.0) |
| 873 |
); |
| 874 |
}); |
| 875 |
|
| 876 |
glam_test!(test_trunc, { |
| 877 |
assert_eq!( |
| 878 |
$vec3::new(1.35, 1.5, -1.5).trunc(), |
| 879 |
$vec3::new(1.0, 1.0, -1.0) |
| 880 |
); |
| 881 |
assert_eq!( |
| 882 |
$vec3::new(INFINITY, NEG_INFINITY, 0.0).trunc(), |
| 883 |
$vec3::new(INFINITY, NEG_INFINITY, 0.0) |
| 884 |
); |
| 885 |
assert!($vec3::new(0.0, NAN, 0.0).trunc().y.is_nan()); |
| 886 |
assert_eq!( |
| 887 |
$vec3::new(-0.0, -2000000.123, 10000000.123).trunc(), |
| 888 |
$vec3::new(-0.0, -2000000.0, 10000000.0) |
| 889 |
); |
| 890 |
}); |
| 891 |
|
| 892 |
glam_test!(test_lerp, { |
| 893 |
let v0 = $vec3::new(-1.0, -1.0, -1.0); |
| 894 |
let v1 = $vec3::new(1.0, 1.0, 1.0); |
| 895 |
assert_approx_eq!(v0, v0.lerp(v1, 0.0)); |
| 896 |
assert_approx_eq!(v1, v0.lerp(v1, 1.0)); |
| 897 |
assert_approx_eq!($vec3::ZERO, v0.lerp(v1, 0.5)); |
| 898 |
}); |
| 899 |
|
| 900 |
glam_test!(test_is_finite, { |
| 901 |
assert!($vec3::new(0.0, 0.0, 0.0).is_finite()); |
| 902 |
assert!($vec3::new(-1e-10, 1.0, 1e10).is_finite()); |
| 903 |
assert!(!$vec3::new(INFINITY, 0.0, 0.0).is_finite()); |
| 904 |
assert!(!$vec3::new(0.0, NAN, 0.0).is_finite()); |
| 905 |
assert!(!$vec3::new(0.0, 0.0, NEG_INFINITY).is_finite()); |
| 906 |
assert!(!$vec3::NAN.is_finite()); |
| 907 |
assert!(!$vec3::INFINITY.is_finite()); |
| 908 |
assert!(!$vec3::NEG_INFINITY.is_finite()); |
| 909 |
}); |
| 910 |
|
| 911 |
glam_test!(test_powf, { |
| 912 |
assert_eq!( |
| 913 |
$vec3::new(2.0, 4.0, 8.0).powf(2.0), |
| 914 |
$vec3::new(4.0, 16.0, 64.0) |
| 915 |
); |
| 916 |
}); |
| 917 |
|
| 918 |
glam_test!(test_exp, { |
| 919 |
assert_approx_eq!( |
| 920 |
$vec3::new(1.0, 2.0, 3.0).exp(), |
| 921 |
$vec3::new((1.0 as $t).exp(), (2.0 as $t).exp(), (3.0 as $t).exp()) |
| 922 |
); |
| 923 |
}); |
| 924 |
|
| 925 |
glam_test!(test_angle_between, { |
| 926 |
let angle = $vec3::new(1.0, 0.0, 1.0).angle_between($vec3::new(1.0, 1.0, 0.0)); |
| 927 |
assert_approx_eq!(core::$t::consts::FRAC_PI_3, angle, 1e-6); |
| 928 |
|
| 929 |
let angle = $vec3::new(10.0, 0.0, 10.0).angle_between($vec3::new(5.0, 5.0, 0.0)); |
| 930 |
assert_approx_eq!(core::$t::consts::FRAC_PI_3, angle, 1e-6); |
| 931 |
|
| 932 |
let angle = $vec3::new(-1.0, 0.0, -1.0).angle_between($vec3::new(1.0, -1.0, 0.0)); |
| 933 |
assert_approx_eq!(2.0 * core::$t::consts::FRAC_PI_3, angle, 1e-6); |
| 934 |
}); |
| 935 |
|
| 936 |
glam_test!(test_clamp_length, { |
| 937 |
// Too long gets shortened |
| 938 |
assert_eq!( |
| 939 |
$vec3::new(12.0, 16.0, 0.0).clamp_length(7.0, 10.0), |
| 940 |
$vec3::new(6.0, 8.0, 0.0) // shortened to length 10.0 |
| 941 |
); |
| 942 |
// In the middle is unchanged |
| 943 |
assert_eq!( |
| 944 |
$vec3::new(2.0, 1.0, 0.0).clamp_length(0.5, 5.0), |
| 945 |
$vec3::new(2.0, 1.0, 0.0) // unchanged |
| 946 |
); |
| 947 |
// Too short gets lengthened |
| 948 |
assert_eq!( |
| 949 |
$vec3::new(0.6, 0.8, 0.0).clamp_length(10.0, 20.0), |
| 950 |
$vec3::new(6.0, 8.0, 0.0) // lengthened to length 10.0 |
| 951 |
); |
| 952 |
should_glam_assert!({ $vec3::ONE.clamp_length(1.0, 0.0) }); |
| 953 |
}); |
| 954 |
|
| 955 |
glam_test!(test_clamp_length_max, { |
| 956 |
// Too long gets shortened |
| 957 |
assert_eq!( |
| 958 |
$vec3::new(12.0, 16.0, 0.0).clamp_length_max(10.0), |
| 959 |
$vec3::new(6.0, 8.0, 0.0) // shortened to length 10.0 |
| 960 |
); |
| 961 |
// Not too long is unchanged |
| 962 |
assert_eq!( |
| 963 |
$vec3::new(2.0, 1.0, 0.0).clamp_length_max(5.0), |
| 964 |
$vec3::new(2.0, 1.0, 0.0) // unchanged |
| 965 |
); |
| 966 |
}); |
| 967 |
|
| 968 |
glam_test!(test_clamp_length_min, { |
| 969 |
// Not too short is unchanged |
| 970 |
assert_eq!( |
| 971 |
$vec3::new(2.0, 1.0, 0.0).clamp_length_min(0.5), |
| 972 |
$vec3::new(2.0, 1.0, 0.0) // unchanged |
| 973 |
); |
| 974 |
// Too short gets lengthened |
| 975 |
assert_eq!( |
| 976 |
$vec3::new(0.6, 0.8, 0.0).clamp_length_min(10.0), |
| 977 |
$vec3::new(6.0, 8.0, 0.0) // lengthened to length 10.0 |
| 978 |
); |
| 979 |
}); |
| 980 |
|
| 981 |
glam_test!(test_any_ortho, { |
| 982 |
let eps = 2.0 * core::$t::EPSILON; |
| 983 |
|
| 984 |
for &v in &vec3_float_test_vectors!($vec3) { |
| 985 |
let orthogonal = v.any_orthogonal_vector(); |
| 986 |
assert!(orthogonal != $vec3::ZERO && orthogonal.is_finite()); |
| 987 |
assert!(v.dot(orthogonal).abs() < eps); |
| 988 |
|
| 989 |
let n = v.normalize(); |
| 990 |
|
| 991 |
let orthonormal = n.any_orthonormal_vector(); |
| 992 |
assert!(orthonormal.is_normalized()); |
| 993 |
assert!(n.dot(orthonormal).abs() < eps); |
| 994 |
|
| 995 |
let (a, b) = n.any_orthonormal_pair(); |
| 996 |
assert!(a.is_normalized() && n.dot(a).abs() < eps); |
| 997 |
assert!(b.is_normalized() && n.dot(b).abs() < eps); |
| 998 |
} |
| 999 |
}); |
| 1000 |
|
| 1001 |
glam_test!(test_mul_add, { |
| 1002 |
assert_eq!( |
| 1003 |
$vec3::new(1.0, 1.0, 1.0) |
| 1004 |
.mul_add($vec3::new(0.5, 2.0, -4.0), $vec3::new(-1.0, -1.0, -1.0)), |
| 1005 |
$vec3::new(-0.5, 1.0, -5.0) |
| 1006 |
); |
| 1007 |
}); |
| 1008 |
}; |
| 1009 |
} |
| 1010 |
|
| 1011 |
macro_rules! impl_vec3_scalar_shift_op_test { |
| 1012 |
($vec3:ident, $t_min:literal, $t_max:literal, $rhs_min:literal, $rhs_max:literal) => { |
| 1013 |
glam_test!(test_vec3_scalar_shift_ops, { |
| 1014 |
for x in $t_min..$t_max { |
| 1015 |
for y in $t_min..$t_max { |
| 1016 |
for z in $t_min..$t_max { |
| 1017 |
for rhs in $rhs_min..$rhs_max { |
| 1018 |
assert_eq!( |
| 1019 |
$vec3::new(x, y, z) << rhs, |
| 1020 |
$vec3::new(x << rhs, y << rhs, z << rhs) |
| 1021 |
); |
| 1022 |
assert_eq!( |
| 1023 |
$vec3::new(x, y, z) >> rhs, |
| 1024 |
$vec3::new(x >> rhs, y >> rhs, z >> rhs) |
| 1025 |
); |
| 1026 |
} |
| 1027 |
} |
| 1028 |
} |
| 1029 |
} |
| 1030 |
}); |
| 1031 |
}; |
| 1032 |
} |
| 1033 |
|
| 1034 |
macro_rules! impl_vec3_scalar_shift_op_tests { |
| 1035 |
($vec3:ident, $t_min:literal, $t_max:literal) => { |
| 1036 |
mod shift_by_i8 { |
| 1037 |
use glam::$vec3; |
| 1038 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0i8, 2); |
| 1039 |
} |
| 1040 |
mod shift_by_i16 { |
| 1041 |
use glam::$vec3; |
| 1042 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0i16, 2); |
| 1043 |
} |
| 1044 |
mod shift_by_i32 { |
| 1045 |
use glam::$vec3; |
| 1046 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0i32, 2); |
| 1047 |
} |
| 1048 |
mod shift_by_i64 { |
| 1049 |
use glam::$vec3; |
| 1050 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0i64, 2); |
| 1051 |
} |
| 1052 |
mod shift_by_u8 { |
| 1053 |
use glam::$vec3; |
| 1054 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0u8, 2); |
| 1055 |
} |
| 1056 |
mod shift_by_u16 { |
| 1057 |
use glam::$vec3; |
| 1058 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0u16, 2); |
| 1059 |
} |
| 1060 |
mod shift_by_u32 { |
| 1061 |
use glam::$vec3; |
| 1062 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0u32, 2); |
| 1063 |
} |
| 1064 |
mod shift_by_u64 { |
| 1065 |
use glam::$vec3; |
| 1066 |
impl_vec3_scalar_shift_op_test!($vec3, $t_min, $t_max, 0u64, 2); |
| 1067 |
} |
| 1068 |
}; |
| 1069 |
} |
| 1070 |
|
| 1071 |
macro_rules! impl_vec3_shift_op_test { |
| 1072 |
($vec3:ident, $rhs:ident, $t_min:literal, $t_max:literal) => { |
| 1073 |
glam_test!(test_vec3_shift_ops, { |
| 1074 |
for x1 in $t_min..$t_max { |
| 1075 |
for y1 in $t_min..$t_max { |
| 1076 |
for z1 in $t_min..$t_max { |
| 1077 |
for x2 in $t_min..$t_max { |
| 1078 |
for y2 in $t_min..$t_max { |
| 1079 |
for z2 in $t_min..$t_max { |
| 1080 |
assert_eq!( |
| 1081 |
$vec3::new(x1, y1, z1) << $rhs::new(x2, y2, z2), |
| 1082 |
$vec3::new(x1 << x2, y1 << y2, z1 << z2) |
| 1083 |
); |
| 1084 |
assert_eq!( |
| 1085 |
$vec3::new(x1, y1, z1) >> $rhs::new(x2, y2, z2), |
| 1086 |
$vec3::new(x1 >> x2, y1 >> y2, z1 >> z2) |
| 1087 |
); |
| 1088 |
} |
| 1089 |
} |
| 1090 |
} |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} |
| 1094 |
}); |
| 1095 |
}; |
| 1096 |
} |
| 1097 |
|
| 1098 |
macro_rules! impl_vec3_shift_op_tests { |
| 1099 |
($vec3:ident) => { |
| 1100 |
mod shift_ivec3_by_ivec3 { |
| 1101 |
use super::*; |
| 1102 |
impl_vec3_shift_op_test!($vec3, IVec3, 0, 2); |
| 1103 |
} |
| 1104 |
mod shift_ivec3_by_uvec3 { |
| 1105 |
use super::*; |
| 1106 |
impl_vec3_shift_op_test!($vec3, UVec3, 0, 2); |
| 1107 |
} |
| 1108 |
}; |
| 1109 |
} |
| 1110 |
|
| 1111 |
macro_rules! impl_vec3_scalar_bit_op_tests { |
| 1112 |
($vec3:ident, $t_min:literal, $t_max:literal) => { |
| 1113 |
glam_test!(test_vec3_scalar_bit_ops, { |
| 1114 |
for x in $t_min..$t_max { |
| 1115 |
for y in $t_min..$t_max { |
| 1116 |
for z in $t_min..$t_max { |
| 1117 |
for rhs in $t_min..$t_max { |
| 1118 |
assert_eq!( |
| 1119 |
$vec3::new(x, y, z) & rhs, |
| 1120 |
$vec3::new(x & rhs, y & rhs, z & rhs) |
| 1121 |
); |
| 1122 |
assert_eq!( |
| 1123 |
$vec3::new(x, y, z) | rhs, |
| 1124 |
$vec3::new(x | rhs, y | rhs, z | rhs) |
| 1125 |
); |
| 1126 |
assert_eq!( |
| 1127 |
$vec3::new(x, y, z) ^ rhs, |
| 1128 |
$vec3::new(x ^ rhs, y ^ rhs, z ^ rhs) |
| 1129 |
); |
| 1130 |
} |
| 1131 |
} |
| 1132 |
} |
| 1133 |
} |
| 1134 |
}); |
| 1135 |
}; |
| 1136 |
} |
| 1137 |
|
| 1138 |
macro_rules! impl_vec3_bit_op_tests { |
| 1139 |
($vec3:ident, $t_min:literal, $t_max:literal) => { |
| 1140 |
glam_test!(test_vec3_bit_ops, { |
| 1141 |
for x1 in $t_min..$t_max { |
| 1142 |
for y1 in $t_min..$t_max { |
| 1143 |
for z1 in $t_min..$t_max { |
| 1144 |
assert_eq!(!$vec3::new(x1, y1, z1), $vec3::new(!x1, !y1, !z1)); |
| 1145 |
|
| 1146 |
for x2 in $t_min..$t_max { |
| 1147 |
for y2 in $t_min..$t_max { |
| 1148 |
for z2 in $t_min..$t_max { |
| 1149 |
assert_eq!( |
| 1150 |
$vec3::new(x1, y1, z1) & $vec3::new(x2, y2, z2), |
| 1151 |
$vec3::new(x1 & x2, y1 & y2, z1 & z2) |
| 1152 |
); |
| 1153 |
assert_eq!( |
| 1154 |
$vec3::new(x1, y1, z1) | $vec3::new(x2, y2, z2), |
| 1155 |
$vec3::new(x1 | x2, y1 | y2, z1 | z2) |
| 1156 |
); |
| 1157 |
assert_eq!( |
| 1158 |
$vec3::new(x1, y1, z1) ^ $vec3::new(x2, y2, z2), |
| 1159 |
$vec3::new(x1 ^ x2, y1 ^ y2, z1 ^ z2) |
| 1160 |
); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
} |
| 1164 |
} |
| 1165 |
} |
| 1166 |
} |
| 1167 |
}); |
| 1168 |
}; |
| 1169 |
} |
| 1170 |
|
| 1171 |
mod vec3 { |
| 1172 |
use glam::{vec3, BVec3, Vec3}; |
| 1173 |
|
| 1174 |
glam_test!(test_align, { |
| 1175 |
use std::mem; |
| 1176 |
assert_eq!(12, mem::size_of::<Vec3>()); |
| 1177 |
assert_eq!(4, mem::align_of::<Vec3>()); |
| 1178 |
assert_eq!(3, mem::size_of::<BVec3>()); |
| 1179 |
assert_eq!(1, mem::align_of::<BVec3>()); |
| 1180 |
}); |
| 1181 |
|
| 1182 |
glam_test!(test_as, { |
| 1183 |
use glam::{DVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec3, Vec3A}; |
| 1184 |
assert_eq!( |
| 1185 |
DVec3::new(-1.0, -2.0, -3.0), |
| 1186 |
Vec3::new(-1.0, -2.0, -3.0).as_dvec3() |
| 1187 |
); |
| 1188 |
assert_eq!( |
| 1189 |
I16Vec3::new(-1, -2, -3), |
| 1190 |
Vec3::new(-1.0, -2.0, -3.0).as_i16vec3() |
| 1191 |
); |
| 1192 |
assert_eq!(U16Vec3::new(1, 2, 3), Vec3::new(1.0, 2.0, 3.0).as_u16vec3()); |
| 1193 |
assert_eq!( |
| 1194 |
IVec3::new(-1, -2, -3), |
| 1195 |
Vec3::new(-1.0, -2.0, -3.0).as_ivec3() |
| 1196 |
); |
| 1197 |
assert_eq!(UVec3::new(1, 2, 3), Vec3::new(1.0, 2.0, 3.0).as_uvec3()); |
| 1198 |
assert_eq!( |
| 1199 |
I64Vec3::new(-1, -2, -3), |
| 1200 |
Vec3::new(-1.0, -2.0, -3.0).as_i64vec3() |
| 1201 |
); |
| 1202 |
assert_eq!(U64Vec3::new(1, 2, 3), Vec3::new(1.0, 2.0, 3.0).as_u64vec3()); |
| 1203 |
|
| 1204 |
assert_eq!( |
| 1205 |
DVec3::new(-1.0, -2.0, -3.0), |
| 1206 |
Vec3A::new(-1.0, -2.0, -3.0).as_dvec3() |
| 1207 |
); |
| 1208 |
assert_eq!( |
| 1209 |
I16Vec3::new(-1, -2, -3), |
| 1210 |
Vec3A::new(-1.0, -2.0, -3.0).as_i16vec3() |
| 1211 |
); |
| 1212 |
assert_eq!( |
| 1213 |
U16Vec3::new(1, 2, 3), |
| 1214 |
Vec3A::new(1.0, 2.0, 3.0).as_u16vec3() |
| 1215 |
); |
| 1216 |
assert_eq!( |
| 1217 |
IVec3::new(-1, -2, -3), |
| 1218 |
Vec3A::new(-1.0, -2.0, -3.0).as_ivec3() |
| 1219 |
); |
| 1220 |
assert_eq!(UVec3::new(1, 2, 3), Vec3A::new(1.0, 2.0, 3.0).as_uvec3()); |
| 1221 |
assert_eq!( |
| 1222 |
I64Vec3::new(-1, -2, -3), |
| 1223 |
Vec3A::new(-1.0, -2.0, -3.0).as_i64vec3() |
| 1224 |
); |
| 1225 |
assert_eq!( |
| 1226 |
U64Vec3::new(1, 2, 3), |
| 1227 |
Vec3A::new(1.0, 2.0, 3.0).as_u64vec3() |
| 1228 |
); |
| 1229 |
|
| 1230 |
assert_eq!( |
| 1231 |
I16Vec3::new(-1, -2, -3), |
| 1232 |
DVec3::new(-1.0, -2.0, -3.0).as_i16vec3() |
| 1233 |
); |
| 1234 |
assert_eq!( |
| 1235 |
U16Vec3::new(1, 2, 3), |
| 1236 |
DVec3::new(1.0, 2.0, 3.0).as_u16vec3() |
| 1237 |
); |
| 1238 |
assert_eq!( |
| 1239 |
IVec3::new(-1, -2, -3), |
| 1240 |
DVec3::new(-1.0, -2.0, -3.0).as_ivec3() |
| 1241 |
); |
| 1242 |
assert_eq!(UVec3::new(1, 2, 3), DVec3::new(1.0, 2.0, 3.0).as_uvec3()); |
| 1243 |
assert_eq!( |
| 1244 |
I64Vec3::new(-1, -2, -3), |
| 1245 |
DVec3::new(-1.0, -2.0, -3.0).as_i64vec3() |
| 1246 |
); |
| 1247 |
assert_eq!( |
| 1248 |
U64Vec3::new(1, 2, 3), |
| 1249 |
DVec3::new(1.0, 2.0, 3.0).as_u64vec3() |
| 1250 |
); |
| 1251 |
assert_eq!( |
| 1252 |
Vec3::new(-1.0, -2.0, -3.0), |
| 1253 |
DVec3::new(-1.0, -2.0, -3.0).as_vec3() |
| 1254 |
); |
| 1255 |
assert_eq!( |
| 1256 |
Vec3A::new(-1.0, -2.0, -3.0), |
| 1257 |
DVec3::new(-1.0, -2.0, -3.0).as_vec3a() |
| 1258 |
); |
| 1259 |
|
| 1260 |
assert_eq!( |
| 1261 |
DVec3::new(-1.0, -2.0, -3.0), |
| 1262 |
I16Vec3::new(-1, -2, -3).as_dvec3() |
| 1263 |
); |
| 1264 |
assert_eq!(U16Vec3::new(1, 2, 3), I16Vec3::new(1, 2, 3).as_u16vec3()); |
| 1265 |
assert_eq!(IVec3::new(-1, -2, -3), I16Vec3::new(-1, -2, -3).as_ivec3()); |
| 1266 |
assert_eq!(UVec3::new(1, 2, 3), I16Vec3::new(1, 2, 3).as_uvec3()); |
| 1267 |
assert_eq!( |
| 1268 |
I64Vec3::new(-1, -2, -3), |
| 1269 |
I16Vec3::new(-1, -2, -3).as_i64vec3() |
| 1270 |
); |
| 1271 |
assert_eq!(U64Vec3::new(1, 2, 3), I16Vec3::new(1, 2, 3).as_u64vec3()); |
| 1272 |
assert_eq!( |
| 1273 |
Vec3::new(-1.0, -2.0, -3.0), |
| 1274 |
I16Vec3::new(-1, -2, -3).as_vec3() |
| 1275 |
); |
| 1276 |
assert_eq!( |
| 1277 |
Vec3A::new(-1.0, -2.0, -3.0), |
| 1278 |
I16Vec3::new(-1, -2, -3).as_vec3a() |
| 1279 |
); |
| 1280 |
|
| 1281 |
assert_eq!(DVec3::new(1.0, 2.0, 3.0), U16Vec3::new(1, 2, 3).as_dvec3()); |
| 1282 |
assert_eq!(I16Vec3::new(1, 2, 3), U16Vec3::new(1, 2, 3).as_i16vec3()); |
| 1283 |
assert_eq!(IVec3::new(1, 2, 3), U16Vec3::new(1, 2, 3).as_ivec3()); |
| 1284 |
assert_eq!(UVec3::new(1, 2, 3), U16Vec3::new(1, 2, 3).as_uvec3()); |
| 1285 |
assert_eq!(I64Vec3::new(1, 2, 3), U16Vec3::new(1, 2, 3).as_i64vec3()); |
| 1286 |
assert_eq!(U64Vec3::new(1, 2, 3), U16Vec3::new(1, 2, 3).as_u64vec3()); |
| 1287 |
assert_eq!(Vec3::new(1.0, 2.0, 3.0), U16Vec3::new(1, 2, 3).as_vec3()); |
| 1288 |
assert_eq!(Vec3A::new(1.0, 2.0, 3.0), U16Vec3::new(1, 2, 3).as_vec3a()); |
| 1289 |
|
| 1290 |
assert_eq!( |
| 1291 |
DVec3::new(-1.0, -2.0, -3.0), |
| 1292 |
IVec3::new(-1, -2, -3).as_dvec3() |
| 1293 |
); |
| 1294 |
assert_eq!( |
| 1295 |
I16Vec3::new(-1, -2, -3), |
| 1296 |
IVec3::new(-1, -2, -3).as_i16vec3() |
| 1297 |
); |
| 1298 |
assert_eq!(U16Vec3::new(1, 2, 3), IVec3::new(1, 2, 3).as_u16vec3()); |
| 1299 |
assert_eq!(UVec3::new(1, 2, 3), IVec3::new(1, 2, 3).as_uvec3()); |
| 1300 |
assert_eq!( |
| 1301 |
I64Vec3::new(-1, -2, -3), |
| 1302 |
IVec3::new(-1, -2, -3).as_i64vec3() |
| 1303 |
); |
| 1304 |
assert_eq!(U64Vec3::new(1, 2, 3), IVec3::new(1, 2, 3).as_u64vec3()); |
| 1305 |
assert_eq!( |
| 1306 |
Vec3::new(-1.0, -2.0, -3.0), |
| 1307 |
IVec3::new(-1, -2, -3).as_vec3() |
| 1308 |
); |
| 1309 |
assert_eq!( |
| 1310 |
Vec3A::new(-1.0, -2.0, -3.0), |
| 1311 |
IVec3::new(-1, -2, -3).as_vec3a() |
| 1312 |
); |
| 1313 |
|
| 1314 |
assert_eq!(DVec3::new(1.0, 2.0, 3.0), UVec3::new(1, 2, 3).as_dvec3()); |
| 1315 |
assert_eq!(I16Vec3::new(1, 2, 3), UVec3::new(1, 2, 3).as_i16vec3()); |
| 1316 |
assert_eq!(U16Vec3::new(1, 2, 3), UVec3::new(1, 2, 3).as_u16vec3()); |
| 1317 |
assert_eq!(IVec3::new(1, 2, 3), UVec3::new(1, 2, 3).as_ivec3()); |
| 1318 |
assert_eq!(I64Vec3::new(1, 2, 3), UVec3::new(1, 2, 3).as_i64vec3()); |
| 1319 |
assert_eq!(U64Vec3::new(1, 2, 3), UVec3::new(1, 2, 3).as_u64vec3()); |
| 1320 |
assert_eq!(Vec3::new(1.0, 2.0, 3.0), UVec3::new(1, 2, 3).as_vec3()); |
| 1321 |
assert_eq!(Vec3A::new(1.0, 2.0, 3.0), UVec3::new(1, 2, 3).as_vec3a()); |
| 1322 |
|
| 1323 |
assert_eq!( |
| 1324 |
DVec3::new(-1.0, -2.0, -3.0), |
| 1325 |
I64Vec3::new(-1, -2, -3).as_dvec3() |
| 1326 |
); |
| 1327 |
assert_eq!(U16Vec3::new(1, 2, 3), I64Vec3::new(1, 2, 3).as_u16vec3()); |
| 1328 |
assert_eq!( |
| 1329 |
I16Vec3::new(-1, -2, -3), |
| 1330 |
I64Vec3::new(-1, -2, -3).as_i16vec3() |
| 1331 |
); |
| 1332 |
assert_eq!(UVec3::new(1, 2, 3), I64Vec3::new(1, 2, 3).as_uvec3()); |
| 1333 |
assert_eq!(IVec3::new(-1, -2, -3), I64Vec3::new(-1, -2, -3).as_ivec3()); |
| 1334 |
assert_eq!(U64Vec3::new(1, 2, 3), I64Vec3::new(1, 2, 3).as_u64vec3()); |
| 1335 |
assert_eq!( |
| 1336 |
Vec3::new(-1.0, -2.0, -3.0), |
| 1337 |
I64Vec3::new(-1, -2, -3).as_vec3() |
| 1338 |
); |
| 1339 |
assert_eq!( |
| 1340 |
Vec3A::new(-1.0, -2.0, -3.0), |
| 1341 |
I64Vec3::new(-1, -2, -3).as_vec3a() |
| 1342 |
); |
| 1343 |
|
| 1344 |
assert_eq!(DVec3::new(1.0, 2.0, 3.0), U64Vec3::new(1, 2, 3).as_dvec3()); |
| 1345 |
assert_eq!(I16Vec3::new(1, 2, 3), U64Vec3::new(1, 2, 3).as_i16vec3()); |
| 1346 |
assert_eq!(U16Vec3::new(1, 2, 3), U64Vec3::new(1, 2, 3).as_u16vec3()); |
| 1347 |
assert_eq!(IVec3::new(1, 2, 3), U64Vec3::new(1, 2, 3).as_ivec3()); |
| 1348 |
assert_eq!(UVec3::new(1, 2, 3), U64Vec3::new(1, 2, 3).as_uvec3()); |
| 1349 |
assert_eq!(I64Vec3::new(1, 2, 3), U64Vec3::new(1, 2, 3).as_i64vec3()); |
| 1350 |
assert_eq!(Vec3::new(1.0, 2.0, 3.0), U64Vec3::new(1, 2, 3).as_vec3()); |
| 1351 |
assert_eq!(Vec3A::new(1.0, 2.0, 3.0), U64Vec3::new(1, 2, 3).as_vec3a()); |
| 1352 |
}); |
| 1353 |
|
| 1354 |
impl_vec3_float_tests!(f32, vec3, Vec3, BVec3); |
| 1355 |
} |
| 1356 |
|
| 1357 |
mod vec3a { |
| 1358 |
use glam::BVec3A; |
| 1359 |
use glam::{vec3a, Vec3A, Vec4}; |
| 1360 |
|
| 1361 |
glam_test!(test_align, { |
| 1362 |
use std::mem; |
| 1363 |
assert_eq!(16, mem::size_of::<Vec3A>()); |
| 1364 |
assert_eq!(16, mem::align_of::<Vec3A>()); |
| 1365 |
assert_eq!(16, mem::size_of::<BVec3A>()); |
| 1366 |
assert_eq!(16, mem::align_of::<BVec3A>()); |
| 1367 |
}); |
| 1368 |
|
| 1369 |
glam_test!(test_mask_align16, { |
| 1370 |
// make sure the unused 'w' value doesn't break Vec3Ab behaviour |
| 1371 |
let a = Vec4::ZERO; |
| 1372 |
let mut b = Vec3A::from(a); |
| 1373 |
b.x = 1.0; |
| 1374 |
b.y = 1.0; |
| 1375 |
b.z = 1.0; |
| 1376 |
assert!(!b.cmpeq(Vec3A::ZERO).any()); |
| 1377 |
assert!(b.cmpeq(Vec3A::splat(1.0)).all()); |
| 1378 |
}); |
| 1379 |
|
| 1380 |
#[cfg(all( |
| 1381 |
target_feature = "sse2", |
| 1382 |
not(any(feature = "core-simd", feature = "scalar-math")) |
| 1383 |
))] |
| 1384 |
#[test] |
| 1385 |
fn test_m128() { |
| 1386 |
#[cfg(target_arch = "x86")] |
| 1387 |
use core::arch::x86::*; |
| 1388 |
#[cfg(target_arch = "x86_64")] |
| 1389 |
use core::arch::x86_64::*; |
| 1390 |
|
| 1391 |
#[repr(C, align(16))] |
| 1392 |
struct F32x3_A16([f32; 3]); |
| 1393 |
|
| 1394 |
let v0 = Vec3A::new(1.0, 2.0, 3.0); |
| 1395 |
let m0: __m128 = v0.into(); |
| 1396 |
let mut a0 = F32x3_A16([0.0, 0.0, 0.0]); |
| 1397 |
unsafe { |
| 1398 |
_mm_store_ps(a0.0.as_mut_ptr(), m0); |
| 1399 |
} |
| 1400 |
assert_eq!([1.0, 2.0, 3.0], a0.0); |
| 1401 |
let v1 = Vec3A::from(m0); |
| 1402 |
assert_eq!(v0, v1); |
| 1403 |
|
| 1404 |
#[repr(C, align(16))] |
| 1405 |
struct U32x3_A16([u32; 3]); |
| 1406 |
|
| 1407 |
let v0 = BVec3A::new(true, false, true); |
| 1408 |
let m0: __m128 = v0.into(); |
| 1409 |
let mut a0 = U32x3_A16([1, 2, 3]); |
| 1410 |
unsafe { |
| 1411 |
_mm_store_ps(a0.0.as_mut_ptr() as *mut f32, m0); |
| 1412 |
} |
| 1413 |
assert_eq!([0xffffffff, 0, 0xffffffff], a0.0); |
| 1414 |
} |
| 1415 |
|
| 1416 |
glam_test!(test_min_max_from_vec4, { |
| 1417 |
// checks that the 4th element is unused. |
| 1418 |
let v1 = Vec3A::from(Vec4::new(1.0, 2.0, 3.0, 4.0)); |
| 1419 |
assert_eq!(v1.max_element(), 3.0); |
| 1420 |
let v2 = Vec3A::from(Vec4::new(4.0, 3.0, 2.0, 1.0)); |
| 1421 |
assert_eq!(v2.min_element(), 2.0); |
| 1422 |
}); |
| 1423 |
|
| 1424 |
impl_vec3_float_tests!(f32, vec3a, Vec3A, BVec3A); |
| 1425 |
} |
| 1426 |
|
| 1427 |
mod dvec3 { |
| 1428 |
use glam::{dvec3, BVec3, DVec3, IVec3, UVec3, Vec3}; |
| 1429 |
|
| 1430 |
glam_test!(test_align, { |
| 1431 |
use std::mem; |
| 1432 |
assert_eq!(24, mem::size_of::<DVec3>()); |
| 1433 |
assert_eq!(mem::align_of::<f64>(), mem::align_of::<DVec3>()); |
| 1434 |
assert_eq!(3, mem::size_of::<BVec3>()); |
| 1435 |
assert_eq!(1, mem::align_of::<BVec3>()); |
| 1436 |
}); |
| 1437 |
|
| 1438 |
glam_test!(test_try_from, { |
| 1439 |
assert_eq!( |
| 1440 |
DVec3::new(1.0, 2.0, 3.0), |
| 1441 |
DVec3::from(Vec3::new(1.0, 2.0, 3.0)) |
| 1442 |
); |
| 1443 |
assert_eq!(DVec3::new(1.0, 2.0, 3.0), DVec3::from(IVec3::new(1, 2, 3))); |
| 1444 |
assert_eq!(DVec3::new(1.0, 2.0, 3.0), DVec3::from(UVec3::new(1, 2, 3))); |
| 1445 |
}); |
| 1446 |
|
| 1447 |
impl_vec3_float_tests!(f64, dvec3, DVec3, BVec3); |
| 1448 |
} |
| 1449 |
|
| 1450 |
mod i16vec3 { |
| 1451 |
use glam::{i16vec3, BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec3}; |
| 1452 |
|
| 1453 |
glam_test!(test_align, { |
| 1454 |
use std::mem; |
| 1455 |
assert_eq!(6, mem::size_of::<I16Vec3>()); |
| 1456 |
assert_eq!(2, mem::align_of::<I16Vec3>()); |
| 1457 |
}); |
| 1458 |
|
| 1459 |
glam_test!(test_try_from, { |
| 1460 |
assert_eq!( |
| 1461 |
I16Vec3::new(1, 2, 3), |
| 1462 |
I16Vec3::try_from(U16Vec3::new(1, 2, 3)).unwrap() |
| 1463 |
); |
| 1464 |
assert!(I16Vec3::try_from(U16Vec3::new(u16::MAX, 2, 3)).is_err()); |
| 1465 |
assert!(I16Vec3::try_from(U16Vec3::new(1, u16::MAX, 3)).is_err()); |
| 1466 |
assert!(I16Vec3::try_from(U16Vec3::new(1, 2, u16::MAX)).is_err()); |
| 1467 |
|
| 1468 |
assert_eq!( |
| 1469 |
I16Vec3::new(1, 2, 3), |
| 1470 |
I16Vec3::try_from(IVec3::new(1, 2, 3)).unwrap() |
| 1471 |
); |
| 1472 |
assert!(I16Vec3::try_from(IVec3::new(i32::MAX, 2, 3)).is_err()); |
| 1473 |
assert!(I16Vec3::try_from(IVec3::new(1, i32::MAX, 3)).is_err()); |
| 1474 |
assert!(I16Vec3::try_from(IVec3::new(1, 2, i32::MAX)).is_err()); |
| 1475 |
|
| 1476 |
assert_eq!( |
| 1477 |
I16Vec3::new(1, 2, 3), |
| 1478 |
I16Vec3::try_from(UVec3::new(1, 2, 3)).unwrap() |
| 1479 |
); |
| 1480 |
assert!(I16Vec3::try_from(UVec3::new(u32::MAX, 2, 3)).is_err()); |
| 1481 |
assert!(I16Vec3::try_from(UVec3::new(1, u32::MAX, 3)).is_err()); |
| 1482 |
assert!(I16Vec3::try_from(UVec3::new(1, 2, u32::MAX)).is_err()); |
| 1483 |
|
| 1484 |
assert_eq!( |
| 1485 |
I16Vec3::new(1, 2, 3), |
| 1486 |
I16Vec3::try_from(I64Vec3::new(1, 2, 3)).unwrap() |
| 1487 |
); |
| 1488 |
assert!(I16Vec3::try_from(I64Vec3::new(i64::MAX, 2, 3)).is_err()); |
| 1489 |
assert!(I16Vec3::try_from(I64Vec3::new(1, i64::MAX, 3)).is_err()); |
| 1490 |
assert!(I16Vec3::try_from(I64Vec3::new(1, 2, i64::MAX)).is_err()); |
| 1491 |
|
| 1492 |
assert_eq!( |
| 1493 |
I16Vec3::new(1, 2, 3), |
| 1494 |
I16Vec3::try_from(U64Vec3::new(1, 2, 3)).unwrap() |
| 1495 |
); |
| 1496 |
assert!(I16Vec3::try_from(U64Vec3::new(u64::MAX, 2, 3)).is_err()); |
| 1497 |
assert!(I16Vec3::try_from(U64Vec3::new(1, u64::MAX, 3)).is_err()); |
| 1498 |
assert!(I16Vec3::try_from(U64Vec3::new(1, 2, u64::MAX)).is_err()); |
| 1499 |
}); |
| 1500 |
|
| 1501 |
glam_test!(test_wrapping_add, { |
| 1502 |
assert_eq!( |
| 1503 |
I16Vec3::new(i16::MAX, 5, i16::MIN).wrapping_add(I16Vec3::new(1, 3, i16::MAX)), |
| 1504 |
I16Vec3::new(i16::MIN, 8, -1), |
| 1505 |
); |
| 1506 |
}); |
| 1507 |
|
| 1508 |
glam_test!(test_wrapping_sub, { |
| 1509 |
assert_eq!( |
| 1510 |
I16Vec3::new(i16::MAX, 5, i16::MIN).wrapping_sub(I16Vec3::new(1, 3, i16::MAX)), |
| 1511 |
I16Vec3::new(32766, 2, 1), |
| 1512 |
); |
| 1513 |
}); |
| 1514 |
|
| 1515 |
glam_test!(test_wrapping_mul, { |
| 1516 |
assert_eq!( |
| 1517 |
I16Vec3::new(i16::MAX, 5, i16::MIN).wrapping_mul(I16Vec3::new(3, 3, 5)), |
| 1518 |
I16Vec3::new(32765, 15, -32768) |
| 1519 |
); |
| 1520 |
}); |
| 1521 |
|
| 1522 |
glam_test!(test_wrapping_div, { |
| 1523 |
assert_eq!( |
| 1524 |
I16Vec3::new(i16::MAX, 5, i16::MIN).wrapping_div(I16Vec3::new(3, 3, 5)), |
| 1525 |
I16Vec3::new(10922, 1, -6553) |
| 1526 |
); |
| 1527 |
}); |
| 1528 |
|
| 1529 |
glam_test!(test_saturating_add, { |
| 1530 |
assert_eq!( |
| 1531 |
I16Vec3::new(i16::MAX, i16::MIN, 0).saturating_add(I16Vec3::new(1, -1, 2)), |
| 1532 |
I16Vec3::new(i16::MAX, i16::MIN, 2) |
| 1533 |
); |
| 1534 |
}); |
| 1535 |
|
| 1536 |
glam_test!(test_saturating_sub, { |
| 1537 |
assert_eq!( |
| 1538 |
I16Vec3::new(i16::MIN, i16::MAX, 0).saturating_sub(I16Vec3::new(1, -1, 2)), |
| 1539 |
I16Vec3::new(i16::MIN, i16::MAX, -2) |
| 1540 |
); |
| 1541 |
}); |
| 1542 |
|
| 1543 |
glam_test!(test_saturating_mul, { |
| 1544 |
assert_eq!( |
| 1545 |
I16Vec3::new(i16::MAX, i16::MIN, 0).saturating_mul(I16Vec3::new(2, 2, 0)), |
| 1546 |
I16Vec3::new(i16::MAX, i16::MIN, 0) |
| 1547 |
); |
| 1548 |
}); |
| 1549 |
|
| 1550 |
glam_test!(test_saturating_div, { |
| 1551 |
assert_eq!( |
| 1552 |
I16Vec3::new(i16::MAX, i16::MIN, 0).saturating_div(I16Vec3::new(2, 2, 3)), |
| 1553 |
I16Vec3::new(16383, -16384, 0) |
| 1554 |
); |
| 1555 |
}); |
| 1556 |
|
| 1557 |
impl_vec3_signed_integer_tests!(i16, i16vec3, I16Vec3, BVec3); |
| 1558 |
impl_vec3_eq_hash_tests!(i16, i16vec3); |
| 1559 |
|
| 1560 |
impl_vec3_scalar_shift_op_tests!(I16Vec3, -2, 2); |
| 1561 |
impl_vec3_shift_op_tests!(I16Vec3); |
| 1562 |
|
| 1563 |
impl_vec3_scalar_bit_op_tests!(I16Vec3, -2, 2); |
| 1564 |
impl_vec3_bit_op_tests!(I16Vec3, -2, 2); |
| 1565 |
} |
| 1566 |
|
| 1567 |
mod u16vec3 { |
| 1568 |
use glam::{u16vec3, BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec3}; |
| 1569 |
|
| 1570 |
glam_test!(test_align, { |
| 1571 |
use std::mem; |
| 1572 |
assert_eq!(6, mem::size_of::<U16Vec3>()); |
| 1573 |
assert_eq!(2, mem::align_of::<U16Vec3>()); |
| 1574 |
}); |
| 1575 |
|
| 1576 |
glam_test!(test_try_from, { |
| 1577 |
assert_eq!( |
| 1578 |
U16Vec3::new(1, 2, 3), |
| 1579 |
U16Vec3::try_from(I16Vec3::new(1, 2, 3)).unwrap() |
| 1580 |
); |
| 1581 |
assert!(U16Vec3::try_from(I16Vec3::new(-1, 2, 3)).is_err()); |
| 1582 |
assert!(U16Vec3::try_from(I16Vec3::new(1, -2, 3)).is_err()); |
| 1583 |
assert!(U16Vec3::try_from(I16Vec3::new(1, 2, -3)).is_err()); |
| 1584 |
|
| 1585 |
assert_eq!( |
| 1586 |
U16Vec3::new(1, 2, 3), |
| 1587 |
U16Vec3::try_from(IVec3::new(1, 2, 3)).unwrap() |
| 1588 |
); |
| 1589 |
assert!(U16Vec3::try_from(IVec3::new(-1, 2, 3)).is_err()); |
| 1590 |
assert!(U16Vec3::try_from(IVec3::new(1, -2, 3)).is_err()); |
| 1591 |
assert!(U16Vec3::try_from(IVec3::new(1, 2, -3)).is_err()); |
| 1592 |
|
| 1593 |
assert!(U16Vec3::try_from(IVec3::new(i32::MAX, 2, 3)).is_err()); |
| 1594 |
assert!(U16Vec3::try_from(IVec3::new(1, i32::MAX, 3)).is_err()); |
| 1595 |
assert!(U16Vec3::try_from(IVec3::new(1, 2, i32::MAX)).is_err()); |
| 1596 |
|
| 1597 |
assert_eq!( |
| 1598 |
U16Vec3::new(1, 2, 3), |
| 1599 |
U16Vec3::try_from(UVec3::new(1, 2, 3)).unwrap() |
| 1600 |
); |
| 1601 |
assert!(U16Vec3::try_from(UVec3::new(u32::MAX, 2, 3)).is_err()); |
| 1602 |
assert!(U16Vec3::try_from(UVec3::new(1, u32::MAX, 3)).is_err()); |
| 1603 |
assert!(U16Vec3::try_from(UVec3::new(1, 2, u32::MAX)).is_err()); |
| 1604 |
|
| 1605 |
assert_eq!( |
| 1606 |
U16Vec3::new(1, 2, 3), |
| 1607 |
U16Vec3::try_from(I64Vec3::new(1, 2, 3)).unwrap() |
| 1608 |
); |
| 1609 |
assert!(U16Vec3::try_from(I64Vec3::new(-1, 2, 3)).is_err()); |
| 1610 |
assert!(U16Vec3::try_from(I64Vec3::new(1, -2, 3)).is_err()); |
| 1611 |
assert!(U16Vec3::try_from(I64Vec3::new(1, 2, -3)).is_err()); |
| 1612 |
|
| 1613 |
assert!(U16Vec3::try_from(I64Vec3::new(i64::MAX, 2, 3)).is_err()); |
| 1614 |
assert!(U16Vec3::try_from(I64Vec3::new(1, i64::MAX, 3)).is_err()); |
| 1615 |
assert!(U16Vec3::try_from(I64Vec3::new(1, 2, i64::MAX)).is_err()); |
| 1616 |
|
| 1617 |
assert_eq!( |
| 1618 |
U16Vec3::new(1, 2, 3), |
| 1619 |
U16Vec3::try_from(U64Vec3::new(1, 2, 3)).unwrap() |
| 1620 |
); |
| 1621 |
assert!(U16Vec3::try_from(U64Vec3::new(u64::MAX, 2, 3)).is_err()); |
| 1622 |
assert!(U16Vec3::try_from(U64Vec3::new(1, u64::MAX, 3)).is_err()); |
| 1623 |
assert!(U16Vec3::try_from(U64Vec3::new(1, 2, u64::MAX)).is_err()); |
| 1624 |
}); |
| 1625 |
|
| 1626 |
glam_test!(test_wrapping_add, { |
| 1627 |
assert_eq!( |
| 1628 |
U16Vec3::new(u16::MAX, 5, u16::MAX).wrapping_add(U16Vec3::new(1, 3, u16::MAX)), |
| 1629 |
U16Vec3::new(0, 8, 65534), |
| 1630 |
); |
| 1631 |
}); |
| 1632 |
|
| 1633 |
glam_test!(test_wrapping_sub, { |
| 1634 |
assert_eq!( |
| 1635 |
U16Vec3::new(u16::MAX, 5, u16::MAX - 1).wrapping_sub(U16Vec3::new(1, 3, u16::MAX)), |
| 1636 |
U16Vec3::new(65534, 2, 65535) |
| 1637 |
); |
| 1638 |
}); |
| 1639 |
|
| 1640 |
glam_test!(test_wrapping_mul, { |
| 1641 |
assert_eq!( |
| 1642 |
U16Vec3::new(u16::MAX, 5, u16::MAX).wrapping_mul(U16Vec3::new(3, 3, 5)), |
| 1643 |
U16Vec3::new(65533, 15, 65531) |
| 1644 |
); |
| 1645 |
}); |
| 1646 |
|
| 1647 |
glam_test!(test_wrapping_div, { |
| 1648 |
assert_eq!( |
| 1649 |
U16Vec3::new(u16::MAX, 5, u16::MAX).wrapping_div(U16Vec3::new(3, 3, 5)), |
| 1650 |
U16Vec3::new(21845, 1, 13107) |
| 1651 |
); |
| 1652 |
}); |
| 1653 |
|
| 1654 |
glam_test!(test_saturating_add, { |
| 1655 |
assert_eq!( |
| 1656 |
U16Vec3::new(u16::MAX, u16::MAX, 0).saturating_add(U16Vec3::new(1, u16::MAX, 2)), |
| 1657 |
U16Vec3::new(u16::MAX, u16::MAX, 2) |
| 1658 |
); |
| 1659 |
}); |
| 1660 |
|
| 1661 |
glam_test!(test_saturating_sub, { |
| 1662 |
assert_eq!( |
| 1663 |
U16Vec3::new(0, u16::MAX, 0).saturating_sub(U16Vec3::new(1, 1, 2)), |
| 1664 |
U16Vec3::new(0, 65534, 0) |
| 1665 |
); |
| 1666 |
}); |
| 1667 |
|
| 1668 |
glam_test!(test_saturating_mul, { |
| 1669 |
assert_eq!( |
| 1670 |
U16Vec3::new(u16::MAX, u16::MAX, 0).saturating_mul(U16Vec3::new(2, u16::MAX, 0)), |
| 1671 |
U16Vec3::new(u16::MAX, u16::MAX, 0) |
| 1672 |
); |
| 1673 |
}); |
| 1674 |
|
| 1675 |
glam_test!(test_saturating_div, { |
| 1676 |
assert_eq!( |
| 1677 |
U16Vec3::new(u16::MAX, u16::MAX, 0).saturating_div(U16Vec3::new(2, u16::MAX, 3)), |
| 1678 |
U16Vec3::new(32767, 1, 0) |
| 1679 |
); |
| 1680 |
}); |
| 1681 |
|
| 1682 |
impl_vec3_tests!(u16, u16vec3, U16Vec3, BVec3); |
| 1683 |
impl_vec3_eq_hash_tests!(u16, u16vec3); |
| 1684 |
|
| 1685 |
impl_vec3_scalar_shift_op_tests!(U16Vec3, 0, 2); |
| 1686 |
impl_vec3_shift_op_tests!(U16Vec3); |
| 1687 |
|
| 1688 |
impl_vec3_scalar_bit_op_tests!(U16Vec3, 0, 2); |
| 1689 |
impl_vec3_bit_op_tests!(U16Vec3, 0, 2); |
| 1690 |
} |
| 1691 |
|
| 1692 |
mod ivec3 { |
| 1693 |
use glam::{ivec3, BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec3}; |
| 1694 |
|
| 1695 |
glam_test!(test_align, { |
| 1696 |
use std::mem; |
| 1697 |
assert_eq!(12, mem::size_of::<IVec3>()); |
| 1698 |
assert_eq!(4, mem::align_of::<IVec3>()); |
| 1699 |
assert_eq!(3, mem::size_of::<BVec3>()); |
| 1700 |
assert_eq!(1, mem::align_of::<BVec3>()); |
| 1701 |
}); |
| 1702 |
|
| 1703 |
glam_test!(test_try_from, { |
| 1704 |
assert_eq!(IVec3::new(1, 2, 3), IVec3::from(U16Vec3::new(1, 2, 3))); |
| 1705 |
assert_eq!(IVec3::new(1, 2, 3), IVec3::from(I16Vec3::new(1, 2, 3))); |
| 1706 |
|
| 1707 |
assert_eq!( |
| 1708 |
IVec3::new(1, 2, 3), |
| 1709 |
IVec3::try_from(UVec3::new(1, 2, 3)).unwrap() |
| 1710 |
); |
| 1711 |
assert!(IVec3::try_from(UVec3::new(u32::MAX, 2, 3)).is_err()); |
| 1712 |
assert!(IVec3::try_from(UVec3::new(1, u32::MAX, 3)).is_err()); |
| 1713 |
assert!(IVec3::try_from(UVec3::new(1, 2, u32::MAX)).is_err()); |
| 1714 |
|
| 1715 |
assert_eq!( |
| 1716 |
IVec3::new(1, 2, 3), |
| 1717 |
IVec3::try_from(I64Vec3::new(1, 2, 3)).unwrap() |
| 1718 |
); |
| 1719 |
assert!(IVec3::try_from(I64Vec3::new(i64::MAX, 2, 3)).is_err()); |
| 1720 |
assert!(IVec3::try_from(I64Vec3::new(1, i64::MAX, 3)).is_err()); |
| 1721 |
assert!(IVec3::try_from(I64Vec3::new(1, 2, i64::MAX)).is_err()); |
| 1722 |
|
| 1723 |
assert_eq!( |
| 1724 |
IVec3::new(1, 2, 3), |
| 1725 |
IVec3::try_from(U64Vec3::new(1, 2, 3)).unwrap() |
| 1726 |
); |
| 1727 |
assert!(IVec3::try_from(U64Vec3::new(u64::MAX, 2, 3)).is_err()); |
| 1728 |
assert!(IVec3::try_from(U64Vec3::new(1, u64::MAX, 3)).is_err()); |
| 1729 |
assert!(IVec3::try_from(U64Vec3::new(1, 2, u64::MAX)).is_err()); |
| 1730 |
}); |
| 1731 |
|
| 1732 |
glam_test!(test_wrapping_add, { |
| 1733 |
assert_eq!( |
| 1734 |
IVec3::new(i32::MAX, 5, i32::MIN).wrapping_add(IVec3::new(1, 3, i32::MAX)), |
| 1735 |
IVec3::new(i32::MIN, 8, -1), |
| 1736 |
); |
| 1737 |
}); |
| 1738 |
|
| 1739 |
glam_test!(test_wrapping_sub, { |
| 1740 |
assert_eq!( |
| 1741 |
IVec3::new(i32::MAX, 5, i32::MIN).wrapping_sub(IVec3::new(1, 3, i32::MAX)), |
| 1742 |
IVec3::new(2147483646, 2, 1), |
| 1743 |
); |
| 1744 |
}); |
| 1745 |
|
| 1746 |
glam_test!(test_wrapping_mul, { |
| 1747 |
assert_eq!( |
| 1748 |
IVec3::new(i32::MAX, 5, i32::MIN).wrapping_mul(IVec3::new(3, 3, 5)), |
| 1749 |
IVec3::new(2147483645, 15, -2147483648) |
| 1750 |
); |
| 1751 |
}); |
| 1752 |
|
| 1753 |
glam_test!(test_wrapping_div, { |
| 1754 |
assert_eq!( |
| 1755 |
IVec3::new(i32::MAX, 5, i32::MIN).wrapping_div(IVec3::new(3, 3, 5)), |
| 1756 |
IVec3::new(715827882, 1, -429496729) |
| 1757 |
); |
| 1758 |
}); |
| 1759 |
|
| 1760 |
glam_test!(test_saturating_add, { |
| 1761 |
assert_eq!( |
| 1762 |
IVec3::new(i32::MAX, i32::MIN, 0).saturating_add(IVec3::new(1, -1, 2)), |
| 1763 |
IVec3::new(i32::MAX, i32::MIN, 2) |
| 1764 |
); |
| 1765 |
}); |
| 1766 |
|
| 1767 |
glam_test!(test_saturating_sub, { |
| 1768 |
assert_eq!( |
| 1769 |
IVec3::new(i32::MIN, i32::MAX, 0).saturating_sub(IVec3::new(1, -1, 2)), |
| 1770 |
IVec3::new(i32::MIN, i32::MAX, -2) |
| 1771 |
); |
| 1772 |
}); |
| 1773 |
|
| 1774 |
glam_test!(test_saturating_mul, { |
| 1775 |
assert_eq!( |
| 1776 |
IVec3::new(i32::MAX, i32::MIN, 0).saturating_mul(IVec3::new(2, 2, 0)), |
| 1777 |
IVec3::new(i32::MAX, i32::MIN, 0) |
| 1778 |
); |
| 1779 |
}); |
| 1780 |
|
| 1781 |
glam_test!(test_saturating_div, { |
| 1782 |
assert_eq!( |
| 1783 |
IVec3::new(i32::MAX, i32::MIN, 0).saturating_div(IVec3::new(2, 2, 3)), |
| 1784 |
IVec3::new(1073741823, -1073741824, 0) |
| 1785 |
); |
| 1786 |
}); |
| 1787 |
|
| 1788 |
impl_vec3_signed_integer_tests!(i32, ivec3, IVec3, BVec3); |
| 1789 |
impl_vec3_eq_hash_tests!(i32, ivec3); |
| 1790 |
|
| 1791 |
impl_vec3_scalar_shift_op_tests!(IVec3, -2, 2); |
| 1792 |
impl_vec3_shift_op_tests!(IVec3); |
| 1793 |
|
| 1794 |
impl_vec3_scalar_bit_op_tests!(IVec3, -2, 2); |
| 1795 |
impl_vec3_bit_op_tests!(IVec3, -2, 2); |
| 1796 |
} |
| 1797 |
|
| 1798 |
mod uvec3 { |
| 1799 |
use glam::{uvec3, BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec3}; |
| 1800 |
|
| 1801 |
glam_test!(test_align, { |
| 1802 |
use std::mem; |
| 1803 |
assert_eq!(12, mem::size_of::<UVec3>()); |
| 1804 |
assert_eq!(4, mem::align_of::<UVec3>()); |
| 1805 |
assert_eq!(3, mem::size_of::<BVec3>()); |
| 1806 |
assert_eq!(1, mem::align_of::<BVec3>()); |
| 1807 |
}); |
| 1808 |
|
| 1809 |
glam_test!(test_try_from, { |
| 1810 |
assert_eq!( |
| 1811 |
UVec3::new(1, 2, 3), |
| 1812 |
UVec3::try_from(I16Vec3::new(1, 2, 3)).unwrap() |
| 1813 |
); |
| 1814 |
assert!(UVec3::try_from(I16Vec3::new(-1, 2, 3)).is_err()); |
| 1815 |
assert!(UVec3::try_from(I16Vec3::new(1, -2, 3)).is_err()); |
| 1816 |
assert!(UVec3::try_from(I16Vec3::new(1, 2, -3)).is_err()); |
| 1817 |
|
| 1818 |
assert_eq!(UVec3::new(1, 2, 3), UVec3::from(U16Vec3::new(1, 2, 3))); |
| 1819 |
|
| 1820 |
assert_eq!( |
| 1821 |
UVec3::new(1, 2, 3), |
| 1822 |
UVec3::try_from(IVec3::new(1, 2, 3)).unwrap() |
| 1823 |
); |
| 1824 |
assert!(UVec3::try_from(IVec3::new(-1, 2, 3)).is_err()); |
| 1825 |
assert!(UVec3::try_from(IVec3::new(1, -2, 3)).is_err()); |
| 1826 |
assert!(UVec3::try_from(IVec3::new(1, 2, -3)).is_err()); |
| 1827 |
|
| 1828 |
assert_eq!( |
| 1829 |
UVec3::new(1, 2, 3), |
| 1830 |
UVec3::try_from(I64Vec3::new(1, 2, 3)).unwrap() |
| 1831 |
); |
| 1832 |
assert!(UVec3::try_from(I64Vec3::new(-1, 2, 3)).is_err()); |
| 1833 |
assert!(UVec3::try_from(I64Vec3::new(1, -2, 3)).is_err()); |
| 1834 |
assert!(UVec3::try_from(I64Vec3::new(1, 2, -3)).is_err()); |
| 1835 |
|
| 1836 |
assert!(UVec3::try_from(I64Vec3::new(i64::MAX, 2, 3)).is_err()); |
| 1837 |
assert!(UVec3::try_from(I64Vec3::new(1, i64::MAX, 3)).is_err()); |
| 1838 |
assert!(UVec3::try_from(I64Vec3::new(1, 2, i64::MAX)).is_err()); |
| 1839 |
|
| 1840 |
assert_eq!( |
| 1841 |
UVec3::new(1, 2, 3), |
| 1842 |
UVec3::try_from(U64Vec3::new(1, 2, 3)).unwrap() |
| 1843 |
); |
| 1844 |
assert!(UVec3::try_from(U64Vec3::new(u64::MAX, 2, 3)).is_err()); |
| 1845 |
assert!(UVec3::try_from(U64Vec3::new(1, u64::MAX, 3)).is_err()); |
| 1846 |
assert!(UVec3::try_from(U64Vec3::new(1, 2, u64::MAX)).is_err()); |
| 1847 |
}); |
| 1848 |
|
| 1849 |
glam_test!(test_wrapping_add, { |
| 1850 |
assert_eq!( |
| 1851 |
UVec3::new(u32::MAX, 5, u32::MAX).wrapping_add(UVec3::new(1, 3, u32::MAX)), |
| 1852 |
UVec3::new(0, 8, 4294967294), |
| 1853 |
); |
| 1854 |
}); |
| 1855 |
|
| 1856 |
glam_test!(test_wrapping_sub, { |
| 1857 |
assert_eq!( |
| 1858 |
UVec3::new(u32::MAX, 5, u32::MAX - 1).wrapping_sub(UVec3::new(1, 3, u32::MAX)), |
| 1859 |
UVec3::new(4294967294, 2, 4294967295) |
| 1860 |
); |
| 1861 |
}); |
| 1862 |
|
| 1863 |
glam_test!(test_wrapping_mul, { |
| 1864 |
assert_eq!( |
| 1865 |
UVec3::new(u32::MAX, 5, u32::MAX).wrapping_mul(UVec3::new(3, 3, 5)), |
| 1866 |
UVec3::new(4294967293, 15, 4294967291) |
| 1867 |
); |
| 1868 |
}); |
| 1869 |
|
| 1870 |
glam_test!(test_wrapping_div, { |
| 1871 |
assert_eq!( |
| 1872 |
UVec3::new(u32::MAX, 5, u32::MAX).wrapping_div(UVec3::new(3, 3, 5)), |
| 1873 |
UVec3::new(1431655765, 1, 858993459) |
| 1874 |
); |
| 1875 |
}); |
| 1876 |
|
| 1877 |
glam_test!(test_saturating_add, { |
| 1878 |
assert_eq!( |
| 1879 |
UVec3::new(u32::MAX, u32::MAX, 0).saturating_add(UVec3::new(1, u32::MAX, 2)), |
| 1880 |
UVec3::new(u32::MAX, u32::MAX, 2) |
| 1881 |
); |
| 1882 |
}); |
| 1883 |
|
| 1884 |
glam_test!(test_saturating_sub, { |
| 1885 |
assert_eq!( |
| 1886 |
UVec3::new(0, u32::MAX, 0).saturating_sub(UVec3::new(1, 1, 2)), |
| 1887 |
UVec3::new(0, 4294967294, 0) |
| 1888 |
); |
| 1889 |
}); |
| 1890 |
|
| 1891 |
glam_test!(test_saturating_mul, { |
| 1892 |
assert_eq!( |
| 1893 |
UVec3::new(u32::MAX, u32::MAX, 0).saturating_mul(UVec3::new(2, u32::MAX, 0)), |
| 1894 |
UVec3::new(u32::MAX, u32::MAX, 0) |
| 1895 |
); |
| 1896 |
}); |
| 1897 |
|
| 1898 |
glam_test!(test_saturating_div, { |
| 1899 |
assert_eq!( |
| 1900 |
UVec3::new(u32::MAX, u32::MAX, 0).saturating_div(UVec3::new(2, u32::MAX, 3)), |
| 1901 |
UVec3::new(2147483647, 1, 0) |
| 1902 |
); |
| 1903 |
}); |
| 1904 |
|
| 1905 |
impl_vec3_tests!(u32, uvec3, UVec3, BVec3); |
| 1906 |
impl_vec3_eq_hash_tests!(u32, uvec3); |
| 1907 |
|
| 1908 |
impl_vec3_scalar_shift_op_tests!(UVec3, 0, 2); |
| 1909 |
impl_vec3_shift_op_tests!(UVec3); |
| 1910 |
|
| 1911 |
impl_vec3_scalar_bit_op_tests!(UVec3, 0, 2); |
| 1912 |
impl_vec3_bit_op_tests!(UVec3, 0, 2); |
| 1913 |
} |
| 1914 |
|
| 1915 |
mod i64vec3 { |
| 1916 |
use glam::{i64vec3, BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec3}; |
| 1917 |
|
| 1918 |
glam_test!(test_align, { |
| 1919 |
use std::mem; |
| 1920 |
assert_eq!(24, mem::size_of::<I64Vec3>()); |
| 1921 |
assert_eq!(8, mem::align_of::<I64Vec3>()); |
| 1922 |
assert_eq!(3, mem::size_of::<BVec3>()); |
| 1923 |
assert_eq!(1, mem::align_of::<BVec3>()); |
| 1924 |
}); |
| 1925 |
|
| 1926 |
glam_test!(test_try_from, { |
| 1927 |
assert_eq!(I64Vec3::new(1, 2, 3), I64Vec3::from(I16Vec3::new(1, 2, 3))); |
| 1928 |
assert_eq!(I64Vec3::new(1, 2, 3), I64Vec3::from(U16Vec3::new(1, 2, 3))); |
| 1929 |
assert_eq!(I64Vec3::new(1, 2, 3), I64Vec3::from(IVec3::new(1, 2, 3))); |
| 1930 |
assert_eq!(I64Vec3::new(1, 2, 3), I64Vec3::from(UVec3::new(1, 2, 3))); |
| 1931 |
|
| 1932 |
assert_eq!( |
| 1933 |
I64Vec3::new(1, 2, 3), |
| 1934 |
I64Vec3::try_from(U64Vec3::new(1, 2, 3)).unwrap() |
| 1935 |
); |
| 1936 |
assert!(I64Vec3::try_from(U64Vec3::new(u64::MAX, 2, 3)).is_err()); |
| 1937 |
assert!(I64Vec3::try_from(U64Vec3::new(1, u64::MAX, 3)).is_err()); |
| 1938 |
assert!(I64Vec3::try_from(U64Vec3::new(1, 2, u64::MAX)).is_err()); |
| 1939 |
}); |
| 1940 |
|
| 1941 |
impl_vec3_signed_integer_tests!(i64, i64vec3, I64Vec3, BVec3); |
| 1942 |
impl_vec3_eq_hash_tests!(i64, i64vec3); |
| 1943 |
|
| 1944 |
impl_vec3_scalar_shift_op_tests!(I64Vec3, -2, 2); |
| 1945 |
impl_vec3_shift_op_tests!(I64Vec3); |
| 1946 |
|
| 1947 |
impl_vec3_scalar_bit_op_tests!(I64Vec3, -2, 2); |
| 1948 |
impl_vec3_bit_op_tests!(I64Vec3, -2, 2); |
| 1949 |
} |
| 1950 |
|
| 1951 |
mod u64vec3 { |
| 1952 |
use glam::{u64vec3, BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec3}; |
| 1953 |
|
| 1954 |
glam_test!(test_align, { |
| 1955 |
use std::mem; |
| 1956 |
assert_eq!(24, mem::size_of::<U64Vec3>()); |
| 1957 |
assert_eq!(8, mem::align_of::<U64Vec3>()); |
| 1958 |
assert_eq!(3, mem::size_of::<BVec3>()); |
| 1959 |
assert_eq!(1, mem::align_of::<BVec3>()); |
| 1960 |
}); |
| 1961 |
|
| 1962 |
glam_test!(test_try_from, { |
| 1963 |
assert_eq!( |
| 1964 |
U64Vec3::new(1, 2, 3), |
| 1965 |
U64Vec3::try_from(I16Vec3::new(1, 2, 3)).unwrap() |
| 1966 |
); |
| 1967 |
assert!(U64Vec3::try_from(I16Vec3::new(-1, 2, 3)).is_err()); |
| 1968 |
assert!(U64Vec3::try_from(I16Vec3::new(1, -2, 3)).is_err()); |
| 1969 |
assert!(U64Vec3::try_from(I16Vec3::new(1, 2, -3)).is_err()); |
| 1970 |
|
| 1971 |
assert_eq!(U64Vec3::new(1, 2, 3), U64Vec3::from(U16Vec3::new(1, 2, 3))); |
| 1972 |
|
| 1973 |
assert_eq!( |
| 1974 |
U64Vec3::new(1, 2, 3), |
| 1975 |
U64Vec3::try_from(IVec3::new(1, 2, 3)).unwrap() |
| 1976 |
); |
| 1977 |
assert!(U64Vec3::try_from(IVec3::new(-1, 2, 3)).is_err()); |
| 1978 |
assert!(U64Vec3::try_from(IVec3::new(1, -2, 3)).is_err()); |
| 1979 |
assert!(U64Vec3::try_from(IVec3::new(1, 2, -3)).is_err()); |
| 1980 |
|
| 1981 |
assert_eq!(U64Vec3::new(1, 2, 3), U64Vec3::from(UVec3::new(1, 2, 3))); |
| 1982 |
|
| 1983 |
assert_eq!( |
| 1984 |
U64Vec3::new(1, 2, 3), |
| 1985 |
U64Vec3::try_from(I64Vec3::new(1, 2, 3)).unwrap() |
| 1986 |
); |
| 1987 |
assert!(U64Vec3::try_from(I64Vec3::new(-1, 2, 3)).is_err()); |
| 1988 |
assert!(U64Vec3::try_from(I64Vec3::new(1, -2, 3)).is_err()); |
| 1989 |
assert!(U64Vec3::try_from(I64Vec3::new(1, 2, -3)).is_err()); |
| 1990 |
}); |
| 1991 |
|
| 1992 |
impl_vec3_tests!(u64, u64vec3, U64Vec3, BVec3); |
| 1993 |
impl_vec3_eq_hash_tests!(u64, u64vec3); |
| 1994 |
|
| 1995 |
impl_vec3_scalar_shift_op_tests!(U64Vec3, 0, 2); |
| 1996 |
impl_vec3_shift_op_tests!(U64Vec3); |
| 1997 |
|
| 1998 |
impl_vec3_scalar_bit_op_tests!(U64Vec3, 0, 2); |
| 1999 |
impl_vec3_bit_op_tests!(U64Vec3, 0, 2); |
| 2000 |
} |