| 1 |
#![allow(clippy::excessive_precision)] |
| 2 |
|
| 3 |
#[macro_use] |
| 4 |
mod support; |
| 5 |
|
| 6 |
macro_rules! impl_bvec4_tests { |
| 7 |
($mask:ident, $masknew:ident) => { |
| 8 |
glam_test!(test_mask_new, { |
| 9 |
assert_eq!( |
| 10 |
$mask::new(false, false, false, false), |
| 11 |
$masknew(false, false, false, false) |
| 12 |
); |
| 13 |
assert_eq!( |
| 14 |
$mask::new(false, false, true, true), |
| 15 |
$masknew(false, false, true, true) |
| 16 |
); |
| 17 |
assert_eq!( |
| 18 |
$mask::new(true, true, false, false), |
| 19 |
$masknew(true, true, false, false) |
| 20 |
); |
| 21 |
assert_eq!( |
| 22 |
$mask::new(false, true, false, true), |
| 23 |
$masknew(false, true, false, true) |
| 24 |
); |
| 25 |
assert_eq!( |
| 26 |
$mask::new(true, false, true, false), |
| 27 |
$masknew(true, false, true, false) |
| 28 |
); |
| 29 |
assert_eq!( |
| 30 |
$mask::new(true, true, true, true), |
| 31 |
$masknew(true, true, true, true) |
| 32 |
); |
| 33 |
|
| 34 |
assert_eq!($mask::default(), $mask::FALSE); |
| 35 |
}); |
| 36 |
|
| 37 |
glam_test!(test_mask_from_array_bool, { |
| 38 |
assert_eq!( |
| 39 |
$mask::new(false, false, false, false), |
| 40 |
$mask::from([false, false, false, false]) |
| 41 |
); |
| 42 |
assert_eq!( |
| 43 |
$mask::new(false, false, true, true), |
| 44 |
$mask::from([false, false, true, true]) |
| 45 |
); |
| 46 |
assert_eq!( |
| 47 |
$mask::new(true, true, false, false), |
| 48 |
$mask::from([true, true, false, false]) |
| 49 |
); |
| 50 |
assert_eq!( |
| 51 |
$mask::new(false, true, false, true), |
| 52 |
$mask::from([false, true, false, true]) |
| 53 |
); |
| 54 |
assert_eq!( |
| 55 |
$mask::new(true, false, true, false), |
| 56 |
$mask::from([true, false, true, false]) |
| 57 |
); |
| 58 |
assert_eq!( |
| 59 |
$mask::new(true, true, true, true), |
| 60 |
$mask::from([true, true, true, true]) |
| 61 |
); |
| 62 |
}); |
| 63 |
|
| 64 |
glam_test!(test_mask_into_array_u32, { |
| 65 |
assert_eq!( |
| 66 |
Into::<[u32; 4]>::into($mask::new(false, false, false, false)), |
| 67 |
[0, 0, 0, 0] |
| 68 |
); |
| 69 |
assert_eq!( |
| 70 |
Into::<[u32; 4]>::into($mask::new(false, false, true, true)), |
| 71 |
[0, 0, !0, !0] |
| 72 |
); |
| 73 |
assert_eq!( |
| 74 |
Into::<[u32; 4]>::into($mask::new(true, true, false, false)), |
| 75 |
[!0, !0, 0, 0] |
| 76 |
); |
| 77 |
assert_eq!( |
| 78 |
Into::<[u32; 4]>::into($mask::new(false, true, false, true)), |
| 79 |
[0, !0, 0, !0] |
| 80 |
); |
| 81 |
assert_eq!( |
| 82 |
Into::<[u32; 4]>::into($mask::new(true, false, true, false)), |
| 83 |
[!0, 0, !0, 0] |
| 84 |
); |
| 85 |
assert_eq!( |
| 86 |
Into::<[u32; 4]>::into($mask::new(true, true, true, true)), |
| 87 |
[!0, !0, !0, !0] |
| 88 |
); |
| 89 |
}); |
| 90 |
|
| 91 |
glam_test!(test_mask_into_array_bool, { |
| 92 |
assert_eq!( |
| 93 |
Into::<[bool; 4]>::into($mask::new(false, false, false, false)), |
| 94 |
[false, false, false, false] |
| 95 |
); |
| 96 |
assert_eq!( |
| 97 |
Into::<[bool; 4]>::into($mask::new(false, false, true, true)), |
| 98 |
[false, false, true, true] |
| 99 |
); |
| 100 |
assert_eq!( |
| 101 |
Into::<[bool; 4]>::into($mask::new(true, true, false, false)), |
| 102 |
[true, true, false, false] |
| 103 |
); |
| 104 |
assert_eq!( |
| 105 |
Into::<[bool; 4]>::into($mask::new(false, true, false, true)), |
| 106 |
[false, true, false, true] |
| 107 |
); |
| 108 |
assert_eq!( |
| 109 |
Into::<[bool; 4]>::into($mask::new(true, false, true, false)), |
| 110 |
[true, false, true, false] |
| 111 |
); |
| 112 |
assert_eq!( |
| 113 |
Into::<[bool; 4]>::into($mask::new(true, true, true, true)), |
| 114 |
[true, true, true, true] |
| 115 |
); |
| 116 |
}); |
| 117 |
|
| 118 |
glam_test!(test_mask_splat, { |
| 119 |
assert_eq!($mask::splat(false), $mask::new(false, false, false, false)); |
| 120 |
assert_eq!($mask::splat(true), $mask::new(true, true, true, true)); |
| 121 |
}); |
| 122 |
|
| 123 |
glam_test!(test_mask_bitmask, { |
| 124 |
assert_eq!($mask::new(false, false, false, false).bitmask(), 0b0000); |
| 125 |
assert_eq!($mask::new(false, false, true, true).bitmask(), 0b1100); |
| 126 |
assert_eq!($mask::new(true, true, false, false).bitmask(), 0b0011); |
| 127 |
assert_eq!($mask::new(false, true, false, true).bitmask(), 0b1010); |
| 128 |
assert_eq!($mask::new(true, false, true, false).bitmask(), 0b0101); |
| 129 |
assert_eq!($mask::new(true, true, true, true).bitmask(), 0b1111); |
| 130 |
}); |
| 131 |
|
| 132 |
glam_test!(test_mask_any, { |
| 133 |
assert_eq!($mask::new(false, false, false, false).any(), false); |
| 134 |
assert_eq!($mask::new(true, false, false, false).any(), true); |
| 135 |
assert_eq!($mask::new(false, true, false, false).any(), true); |
| 136 |
assert_eq!($mask::new(false, false, true, false).any(), true); |
| 137 |
assert_eq!($mask::new(false, false, false, true).any(), true); |
| 138 |
}); |
| 139 |
|
| 140 |
glam_test!(test_mask_all, { |
| 141 |
assert_eq!($mask::new(true, true, true, true).all(), true); |
| 142 |
assert_eq!($mask::new(false, true, true, true).all(), false); |
| 143 |
assert_eq!($mask::new(true, false, true, true).all(), false); |
| 144 |
assert_eq!($mask::new(true, true, false, true).all(), false); |
| 145 |
assert_eq!($mask::new(true, true, true, false).all(), false); |
| 146 |
}); |
| 147 |
|
| 148 |
glam_test!(test_mask_and, { |
| 149 |
assert_eq!( |
| 150 |
($mask::new(false, false, false, false) & $mask::new(false, false, false, false)) |
| 151 |
.bitmask(), |
| 152 |
0b0000, |
| 153 |
); |
| 154 |
assert_eq!( |
| 155 |
($mask::new(true, true, true, true) & $mask::new(true, true, true, true)).bitmask(), |
| 156 |
0b1111, |
| 157 |
); |
| 158 |
assert_eq!( |
| 159 |
($mask::new(true, false, true, false) & $mask::new(false, true, false, true)) |
| 160 |
.bitmask(), |
| 161 |
0b0000, |
| 162 |
); |
| 163 |
assert_eq!( |
| 164 |
($mask::new(true, false, true, true) & $mask::new(true, true, true, false)) |
| 165 |
.bitmask(), |
| 166 |
0b0101, |
| 167 |
); |
| 168 |
|
| 169 |
assert_eq!( |
| 170 |
(&$mask::new(false, false, false, false) & $mask::new(false, false, false, false)) |
| 171 |
.bitmask(), |
| 172 |
0b0000, |
| 173 |
); |
| 174 |
assert_eq!( |
| 175 |
(&$mask::new(true, true, true, true) & $mask::new(true, true, true, true)) |
| 176 |
.bitmask(), |
| 177 |
0b1111, |
| 178 |
); |
| 179 |
assert_eq!( |
| 180 |
(&$mask::new(true, false, true, false) & $mask::new(false, true, false, true)) |
| 181 |
.bitmask(), |
| 182 |
0b0000, |
| 183 |
); |
| 184 |
assert_eq!( |
| 185 |
(&$mask::new(true, false, true, true) & $mask::new(true, true, true, false)) |
| 186 |
.bitmask(), |
| 187 |
0b0101, |
| 188 |
); |
| 189 |
|
| 190 |
assert_eq!( |
| 191 |
($mask::new(false, false, false, false) & &$mask::new(false, false, false, false)) |
| 192 |
.bitmask(), |
| 193 |
0b0000, |
| 194 |
); |
| 195 |
assert_eq!( |
| 196 |
($mask::new(true, true, true, true) & &$mask::new(true, true, true, true)) |
| 197 |
.bitmask(), |
| 198 |
0b1111, |
| 199 |
); |
| 200 |
assert_eq!( |
| 201 |
($mask::new(true, false, true, false) & &$mask::new(false, true, false, true)) |
| 202 |
.bitmask(), |
| 203 |
0b0000, |
| 204 |
); |
| 205 |
assert_eq!( |
| 206 |
($mask::new(true, false, true, true) & &$mask::new(true, true, true, false)) |
| 207 |
.bitmask(), |
| 208 |
0b0101, |
| 209 |
); |
| 210 |
|
| 211 |
assert_eq!( |
| 212 |
(&$mask::new(false, false, false, false) & &$mask::new(false, false, false, false)) |
| 213 |
.bitmask(), |
| 214 |
0b0000, |
| 215 |
); |
| 216 |
assert_eq!( |
| 217 |
(&$mask::new(true, true, true, true) & &$mask::new(true, true, true, true)) |
| 218 |
.bitmask(), |
| 219 |
0b1111, |
| 220 |
); |
| 221 |
assert_eq!( |
| 222 |
(&$mask::new(true, false, true, false) & &$mask::new(false, true, false, true)) |
| 223 |
.bitmask(), |
| 224 |
0b0000, |
| 225 |
); |
| 226 |
assert_eq!( |
| 227 |
(&$mask::new(true, false, true, true) & &$mask::new(true, true, true, false)) |
| 228 |
.bitmask(), |
| 229 |
0b0101, |
| 230 |
); |
| 231 |
|
| 232 |
let mut mask = $mask::new(true, true, false, false); |
| 233 |
mask &= $mask::new(true, false, true, false); |
| 234 |
assert_eq!(mask.bitmask(), 0b0001); |
| 235 |
|
| 236 |
let mut mask = $mask::new(true, true, false, false); |
| 237 |
mask &= &$mask::new(true, false, true, false); |
| 238 |
assert_eq!(mask.bitmask(), 0b0001); |
| 239 |
}); |
| 240 |
|
| 241 |
glam_test!(test_mask_or, { |
| 242 |
assert_eq!( |
| 243 |
($mask::new(false, false, false, false) | $mask::new(false, false, false, false)) |
| 244 |
.bitmask(), |
| 245 |
0b0000, |
| 246 |
); |
| 247 |
assert_eq!( |
| 248 |
($mask::new(true, true, true, true) | $mask::new(true, true, true, true)).bitmask(), |
| 249 |
0b1111, |
| 250 |
); |
| 251 |
assert_eq!( |
| 252 |
($mask::new(true, false, true, false) | $mask::new(false, true, false, true)) |
| 253 |
.bitmask(), |
| 254 |
0b1111, |
| 255 |
); |
| 256 |
assert_eq!( |
| 257 |
($mask::new(true, false, true, false) | $mask::new(true, false, true, false)) |
| 258 |
.bitmask(), |
| 259 |
0b0101, |
| 260 |
); |
| 261 |
|
| 262 |
assert_eq!( |
| 263 |
(&$mask::new(false, false, false, false) | $mask::new(false, false, false, false)) |
| 264 |
.bitmask(), |
| 265 |
0b0000, |
| 266 |
); |
| 267 |
assert_eq!( |
| 268 |
(&$mask::new(true, true, true, true) | $mask::new(true, true, true, true)) |
| 269 |
.bitmask(), |
| 270 |
0b1111, |
| 271 |
); |
| 272 |
assert_eq!( |
| 273 |
(&$mask::new(true, false, true, false) | $mask::new(false, true, false, true)) |
| 274 |
.bitmask(), |
| 275 |
0b1111, |
| 276 |
); |
| 277 |
assert_eq!( |
| 278 |
(&$mask::new(true, false, true, false) | $mask::new(true, false, true, false)) |
| 279 |
.bitmask(), |
| 280 |
0b0101, |
| 281 |
); |
| 282 |
|
| 283 |
assert_eq!( |
| 284 |
($mask::new(false, false, false, false) | &$mask::new(false, false, false, false)) |
| 285 |
.bitmask(), |
| 286 |
0b0000, |
| 287 |
); |
| 288 |
assert_eq!( |
| 289 |
($mask::new(true, true, true, true) | &$mask::new(true, true, true, true)) |
| 290 |
.bitmask(), |
| 291 |
0b1111, |
| 292 |
); |
| 293 |
assert_eq!( |
| 294 |
($mask::new(true, false, true, false) | &$mask::new(false, true, false, true)) |
| 295 |
.bitmask(), |
| 296 |
0b1111, |
| 297 |
); |
| 298 |
assert_eq!( |
| 299 |
($mask::new(true, false, true, false) | &$mask::new(true, false, true, false)) |
| 300 |
.bitmask(), |
| 301 |
0b0101, |
| 302 |
); |
| 303 |
|
| 304 |
assert_eq!( |
| 305 |
(&$mask::new(false, false, false, false) | &$mask::new(false, false, false, false)) |
| 306 |
.bitmask(), |
| 307 |
0b0000, |
| 308 |
); |
| 309 |
assert_eq!( |
| 310 |
(&$mask::new(true, true, true, true) | &$mask::new(true, true, true, true)) |
| 311 |
.bitmask(), |
| 312 |
0b1111, |
| 313 |
); |
| 314 |
assert_eq!( |
| 315 |
(&$mask::new(true, false, true, false) | &$mask::new(false, true, false, true)) |
| 316 |
.bitmask(), |
| 317 |
0b1111, |
| 318 |
); |
| 319 |
assert_eq!( |
| 320 |
(&$mask::new(true, false, true, false) | &$mask::new(true, false, true, false)) |
| 321 |
.bitmask(), |
| 322 |
0b0101, |
| 323 |
); |
| 324 |
|
| 325 |
let mut mask = $mask::new(true, true, false, false); |
| 326 |
mask |= $mask::new(true, false, true, false); |
| 327 |
assert_eq!(mask.bitmask(), 0b0111); |
| 328 |
|
| 329 |
let mut mask = $mask::new(true, true, false, false); |
| 330 |
mask |= &$mask::new(true, false, true, false); |
| 331 |
assert_eq!(mask.bitmask(), 0b0111); |
| 332 |
}); |
| 333 |
|
| 334 |
glam_test!(test_mask_xor, { |
| 335 |
assert_eq!( |
| 336 |
($mask::new(false, false, false, false) ^ $mask::new(false, false, false, false)) |
| 337 |
.bitmask(), |
| 338 |
0b0000, |
| 339 |
); |
| 340 |
assert_eq!( |
| 341 |
($mask::new(true, true, true, true) ^ $mask::new(true, true, true, true)).bitmask(), |
| 342 |
0b0000, |
| 343 |
); |
| 344 |
assert_eq!( |
| 345 |
($mask::new(true, false, true, false) ^ $mask::new(false, true, false, true)) |
| 346 |
.bitmask(), |
| 347 |
0b1111, |
| 348 |
); |
| 349 |
assert_eq!( |
| 350 |
($mask::new(true, false, true, false) ^ $mask::new(true, false, true, false)) |
| 351 |
.bitmask(), |
| 352 |
0b0000, |
| 353 |
); |
| 354 |
|
| 355 |
assert_eq!( |
| 356 |
(&$mask::new(false, false, false, false) ^ $mask::new(false, false, false, false)) |
| 357 |
.bitmask(), |
| 358 |
0b0000, |
| 359 |
); |
| 360 |
assert_eq!( |
| 361 |
(&$mask::new(true, true, true, true) ^ $mask::new(true, true, true, true)) |
| 362 |
.bitmask(), |
| 363 |
0b0000, |
| 364 |
); |
| 365 |
assert_eq!( |
| 366 |
(&$mask::new(true, false, true, false) ^ $mask::new(false, true, false, true)) |
| 367 |
.bitmask(), |
| 368 |
0b1111, |
| 369 |
); |
| 370 |
assert_eq!( |
| 371 |
(&$mask::new(true, false, true, false) ^ $mask::new(true, false, true, false)) |
| 372 |
.bitmask(), |
| 373 |
0b0000, |
| 374 |
); |
| 375 |
|
| 376 |
assert_eq!( |
| 377 |
($mask::new(false, false, false, false) ^ &$mask::new(false, false, false, false)) |
| 378 |
.bitmask(), |
| 379 |
0b0000, |
| 380 |
); |
| 381 |
assert_eq!( |
| 382 |
($mask::new(true, true, true, true) ^ &$mask::new(true, true, true, true)) |
| 383 |
.bitmask(), |
| 384 |
0b0000, |
| 385 |
); |
| 386 |
assert_eq!( |
| 387 |
($mask::new(true, false, true, false) ^ &$mask::new(false, true, false, true)) |
| 388 |
.bitmask(), |
| 389 |
0b1111, |
| 390 |
); |
| 391 |
assert_eq!( |
| 392 |
($mask::new(true, false, true, false) ^ &$mask::new(true, false, true, false)) |
| 393 |
.bitmask(), |
| 394 |
0b0000, |
| 395 |
); |
| 396 |
|
| 397 |
assert_eq!( |
| 398 |
(&$mask::new(false, false, false, false) ^ &$mask::new(false, false, false, false)) |
| 399 |
.bitmask(), |
| 400 |
0b0000, |
| 401 |
); |
| 402 |
assert_eq!( |
| 403 |
(&$mask::new(true, true, true, true) ^ &$mask::new(true, true, true, true)) |
| 404 |
.bitmask(), |
| 405 |
0b0000, |
| 406 |
); |
| 407 |
assert_eq!( |
| 408 |
(&$mask::new(true, false, true, false) ^ &$mask::new(false, true, false, true)) |
| 409 |
.bitmask(), |
| 410 |
0b1111, |
| 411 |
); |
| 412 |
assert_eq!( |
| 413 |
(&$mask::new(true, false, true, false) ^ &$mask::new(true, false, true, false)) |
| 414 |
.bitmask(), |
| 415 |
0b0000, |
| 416 |
); |
| 417 |
|
| 418 |
let mut mask = $mask::new(true, true, false, false); |
| 419 |
mask ^= $mask::new(true, false, true, false); |
| 420 |
assert_eq!(mask.bitmask(), 0b0110); |
| 421 |
|
| 422 |
let mut mask = $mask::new(true, true, false, false); |
| 423 |
mask ^= &$mask::new(true, false, true, false); |
| 424 |
assert_eq!(mask.bitmask(), 0b0110); |
| 425 |
}); |
| 426 |
|
| 427 |
glam_test!(test_mask_not, { |
| 428 |
assert_eq!((!$mask::new(false, false, false, false)).bitmask(), 0b1111); |
| 429 |
assert_eq!((!$mask::new(true, true, true, true)).bitmask(), 0b0000); |
| 430 |
assert_eq!((!$mask::new(true, false, true, false)).bitmask(), 0b1010); |
| 431 |
assert_eq!((!$mask::new(false, true, false, true)).bitmask(), 0b0101); |
| 432 |
|
| 433 |
assert_eq!((!&$mask::new(false, false, false, false)).bitmask(), 0b1111); |
| 434 |
assert_eq!((!&$mask::new(true, true, true, true)).bitmask(), 0b0000); |
| 435 |
assert_eq!((!&$mask::new(true, false, true, false)).bitmask(), 0b1010); |
| 436 |
assert_eq!((!&$mask::new(false, true, false, true)).bitmask(), 0b0101); |
| 437 |
}); |
| 438 |
|
| 439 |
glam_test!(test_mask_fmt, { |
| 440 |
let a = $mask::new(true, false, true, false); |
| 441 |
|
| 442 |
assert_eq!(format!("{}", a), "[true, false, true, false]"); |
| 443 |
assert_eq!( |
| 444 |
format!("{:?}", a), |
| 445 |
format!("{}(0xffffffff, 0x0, 0xffffffff, 0x0)", stringify!($mask)) |
| 446 |
); |
| 447 |
}); |
| 448 |
|
| 449 |
glam_test!(test_mask_eq, { |
| 450 |
let a = $mask::new(true, false, true, false); |
| 451 |
let b = $mask::new(true, false, true, false); |
| 452 |
let c = $mask::new(false, true, true, false); |
| 453 |
|
| 454 |
assert_eq!(a, b); |
| 455 |
assert_eq!(b, a); |
| 456 |
assert_ne!(a, c); |
| 457 |
assert_ne!(b, c); |
| 458 |
}); |
| 459 |
|
| 460 |
glam_test!(test_mask_test, { |
| 461 |
let a = $mask::new(true, false, true, false); |
| 462 |
assert_eq!(a.test(0), true); |
| 463 |
assert_eq!(a.test(1), false); |
| 464 |
assert_eq!(a.test(2), true); |
| 465 |
assert_eq!(a.test(3), false); |
| 466 |
|
| 467 |
let b = $mask::new(false, true, false, true); |
| 468 |
assert_eq!(b.test(0), false); |
| 469 |
assert_eq!(b.test(1), true); |
| 470 |
assert_eq!(b.test(2), false); |
| 471 |
assert_eq!(b.test(3), true); |
| 472 |
|
| 473 |
should_panic!({ a.test(4) }); |
| 474 |
}); |
| 475 |
|
| 476 |
glam_test!(test_mask_set, { |
| 477 |
let mut a = $mask::new(false, true, false, true); |
| 478 |
a.set(0, true); |
| 479 |
assert_eq!(a.test(0), true); |
| 480 |
a.set(1, false); |
| 481 |
assert_eq!(a.test(1), false); |
| 482 |
a.set(2, true); |
| 483 |
assert_eq!(a.test(2), true); |
| 484 |
a.set(3, false); |
| 485 |
assert_eq!(a.test(3), false); |
| 486 |
|
| 487 |
let mut b = $mask::new(true, false, true, false); |
| 488 |
b.set(0, false); |
| 489 |
assert_eq!(b.test(0), false); |
| 490 |
b.set(1, true); |
| 491 |
assert_eq!(b.test(1), true); |
| 492 |
b.set(2, false); |
| 493 |
assert_eq!(b.test(2), false); |
| 494 |
b.set(3, true); |
| 495 |
assert_eq!(b.test(3), true); |
| 496 |
|
| 497 |
should_panic!({ |
| 498 |
let mut a = $mask::FALSE; |
| 499 |
a.set(4, true) |
| 500 |
}); |
| 501 |
}); |
| 502 |
|
| 503 |
glam_test!(test_mask_hash, { |
| 504 |
use std::collections::hash_map::DefaultHasher; |
| 505 |
use std::hash::Hash; |
| 506 |
use std::hash::Hasher; |
| 507 |
|
| 508 |
let a = $mask::new(true, false, true, false); |
| 509 |
let b = $mask::new(true, false, true, false); |
| 510 |
let c = $mask::new(false, true, true, false); |
| 511 |
|
| 512 |
let mut hasher = DefaultHasher::new(); |
| 513 |
a.hash(&mut hasher); |
| 514 |
let a_hashed = hasher.finish(); |
| 515 |
|
| 516 |
let mut hasher = DefaultHasher::new(); |
| 517 |
b.hash(&mut hasher); |
| 518 |
let b_hashed = hasher.finish(); |
| 519 |
|
| 520 |
let mut hasher = DefaultHasher::new(); |
| 521 |
c.hash(&mut hasher); |
| 522 |
let c_hashed = hasher.finish(); |
| 523 |
|
| 524 |
assert_eq!(a, b); |
| 525 |
assert_eq!(a_hashed, b_hashed); |
| 526 |
assert_ne!(a, c); |
| 527 |
assert_ne!(a_hashed, c_hashed); |
| 528 |
}); |
| 529 |
}; |
| 530 |
} |
| 531 |
|
| 532 |
macro_rules! impl_vec4_tests { |
| 533 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 534 |
glam_test!(test_const, { |
| 535 |
const V0: $vec4 = $vec4::splat(1 as $t); |
| 536 |
const V1: $vec4 = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 537 |
const V2: $vec4 = $vec4::from_array([1 as $t, 2 as $t, 3 as $t, 4 as $t]); |
| 538 |
assert_eq!([1 as $t, 1 as $t, 1 as $t, 1 as $t], *V0.as_ref()); |
| 539 |
assert_eq!([1 as $t, 2 as $t, 3 as $t, 4 as $t], *V1.as_ref()); |
| 540 |
assert_eq!([1 as $t, 2 as $t, 3 as $t, 4 as $t], *V2.as_ref()); |
| 541 |
}); |
| 542 |
|
| 543 |
glam_test!(test_vec4_consts, { |
| 544 |
assert_eq!($vec4::ZERO, $new(0 as $t, 0 as $t, 0 as $t, 0 as $t)); |
| 545 |
assert_eq!($vec4::ONE, $new(1 as $t, 1 as $t, 1 as $t, 1 as $t)); |
| 546 |
assert_eq!($vec4::X, $new(1 as $t, 0 as $t, 0 as $t, 0 as $t)); |
| 547 |
assert_eq!($vec4::Y, $new(0 as $t, 1 as $t, 0 as $t, 0 as $t)); |
| 548 |
assert_eq!($vec4::Z, $new(0 as $t, 0 as $t, 1 as $t, 0 as $t)); |
| 549 |
assert_eq!($vec4::W, $new(0 as $t, 0 as $t, 0 as $t, 1 as $t)); |
| 550 |
assert_eq!($vec4::MIN, $new($t::MIN, $t::MIN, $t::MIN, $t::MIN)); |
| 551 |
assert_eq!($vec4::MAX, $new($t::MAX, $t::MAX, $t::MAX, $t::MAX)); |
| 552 |
}); |
| 553 |
|
| 554 |
glam_test!(test_new, { |
| 555 |
let v = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 556 |
|
| 557 |
assert_eq!(v.x, 1 as $t); |
| 558 |
assert_eq!(v.y, 2 as $t); |
| 559 |
assert_eq!(v.z, 3 as $t); |
| 560 |
assert_eq!(v.w, 4 as $t); |
| 561 |
|
| 562 |
let t = (1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 563 |
let v = $vec4::from(t); |
| 564 |
assert_eq!(t, v.into()); |
| 565 |
|
| 566 |
let a = [1 as $t, 2 as $t, 3 as $t, 4 as $t]; |
| 567 |
let v = $vec4::from(a); |
| 568 |
let a1: [$t; 4] = v.into(); |
| 569 |
assert_eq!(a, a1); |
| 570 |
|
| 571 |
assert_eq!(a, v.to_array()); |
| 572 |
assert_eq!(a, *v.as_ref()); |
| 573 |
|
| 574 |
let mut v2 = $vec4::default(); |
| 575 |
*v2.as_mut() = a; |
| 576 |
assert_eq!(a, v2.to_array()); |
| 577 |
|
| 578 |
let v = $vec4::new(t.0, t.1, t.2, t.3); |
| 579 |
assert_eq!(t, v.into()); |
| 580 |
|
| 581 |
assert_eq!( |
| 582 |
$vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), |
| 583 |
glam::BVec4::new(true, false, false, false).into() |
| 584 |
); |
| 585 |
assert_eq!( |
| 586 |
$vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), |
| 587 |
glam::BVec4::new(false, true, false, false).into() |
| 588 |
); |
| 589 |
assert_eq!( |
| 590 |
$vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t), |
| 591 |
glam::BVec4::new(false, false, true, false).into() |
| 592 |
); |
| 593 |
|
| 594 |
#[cfg(not(feature = "scalar-math"))] |
| 595 |
{ |
| 596 |
assert_eq!( |
| 597 |
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t), |
| 598 |
glam::BVec4::new(false, false, false, true).into() |
| 599 |
); |
| 600 |
assert_eq!( |
| 601 |
$vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), |
| 602 |
glam::BVec4A::new(true, false, false, false).into() |
| 603 |
); |
| 604 |
assert_eq!( |
| 605 |
$vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), |
| 606 |
glam::BVec4A::new(false, true, false, false).into() |
| 607 |
); |
| 608 |
assert_eq!( |
| 609 |
$vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t), |
| 610 |
glam::BVec4A::new(false, false, true, false).into() |
| 611 |
); |
| 612 |
assert_eq!( |
| 613 |
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t), |
| 614 |
glam::BVec4A::new(false, false, false, true).into() |
| 615 |
); |
| 616 |
} |
| 617 |
|
| 618 |
assert_eq!($vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), $vec4::X); |
| 619 |
assert_eq!($vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), $vec4::Y); |
| 620 |
assert_eq!($vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t), $vec4::Z); |
| 621 |
assert_eq!($vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t), $vec4::W); |
| 622 |
|
| 623 |
assert_eq!( |
| 624 |
v, |
| 625 |
$vec4::from(($vec3::new(1 as $t, 2 as $t, 3 as $t), 4 as $t)) |
| 626 |
); |
| 627 |
|
| 628 |
assert_eq!( |
| 629 |
v, |
| 630 |
$vec4::from((1 as $t, $vec3::new(2 as $t, 3 as $t, 4 as $t))) |
| 631 |
); |
| 632 |
|
| 633 |
assert_eq!( |
| 634 |
v, |
| 635 |
$vec4::from(($vec2::new(1 as $t, 2 as $t), 3 as $t, 4 as $t)) |
| 636 |
); |
| 637 |
assert_eq!( |
| 638 |
v, |
| 639 |
$vec4::from(($vec2::new(1 as $t, 2 as $t), $vec2::new(3 as $t, 4 as $t))) |
| 640 |
); |
| 641 |
}); |
| 642 |
|
| 643 |
glam_test!(test_fmt, { |
| 644 |
let a = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 645 |
assert_eq!( |
| 646 |
format!("{:?}", a), |
| 647 |
format!( |
| 648 |
"{}({:?}, {:?}, {:?}, {:?})", |
| 649 |
stringify!($vec4), |
| 650 |
a.x, |
| 651 |
a.y, |
| 652 |
a.z, |
| 653 |
a.w |
| 654 |
) |
| 655 |
); |
| 656 |
assert_eq!( |
| 657 |
format!("{:#?}", a), |
| 658 |
format!( |
| 659 |
"{}(\n {:#?},\n {:#?},\n {:#?},\n {:#?},\n)", |
| 660 |
stringify!($vec4), |
| 661 |
a.x, |
| 662 |
a.y, |
| 663 |
a.z, |
| 664 |
a.w |
| 665 |
) |
| 666 |
); |
| 667 |
assert_eq!(format!("{}", a), "[1, 2, 3, 4]"); |
| 668 |
}); |
| 669 |
|
| 670 |
glam_test!(test_zero, { |
| 671 |
let v = $vec4::ZERO; |
| 672 |
assert_eq!((0 as $t, 0 as $t, 0 as $t, 0 as $t), v.into()); |
| 673 |
assert_eq!(v, $vec4::default()); |
| 674 |
}); |
| 675 |
|
| 676 |
glam_test!(test_splat, { |
| 677 |
let v = $vec4::splat(1 as $t); |
| 678 |
assert_eq!($vec4::ONE, v); |
| 679 |
}); |
| 680 |
|
| 681 |
glam_test!(test_map, { |
| 682 |
let v = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 683 |
assert_eq!(v.map(|n| n + 3 as $t), v + $vec4::splat(3 as $t)); |
| 684 |
assert_eq!(v.map(|_| 0 as $t), $vec4::ZERO); |
| 685 |
}); |
| 686 |
|
| 687 |
glam_test!(test_with, { |
| 688 |
assert_eq!($vec4::X, $vec4::ZERO.with_x(1 as $t)); |
| 689 |
assert_eq!($vec4::Y, $vec4::ZERO.with_y(1 as $t)); |
| 690 |
assert_eq!($vec4::Z, $vec4::ZERO.with_z(1 as $t)); |
| 691 |
assert_eq!($vec4::W, $vec4::ZERO.with_w(1 as $t)); |
| 692 |
}); |
| 693 |
|
| 694 |
glam_test!(test_accessors, { |
| 695 |
let mut a = $vec4::ZERO; |
| 696 |
a.x = 1 as $t; |
| 697 |
a.y = 2 as $t; |
| 698 |
a.z = 3 as $t; |
| 699 |
a.w = 4 as $t; |
| 700 |
assert_eq!(1 as $t, a.x); |
| 701 |
assert_eq!(2 as $t, a.y); |
| 702 |
assert_eq!(3 as $t, a.z); |
| 703 |
assert_eq!(4 as $t, a.w); |
| 704 |
assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into()); |
| 705 |
|
| 706 |
let mut a = $vec4::ZERO; |
| 707 |
a[0] = 1 as $t; |
| 708 |
a[1] = 2 as $t; |
| 709 |
a[2] = 3 as $t; |
| 710 |
a[3] = 4 as $t; |
| 711 |
assert_eq!(1 as $t, a[0]); |
| 712 |
assert_eq!(2 as $t, a[1]); |
| 713 |
assert_eq!(3 as $t, a[2]); |
| 714 |
assert_eq!(4 as $t, a[3]); |
| 715 |
assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into()); |
| 716 |
}); |
| 717 |
|
| 718 |
glam_test!(test_dot_unsigned, { |
| 719 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 720 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 721 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 722 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 723 |
assert_eq!(1 as $t, x.dot(x)); |
| 724 |
assert_eq!(0 as $t, x.dot(y)); |
| 725 |
assert_eq!(0 as $t, y.dot(z)); |
| 726 |
assert_eq!(0 as $t, z.dot(w)); |
| 727 |
|
| 728 |
assert_eq!( |
| 729 |
$new(28 as $t, 28 as $t, 28 as $t, 28 as $t), |
| 730 |
$new(0 as $t, 5 as $t, 3 as $t, 6 as $t) |
| 731 |
.dot_into_vec($new(7 as $t, 2 as $t, 4 as $t, 1 as $t)) |
| 732 |
); |
| 733 |
}); |
| 734 |
|
| 735 |
glam_test!(test_length_squared_unsigned, { |
| 736 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 737 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 738 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 739 |
assert_eq!(4 as $t, (2 as $t * x).length_squared()); |
| 740 |
assert_eq!(16 as $t, (4 as $t * z).length_squared()); |
| 741 |
assert_eq!(64 as $t, (8 as $t * w).length_squared()); |
| 742 |
assert_eq!( |
| 743 |
2 as $t * 2 as $t + 3 as $t * 3 as $t + 4 as $t * 4 as $t + 5 as $t * 5 as $t, |
| 744 |
$new(2 as $t, 3 as $t, 4 as $t, 5 as $t).length_squared() |
| 745 |
); |
| 746 |
}); |
| 747 |
|
| 748 |
glam_test!(test_ops, { |
| 749 |
let a = $new(2 as $t, 4 as $t, 8 as $t, 10 as $t); |
| 750 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 20 as $t), a + a); |
| 751 |
assert_eq!($new(2 as $t, 4 as $t, 8 as $t, 10 as $t), 0 as $t + a); |
| 752 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a - a); |
| 753 |
assert_eq!($new(8 as $t, 6 as $t, 2 as $t, 0 as $t), 10 as $t - a); |
| 754 |
assert_eq!($new(4 as $t, 16 as $t, 64 as $t, 100 as $t), a * a); |
| 755 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 20 as $t), a * 2 as $t); |
| 756 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 20 as $t), 2 as $t * a); |
| 757 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 1 as $t), a / a); |
| 758 |
assert_eq!($new(1 as $t, 2 as $t, 4 as $t, 5 as $t), a / 2 as $t); |
| 759 |
assert_eq!($new(8 as $t, 4 as $t, 2 as $t, 1.6 as $t), 16 as $t / a); |
| 760 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % a); |
| 761 |
assert_eq!($new(0 as $t, 1 as $t, 1 as $t, 1 as $t), a % (a - 1 as $t)); |
| 762 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % 1 as $t); |
| 763 |
assert_eq!($new(2 as $t, 1 as $t, 2 as $t, 1 as $t), a % 3 as $t); |
| 764 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 7 as $t), 17 as $t % a); |
| 765 |
assert_eq!($new(2 as $t, 4 as $t, 0 as $t, 2 as $t), a % 8 as $t); |
| 766 |
}); |
| 767 |
|
| 768 |
glam_test!(test_ops_propagated, { |
| 769 |
let vec = $new(2 as $t, 4 as $t, 8 as $t, 10 as $t); |
| 770 |
let scalar = 2 as $t; |
| 771 |
let g_scalar = 10 as $t; |
| 772 |
|
| 773 |
assert_eq!((vec + vec), (vec + &vec)); |
| 774 |
assert_eq!((vec + vec), (&vec + vec)); |
| 775 |
assert_eq!((vec + vec), (&vec + &vec)); |
| 776 |
assert_eq!((vec + scalar), (vec + &scalar)); |
| 777 |
assert_eq!((vec + scalar), (&vec + &scalar)); |
| 778 |
assert_eq!((vec + scalar), (&vec + scalar)); |
| 779 |
assert_eq!((scalar + vec), (&scalar + vec)); |
| 780 |
assert_eq!((scalar + vec), (&scalar + &vec)); |
| 781 |
assert_eq!((scalar + vec), (scalar + &vec)); |
| 782 |
|
| 783 |
assert_eq!((vec - vec), (vec - &vec)); |
| 784 |
assert_eq!((vec - vec), (&vec - vec)); |
| 785 |
assert_eq!((vec - vec), (&vec - &vec)); |
| 786 |
assert_eq!((vec - scalar), (vec - &scalar)); |
| 787 |
assert_eq!((vec - scalar), (&vec - &scalar)); |
| 788 |
assert_eq!((vec - scalar), (&vec - scalar)); |
| 789 |
assert_eq!((g_scalar - vec), (&g_scalar - vec)); |
| 790 |
assert_eq!((g_scalar - vec), (&g_scalar - &vec)); |
| 791 |
assert_eq!((g_scalar - vec), (g_scalar - &vec)); |
| 792 |
|
| 793 |
assert_eq!((vec * vec), (vec * &vec)); |
| 794 |
assert_eq!((vec * vec), (&vec * vec)); |
| 795 |
assert_eq!((vec * vec), (&vec * &vec)); |
| 796 |
assert_eq!((vec * scalar), (vec * &scalar)); |
| 797 |
assert_eq!((vec * scalar), (&vec * &scalar)); |
| 798 |
assert_eq!((vec * scalar), (&vec * scalar)); |
| 799 |
assert_eq!((scalar * vec), (&scalar * vec)); |
| 800 |
assert_eq!((scalar * vec), (&scalar * &vec)); |
| 801 |
assert_eq!((scalar * vec), (scalar * &vec)); |
| 802 |
|
| 803 |
assert_eq!((vec / vec), (vec / &vec)); |
| 804 |
assert_eq!((vec / vec), (&vec / vec)); |
| 805 |
assert_eq!((vec / vec), (&vec / &vec)); |
| 806 |
assert_eq!((vec / scalar), (vec / &scalar)); |
| 807 |
assert_eq!((vec / scalar), (&vec / &scalar)); |
| 808 |
assert_eq!((vec / scalar), (&vec / scalar)); |
| 809 |
assert_eq!((scalar / vec), (&scalar / vec)); |
| 810 |
assert_eq!((scalar / vec), (&scalar / &vec)); |
| 811 |
assert_eq!((scalar / vec), (scalar / &vec)); |
| 812 |
|
| 813 |
assert_eq!((vec % vec), (vec % &vec)); |
| 814 |
assert_eq!((vec % vec), (&vec % vec)); |
| 815 |
assert_eq!((vec % vec), (&vec % &vec)); |
| 816 |
assert_eq!((vec % scalar), (vec % &scalar)); |
| 817 |
assert_eq!((vec % scalar), (&vec % &scalar)); |
| 818 |
assert_eq!((vec % scalar), (&vec % scalar)); |
| 819 |
assert_eq!((scalar % vec), (&scalar % vec)); |
| 820 |
assert_eq!((scalar % vec), (&scalar % &vec)); |
| 821 |
assert_eq!((scalar % vec), (scalar % &vec)); |
| 822 |
}); |
| 823 |
|
| 824 |
glam_test!(test_assign_ops, { |
| 825 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 826 |
let mut b = a; |
| 827 |
|
| 828 |
b += 2 as $t; |
| 829 |
assert_eq!($new(3 as $t, 4 as $t, 5 as $t, 6 as $t), b); |
| 830 |
b -= 2 as $t; |
| 831 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 832 |
b *= 2 as $t; |
| 833 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 834 |
b /= 2 as $t; |
| 835 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 836 |
b %= 2 as $t; |
| 837 |
assert_eq!($new(1 as $t, 0 as $t, 1 as $t, 0 as $t), b); |
| 838 |
|
| 839 |
b = a; |
| 840 |
b += a; |
| 841 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 842 |
b -= a; |
| 843 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 844 |
b *= a; |
| 845 |
assert_eq!($new(1 as $t, 4 as $t, 9 as $t, 16 as $t), b); |
| 846 |
b /= a; |
| 847 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 848 |
b *= 2 as $t; |
| 849 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 850 |
b /= 2 as $t; |
| 851 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 852 |
b %= (b + 1 as $t); |
| 853 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 854 |
b %= b; |
| 855 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), b); |
| 856 |
}); |
| 857 |
|
| 858 |
glam_test!(test_assign_ops_propagation, { |
| 859 |
let vec = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 860 |
let mut a = vec; |
| 861 |
let mut b = vec; |
| 862 |
let scalar = 2 as $t; |
| 863 |
|
| 864 |
a += &scalar; |
| 865 |
b += scalar; |
| 866 |
assert_eq!(b, a, "AddAssign<Scalar>"); |
| 867 |
a -= &scalar; |
| 868 |
b -= scalar; |
| 869 |
assert_eq!(b, a, "SubAssign<Scalar>"); |
| 870 |
a *= &scalar; |
| 871 |
b *= scalar; |
| 872 |
assert_eq!(b, a, "MulAssign<Scalar>"); |
| 873 |
a /= &scalar; |
| 874 |
b /= scalar; |
| 875 |
assert_eq!(b, a, "DivAssign<Scalar>"); |
| 876 |
a %= &scalar; |
| 877 |
b %= scalar; |
| 878 |
assert_eq!(b, a, "MulAssign<Scalar>"); |
| 879 |
|
| 880 |
a = vec; |
| 881 |
b = vec; |
| 882 |
a += &vec; |
| 883 |
b += vec; |
| 884 |
assert_eq!(b, a, "AddAssign<Vec>"); |
| 885 |
a -= &vec; |
| 886 |
b -= vec; |
| 887 |
assert_eq!(b, a, "SubAssign<Vec>"); |
| 888 |
a *= &vec; |
| 889 |
b *= vec; |
| 890 |
assert_eq!(b, a, "MulAssign<Vec>"); |
| 891 |
a /= &vec; |
| 892 |
b /= vec; |
| 893 |
assert_eq!(b, a, "DivAssign<Vec>"); |
| 894 |
a %= &vec; |
| 895 |
b %= vec; |
| 896 |
assert_eq!(b, a, "RemAssign<Vec>"); |
| 897 |
}); |
| 898 |
|
| 899 |
glam_test!(test_min_max, { |
| 900 |
let a = $new(4 as $t, 6 as $t, 2 as $t, 8 as $t); |
| 901 |
let b = $new(5 as $t, 3 as $t, 7 as $t, 1 as $t); |
| 902 |
assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), a.min(b).into()); |
| 903 |
assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), b.min(a).into()); |
| 904 |
assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), a.max(b).into()); |
| 905 |
assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), b.max(a).into()); |
| 906 |
}); |
| 907 |
|
| 908 |
glam_test!(test_min_position_max_position, { |
| 909 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 910 |
let b = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t); |
| 911 |
let c = $new(4 as $t, 3 as $t, 2 as $t, 1 as $t); |
| 912 |
let d = $new(1 as $t, 2 as $t, 0 as $t, 1 as $t); |
| 913 |
let e = $new(1 as $t, 0 as $t, 2 as $t, 1 as $t); |
| 914 |
assert_eq!(0, a.min_position()); |
| 915 |
assert_eq!(0, b.min_position()); |
| 916 |
assert_eq!(3, c.min_position()); |
| 917 |
assert_eq!(2, d.min_position()); |
| 918 |
assert_eq!(1, e.min_position()); |
| 919 |
assert_eq!(3, a.max_position()); |
| 920 |
assert_eq!(0, b.max_position()); |
| 921 |
assert_eq!(0, c.max_position()); |
| 922 |
assert_eq!(1, d.max_position()); |
| 923 |
assert_eq!(2, e.max_position()); |
| 924 |
}); |
| 925 |
|
| 926 |
glam_test!(test_clamp, { |
| 927 |
fn vec(x: i32, y: i32, z: i32, w: i32) -> $vec4 { |
| 928 |
$vec4::new(x as $t, y as $t, z as $t, w as $t) |
| 929 |
} |
| 930 |
let min = vec(1, 1, 3, 3); |
| 931 |
let max = vec(6, 6, 8, 8); |
| 932 |
assert_eq!(vec(0, 0, 0, 0).clamp(min, max), vec(1, 1, 3, 3)); |
| 933 |
assert_eq!(vec(2, 2, 2, 2).clamp(min, max), vec(2, 2, 3, 3)); |
| 934 |
assert_eq!(vec(4, 4, 5, 5).clamp(min, max), vec(4, 4, 5, 5)); |
| 935 |
assert_eq!(vec(6, 6, 6, 6).clamp(min, max), vec(6, 6, 6, 6)); |
| 936 |
assert_eq!(vec(7, 7, 7, 7).clamp(min, max), vec(6, 6, 7, 7)); |
| 937 |
assert_eq!(vec(9, 9, 9, 9).clamp(min, max), vec(6, 6, 8, 8)); |
| 938 |
|
| 939 |
should_glam_assert!({ $vec4::clamp($vec4::ZERO, $vec4::ONE, $vec4::ZERO) }); |
| 940 |
}); |
| 941 |
|
| 942 |
glam_test!(test_hmin_hmax, { |
| 943 |
assert_eq!( |
| 944 |
1 as $t, |
| 945 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t).min_element() |
| 946 |
); |
| 947 |
assert_eq!( |
| 948 |
1 as $t, |
| 949 |
$new(4 as $t, 1 as $t, 2 as $t, 3 as $t).min_element() |
| 950 |
); |
| 951 |
assert_eq!( |
| 952 |
1 as $t, |
| 953 |
$new(3 as $t, 4 as $t, 1 as $t, 2 as $t).min_element() |
| 954 |
); |
| 955 |
assert_eq!( |
| 956 |
1 as $t, |
| 957 |
$new(2 as $t, 3 as $t, 4 as $t, 1 as $t).min_element() |
| 958 |
); |
| 959 |
assert_eq!( |
| 960 |
4 as $t, |
| 961 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t).max_element() |
| 962 |
); |
| 963 |
assert_eq!( |
| 964 |
4 as $t, |
| 965 |
$new(4 as $t, 1 as $t, 2 as $t, 3 as $t).max_element() |
| 966 |
); |
| 967 |
assert_eq!( |
| 968 |
4 as $t, |
| 969 |
$new(3 as $t, 4 as $t, 1 as $t, 2 as $t).max_element() |
| 970 |
); |
| 971 |
assert_eq!( |
| 972 |
4 as $t, |
| 973 |
$new(2 as $t, 3 as $t, 4 as $t, 1 as $t).max_element() |
| 974 |
); |
| 975 |
assert_eq!( |
| 976 |
3 as $t, |
| 977 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t) |
| 978 |
.truncate() |
| 979 |
.max_element() |
| 980 |
); |
| 981 |
assert_eq!( |
| 982 |
2 as $t, |
| 983 |
$new(4 as $t, 3 as $t, 2 as $t, 1 as $t) |
| 984 |
.truncate() |
| 985 |
.min_element() |
| 986 |
); |
| 987 |
}); |
| 988 |
|
| 989 |
glam_test!(test_sum_product, { |
| 990 |
let a = $new(2 as $t, 3 as $t, 4 as $t, 5 as $t); |
| 991 |
assert_eq!(a.element_sum(), 14 as $t); |
| 992 |
assert_eq!(a.element_product(), 120 as $t); |
| 993 |
}); |
| 994 |
|
| 995 |
glam_test!(test_eq, { |
| 996 |
let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t); |
| 997 |
let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 998 |
assert!(a.cmpeq(a).all()); |
| 999 |
assert!(b.cmpeq(b).all()); |
| 1000 |
assert!(a.cmpne(b).any()); |
| 1001 |
assert!(b.cmpne(a).any()); |
| 1002 |
assert!(b.cmpeq(a).any()); |
| 1003 |
}); |
| 1004 |
|
| 1005 |
glam_test!(test_cmp, { |
| 1006 |
assert!(!$mask::default().any()); |
| 1007 |
assert!(!$mask::default().all()); |
| 1008 |
assert_eq!($mask::default().bitmask(), 0x0); |
| 1009 |
let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t); |
| 1010 |
let b = $new(2 as $t, 2 as $t, 2 as $t, 2 as $t); |
| 1011 |
let c = $new(1 as $t, 1 as $t, 2 as $t, 2 as $t); |
| 1012 |
let d = $new(2 as $t, 1 as $t, 1 as $t, 2 as $t); |
| 1013 |
assert_eq!(a.cmplt(a).bitmask(), 0x0); |
| 1014 |
assert_eq!(a.cmplt(b).bitmask(), 0xf); |
| 1015 |
assert_eq!(a.cmplt(c).bitmask(), 0xc); |
| 1016 |
assert_eq!(c.cmple(a).bitmask(), 0x3); |
| 1017 |
assert_eq!(a.cmplt(d).bitmask(), 0x9); |
| 1018 |
assert!(a.cmplt(b).all()); |
| 1019 |
assert!(a.cmplt(c).any()); |
| 1020 |
assert!(a.cmple(b).all()); |
| 1021 |
assert!(a.cmple(a).all()); |
| 1022 |
assert!(b.cmpgt(a).all()); |
| 1023 |
assert!(b.cmpge(a).all()); |
| 1024 |
assert!(b.cmpge(b).all()); |
| 1025 |
assert!(!(a.cmpge(c).all())); |
| 1026 |
assert!(c.cmple(c).all()); |
| 1027 |
assert!(c.cmpge(c).all()); |
| 1028 |
assert!(a.cmpeq(a).all()); |
| 1029 |
assert!(!a.cmpeq(b).all()); |
| 1030 |
assert!(a.cmpeq(c).any()); |
| 1031 |
assert!(!a.cmpne(a).all()); |
| 1032 |
assert!(a.cmpne(b).all()); |
| 1033 |
assert!(a.cmpne(c).any()); |
| 1034 |
assert!(a == a); |
| 1035 |
}); |
| 1036 |
|
| 1037 |
glam_test!(test_select, { |
| 1038 |
let a = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 1039 |
let b = $vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t); |
| 1040 |
assert_eq!( |
| 1041 |
$vec4::select($mask::new(true, true, true, true), a, b), |
| 1042 |
$vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t), |
| 1043 |
); |
| 1044 |
assert_eq!( |
| 1045 |
$vec4::select($mask::new(true, false, true, false), a, b), |
| 1046 |
$vec4::new(1 as $t, 6 as $t, 3 as $t, 8 as $t), |
| 1047 |
); |
| 1048 |
assert_eq!( |
| 1049 |
$vec4::select($mask::new(false, true, false, true), a, b), |
| 1050 |
$vec4::new(5 as $t, 2 as $t, 7 as $t, 4 as $t), |
| 1051 |
); |
| 1052 |
assert_eq!( |
| 1053 |
$vec4::select($mask::new(false, false, false, false), a, b), |
| 1054 |
$vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t), |
| 1055 |
); |
| 1056 |
}); |
| 1057 |
|
| 1058 |
glam_test!(test_slice, { |
| 1059 |
let a = [1 as $t, 2 as $t, 3 as $t, 4 as $t]; |
| 1060 |
let b = $vec4::from_slice(&a); |
| 1061 |
let c: [$t; 4] = b.into(); |
| 1062 |
assert_eq!(a, c); |
| 1063 |
let mut d = [0 as $t, 0 as $t, 0 as $t, 0 as $t]; |
| 1064 |
b.write_to_slice(&mut d[..]); |
| 1065 |
assert_eq!(a, d); |
| 1066 |
|
| 1067 |
should_panic!({ $vec4::ONE.write_to_slice(&mut [0 as $t; 3]) }); |
| 1068 |
should_panic!({ $vec4::from_slice(&[0 as $t; 3]) }); |
| 1069 |
}); |
| 1070 |
|
| 1071 |
glam_test!(test_to_from_slice, { |
| 1072 |
let v = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 1073 |
let mut a = [0 as $t, 0 as $t, 0 as $t, 0 as $t]; |
| 1074 |
v.write_to_slice(&mut a); |
| 1075 |
assert_eq!(v, $vec4::from_slice(&a)); |
| 1076 |
|
| 1077 |
let mut a = [0 as $t; 17]; |
| 1078 |
v.write_to_slice(&mut a); |
| 1079 |
assert_eq!(v, $vec4::from_slice(&a[..4])); |
| 1080 |
assert_eq!([0 as $t; 13], a[4..]); |
| 1081 |
}); |
| 1082 |
|
| 1083 |
glam_test!(test_sum, { |
| 1084 |
let one = $vec4::ONE; |
| 1085 |
assert_eq!([one, one].iter().sum::<$vec4>(), one + one); |
| 1086 |
assert_eq!([one, one].into_iter().sum::<$vec4>(), one + one); |
| 1087 |
}); |
| 1088 |
|
| 1089 |
glam_test!(test_product, { |
| 1090 |
let two = $vec4::new(2 as $t, 2 as $t, 2 as $t, 2 as $t); |
| 1091 |
assert_eq!([two, two].iter().product::<$vec4>(), two * two); |
| 1092 |
assert_eq!([two, two].into_iter().product::<$vec4>(), two * two); |
| 1093 |
}); |
| 1094 |
}; |
| 1095 |
} |
| 1096 |
|
| 1097 |
macro_rules! impl_vec4_signed_tests { |
| 1098 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 1099 |
impl_vec4_tests!($t, $new, $vec4, $vec3, $vec2, $mask); |
| 1100 |
|
| 1101 |
glam_test!(test_neg, { |
| 1102 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 1103 |
assert_eq!((-1 as $t, -2 as $t, -3 as $t, -4 as $t), (-a).into()); |
| 1104 |
assert_eq!( |
| 1105 |
$new(-0 as $t, -0 as $t, -0 as $t, -0 as $t), |
| 1106 |
-$new(0 as $t, 0 as $t, 0 as $t, 0 as $t) |
| 1107 |
); |
| 1108 |
assert_eq!( |
| 1109 |
$new(0 as $t, -0 as $t, -0 as $t, -0 as $t), |
| 1110 |
-$new(-0 as $t, 0 as $t, 0 as $t, 0 as $t) |
| 1111 |
); |
| 1112 |
}); |
| 1113 |
|
| 1114 |
glam_test!(test_neg_propagation, { |
| 1115 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 1116 |
assert_eq!(-a, -(&a)); |
| 1117 |
}); |
| 1118 |
|
| 1119 |
glam_test!(test_is_negative_bitmask, { |
| 1120 |
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000); |
| 1121 |
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000); |
| 1122 |
assert_eq!((-$vec4::ONE).is_negative_bitmask(), 0b1111); |
| 1123 |
assert_eq!( |
| 1124 |
$vec4::new(-1 as $t, 2 as $t, 3 as $t, -4 as $t).is_negative_bitmask(), |
| 1125 |
0b1001 |
| 1126 |
); |
| 1127 |
assert_eq!( |
| 1128 |
$vec4::new(1 as $t, 5 as $t, -3 as $t, 7 as $t).is_negative_bitmask(), |
| 1129 |
0b0100 |
| 1130 |
); |
| 1131 |
assert_eq!( |
| 1132 |
$vec4::new(3 as $t, -4 as $t, 1 as $t, 6 as $t).is_negative_bitmask(), |
| 1133 |
0b0010 |
| 1134 |
); |
| 1135 |
assert_eq!( |
| 1136 |
$vec4::new(2 as $t, -6 as $t, 5 as $t, -3 as $t).is_negative_bitmask(), |
| 1137 |
0b1010 |
| 1138 |
); |
| 1139 |
}); |
| 1140 |
|
| 1141 |
glam_test!(test_abs, { |
| 1142 |
assert_eq!($vec4::ZERO.abs(), $vec4::ZERO); |
| 1143 |
assert_eq!($vec4::ONE.abs(), $vec4::ONE); |
| 1144 |
assert_eq!((-$vec4::ONE).abs(), $vec4::ONE); |
| 1145 |
}); |
| 1146 |
|
| 1147 |
glam_test!(test_dot_signed, { |
| 1148 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 1149 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 1150 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 1151 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 1152 |
assert_eq!(1 as $t, x.dot(x)); |
| 1153 |
assert_eq!(0 as $t, x.dot(y)); |
| 1154 |
assert_eq!(0 as $t, x.dot(-z)); |
| 1155 |
assert_eq!(-1 as $t, w.dot(-w)); |
| 1156 |
}); |
| 1157 |
|
| 1158 |
glam_test!(test_length_squared_signed, { |
| 1159 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 1160 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 1161 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 1162 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 1163 |
assert_eq!(4 as $t, (2 as $t * x).length_squared()); |
| 1164 |
assert_eq!(9 as $t, (-3 as $t * y).length_squared()); |
| 1165 |
assert_eq!(16 as $t, (4 as $t * z).length_squared()); |
| 1166 |
assert_eq!(64 as $t, (8 as $t * w).length_squared()); |
| 1167 |
assert_eq!( |
| 1168 |
2 as $t * 2 as $t + 3 as $t * 3 as $t + 4 as $t * 4 as $t + 5 as $t * 5 as $t, |
| 1169 |
$new(2 as $t, 3 as $t, 4 as $t, 5 as $t).length_squared() |
| 1170 |
); |
| 1171 |
assert_eq!(2 as $t, x.distance_squared(y)); |
| 1172 |
assert_eq!(13 as $t, (2 as $t * x).distance_squared(-3 as $t * z)); |
| 1173 |
}); |
| 1174 |
|
| 1175 |
glam_test!(test_div_euclid, { |
| 1176 |
let one = $vec4::ONE; |
| 1177 |
let two = one + one; |
| 1178 |
let three = two + one; |
| 1179 |
assert_eq!(three.div_euclid(two), one); |
| 1180 |
assert_eq!((-three).div_euclid(two), -two); |
| 1181 |
assert_eq!(three.div_euclid(-two), -one); |
| 1182 |
assert_eq!((-three).div_euclid(-two), two); |
| 1183 |
}); |
| 1184 |
|
| 1185 |
glam_test!(test_rem_euclid, { |
| 1186 |
let one = $vec4::ONE; |
| 1187 |
let two = one + one; |
| 1188 |
let three = two + one; |
| 1189 |
let four = three + one; |
| 1190 |
assert_eq!(four.rem_euclid(three), one); |
| 1191 |
assert_eq!((-four).rem_euclid(three), two); |
| 1192 |
assert_eq!(four.rem_euclid(-three), one); |
| 1193 |
assert_eq!((-four).rem_euclid(-three), two); |
| 1194 |
}); |
| 1195 |
}; |
| 1196 |
} |
| 1197 |
|
| 1198 |
macro_rules! impl_vec4_signed_integer_tests { |
| 1199 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 1200 |
impl_vec4_signed_tests!($t, $new, $vec4, $vec3, $vec2, $mask); |
| 1201 |
|
| 1202 |
glam_test!(test_signum, { |
| 1203 |
assert_eq!($vec4::ZERO.signum(), $vec4::ZERO); |
| 1204 |
assert_eq!($vec4::ONE.signum(), $vec4::ONE); |
| 1205 |
assert_eq!((-$vec4::ONE).signum(), -$vec4::ONE); |
| 1206 |
}); |
| 1207 |
|
| 1208 |
glam_test!(test_checked_add, { |
| 1209 |
assert_eq!($vec4::MAX.checked_add($vec4::ONE), None); |
| 1210 |
assert_eq!($vec4::MAX.checked_add($vec4::X), None); |
| 1211 |
assert_eq!($vec4::MAX.checked_add($vec4::Y), None); |
| 1212 |
assert_eq!($vec4::MAX.checked_add($vec4::Z), None); |
| 1213 |
assert_eq!($vec4::MAX.checked_add($vec4::W), None); |
| 1214 |
assert_eq!($vec4::MAX.checked_add($vec4::ZERO), Some($vec4::MAX)); |
| 1215 |
}); |
| 1216 |
|
| 1217 |
glam_test!(test_checked_sub, { |
| 1218 |
assert_eq!($vec4::MIN.checked_sub($vec4::ONE), None); |
| 1219 |
assert_eq!($vec4::MIN.checked_sub($vec4::X), None); |
| 1220 |
assert_eq!($vec4::MIN.checked_sub($vec4::Y), None); |
| 1221 |
assert_eq!($vec4::MIN.checked_sub($vec4::Z), None); |
| 1222 |
assert_eq!($vec4::MIN.checked_sub($vec4::W), None); |
| 1223 |
assert_eq!($vec4::MIN.checked_sub($vec4::ZERO), Some($vec4::MIN)); |
| 1224 |
}); |
| 1225 |
|
| 1226 |
glam_test!(test_checked_mul, { |
| 1227 |
assert_eq!($vec4::MIN.checked_mul($vec4::MIN), None); |
| 1228 |
assert_eq!($vec4::MAX.checked_mul($vec4::MIN), None); |
| 1229 |
assert_eq!($vec4::MIN.checked_mul($vec4::MAX), None); |
| 1230 |
assert_eq!($vec4::MAX.checked_mul($vec4::MAX), None); |
| 1231 |
assert_eq!($vec4::ZERO.checked_mul($vec4::MIN), Some($vec4::ZERO)); |
| 1232 |
assert_eq!($vec4::MAX.checked_mul($vec4::ZERO), Some($vec4::ZERO)); |
| 1233 |
assert_eq!($vec4::MIN.checked_mul($vec4::ONE), Some($vec4::MIN)); |
| 1234 |
assert_eq!($vec4::MAX.checked_mul($vec4::ONE), Some($vec4::MAX)); |
| 1235 |
assert_eq!($vec4::ZERO.checked_mul($vec4::ZERO), Some($vec4::ZERO)); |
| 1236 |
assert_eq!($vec4::ONE.checked_mul($vec4::ONE), Some($vec4::ONE)); |
| 1237 |
}); |
| 1238 |
|
| 1239 |
glam_test!(test_checked_div, { |
| 1240 |
assert_eq!($vec4::MIN.checked_div($vec4::ZERO), None); |
| 1241 |
assert_eq!($vec4::MAX.checked_div($vec4::ZERO), None); |
| 1242 |
assert_eq!($vec4::MAX.checked_div($vec4::X), None); |
| 1243 |
assert_eq!($vec4::MAX.checked_div($vec4::Y), None); |
| 1244 |
assert_eq!($vec4::MAX.checked_div($vec4::Z), None); |
| 1245 |
assert_eq!($vec4::MAX.checked_div($vec4::W), None); |
| 1246 |
assert_eq!($vec4::ZERO.checked_div($vec4::ONE), Some($vec4::ZERO)); |
| 1247 |
assert_eq!($vec4::MIN.checked_div($vec4::ONE), Some($vec4::MIN)); |
| 1248 |
assert_eq!($vec4::MAX.checked_div($vec4::ONE), Some($vec4::MAX)); |
| 1249 |
}); |
| 1250 |
|
| 1251 |
glam_test!(test_manhattan_distance, { |
| 1252 |
assert_eq!( |
| 1253 |
$vec4::new(41, 8, 21, 87).manhattan_distance($vec4::new(49, 48, 28, 40)), |
| 1254 |
102 |
| 1255 |
); |
| 1256 |
assert_eq!( |
| 1257 |
$vec4::new(19, 16, 100, 74).manhattan_distance($vec4::new(14, 55, 115, 48)), |
| 1258 |
85 |
| 1259 |
); |
| 1260 |
|
| 1261 |
assert_eq!( |
| 1262 |
$vec4::new(26, 2, 24, -22).manhattan_distance($vec4::new(26, 23, 6, 23)), |
| 1263 |
84 |
| 1264 |
); |
| 1265 |
|
| 1266 |
assert_eq!( |
| 1267 |
$vec4::new(41, 8, 21, 87).checked_manhattan_distance($vec4::new(49, 48, 28, 40)), |
| 1268 |
Some(102) |
| 1269 |
); |
| 1270 |
assert_eq!( |
| 1271 |
$vec4::new(19, 16, 100, 74).checked_manhattan_distance($vec4::new(14, 55, 115, 48)), |
| 1272 |
Some(85) |
| 1273 |
); |
| 1274 |
|
| 1275 |
assert_eq!( |
| 1276 |
$vec4::new(26, 2, 24, -22).checked_manhattan_distance($vec4::new(26, 23, 6, 23)), |
| 1277 |
Some(84) |
| 1278 |
); |
| 1279 |
|
| 1280 |
assert_eq!( |
| 1281 |
$vec4::new($t::MIN, $t::MIN, $t::MIN, $t::MIN) |
| 1282 |
.checked_manhattan_distance($vec4::new($t::MAX, $t::MAX, $t::MAX, $t::MAX)), |
| 1283 |
None |
| 1284 |
); |
| 1285 |
}); |
| 1286 |
|
| 1287 |
glam_test!(test_chebyshev_distance, { |
| 1288 |
assert_eq!( |
| 1289 |
$vec4::new(41, 8, 21, 87).chebyshev_distance($vec4::new(49, 48, 28, 40)), |
| 1290 |
47 |
| 1291 |
); |
| 1292 |
assert_eq!( |
| 1293 |
$vec4::new(119, 16, 100, 74).chebyshev_distance($vec4::new(14, 55, 115, 48)), |
| 1294 |
105 |
| 1295 |
); |
| 1296 |
assert_eq!( |
| 1297 |
$vec4::new(26, 2, 24, -22).chebyshev_distance($vec4::new(26, 23, 6, 23)), |
| 1298 |
45 |
| 1299 |
); |
| 1300 |
}); |
| 1301 |
}; |
| 1302 |
} |
| 1303 |
|
| 1304 |
macro_rules! impl_vec4_unsigned_integer_tests { |
| 1305 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 1306 |
impl_vec4_tests!($t, $new, $vec4, $vec3, $vec2, $mask); |
| 1307 |
|
| 1308 |
glam_test!(test_checked_add, { |
| 1309 |
assert_eq!($vec4::MAX.checked_add($vec4::ONE), None); |
| 1310 |
assert_eq!($vec4::MAX.checked_add($vec4::X), None); |
| 1311 |
assert_eq!($vec4::MAX.checked_add($vec4::Y), None); |
| 1312 |
assert_eq!($vec4::MAX.checked_add($vec4::Z), None); |
| 1313 |
assert_eq!($vec4::MAX.checked_add($vec4::W), None); |
| 1314 |
assert_eq!($vec4::MAX.checked_add($vec4::ZERO), Some($vec4::MAX)); |
| 1315 |
}); |
| 1316 |
|
| 1317 |
glam_test!(test_checked_sub, { |
| 1318 |
assert_eq!($vec4::ZERO.checked_sub($vec4::ONE), None); |
| 1319 |
assert_eq!($vec4::ZERO.checked_sub($vec4::X), None); |
| 1320 |
assert_eq!($vec4::ZERO.checked_sub($vec4::Y), None); |
| 1321 |
assert_eq!($vec4::ZERO.checked_sub($vec4::Z), None); |
| 1322 |
assert_eq!($vec4::ZERO.checked_sub($vec4::W), None); |
| 1323 |
assert_eq!($vec4::ZERO.checked_sub($vec4::ZERO), Some($vec4::MIN)); |
| 1324 |
}); |
| 1325 |
|
| 1326 |
glam_test!(test_checked_mul, { |
| 1327 |
assert_eq!($vec4::MAX.checked_mul($vec4::MAX), None); |
| 1328 |
assert_eq!($vec4::MAX.checked_mul($vec4::ZERO), Some($vec4::ZERO)); |
| 1329 |
assert_eq!($vec4::MAX.checked_mul($vec4::ONE), Some($vec4::MAX)); |
| 1330 |
assert_eq!($vec4::ZERO.checked_mul($vec4::ZERO), Some($vec4::ZERO)); |
| 1331 |
assert_eq!($vec4::ONE.checked_mul($vec4::ONE), Some($vec4::ONE)); |
| 1332 |
}); |
| 1333 |
|
| 1334 |
glam_test!(test_checked_div, { |
| 1335 |
assert_eq!($vec4::MAX.checked_div($vec4::ZERO), None); |
| 1336 |
assert_eq!($vec4::MAX.checked_div($vec4::X), None); |
| 1337 |
assert_eq!($vec4::MAX.checked_div($vec4::Y), None); |
| 1338 |
assert_eq!($vec4::MAX.checked_div($vec4::Z), None); |
| 1339 |
assert_eq!($vec4::MAX.checked_div($vec4::W), None); |
| 1340 |
assert_eq!($vec4::ZERO.checked_div($vec4::ONE), Some($vec4::ZERO)); |
| 1341 |
assert_eq!($vec4::MAX.checked_div($vec4::ONE), Some($vec4::MAX)); |
| 1342 |
}); |
| 1343 |
|
| 1344 |
glam_test!(test_manhattan_distance, { |
| 1345 |
assert_eq!( |
| 1346 |
$vec4::new(41, 8, 21, 87).manhattan_distance($vec4::new(49, 48, 128, 40)), |
| 1347 |
202 |
| 1348 |
); |
| 1349 |
assert_eq!( |
| 1350 |
$vec4::new(19, 16, 179, 174).manhattan_distance($vec4::new(14, 55, 115, 148)), |
| 1351 |
134 |
| 1352 |
); |
| 1353 |
|
| 1354 |
assert_eq!( |
| 1355 |
$vec4::new(41, 8, 21, 87).checked_manhattan_distance($vec4::new(49, 48, 128, 40)), |
| 1356 |
Some(202) |
| 1357 |
); |
| 1358 |
assert_eq!( |
| 1359 |
$vec4::new(19, 16, 179, 174) |
| 1360 |
.checked_manhattan_distance($vec4::new(14, 55, 115, 148)), |
| 1361 |
Some(134) |
| 1362 |
); |
| 1363 |
|
| 1364 |
assert_eq!( |
| 1365 |
$vec4::new($t::MIN, $t::MIN, $t::MIN, $t::MIN) |
| 1366 |
.checked_manhattan_distance($vec4::new($t::MAX, $t::MAX, $t::MAX, $t::MAX)), |
| 1367 |
None |
| 1368 |
); |
| 1369 |
}); |
| 1370 |
|
| 1371 |
glam_test!(test_chebyshev_distance, { |
| 1372 |
assert_eq!( |
| 1373 |
$vec4::new(41, 8, 21, 87).chebyshev_distance($vec4::new(49, 48, 128, 40)), |
| 1374 |
107 |
| 1375 |
); |
| 1376 |
assert_eq!( |
| 1377 |
$vec4::new(119, 16, 179, 174).chebyshev_distance($vec4::new(14, 55, 115, 148)), |
| 1378 |
105 |
| 1379 |
); |
| 1380 |
}); |
| 1381 |
}; |
| 1382 |
} |
| 1383 |
|
| 1384 |
macro_rules! impl_vec4_eq_hash_tests { |
| 1385 |
($t:ident, $new:ident) => { |
| 1386 |
glam_test!(test_ve2_hash, { |
| 1387 |
use std::collections::hash_map::DefaultHasher; |
| 1388 |
use std::hash::Hash; |
| 1389 |
use std::hash::Hasher; |
| 1390 |
|
| 1391 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 1392 |
let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 1393 |
let c = $new(3 as $t, 2 as $t, 1 as $t, 4 as $t); |
| 1394 |
|
| 1395 |
let mut hasher = DefaultHasher::new(); |
| 1396 |
a.hash(&mut hasher); |
| 1397 |
let a_hashed = hasher.finish(); |
| 1398 |
|
| 1399 |
let mut hasher = DefaultHasher::new(); |
| 1400 |
b.hash(&mut hasher); |
| 1401 |
let b_hashed = hasher.finish(); |
| 1402 |
|
| 1403 |
let mut hasher = DefaultHasher::new(); |
| 1404 |
c.hash(&mut hasher); |
| 1405 |
let c_hashed = hasher.finish(); |
| 1406 |
|
| 1407 |
assert_eq!(a, b); |
| 1408 |
assert_eq!(a_hashed, b_hashed); |
| 1409 |
assert_ne!(a, c); |
| 1410 |
assert_ne!(a_hashed, c_hashed); |
| 1411 |
}); |
| 1412 |
}; |
| 1413 |
} |
| 1414 |
|
| 1415 |
macro_rules! impl_vec4_float_tests { |
| 1416 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 1417 |
impl_vec4_signed_tests!($t, $new, $vec4, $vec3, $vec2, $mask); |
| 1418 |
impl_vec_float_normalize_tests!($t, $vec4); |
| 1419 |
|
| 1420 |
glam_test!(test_vec4_nan, { |
| 1421 |
assert!($vec4::NAN.is_nan()); |
| 1422 |
assert!(!$vec4::NAN.is_finite()); |
| 1423 |
}); |
| 1424 |
|
| 1425 |
glam_test!(test_funcs, { |
| 1426 |
let x = $new(1.0, 0.0, 0.0, 0.0); |
| 1427 |
let y = $new(0.0, 1.0, 0.0, 0.0); |
| 1428 |
let z = $new(0.0, 0.0, 1.0, 0.0); |
| 1429 |
let w = $new(0.0, 0.0, 0.0, 1.0); |
| 1430 |
assert_eq!(2.0, (-2.0 * x).length()); |
| 1431 |
assert_eq!(3.0, (3.0 * y).length()); |
| 1432 |
assert_eq!(4.0, (-4.0 * z).length()); |
| 1433 |
assert_eq!(5.0, (-5.0 * w).length()); |
| 1434 |
assert_eq!((2.0 as $t).sqrt(), w.distance(y)); |
| 1435 |
assert_eq!(5.0, (3.0 * x).distance(-4.0 * y)); |
| 1436 |
assert_eq!(13.0, (-5.0 * w).distance(12.0 * y)); |
| 1437 |
assert_eq!(x, (2.0 * x).normalize()); |
| 1438 |
assert_eq!( |
| 1439 |
1.0 * 5.0 + 2.0 * 6.0 + 3.0 * 7.0 + 4.0 * 8.0, |
| 1440 |
$new(1.0, 2.0, 3.0, 4.0).dot($new(5.0, 6.0, 7.0, 8.0)) |
| 1441 |
); |
| 1442 |
assert_eq!( |
| 1443 |
(2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 1444 |
$new(2.0, 3.0, 4.0, 5.0).length() |
| 1445 |
); |
| 1446 |
assert_eq!( |
| 1447 |
1.0 / (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 1448 |
$new(2.0, 3.0, 4.0, 5.0).length_recip() |
| 1449 |
); |
| 1450 |
assert!($new(2.0, 3.0, 4.0, 5.0).normalize().is_normalized()); |
| 1451 |
assert_approx_eq!( |
| 1452 |
$new(2.0, 3.0, 4.0, 5.0) |
| 1453 |
/ (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 1454 |
$new(2.0, 3.0, 4.0, 5.0).normalize() |
| 1455 |
); |
| 1456 |
assert_eq!( |
| 1457 |
$new(0.5, 0.25, 0.125, 0.0625), |
| 1458 |
$new(2.0, 4.0, 8.0, 16.0).recip() |
| 1459 |
); |
| 1460 |
}); |
| 1461 |
|
| 1462 |
glam_test!(test_project_reject, { |
| 1463 |
assert_eq!( |
| 1464 |
$new(0.0, 0.0, 0.0, 1.0), |
| 1465 |
$new(0.0, 1.0, 0.0, 1.0).project_onto($new(0.0, 0.0, 0.0, 2.0)) |
| 1466 |
); |
| 1467 |
assert_eq!( |
| 1468 |
$new(0.0, 1.0, 0.0, 0.0), |
| 1469 |
$new(0.0, 1.0, 0.0, 1.0).reject_from($new(0.0, 0.0, 0.0, 2.0)) |
| 1470 |
); |
| 1471 |
assert_eq!( |
| 1472 |
$new(0.0, 0.0, 0.0, 1.0), |
| 1473 |
$new(0.0, 1.0, 0.0, 1.0).project_onto_normalized($new(0.0, 0.0, 0.0, 1.0)) |
| 1474 |
); |
| 1475 |
assert_eq!( |
| 1476 |
$new(0.0, 1.0, 0.0, 0.0), |
| 1477 |
$new(0.0, 1.0, 0.0, 1.0).reject_from_normalized($new(0.0, 0.0, 0.0, 1.0)) |
| 1478 |
); |
| 1479 |
should_glam_assert!({ $vec4::ONE.project_onto($vec4::ZERO) }); |
| 1480 |
should_glam_assert!({ $vec4::ONE.reject_from($vec4::ZERO) }); |
| 1481 |
should_glam_assert!({ $vec4::ONE.project_onto_normalized($vec4::ONE) }); |
| 1482 |
should_glam_assert!({ $vec4::ONE.reject_from_normalized($vec4::ONE) }); |
| 1483 |
}); |
| 1484 |
|
| 1485 |
glam_test!(test_min_max_nan, { |
| 1486 |
// NaN propogation is not consistent between scalar and different simd architectures. |
| 1487 |
// The purpose of this test is to document the different behaviour. |
| 1488 |
if $vec4::USES_SCALAR_MATH { |
| 1489 |
assert!(!$vec4::NAN.min($vec4::ZERO).is_nan_mask().all()); |
| 1490 |
assert!($vec4::ZERO.min($vec4::NAN).is_nan_mask().all()); |
| 1491 |
assert!($vec4::NAN.min($vec4::NAN).is_nan_mask().all()); |
| 1492 |
assert!(!$vec4::NAN.max($vec4::ZERO).is_nan_mask().all()); |
| 1493 |
assert!($vec4::ZERO.max($vec4::NAN).is_nan_mask().all()); |
| 1494 |
assert!($vec4::NAN.max($vec4::NAN).is_nan_mask().all()); |
| 1495 |
} else if $vec4::USES_NEON { |
| 1496 |
assert!($vec4::NAN.min($vec4::ZERO).is_nan_mask().all()); |
| 1497 |
assert!($vec4::ZERO.min($vec4::NAN).is_nan_mask().all()); |
| 1498 |
assert!($vec4::NAN.min($vec4::NAN).is_nan_mask().all()); |
| 1499 |
assert!($vec4::NAN.max($vec4::ZERO).is_nan_mask().all()); |
| 1500 |
assert!($vec4::ZERO.max($vec4::NAN).is_nan_mask().all()); |
| 1501 |
assert!($vec4::NAN.max($vec4::NAN).is_nan_mask().all()); |
| 1502 |
} else if $vec4::USES_SSE2 { |
| 1503 |
assert!(!$vec4::NAN.min($vec4::ZERO).is_nan_mask().all()); |
| 1504 |
assert!($vec4::ZERO.min($vec4::NAN).is_nan_mask().all()); |
| 1505 |
assert!($vec4::NAN.min($vec4::NAN).is_nan_mask().all()); |
| 1506 |
assert!(!$vec4::NAN.max($vec4::ZERO).is_nan_mask().all()); |
| 1507 |
assert!($vec4::ZERO.max($vec4::NAN).is_nan_mask().all()); |
| 1508 |
assert!($vec4::NAN.max($vec4::NAN).is_nan_mask().all()); |
| 1509 |
} else if $vec4::USES_WASM32_SIMD { |
| 1510 |
assert!($vec4::NAN.min($vec4::ZERO).is_nan_mask().all()); |
| 1511 |
assert!(!$vec4::ZERO.min($vec4::NAN).is_nan_mask().all()); |
| 1512 |
assert!($vec4::NAN.min($vec4::NAN).is_nan_mask().all()); |
| 1513 |
assert!($vec4::NAN.max($vec4::ZERO).is_nan_mask().all()); |
| 1514 |
assert!(!$vec4::ZERO.max($vec4::NAN).is_nan_mask().all()); |
| 1515 |
assert!($vec4::NAN.max($vec4::NAN).is_nan_mask().all()); |
| 1516 |
} else if $vec4::USES_CORE_SIMD { |
| 1517 |
assert!(!$vec4::NAN.min($vec4::ZERO).is_nan_mask().all()); |
| 1518 |
assert!($vec4::ZERO.min($vec4::NAN).is_nan_mask().all()); |
| 1519 |
assert!($vec4::NAN.min($vec4::NAN).is_nan_mask().all()); |
| 1520 |
assert!(!$vec4::NAN.max($vec4::ZERO).is_nan_mask().all()); |
| 1521 |
assert!($vec4::ZERO.max($vec4::NAN).is_nan_mask().all()); |
| 1522 |
assert!($vec4::NAN.max($vec4::NAN).is_nan_mask().all()); |
| 1523 |
} |
| 1524 |
}); |
| 1525 |
|
| 1526 |
glam_test!(test_min_max_element_nan, { |
| 1527 |
// NaN propogation is not consistent between scalar and different simd architectures. |
| 1528 |
// The purpose of this test is to document the different behaviour. |
| 1529 |
let v = $vec4::new(4.0, 3.0, 2.0, $t::NAN); |
| 1530 |
if $vec4::USES_SCALAR_MATH { |
| 1531 |
assert!(v.min_element().is_nan()); |
| 1532 |
assert!(v.max_element().is_nan()); |
| 1533 |
} else if $vec4::USES_NEON { |
| 1534 |
assert_eq!(2.0, v.min_element()); |
| 1535 |
assert_eq!(4.0, v.max_element()); |
| 1536 |
} else if $vec4::USES_SSE2 { |
| 1537 |
assert!(v.min_element().is_nan()); |
| 1538 |
assert!(v.max_element().is_nan()); |
| 1539 |
} else if $vec4::USES_WASM32_SIMD { |
| 1540 |
assert_eq!(2.0, v.min_element()); |
| 1541 |
assert_eq!(4.0, v.max_element()); |
| 1542 |
} else if $vec4::USES_CORE_SIMD { |
| 1543 |
assert!(v.min_element().is_nan()); |
| 1544 |
assert!(v.max_element().is_nan()); |
| 1545 |
} |
| 1546 |
}); |
| 1547 |
|
| 1548 |
glam_test!(test_clamp_nan, { |
| 1549 |
// NaN propogation is not consistent between scalar and different simd architectures. |
| 1550 |
// The purpose of this test is to document the different behaviour. |
| 1551 |
if $vec4::USES_SCALAR_MATH { |
| 1552 |
assert_eq!($vec4::NEG_ONE, $vec4::NAN.clamp($vec4::NEG_ONE, $vec4::ONE)); |
| 1553 |
#[cfg(not(any(feature = "debug-glam-assert", feature = "glam-assert")))] |
| 1554 |
{ |
| 1555 |
assert_eq!($vec4::ONE, $vec4::NAN.clamp($vec4::NAN, $vec4::ONE)); |
| 1556 |
assert!($vec4::NAN |
| 1557 |
.clamp($vec4::NEG_ONE, $vec4::NAN) |
| 1558 |
.is_nan_mask() |
| 1559 |
.all()); |
| 1560 |
} |
| 1561 |
} else if $vec4::USES_NEON { |
| 1562 |
assert!($vec4::NAN |
| 1563 |
.clamp($vec4::NEG_ONE, $vec4::ONE) |
| 1564 |
.is_nan_mask() |
| 1565 |
.all()); |
| 1566 |
#[cfg(not(any(feature = "debug-glam-assert", feature = "glam-assert")))] |
| 1567 |
{ |
| 1568 |
assert!($vec4::NAN.clamp($vec4::NAN, $vec4::ONE).is_nan_mask().all()); |
| 1569 |
assert!($vec4::NAN |
| 1570 |
.clamp($vec4::NEG_ONE, $vec4::NAN) |
| 1571 |
.is_nan_mask() |
| 1572 |
.all()); |
| 1573 |
} |
| 1574 |
} else if $vec4::USES_SSE2 { |
| 1575 |
assert_eq!($vec4::NEG_ONE, $vec4::NAN.clamp($vec4::NEG_ONE, $vec4::ONE)); |
| 1576 |
#[cfg(not(any(feature = "debug-glam-assert", feature = "glam-assert")))] |
| 1577 |
{ |
| 1578 |
assert_eq!($vec4::ONE, $vec4::NAN.clamp($vec4::NAN, $vec4::ONE)); |
| 1579 |
assert!($vec4::NAN |
| 1580 |
.clamp($vec4::NEG_ONE, $vec4::NAN) |
| 1581 |
.is_nan_mask() |
| 1582 |
.all()); |
| 1583 |
} |
| 1584 |
} else if $vec4::USES_WASM32_SIMD { |
| 1585 |
assert!($vec4::NAN |
| 1586 |
.clamp($vec4::NEG_ONE, $vec4::ONE) |
| 1587 |
.is_nan_mask() |
| 1588 |
.all()); |
| 1589 |
#[cfg(not(any(feature = "debug-glam-assert", feature = "glam-assert")))] |
| 1590 |
{ |
| 1591 |
assert!($vec4::NAN.clamp($vec4::NAN, $vec4::ONE).is_nan_mask().all()); |
| 1592 |
assert!($vec4::NAN |
| 1593 |
.clamp($vec4::NEG_ONE, $vec4::NAN) |
| 1594 |
.is_nan_mask() |
| 1595 |
.all()); |
| 1596 |
} |
| 1597 |
} else if $vec4::USES_CORE_SIMD { |
| 1598 |
assert_eq!($vec4::NEG_ONE, $vec4::NAN.clamp($vec4::NEG_ONE, $vec4::ONE)); |
| 1599 |
#[cfg(not(any(feature = "debug-glam-assert", feature = "glam-assert")))] |
| 1600 |
{ |
| 1601 |
assert_eq!($vec4::ONE, $vec4::NAN.clamp($vec4::NAN, $vec4::ONE)); |
| 1602 |
assert!($vec4::NAN |
| 1603 |
.clamp($vec4::NEG_ONE, $vec4::NAN) |
| 1604 |
.is_nan_mask() |
| 1605 |
.all()); |
| 1606 |
} |
| 1607 |
} |
| 1608 |
}); |
| 1609 |
|
| 1610 |
glam_test!(test_signum, { |
| 1611 |
assert_eq!($vec4::ZERO.signum(), $vec4::ONE); |
| 1612 |
assert_eq!((-$vec4::ZERO).signum(), -$vec4::ONE); |
| 1613 |
assert_eq!($vec4::ONE.signum(), $vec4::ONE); |
| 1614 |
assert_eq!((-$vec4::ONE).signum(), -$vec4::ONE); |
| 1615 |
assert_eq!($vec4::INFINITY.signum(), $vec4::ONE); |
| 1616 |
assert_eq!($vec4::NEG_INFINITY.signum(), -$vec4::ONE); |
| 1617 |
assert!($vec4::NAN.signum().is_nan_mask().all()); |
| 1618 |
}); |
| 1619 |
|
| 1620 |
glam_test!(test_copysign, { |
| 1621 |
assert_eq!($vec4::ZERO.copysign(-$vec4::ZERO), -$vec4::ZERO); |
| 1622 |
assert_eq!((-$vec4::ZERO).copysign(-$vec4::ZERO), -$vec4::ZERO); |
| 1623 |
assert_eq!($vec4::ZERO.copysign($vec4::ZERO), $vec4::ZERO); |
| 1624 |
assert_eq!((-$vec4::ZERO).copysign($vec4::ZERO), $vec4::ZERO); |
| 1625 |
assert_eq!($vec4::ONE.copysign(-$vec4::ZERO), -$vec4::ONE); |
| 1626 |
assert_eq!((-$vec4::ONE).copysign(-$vec4::ZERO), -$vec4::ONE); |
| 1627 |
assert_eq!($vec4::ONE.copysign($vec4::ZERO), $vec4::ONE); |
| 1628 |
assert_eq!((-$vec4::ONE).copysign($vec4::ZERO), $vec4::ONE); |
| 1629 |
assert_eq!($vec4::ZERO.copysign(-$vec4::ONE), -$vec4::ZERO); |
| 1630 |
assert_eq!((-$vec4::ZERO).copysign(-$vec4::ONE), -$vec4::ZERO); |
| 1631 |
assert_eq!($vec4::ZERO.copysign($vec4::ONE), $vec4::ZERO); |
| 1632 |
assert_eq!((-$vec4::ZERO).copysign($vec4::ONE), $vec4::ZERO); |
| 1633 |
assert_eq!($vec4::ONE.copysign(-$vec4::ONE), -$vec4::ONE); |
| 1634 |
assert_eq!((-$vec4::ONE).copysign(-$vec4::ONE), -$vec4::ONE); |
| 1635 |
assert_eq!($vec4::ONE.copysign($vec4::ONE), $vec4::ONE); |
| 1636 |
assert_eq!((-$vec4::ONE).copysign($vec4::ONE), $vec4::ONE); |
| 1637 |
assert_eq!($vec4::INFINITY.copysign($vec4::ONE), $vec4::INFINITY); |
| 1638 |
assert_eq!($vec4::INFINITY.copysign(-$vec4::ONE), $vec4::NEG_INFINITY); |
| 1639 |
assert_eq!($vec4::NEG_INFINITY.copysign($vec4::ONE), $vec4::INFINITY); |
| 1640 |
assert_eq!( |
| 1641 |
$vec4::NEG_INFINITY.copysign(-$vec4::ONE), |
| 1642 |
$vec4::NEG_INFINITY |
| 1643 |
); |
| 1644 |
assert!($vec4::NAN.copysign($vec4::ONE).is_nan_mask().all()); |
| 1645 |
assert!($vec4::NAN.copysign(-$vec4::ONE).is_nan_mask().all()); |
| 1646 |
}); |
| 1647 |
|
| 1648 |
glam_test!(test_float_is_negative_bitmask, { |
| 1649 |
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000); |
| 1650 |
assert_eq!((-$vec4::ZERO).is_negative_bitmask(), 0b1111); |
| 1651 |
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000); |
| 1652 |
assert_eq!((-$vec4::ONE).is_negative_bitmask(), 0b1111); |
| 1653 |
assert_eq!( |
| 1654 |
$vec4::new(-1.0, 2.0, 3.0, -4.0).is_negative_bitmask(), |
| 1655 |
0b1001 |
| 1656 |
); |
| 1657 |
assert_eq!( |
| 1658 |
$vec4::new(8.0, 3.0, 1.0, -0.0).is_negative_bitmask(), |
| 1659 |
0b1000 |
| 1660 |
); |
| 1661 |
assert_eq!( |
| 1662 |
$vec4::new(1.0, 5.0, -3.0, 7.0).is_negative_bitmask(), |
| 1663 |
0b0100 |
| 1664 |
); |
| 1665 |
assert_eq!( |
| 1666 |
$vec4::new(3.0, -4.0, 1.0, 6.0).is_negative_bitmask(), |
| 1667 |
0b0010 |
| 1668 |
); |
| 1669 |
assert_eq!( |
| 1670 |
$vec4::new(2.0, -6.0, 5.0, -3.0).is_negative_bitmask(), |
| 1671 |
0b1010 |
| 1672 |
); |
| 1673 |
}); |
| 1674 |
|
| 1675 |
glam_test!(test_round, { |
| 1676 |
assert_eq!($vec4::new(1.35, 0.0, 0.0, 0.0).round().x, 1.0); |
| 1677 |
assert_eq!($vec4::new(0.0, 1.5, 0.0, 0.0).round().y, 2.0); |
| 1678 |
assert_eq!($vec4::new(0.0, 0.0, -15.5, 0.0).round().z, -16.0); |
| 1679 |
assert_eq!($vec4::new(0.0, 0.0, 0.0, 0.0).round().z, 0.0); |
| 1680 |
assert_eq!($vec4::new(0.0, 21.1, 0.0, 0.0).round().y, 21.0); |
| 1681 |
assert_eq!($vec4::new(0.0, 0.0, 0.0, 11.123).round().w, 11.0); |
| 1682 |
assert_eq!($vec4::new(0.0, 0.0, 11.501, 0.0).round().z, 12.0); |
| 1683 |
assert_eq!( |
| 1684 |
$vec4::new($t::NEG_INFINITY, $t::INFINITY, 1.0, -1.0).round(), |
| 1685 |
$vec4::new($t::NEG_INFINITY, $t::INFINITY, 1.0, -1.0) |
| 1686 |
); |
| 1687 |
assert!($vec4::new($t::NAN, 0.0, 0.0, 1.0).round().x.is_nan()); |
| 1688 |
}); |
| 1689 |
|
| 1690 |
glam_test!(test_floor, { |
| 1691 |
assert_eq!( |
| 1692 |
$vec4::new(1.35, 1.5, -1.5, 1.999).floor(), |
| 1693 |
$vec4::new(1.0, 1.0, -2.0, 1.0) |
| 1694 |
); |
| 1695 |
assert_eq!( |
| 1696 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0).floor(), |
| 1697 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0) |
| 1698 |
); |
| 1699 |
assert!($vec4::new(0.0, $t::NAN, 0.0, 0.0).floor().y.is_nan()); |
| 1700 |
assert_eq!( |
| 1701 |
$vec4::new(-0.0, -2000000.123, 10000000.123, 1000.9).floor(), |
| 1702 |
$vec4::new(-0.0, -2000001.0, 10000000.0, 1000.0) |
| 1703 |
); |
| 1704 |
}); |
| 1705 |
|
| 1706 |
glam_test!(test_fract_gl, { |
| 1707 |
assert_approx_eq!( |
| 1708 |
$vec4::new(1.35, 1.5, -1.5, 1.999).fract_gl(), |
| 1709 |
$vec4::new(0.35, 0.5, 0.5, 0.999) |
| 1710 |
); |
| 1711 |
assert_approx_eq!( |
| 1712 |
$vec4::new(-0.0, -200000.123, 1000000.123, 1000.9).fract_gl(), |
| 1713 |
$vec4::new(0.0, 0.877, 0.123, 0.9), |
| 1714 |
0.002 |
| 1715 |
); |
| 1716 |
}); |
| 1717 |
|
| 1718 |
glam_test!(test_fract, { |
| 1719 |
assert_approx_eq!( |
| 1720 |
$vec4::new(1.35, 1.5, -1.5, 1.999).fract(), |
| 1721 |
$vec4::new(0.35, 0.5, -0.5, 0.999) |
| 1722 |
); |
| 1723 |
assert_approx_eq!( |
| 1724 |
$vec4::new(-0.0, -200000.123, 1000000.123, 1000.9).fract(), |
| 1725 |
$vec4::new(0.0, -0.123, 0.123, 0.9), |
| 1726 |
0.002 |
| 1727 |
); |
| 1728 |
}); |
| 1729 |
|
| 1730 |
glam_test!(test_ceil, { |
| 1731 |
assert_eq!( |
| 1732 |
$vec4::new(1.35, 1.5, -1.5, 1234.1234).ceil(), |
| 1733 |
$vec4::new(2.0, 2.0, -1.0, 1235.0) |
| 1734 |
); |
| 1735 |
assert_eq!( |
| 1736 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0).ceil(), |
| 1737 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0) |
| 1738 |
); |
| 1739 |
assert!($vec4::new(0.0, 0.0, $t::NAN, 0.0).ceil().z.is_nan()); |
| 1740 |
assert_eq!( |
| 1741 |
$vec4::new(-1234.1234, -2000000.123, 1000000.123, 1000.9).ceil(), |
| 1742 |
$vec4::new(-1234.0, -2000000.0, 1000001.0, 1001.0) |
| 1743 |
); |
| 1744 |
}); |
| 1745 |
|
| 1746 |
glam_test!(test_trunc, { |
| 1747 |
assert_eq!( |
| 1748 |
$vec4::new(1.35, 1.5, -1.5, 1.999).trunc(), |
| 1749 |
$vec4::new(1.0, 1.0, -1.0, 1.0) |
| 1750 |
); |
| 1751 |
assert_eq!( |
| 1752 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0).trunc(), |
| 1753 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0) |
| 1754 |
); |
| 1755 |
assert!($vec4::new(0.0, $t::NAN, 0.0, 0.0).trunc().y.is_nan()); |
| 1756 |
assert_eq!( |
| 1757 |
$vec4::new(-0.0, -2000000.123, 10000000.123, 1000.9).trunc(), |
| 1758 |
$vec4::new(-0.0, -2000000.0, 10000000.0, 1000.0) |
| 1759 |
); |
| 1760 |
}); |
| 1761 |
|
| 1762 |
glam_test!(test_lerp, { |
| 1763 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1764 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1765 |
assert_approx_eq!(v0, v0.lerp(v1, 0.0)); |
| 1766 |
assert_approx_eq!(v1, v0.lerp(v1, 1.0)); |
| 1767 |
assert_approx_eq!($vec4::ZERO, v0.lerp(v1, 0.5)); |
| 1768 |
}); |
| 1769 |
|
| 1770 |
glam_test!(test_lerp_big_difference, { |
| 1771 |
let v0 = $vec4::new(-1e30, -1e30, -1e30, -1e30); |
| 1772 |
let v1 = $vec4::new(16.0, 16.0, 16.0, 16.0); |
| 1773 |
assert_approx_eq!(v0, v0.lerp(v1, 0.0)); |
| 1774 |
assert_approx_eq!(v1, v0.lerp(v1, 1.0)); |
| 1775 |
}); |
| 1776 |
|
| 1777 |
glam_test!(test_move_towards, { |
| 1778 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1779 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1780 |
assert_approx_eq!(v0, v0.move_towards(v1, 0.0)); |
| 1781 |
assert_approx_eq!(v1, v0.move_towards(v1, v0.distance(v1))); |
| 1782 |
assert_approx_eq!(v1, v0.move_towards(v1, v0.distance(v1) + 1.0)); |
| 1783 |
}); |
| 1784 |
|
| 1785 |
glam_test!(test_midpoint, { |
| 1786 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1787 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1788 |
let v2 = $vec4::new(-1.5, 0.0, 1.0, 0.5); |
| 1789 |
assert_approx_eq!($vec4::ZERO, v0.midpoint(v1)); |
| 1790 |
assert_approx_eq!($vec4::new(-0.25, 0.5, 1.0, 0.75), v1.midpoint(v2)); |
| 1791 |
}); |
| 1792 |
|
| 1793 |
glam_test!(test_is_finite, { |
| 1794 |
assert!($vec4::new(0.0, 0.0, 0.0, 0.0).is_finite()); |
| 1795 |
assert!($vec4::new(-1e-10, 1.0, 1e10, 42.0).is_finite()); |
| 1796 |
assert!(!$vec4::new($t::INFINITY, 0.0, 0.0, 0.0).is_finite()); |
| 1797 |
assert!(!$vec4::new(0.0, $t::NAN, 0.0, 0.0).is_finite()); |
| 1798 |
assert!(!$vec4::new(0.0, 0.0, $t::NEG_INFINITY, 0.0).is_finite()); |
| 1799 |
assert!(!$vec4::new(0.0, 0.0, 0.0, $t::NAN).is_finite()); |
| 1800 |
assert!(!$vec4::INFINITY.is_finite()); |
| 1801 |
assert!(!$vec4::NEG_INFINITY.is_finite()); |
| 1802 |
}); |
| 1803 |
|
| 1804 |
glam_test!(test_powf, { |
| 1805 |
assert_eq!( |
| 1806 |
$vec4::new(2.0, 4.0, 8.0, 16.0).powf(2.0), |
| 1807 |
$vec4::new(4.0, 16.0, 64.0, 256.0) |
| 1808 |
); |
| 1809 |
}); |
| 1810 |
|
| 1811 |
glam_test!(test_exp, { |
| 1812 |
assert_approx_eq!( |
| 1813 |
$vec4::new(1.0, 2.0, 3.0, 4.0).exp(), |
| 1814 |
$vec4::new( |
| 1815 |
(1.0 as $t).exp(), |
| 1816 |
(2.0 as $t).exp(), |
| 1817 |
(3.0 as $t).exp(), |
| 1818 |
(4.0 as $t).exp() |
| 1819 |
), |
| 1820 |
1e-5 |
| 1821 |
); |
| 1822 |
}); |
| 1823 |
|
| 1824 |
glam_test!(test_exp2, { |
| 1825 |
assert_approx_eq!( |
| 1826 |
$vec4::new(1.0, 2.0, 3.0, 4.0).exp2(), |
| 1827 |
$vec4::new( |
| 1828 |
(1.0 as $t).exp2(), |
| 1829 |
(2.0 as $t).exp2(), |
| 1830 |
(3.0 as $t).exp2(), |
| 1831 |
(4.0 as $t).exp2() |
| 1832 |
), |
| 1833 |
1e-5 |
| 1834 |
); |
| 1835 |
}); |
| 1836 |
|
| 1837 |
glam_test!(test_ln, { |
| 1838 |
assert_approx_eq!( |
| 1839 |
$vec4::new(1.0, 2.0, 3.0, 4.0).ln(), |
| 1840 |
$vec4::new( |
| 1841 |
(1.0 as $t).ln(), |
| 1842 |
(2.0 as $t).ln(), |
| 1843 |
(3.0 as $t).ln(), |
| 1844 |
(4.0 as $t).ln() |
| 1845 |
), |
| 1846 |
1e-5 |
| 1847 |
); |
| 1848 |
assert!($vec4::NEG_ONE.ln().is_nan()); |
| 1849 |
assert_eq!($vec4::ZERO.ln(), $vec4::NEG_INFINITY); |
| 1850 |
}); |
| 1851 |
|
| 1852 |
glam_test!(test_log2, { |
| 1853 |
assert_approx_eq!( |
| 1854 |
$vec4::new(1.0, 2.0, 3.0, 4.0).log2(), |
| 1855 |
$vec4::new( |
| 1856 |
(1.0 as $t).log2(), |
| 1857 |
(2.0 as $t).log2(), |
| 1858 |
(3.0 as $t).log2(), |
| 1859 |
(4.0 as $t).log2() |
| 1860 |
), |
| 1861 |
1e-5 |
| 1862 |
); |
| 1863 |
assert!($vec4::NEG_ONE.log2().is_nan()); |
| 1864 |
assert_eq!($vec4::ZERO.log2(), $vec4::NEG_INFINITY); |
| 1865 |
}); |
| 1866 |
|
| 1867 |
glam_test!(test_clamp_length, { |
| 1868 |
// Too long gets shortened |
| 1869 |
assert_eq!( |
| 1870 |
$vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length(7.0, 10.0), |
| 1871 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0 |
| 1872 |
); |
| 1873 |
// In the middle is unchanged |
| 1874 |
assert_eq!( |
| 1875 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length(0.5, 5.0), |
| 1876 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1877 |
); |
| 1878 |
// Too short gets lengthened |
| 1879 |
assert_eq!( |
| 1880 |
$vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length(10.0, 20.0), |
| 1881 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0 |
| 1882 |
); |
| 1883 |
should_glam_assert!({ $vec4::ONE.clamp_length(1.0, 0.0) }); |
| 1884 |
}); |
| 1885 |
|
| 1886 |
glam_test!(test_clamp_length_max, { |
| 1887 |
// Too long gets shortened |
| 1888 |
assert_eq!( |
| 1889 |
$vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length_max(10.0), |
| 1890 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0 |
| 1891 |
); |
| 1892 |
// Not too long is unchanged |
| 1893 |
assert_eq!( |
| 1894 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_max(5.0), |
| 1895 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1896 |
); |
| 1897 |
}); |
| 1898 |
|
| 1899 |
glam_test!(test_clamp_length_min, { |
| 1900 |
// Not too short is unchanged |
| 1901 |
assert_eq!( |
| 1902 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_min(0.5), |
| 1903 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1904 |
); |
| 1905 |
// Too short gets lengthened |
| 1906 |
assert_eq!( |
| 1907 |
$vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length_min(10.0), |
| 1908 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0 |
| 1909 |
); |
| 1910 |
}); |
| 1911 |
|
| 1912 |
glam_test!(test_mul_add, { |
| 1913 |
assert_eq!( |
| 1914 |
$vec4::new(1.0, 1.0, 1.0, 1.0).mul_add( |
| 1915 |
$vec4::new(0.5, 2.0, -4.0, 0.0), |
| 1916 |
$vec4::new(-1.0, -1.0, -1.0, -1.0) |
| 1917 |
), |
| 1918 |
$vec4::new(-0.5, 1.0, -5.0, -1.0) |
| 1919 |
); |
| 1920 |
}); |
| 1921 |
|
| 1922 |
glam_test!(test_fmt_float, { |
| 1923 |
let a = $vec4::new(1.0, 2.0, 3.0, 4.0); |
| 1924 |
assert_eq!(format!("{:.2}", a), "[1.00, 2.00, 3.00, 4.00]"); |
| 1925 |
}); |
| 1926 |
|
| 1927 |
glam_test!(test_reflect, { |
| 1928 |
let incident = $vec4::new(1.0, -1.0, 1.0, 1.0); |
| 1929 |
let normal = $vec4::Y; |
| 1930 |
assert_approx_eq!(incident.reflect(normal), $vec4::ONE); |
| 1931 |
}); |
| 1932 |
|
| 1933 |
glam_test!(test_refract, { |
| 1934 |
let incident = $vec4::NEG_ONE.normalize(); |
| 1935 |
let normal = $vec4::ONE.normalize(); |
| 1936 |
assert_approx_eq!(incident.refract(normal, 0.5), incident); |
| 1937 |
|
| 1938 |
let incident = $vec4::new(1.0, -1.0, 0.0, 0.0).normalize(); |
| 1939 |
let normal = $vec4::Y; |
| 1940 |
assert_approx_eq!(incident.refract(normal, 1.5), $vec4::ZERO); |
| 1941 |
}); |
| 1942 |
|
| 1943 |
glam_test!(test_homogeneous, { |
| 1944 |
let v = $vec4::new(1.0, 2.0, 3.0, 1.0); |
| 1945 |
assert_approx_eq!(v, v.project().to_homogeneous()); |
| 1946 |
}); |
| 1947 |
}; |
| 1948 |
} |
| 1949 |
|
| 1950 |
macro_rules! impl_vec4_scalar_shift_op_test { |
| 1951 |
($vec4:ident, $t_min:literal, $t_max:literal, $rhs_min:literal, $rhs_max:literal) => { |
| 1952 |
glam_test!(test_vec4_scalar_shift_ops, { |
| 1953 |
for x in $t_min..$t_max { |
| 1954 |
for y in $t_min..$t_max { |
| 1955 |
for z in $t_min..$t_max { |
| 1956 |
for w in $t_min..$t_max { |
| 1957 |
for rhs in $rhs_min..$rhs_max { |
| 1958 |
let lhs = $vec4::new(x, y, z, w); |
| 1959 |
assert_eq!( |
| 1960 |
lhs << rhs, |
| 1961 |
$vec4::new(x << rhs, y << rhs, z << rhs, w << rhs) |
| 1962 |
); |
| 1963 |
assert_eq!( |
| 1964 |
lhs >> rhs, |
| 1965 |
$vec4::new(x >> rhs, y >> rhs, z >> rhs, w >> rhs) |
| 1966 |
); |
| 1967 |
|
| 1968 |
assert_eq!( |
| 1969 |
&lhs << rhs, |
| 1970 |
$vec4::new(x << rhs, y << rhs, z << rhs, w << rhs) |
| 1971 |
); |
| 1972 |
assert_eq!( |
| 1973 |
&lhs >> rhs, |
| 1974 |
$vec4::new(x >> rhs, y >> rhs, z >> rhs, w >> rhs) |
| 1975 |
); |
| 1976 |
|
| 1977 |
assert_eq!( |
| 1978 |
lhs << &rhs, |
| 1979 |
$vec4::new(x << rhs, y << rhs, z << rhs, w << rhs) |
| 1980 |
); |
| 1981 |
assert_eq!( |
| 1982 |
lhs >> &rhs, |
| 1983 |
$vec4::new(x >> rhs, y >> rhs, z >> rhs, w >> rhs) |
| 1984 |
); |
| 1985 |
|
| 1986 |
assert_eq!( |
| 1987 |
&lhs << &rhs, |
| 1988 |
$vec4::new(x << rhs, y << rhs, z << rhs, w << rhs) |
| 1989 |
); |
| 1990 |
assert_eq!( |
| 1991 |
&lhs >> &rhs, |
| 1992 |
$vec4::new(x >> rhs, y >> rhs, z >> rhs, w >> rhs) |
| 1993 |
); |
| 1994 |
|
| 1995 |
let mut a = lhs; |
| 1996 |
a <<= rhs; |
| 1997 |
assert_eq!(a, lhs << rhs); |
| 1998 |
|
| 1999 |
let mut a = lhs; |
| 2000 |
a <<= &rhs; |
| 2001 |
assert_eq!(a, lhs << rhs); |
| 2002 |
|
| 2003 |
let mut a = lhs; |
| 2004 |
a >>= rhs; |
| 2005 |
assert_eq!(a, lhs >> rhs); |
| 2006 |
|
| 2007 |
let mut a = lhs; |
| 2008 |
a >>= &rhs; |
| 2009 |
assert_eq!(a, lhs >> rhs); |
| 2010 |
} |
| 2011 |
} |
| 2012 |
} |
| 2013 |
} |
| 2014 |
} |
| 2015 |
}); |
| 2016 |
}; |
| 2017 |
} |
| 2018 |
|
| 2019 |
macro_rules! impl_vec4_scalar_shift_op_tests { |
| 2020 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 2021 |
mod shift_by_i8 { |
| 2022 |
use glam::$vec4; |
| 2023 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i8, 2); |
| 2024 |
} |
| 2025 |
mod shift_by_i16 { |
| 2026 |
use glam::$vec4; |
| 2027 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i16, 2); |
| 2028 |
} |
| 2029 |
mod shift_by_i32 { |
| 2030 |
use glam::$vec4; |
| 2031 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i32, 2); |
| 2032 |
} |
| 2033 |
mod shift_by_i64 { |
| 2034 |
use glam::$vec4; |
| 2035 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i64, 2); |
| 2036 |
} |
| 2037 |
mod shift_by_u8 { |
| 2038 |
use glam::$vec4; |
| 2039 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u8, 2); |
| 2040 |
} |
| 2041 |
mod shift_by_u16 { |
| 2042 |
use glam::$vec4; |
| 2043 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u16, 2); |
| 2044 |
} |
| 2045 |
mod shift_by_u32 { |
| 2046 |
use glam::$vec4; |
| 2047 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u32, 2); |
| 2048 |
} |
| 2049 |
mod shift_by_u64 { |
| 2050 |
use glam::$vec4; |
| 2051 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u64, 2); |
| 2052 |
} |
| 2053 |
}; |
| 2054 |
} |
| 2055 |
|
| 2056 |
macro_rules! impl_vec4_shift_op_test { |
| 2057 |
($vec4:ident, $rhs:ident, $t_min:literal, $t_max:literal) => { |
| 2058 |
glam_test!(test_vec4_shift_ops, { |
| 2059 |
for x1 in $t_min..$t_max { |
| 2060 |
for y1 in $t_min..$t_max { |
| 2061 |
for z1 in $t_min..$t_max { |
| 2062 |
for w1 in $t_min..$t_max { |
| 2063 |
for x2 in $t_min..$t_max { |
| 2064 |
for y2 in $t_min..$t_max { |
| 2065 |
for z2 in $t_min..$t_max { |
| 2066 |
for w2 in $t_min..$t_max { |
| 2067 |
let lhs = $vec4::new(x1, y1, z1, w1); |
| 2068 |
let rhs = $rhs::new(x2, y2, z2, w2); |
| 2069 |
|
| 2070 |
let shl = |
| 2071 |
$vec4::new(x1 << x2, y1 << y2, z1 << z2, w1 << w2); |
| 2072 |
assert_eq!(lhs << rhs, shl); |
| 2073 |
assert_eq!(&lhs << rhs, shl); |
| 2074 |
assert_eq!(lhs << &rhs, shl); |
| 2075 |
assert_eq!(&lhs << &rhs, shl); |
| 2076 |
|
| 2077 |
let shr = |
| 2078 |
$vec4::new(x1 >> x2, y1 >> y2, z1 >> z2, w1 >> w2); |
| 2079 |
assert_eq!(lhs >> rhs, shr); |
| 2080 |
assert_eq!(&lhs >> rhs, shr); |
| 2081 |
assert_eq!(lhs >> &rhs, shr); |
| 2082 |
assert_eq!(&lhs >> &rhs, shr); |
| 2083 |
} |
| 2084 |
} |
| 2085 |
} |
| 2086 |
} |
| 2087 |
} |
| 2088 |
} |
| 2089 |
} |
| 2090 |
} |
| 2091 |
}); |
| 2092 |
}; |
| 2093 |
} |
| 2094 |
|
| 2095 |
macro_rules! impl_vec4_shift_op_tests { |
| 2096 |
($vec4:ident) => { |
| 2097 |
mod shift_ivec4_by_ivec4 { |
| 2098 |
use super::*; |
| 2099 |
impl_vec4_shift_op_test!($vec4, IVec4, 0, 2); |
| 2100 |
} |
| 2101 |
mod shift_ivec4_by_uvec4 { |
| 2102 |
use super::*; |
| 2103 |
impl_vec4_shift_op_test!($vec4, UVec4, 0, 2); |
| 2104 |
} |
| 2105 |
}; |
| 2106 |
} |
| 2107 |
|
| 2108 |
macro_rules! impl_vec4_scalar_bit_op_tests { |
| 2109 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 2110 |
glam_test!(test_vec4_scalar_bit_ops, { |
| 2111 |
for x in $t_min..$t_max { |
| 2112 |
for y in $t_min..$t_max { |
| 2113 |
for z in $t_min..$t_max { |
| 2114 |
for w in $t_min..$t_max { |
| 2115 |
for rhs in $t_min..$t_max { |
| 2116 |
let lhs = $vec4::new(x, y, z, w); |
| 2117 |
assert_eq!( |
| 2118 |
lhs & rhs, |
| 2119 |
$vec4::new(x & rhs, y & rhs, z & rhs, w & rhs) |
| 2120 |
); |
| 2121 |
assert_eq!( |
| 2122 |
lhs | rhs, |
| 2123 |
$vec4::new(x | rhs, y | rhs, z | rhs, w | rhs) |
| 2124 |
); |
| 2125 |
assert_eq!( |
| 2126 |
lhs ^ rhs, |
| 2127 |
$vec4::new(x ^ rhs, y ^ rhs, z ^ rhs, w ^ rhs) |
| 2128 |
); |
| 2129 |
|
| 2130 |
assert_eq!( |
| 2131 |
&lhs & rhs, |
| 2132 |
$vec4::new(x & rhs, y & rhs, z & rhs, w & rhs) |
| 2133 |
); |
| 2134 |
assert_eq!( |
| 2135 |
&lhs | rhs, |
| 2136 |
$vec4::new(x | rhs, y | rhs, z | rhs, w | rhs) |
| 2137 |
); |
| 2138 |
assert_eq!( |
| 2139 |
&lhs ^ rhs, |
| 2140 |
$vec4::new(x ^ rhs, y ^ rhs, z ^ rhs, w ^ rhs) |
| 2141 |
); |
| 2142 |
|
| 2143 |
assert_eq!( |
| 2144 |
lhs & &rhs, |
| 2145 |
$vec4::new(x & rhs, y & rhs, z & rhs, w & rhs) |
| 2146 |
); |
| 2147 |
assert_eq!( |
| 2148 |
lhs | &rhs, |
| 2149 |
$vec4::new(x | rhs, y | rhs, z | rhs, w | rhs) |
| 2150 |
); |
| 2151 |
assert_eq!( |
| 2152 |
lhs ^ &rhs, |
| 2153 |
$vec4::new(x ^ rhs, y ^ rhs, z ^ rhs, w ^ rhs) |
| 2154 |
); |
| 2155 |
|
| 2156 |
assert_eq!( |
| 2157 |
&lhs & &rhs, |
| 2158 |
$vec4::new(x & rhs, y & rhs, z & rhs, w & rhs) |
| 2159 |
); |
| 2160 |
assert_eq!( |
| 2161 |
&lhs | &rhs, |
| 2162 |
$vec4::new(x | rhs, y | rhs, z | rhs, w | rhs) |
| 2163 |
); |
| 2164 |
assert_eq!( |
| 2165 |
&lhs ^ &rhs, |
| 2166 |
$vec4::new(x ^ rhs, y ^ rhs, z ^ rhs, w ^ rhs) |
| 2167 |
); |
| 2168 |
|
| 2169 |
let mut a = lhs; |
| 2170 |
a &= rhs; |
| 2171 |
assert_eq!(a, lhs & rhs); |
| 2172 |
|
| 2173 |
let mut a = lhs; |
| 2174 |
a &= &rhs; |
| 2175 |
assert_eq!(a, lhs & rhs); |
| 2176 |
|
| 2177 |
let mut a = lhs; |
| 2178 |
a |= rhs; |
| 2179 |
assert_eq!(a, lhs | rhs); |
| 2180 |
|
| 2181 |
let mut a = lhs; |
| 2182 |
a |= &rhs; |
| 2183 |
assert_eq!(a, lhs | rhs); |
| 2184 |
|
| 2185 |
let mut a = lhs; |
| 2186 |
a ^= rhs; |
| 2187 |
assert_eq!(a, lhs ^ rhs); |
| 2188 |
|
| 2189 |
let mut a = lhs; |
| 2190 |
a ^= &rhs; |
| 2191 |
assert_eq!(a, lhs ^ rhs); |
| 2192 |
} |
| 2193 |
} |
| 2194 |
} |
| 2195 |
} |
| 2196 |
} |
| 2197 |
}); |
| 2198 |
}; |
| 2199 |
} |
| 2200 |
|
| 2201 |
macro_rules! impl_vec4_bit_op_tests { |
| 2202 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 2203 |
glam_test!(test_vec4_bit_ops, { |
| 2204 |
for x1 in $t_min..$t_max { |
| 2205 |
for y1 in $t_min..$t_max { |
| 2206 |
for z1 in $t_min..$t_max { |
| 2207 |
for w1 in $t_min..$t_max { |
| 2208 |
let lhs = $vec4::new(x1, y1, z1, w1); |
| 2209 |
assert_eq!(!lhs, $vec4::new(!x1, !y1, !z1, !w1)); |
| 2210 |
assert_eq!(!&lhs, $vec4::new(!x1, !y1, !z1, !w1)); |
| 2211 |
|
| 2212 |
for x2 in $t_min..$t_max { |
| 2213 |
for y2 in $t_min..$t_max { |
| 2214 |
for z2 in $t_min..$t_max { |
| 2215 |
for w2 in $t_min..$t_max { |
| 2216 |
let rhs = $vec4::new(x2, y2, z2, w2); |
| 2217 |
assert_eq!( |
| 2218 |
lhs & rhs, |
| 2219 |
$vec4::new(x1 & x2, y1 & y2, z1 & z2, w1 & w2) |
| 2220 |
); |
| 2221 |
assert_eq!( |
| 2222 |
lhs | rhs, |
| 2223 |
$vec4::new(x1 | x2, y1 | y2, z1 | z2, w1 | w2) |
| 2224 |
); |
| 2225 |
assert_eq!( |
| 2226 |
lhs ^ rhs, |
| 2227 |
$vec4::new(x1 ^ x2, y1 ^ y2, z1 ^ z2, w1 ^ w2) |
| 2228 |
); |
| 2229 |
|
| 2230 |
assert_eq!( |
| 2231 |
&lhs & rhs, |
| 2232 |
$vec4::new(x1 & x2, y1 & y2, z1 & z2, w1 & w2) |
| 2233 |
); |
| 2234 |
assert_eq!( |
| 2235 |
&lhs | rhs, |
| 2236 |
$vec4::new(x1 | x2, y1 | y2, z1 | z2, w1 | w2) |
| 2237 |
); |
| 2238 |
assert_eq!( |
| 2239 |
&lhs ^ rhs, |
| 2240 |
$vec4::new(x1 ^ x2, y1 ^ y2, z1 ^ z2, w1 ^ w2) |
| 2241 |
); |
| 2242 |
|
| 2243 |
assert_eq!( |
| 2244 |
lhs & &rhs, |
| 2245 |
$vec4::new(x1 & x2, y1 & y2, z1 & z2, w1 & w2) |
| 2246 |
); |
| 2247 |
assert_eq!( |
| 2248 |
lhs | &rhs, |
| 2249 |
$vec4::new(x1 | x2, y1 | y2, z1 | z2, w1 | w2) |
| 2250 |
); |
| 2251 |
assert_eq!( |
| 2252 |
lhs ^ &rhs, |
| 2253 |
$vec4::new(x1 ^ x2, y1 ^ y2, z1 ^ z2, w1 ^ w2) |
| 2254 |
); |
| 2255 |
|
| 2256 |
assert_eq!( |
| 2257 |
&lhs & &rhs, |
| 2258 |
$vec4::new(x1 & x2, y1 & y2, z1 & z2, w1 & w2) |
| 2259 |
); |
| 2260 |
assert_eq!( |
| 2261 |
&lhs | &rhs, |
| 2262 |
$vec4::new(x1 | x2, y1 | y2, z1 | z2, w1 | w2) |
| 2263 |
); |
| 2264 |
assert_eq!( |
| 2265 |
&lhs ^ &rhs, |
| 2266 |
$vec4::new(x1 ^ x2, y1 ^ y2, z1 ^ z2, w1 ^ w2) |
| 2267 |
); |
| 2268 |
|
| 2269 |
let mut a = lhs; |
| 2270 |
a &= rhs; |
| 2271 |
assert_eq!(a, lhs & rhs); |
| 2272 |
|
| 2273 |
let mut a = lhs; |
| 2274 |
a &= &rhs; |
| 2275 |
assert_eq!(a, lhs & rhs); |
| 2276 |
|
| 2277 |
let mut a = lhs; |
| 2278 |
a |= rhs; |
| 2279 |
assert_eq!(a, lhs | rhs); |
| 2280 |
|
| 2281 |
let mut a = lhs; |
| 2282 |
a |= &rhs; |
| 2283 |
assert_eq!(a, lhs | rhs); |
| 2284 |
|
| 2285 |
let mut a = lhs; |
| 2286 |
a ^= rhs; |
| 2287 |
assert_eq!(a, lhs ^ rhs); |
| 2288 |
|
| 2289 |
let mut a = lhs; |
| 2290 |
a ^= &rhs; |
| 2291 |
assert_eq!(a, lhs ^ rhs); |
| 2292 |
} |
| 2293 |
} |
| 2294 |
} |
| 2295 |
} |
| 2296 |
} |
| 2297 |
} |
| 2298 |
} |
| 2299 |
} |
| 2300 |
}); |
| 2301 |
}; |
| 2302 |
} |
| 2303 |
|
| 2304 |
mod bvec4 { |
| 2305 |
use glam::{bvec4, BVec4}; |
| 2306 |
|
| 2307 |
glam_test!(test_mask_align, { |
| 2308 |
use std::mem; |
| 2309 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 2310 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 2311 |
}); |
| 2312 |
|
| 2313 |
impl_bvec4_tests!(BVec4, bvec4); |
| 2314 |
} |
| 2315 |
|
| 2316 |
mod bvec4a { |
| 2317 |
use glam::{bvec4a, BVec4A}; |
| 2318 |
|
| 2319 |
glam_test!(test_mask_align, { |
| 2320 |
use std::mem; |
| 2321 |
assert_eq!(16, mem::size_of::<BVec4A>()); |
| 2322 |
assert_eq!(16, mem::align_of::<BVec4A>()); |
| 2323 |
}); |
| 2324 |
|
| 2325 |
impl_bvec4_tests!(BVec4A, bvec4a); |
| 2326 |
} |
| 2327 |
|
| 2328 |
mod vec4 { |
| 2329 |
#[cfg(feature = "scalar-math")] |
| 2330 |
use glam::BVec4; |
| 2331 |
#[cfg(not(feature = "scalar-math"))] |
| 2332 |
use glam::BVec4A; |
| 2333 |
use glam::{vec4, Vec2, Vec3, Vec4}; |
| 2334 |
|
| 2335 |
glam_test!(test_align, { |
| 2336 |
use std::mem; |
| 2337 |
assert_eq!(16, mem::size_of::<Vec4>()); |
| 2338 |
if cfg!(any(not(feature = "scalar-math"), feature = "cuda")) { |
| 2339 |
assert_eq!(16, mem::align_of::<Vec4>()); |
| 2340 |
} else { |
| 2341 |
assert_eq!(4, mem::align_of::<Vec4>()); |
| 2342 |
} |
| 2343 |
}); |
| 2344 |
|
| 2345 |
#[cfg(all( |
| 2346 |
target_feature = "sse2", |
| 2347 |
not(any(feature = "core-simd", feature = "scalar-math")) |
| 2348 |
))] |
| 2349 |
#[test] |
| 2350 |
fn test_m128() { |
| 2351 |
#[cfg(target_arch = "x86")] |
| 2352 |
use core::arch::x86::*; |
| 2353 |
#[cfg(target_arch = "x86_64")] |
| 2354 |
use core::arch::x86_64::*; |
| 2355 |
|
| 2356 |
#[repr(C, align(16))] |
| 2357 |
struct F32x4_A16([f32; 4]); |
| 2358 |
|
| 2359 |
let v0 = Vec4::new(1.0, 2.0, 3.0, 4.0); |
| 2360 |
let m0: __m128 = v0.into(); |
| 2361 |
let mut a0 = F32x4_A16([0.0, 0.0, 0.0, 0.0]); |
| 2362 |
unsafe { |
| 2363 |
_mm_store_ps(a0.0.as_mut_ptr(), m0); |
| 2364 |
} |
| 2365 |
assert_eq!([1.0, 2.0, 3.0, 4.0], a0.0); |
| 2366 |
let v1 = Vec4::from(m0); |
| 2367 |
assert_eq!(v0, v1); |
| 2368 |
|
| 2369 |
#[repr(C, align(16))] |
| 2370 |
struct U32x4_A16([u32; 4]); |
| 2371 |
|
| 2372 |
let v0 = BVec4A::new(true, false, true, false); |
| 2373 |
let m0: __m128 = v0.into(); |
| 2374 |
let mut a0 = U32x4_A16([1, 2, 3, 4]); |
| 2375 |
unsafe { |
| 2376 |
_mm_store_ps(a0.0.as_mut_ptr() as *mut f32, m0); |
| 2377 |
} |
| 2378 |
assert_eq!([0xffffffff, 0, 0xffffffff, 0], a0.0); |
| 2379 |
} |
| 2380 |
|
| 2381 |
glam_test!(test_as, { |
| 2382 |
use glam::{ |
| 2383 |
DVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec4, USizeVec4, UVec4, |
| 2384 |
Vec4, |
| 2385 |
}; |
| 2386 |
assert_eq!( |
| 2387 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2388 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_dvec4() |
| 2389 |
); |
| 2390 |
assert_eq!( |
| 2391 |
I8Vec4::new(-1, -2, -3, -4), |
| 2392 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i8vec4() |
| 2393 |
); |
| 2394 |
assert_eq!( |
| 2395 |
U8Vec4::new(1, 2, 3, 4), |
| 2396 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u8vec4() |
| 2397 |
); |
| 2398 |
assert_eq!( |
| 2399 |
I16Vec4::new(-1, -2, -3, -4), |
| 2400 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i16vec4() |
| 2401 |
); |
| 2402 |
assert_eq!( |
| 2403 |
U16Vec4::new(1, 2, 3, 4), |
| 2404 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u16vec4() |
| 2405 |
); |
| 2406 |
assert_eq!( |
| 2407 |
IVec4::new(-1, -2, -3, -4), |
| 2408 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4() |
| 2409 |
); |
| 2410 |
assert_eq!( |
| 2411 |
UVec4::new(1, 2, 3, 4), |
| 2412 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4() |
| 2413 |
); |
| 2414 |
assert_eq!( |
| 2415 |
I64Vec4::new(-1, -2, -3, -4), |
| 2416 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i64vec4() |
| 2417 |
); |
| 2418 |
assert_eq!( |
| 2419 |
U64Vec4::new(1, 2, 3, 4), |
| 2420 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u64vec4() |
| 2421 |
); |
| 2422 |
assert_eq!( |
| 2423 |
USizeVec4::new(1, 2, 3, 4), |
| 2424 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_usizevec4() |
| 2425 |
); |
| 2426 |
|
| 2427 |
assert_eq!( |
| 2428 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2429 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_vec4() |
| 2430 |
); |
| 2431 |
assert_eq!( |
| 2432 |
I8Vec4::new(-1, -2, -3, -4), |
| 2433 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i8vec4() |
| 2434 |
); |
| 2435 |
assert_eq!( |
| 2436 |
U8Vec4::new(1, 2, 3, 4), |
| 2437 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u8vec4() |
| 2438 |
); |
| 2439 |
assert_eq!( |
| 2440 |
I16Vec4::new(-1, -2, -3, -4), |
| 2441 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i16vec4() |
| 2442 |
); |
| 2443 |
assert_eq!( |
| 2444 |
U16Vec4::new(1, 2, 3, 4), |
| 2445 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u16vec4() |
| 2446 |
); |
| 2447 |
assert_eq!( |
| 2448 |
IVec4::new(-1, -2, -3, -4), |
| 2449 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4() |
| 2450 |
); |
| 2451 |
assert_eq!( |
| 2452 |
UVec4::new(1, 2, 3, 4), |
| 2453 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4() |
| 2454 |
); |
| 2455 |
assert_eq!( |
| 2456 |
I64Vec4::new(-1, -2, -3, -4), |
| 2457 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i64vec4() |
| 2458 |
); |
| 2459 |
assert_eq!( |
| 2460 |
U64Vec4::new(1, 2, 3, 4), |
| 2461 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u64vec4() |
| 2462 |
); |
| 2463 |
assert_eq!( |
| 2464 |
USizeVec4::new(1, 2, 3, 4), |
| 2465 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_usizevec4() |
| 2466 |
); |
| 2467 |
|
| 2468 |
assert_eq!( |
| 2469 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2470 |
I8Vec4::new(-1, -2, -3, -4).as_vec4() |
| 2471 |
); |
| 2472 |
assert_eq!( |
| 2473 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2474 |
I8Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 2475 |
); |
| 2476 |
assert_eq!(U8Vec4::new(1, 2, 3, 4), I8Vec4::new(1, 2, 3, 4).as_u8vec4()); |
| 2477 |
assert_eq!( |
| 2478 |
I16Vec4::new(-1, -2, -3, -4), |
| 2479 |
I8Vec4::new(-1, -2, -3, -4).as_i16vec4() |
| 2480 |
); |
| 2481 |
assert_eq!( |
| 2482 |
U16Vec4::new(1, 2, 3, 4), |
| 2483 |
I8Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 2484 |
); |
| 2485 |
assert_eq!( |
| 2486 |
IVec4::new(-1, -2, -3, -4), |
| 2487 |
I8Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 2488 |
); |
| 2489 |
assert_eq!(UVec4::new(1, 2, 3, 4), I8Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 2490 |
assert_eq!( |
| 2491 |
I64Vec4::new(-1, -2, -3, -4), |
| 2492 |
I8Vec4::new(-1, -2, -3, -4).as_i64vec4() |
| 2493 |
); |
| 2494 |
assert_eq!( |
| 2495 |
U64Vec4::new(1, 2, 3, 4), |
| 2496 |
I8Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 2497 |
); |
| 2498 |
assert_eq!( |
| 2499 |
USizeVec4::new(1, 2, 3, 4), |
| 2500 |
I8Vec4::new(1, 2, 3, 4).as_usizevec4() |
| 2501 |
); |
| 2502 |
|
| 2503 |
assert_eq!( |
| 2504 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 2505 |
U8Vec4::new(1, 2, 3, 4).as_vec4() |
| 2506 |
); |
| 2507 |
assert_eq!( |
| 2508 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2509 |
U8Vec4::new(1, 2, 3, 4).as_dvec4() |
| 2510 |
); |
| 2511 |
assert_eq!(I8Vec4::new(1, 2, 3, 4), U8Vec4::new(1, 2, 3, 4).as_i8vec4()); |
| 2512 |
assert_eq!( |
| 2513 |
I16Vec4::new(1, 2, 3, 4), |
| 2514 |
U8Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 2515 |
); |
| 2516 |
assert_eq!( |
| 2517 |
U16Vec4::new(1, 2, 3, 4), |
| 2518 |
U8Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 2519 |
); |
| 2520 |
assert_eq!(IVec4::new(1, 2, 3, 4), U8Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 2521 |
assert_eq!(UVec4::new(1, 2, 3, 4), U8Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 2522 |
assert_eq!( |
| 2523 |
I64Vec4::new(1, 2, 3, 4), |
| 2524 |
U8Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 2525 |
); |
| 2526 |
assert_eq!( |
| 2527 |
U64Vec4::new(1, 2, 3, 4), |
| 2528 |
U8Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 2529 |
); |
| 2530 |
assert_eq!( |
| 2531 |
USizeVec4::new(1, 2, 3, 4), |
| 2532 |
U8Vec4::new(1, 2, 3, 4).as_usizevec4() |
| 2533 |
); |
| 2534 |
|
| 2535 |
assert_eq!( |
| 2536 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2537 |
I16Vec4::new(-1, -2, -3, -4).as_vec4() |
| 2538 |
); |
| 2539 |
assert_eq!( |
| 2540 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2541 |
I16Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 2542 |
); |
| 2543 |
assert_eq!( |
| 2544 |
I8Vec4::new(-1, -2, -3, -4), |
| 2545 |
I16Vec4::new(-1, -2, -3, -4).as_i8vec4() |
| 2546 |
); |
| 2547 |
assert_eq!( |
| 2548 |
U8Vec4::new(1, 2, 3, 4), |
| 2549 |
I16Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 2550 |
); |
| 2551 |
assert_eq!( |
| 2552 |
U16Vec4::new(1, 2, 3, 4), |
| 2553 |
I16Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 2554 |
); |
| 2555 |
assert_eq!( |
| 2556 |
IVec4::new(-1, -2, -3, -4), |
| 2557 |
I16Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 2558 |
); |
| 2559 |
assert_eq!(UVec4::new(1, 2, 3, 4), I16Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 2560 |
assert_eq!( |
| 2561 |
I64Vec4::new(-1, -2, -3, -4), |
| 2562 |
I16Vec4::new(-1, -2, -3, -4).as_i64vec4() |
| 2563 |
); |
| 2564 |
assert_eq!( |
| 2565 |
U64Vec4::new(1, 2, 3, 4), |
| 2566 |
I16Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 2567 |
); |
| 2568 |
assert_eq!( |
| 2569 |
USizeVec4::new(1, 2, 3, 4), |
| 2570 |
I16Vec4::new(1, 2, 3, 4).as_usizevec4() |
| 2571 |
); |
| 2572 |
|
| 2573 |
assert_eq!( |
| 2574 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 2575 |
U16Vec4::new(1, 2, 3, 4).as_vec4() |
| 2576 |
); |
| 2577 |
assert_eq!( |
| 2578 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2579 |
U16Vec4::new(1, 2, 3, 4).as_dvec4() |
| 2580 |
); |
| 2581 |
assert_eq!( |
| 2582 |
I8Vec4::new(1, 2, 3, 4), |
| 2583 |
U16Vec4::new(1, 2, 3, 4).as_i8vec4() |
| 2584 |
); |
| 2585 |
assert_eq!( |
| 2586 |
U8Vec4::new(1, 2, 3, 4), |
| 2587 |
U16Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 2588 |
); |
| 2589 |
assert_eq!( |
| 2590 |
I16Vec4::new(1, 2, 3, 4), |
| 2591 |
U16Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 2592 |
); |
| 2593 |
assert_eq!(IVec4::new(1, 2, 3, 4), U16Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 2594 |
assert_eq!(UVec4::new(1, 2, 3, 4), U16Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 2595 |
assert_eq!( |
| 2596 |
I64Vec4::new(1, 2, 3, 4), |
| 2597 |
U16Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 2598 |
); |
| 2599 |
assert_eq!( |
| 2600 |
U64Vec4::new(1, 2, 3, 4), |
| 2601 |
U16Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 2602 |
); |
| 2603 |
assert_eq!( |
| 2604 |
USizeVec4::new(1, 2, 3, 4), |
| 2605 |
U16Vec4::new(1, 2, 3, 4).as_usizevec4() |
| 2606 |
); |
| 2607 |
|
| 2608 |
assert_eq!( |
| 2609 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2610 |
IVec4::new(-1, -2, -3, -4).as_vec4() |
| 2611 |
); |
| 2612 |
assert_eq!( |
| 2613 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2614 |
IVec4::new(-1, -2, -3, -4).as_dvec4() |
| 2615 |
); |
| 2616 |
assert_eq!( |
| 2617 |
I8Vec4::new(-1, -2, -3, -4), |
| 2618 |
IVec4::new(-1, -2, -3, -4).as_i8vec4() |
| 2619 |
); |
| 2620 |
assert_eq!(U8Vec4::new(1, 2, 3, 4), IVec4::new(1, 2, 3, 4).as_u8vec4()); |
| 2621 |
assert_eq!(UVec4::new(1, 2, 3, 4), IVec4::new(1, 2, 3, 4).as_uvec4()); |
| 2622 |
assert_eq!( |
| 2623 |
I16Vec4::new(-1, -2, -3, -4), |
| 2624 |
IVec4::new(-1, -2, -3, -4).as_i16vec4() |
| 2625 |
); |
| 2626 |
assert_eq!( |
| 2627 |
U16Vec4::new(1, 2, 3, 4), |
| 2628 |
IVec4::new(1, 2, 3, 4).as_u16vec4() |
| 2629 |
); |
| 2630 |
assert_eq!( |
| 2631 |
I64Vec4::new(-1, -2, -3, -4), |
| 2632 |
IVec4::new(-1, -2, -3, -4).as_i64vec4() |
| 2633 |
); |
| 2634 |
assert_eq!( |
| 2635 |
U64Vec4::new(1, 2, 3, 4), |
| 2636 |
IVec4::new(1, 2, 3, 4).as_u64vec4() |
| 2637 |
); |
| 2638 |
assert_eq!( |
| 2639 |
USizeVec4::new(1, 2, 3, 4), |
| 2640 |
IVec4::new(1, 2, 3, 4).as_usizevec4() |
| 2641 |
); |
| 2642 |
|
| 2643 |
assert_eq!( |
| 2644 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 2645 |
UVec4::new(1, 2, 3, 4).as_vec4() |
| 2646 |
); |
| 2647 |
assert_eq!( |
| 2648 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2649 |
UVec4::new(1, 2, 3, 4).as_dvec4() |
| 2650 |
); |
| 2651 |
assert_eq!(I8Vec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_i8vec4()); |
| 2652 |
assert_eq!(U8Vec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_u8vec4()); |
| 2653 |
assert_eq!( |
| 2654 |
I16Vec4::new(1, 2, 3, 4), |
| 2655 |
UVec4::new(1, 2, 3, 4).as_i16vec4() |
| 2656 |
); |
| 2657 |
assert_eq!( |
| 2658 |
U16Vec4::new(1, 2, 3, 4), |
| 2659 |
UVec4::new(1, 2, 3, 4).as_u16vec4() |
| 2660 |
); |
| 2661 |
assert_eq!(IVec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_ivec4()); |
| 2662 |
assert_eq!( |
| 2663 |
I64Vec4::new(1, 2, 3, 4), |
| 2664 |
UVec4::new(1, 2, 3, 4).as_i64vec4() |
| 2665 |
); |
| 2666 |
assert_eq!( |
| 2667 |
U64Vec4::new(1, 2, 3, 4), |
| 2668 |
UVec4::new(1, 2, 3, 4).as_u64vec4() |
| 2669 |
); |
| 2670 |
assert_eq!( |
| 2671 |
USizeVec4::new(1, 2, 3, 4), |
| 2672 |
UVec4::new(1, 2, 3, 4).as_usizevec4() |
| 2673 |
); |
| 2674 |
|
| 2675 |
assert_eq!( |
| 2676 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2677 |
I64Vec4::new(-1, -2, -3, -4).as_vec4() |
| 2678 |
); |
| 2679 |
assert_eq!( |
| 2680 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 2681 |
I64Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 2682 |
); |
| 2683 |
assert_eq!( |
| 2684 |
U8Vec4::new(1, 2, 3, 4), |
| 2685 |
I64Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 2686 |
); |
| 2687 |
assert_eq!( |
| 2688 |
I8Vec4::new(-1, -2, -3, -4), |
| 2689 |
I64Vec4::new(-1, -2, -3, -4).as_i8vec4() |
| 2690 |
); |
| 2691 |
assert_eq!( |
| 2692 |
U16Vec4::new(1, 2, 3, 4), |
| 2693 |
I64Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 2694 |
); |
| 2695 |
assert_eq!( |
| 2696 |
I16Vec4::new(-1, -2, -3, -4), |
| 2697 |
I64Vec4::new(-1, -2, -3, -4).as_i16vec4() |
| 2698 |
); |
| 2699 |
assert_eq!(UVec4::new(1, 2, 3, 4), I64Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 2700 |
assert_eq!( |
| 2701 |
IVec4::new(-1, -2, -3, -4), |
| 2702 |
I64Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 2703 |
); |
| 2704 |
assert_eq!( |
| 2705 |
U64Vec4::new(1, 2, 3, 4), |
| 2706 |
I64Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 2707 |
); |
| 2708 |
assert_eq!( |
| 2709 |
USizeVec4::new(1, 2, 3, 4), |
| 2710 |
I64Vec4::new(1, 2, 3, 4).as_usizevec4() |
| 2711 |
); |
| 2712 |
|
| 2713 |
assert_eq!( |
| 2714 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 2715 |
U64Vec4::new(1, 2, 3, 4).as_vec4() |
| 2716 |
); |
| 2717 |
assert_eq!( |
| 2718 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2719 |
U64Vec4::new(1, 2, 3, 4).as_dvec4() |
| 2720 |
); |
| 2721 |
assert_eq!( |
| 2722 |
I8Vec4::new(1, 2, 3, 4), |
| 2723 |
U64Vec4::new(1, 2, 3, 4).as_i8vec4() |
| 2724 |
); |
| 2725 |
assert_eq!( |
| 2726 |
U8Vec4::new(1, 2, 3, 4), |
| 2727 |
U64Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 2728 |
); |
| 2729 |
assert_eq!( |
| 2730 |
I16Vec4::new(1, 2, 3, 4), |
| 2731 |
U64Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 2732 |
); |
| 2733 |
assert_eq!( |
| 2734 |
U16Vec4::new(1, 2, 3, 4), |
| 2735 |
U64Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 2736 |
); |
| 2737 |
assert_eq!(IVec4::new(1, 2, 3, 4), U64Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 2738 |
assert_eq!(UVec4::new(1, 2, 3, 4), U64Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 2739 |
assert_eq!( |
| 2740 |
I64Vec4::new(1, 2, 3, 4), |
| 2741 |
U64Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 2742 |
); |
| 2743 |
assert_eq!( |
| 2744 |
USizeVec4::new(1, 2, 3, 4), |
| 2745 |
U64Vec4::new(1, 2, 3, 4).as_usizevec4() |
| 2746 |
); |
| 2747 |
|
| 2748 |
assert_eq!( |
| 2749 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 2750 |
USizeVec4::new(1, 2, 3, 4).as_vec4() |
| 2751 |
); |
| 2752 |
assert_eq!( |
| 2753 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2754 |
USizeVec4::new(1, 2, 3, 4).as_dvec4() |
| 2755 |
); |
| 2756 |
assert_eq!( |
| 2757 |
I8Vec4::new(1, 2, 3, 4), |
| 2758 |
USizeVec4::new(1, 2, 3, 4).as_i8vec4() |
| 2759 |
); |
| 2760 |
assert_eq!( |
| 2761 |
U8Vec4::new(1, 2, 3, 4), |
| 2762 |
USizeVec4::new(1, 2, 3, 4).as_u8vec4() |
| 2763 |
); |
| 2764 |
assert_eq!( |
| 2765 |
I16Vec4::new(1, 2, 3, 4), |
| 2766 |
USizeVec4::new(1, 2, 3, 4).as_i16vec4() |
| 2767 |
); |
| 2768 |
assert_eq!( |
| 2769 |
U16Vec4::new(1, 2, 3, 4), |
| 2770 |
USizeVec4::new(1, 2, 3, 4).as_u16vec4() |
| 2771 |
); |
| 2772 |
assert_eq!( |
| 2773 |
IVec4::new(1, 2, 3, 4), |
| 2774 |
USizeVec4::new(1, 2, 3, 4).as_ivec4() |
| 2775 |
); |
| 2776 |
assert_eq!( |
| 2777 |
UVec4::new(1, 2, 3, 4), |
| 2778 |
USizeVec4::new(1, 2, 3, 4).as_uvec4() |
| 2779 |
); |
| 2780 |
assert_eq!( |
| 2781 |
I64Vec4::new(1, 2, 3, 4), |
| 2782 |
USizeVec4::new(1, 2, 3, 4).as_i64vec4() |
| 2783 |
); |
| 2784 |
assert_eq!( |
| 2785 |
U64Vec4::new(1, 2, 3, 4), |
| 2786 |
USizeVec4::new(1, 2, 3, 4).as_u64vec4() |
| 2787 |
); |
| 2788 |
}); |
| 2789 |
|
| 2790 |
glam_test!(test_vec3a, { |
| 2791 |
use glam::Vec3A; |
| 2792 |
assert_eq!( |
| 2793 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 2794 |
Vec4::from((Vec3A::new(1.0, 2.0, 3.0), 4.0)) |
| 2795 |
); |
| 2796 |
assert_eq!( |
| 2797 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 2798 |
Vec4::from((1.0, Vec3A::new(2.0, 3.0, 4.0))) |
| 2799 |
); |
| 2800 |
}); |
| 2801 |
|
| 2802 |
#[cfg(not(feature = "scalar-math"))] |
| 2803 |
impl_vec4_float_tests!(f32, vec4, Vec4, Vec3, Vec2, BVec4A); |
| 2804 |
|
| 2805 |
#[cfg(feature = "scalar-math")] |
| 2806 |
impl_vec4_float_tests!(f32, vec4, Vec4, Vec3, Vec2, BVec4); |
| 2807 |
} |
| 2808 |
|
| 2809 |
mod dvec4 { |
| 2810 |
use glam::{dvec4, BVec4, DVec2, DVec3, DVec4, IVec4, UVec4, Vec4}; |
| 2811 |
|
| 2812 |
glam_test!(test_align, { |
| 2813 |
use std::mem; |
| 2814 |
assert_eq!(32, mem::size_of::<DVec4>()); |
| 2815 |
#[cfg(not(feature = "cuda"))] |
| 2816 |
assert_eq!(mem::align_of::<f64>(), mem::align_of::<DVec4>()); |
| 2817 |
#[cfg(feature = "cuda")] |
| 2818 |
assert_eq!(16, mem::align_of::<DVec4>()); |
| 2819 |
}); |
| 2820 |
|
| 2821 |
glam_test!(test_try_from, { |
| 2822 |
assert_eq!( |
| 2823 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2824 |
DVec4::from(Vec4::new(1.0, 2.0, 3.0, 4.0)) |
| 2825 |
); |
| 2826 |
assert_eq!( |
| 2827 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2828 |
DVec4::from(IVec4::new(1, 2, 3, 4)) |
| 2829 |
); |
| 2830 |
assert_eq!( |
| 2831 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 2832 |
DVec4::from(UVec4::new(1, 2, 3, 4)) |
| 2833 |
); |
| 2834 |
}); |
| 2835 |
|
| 2836 |
impl_vec4_float_tests!(f64, dvec4, DVec4, DVec3, DVec2, BVec4); |
| 2837 |
} |
| 2838 |
|
| 2839 |
mod i8vec4 { |
| 2840 |
use glam::{ |
| 2841 |
i8vec4, BVec4, I16Vec4, I64Vec4, I8Vec2, I8Vec3, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec4, |
| 2842 |
USizeVec4, UVec4, |
| 2843 |
}; |
| 2844 |
|
| 2845 |
glam_test!(test_align, { |
| 2846 |
use std::mem; |
| 2847 |
assert_eq!(4, mem::size_of::<I8Vec4>()); |
| 2848 |
#[cfg(not(feature = "cuda"))] |
| 2849 |
assert_eq!(1, mem::align_of::<I8Vec4>()); |
| 2850 |
#[cfg(feature = "cuda")] |
| 2851 |
assert_eq!(4, mem::align_of::<I8Vec4>()); |
| 2852 |
}); |
| 2853 |
|
| 2854 |
glam_test!(test_try_from, { |
| 2855 |
assert_eq!( |
| 2856 |
I8Vec4::new(1, 2, 3, 4), |
| 2857 |
I8Vec4::try_from(U8Vec4::new(1, 2, 3, 4)).unwrap() |
| 2858 |
); |
| 2859 |
assert!(I8Vec4::try_from(U8Vec4::new(u8::MAX, 2, 3, 4)).is_err()); |
| 2860 |
assert!(I8Vec4::try_from(U8Vec4::new(1, u8::MAX, 3, 4)).is_err()); |
| 2861 |
assert!(I8Vec4::try_from(U8Vec4::new(1, 2, u8::MAX, 4)).is_err()); |
| 2862 |
assert!(I8Vec4::try_from(U8Vec4::new(1, 2, 3, u8::MAX)).is_err()); |
| 2863 |
|
| 2864 |
assert_eq!( |
| 2865 |
I8Vec4::new(1, 2, 3, 4), |
| 2866 |
I8Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2867 |
); |
| 2868 |
assert!(I8Vec4::try_from(I16Vec4::new(i16::MAX, 2, 3, 4)).is_err()); |
| 2869 |
assert!(I8Vec4::try_from(I16Vec4::new(1, i16::MAX, 3, 4)).is_err()); |
| 2870 |
assert!(I8Vec4::try_from(I16Vec4::new(1, 2, i16::MAX, 4)).is_err()); |
| 2871 |
assert!(I8Vec4::try_from(I16Vec4::new(1, 2, 3, i16::MAX)).is_err()); |
| 2872 |
|
| 2873 |
assert_eq!( |
| 2874 |
I8Vec4::new(1, 2, 3, 4), |
| 2875 |
I8Vec4::try_from(U16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2876 |
); |
| 2877 |
assert!(I8Vec4::try_from(U16Vec4::new(u16::MAX, 2, 3, 4)).is_err()); |
| 2878 |
assert!(I8Vec4::try_from(U16Vec4::new(1, u16::MAX, 3, 4)).is_err()); |
| 2879 |
assert!(I8Vec4::try_from(U16Vec4::new(1, 2, u16::MAX, 4)).is_err()); |
| 2880 |
assert!(I8Vec4::try_from(U16Vec4::new(1, 2, 3, u16::MAX)).is_err()); |
| 2881 |
|
| 2882 |
assert_eq!( |
| 2883 |
I8Vec4::new(1, 2, 3, 4), |
| 2884 |
I8Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2885 |
); |
| 2886 |
assert!(I8Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 2887 |
assert!(I8Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 2888 |
assert!(I8Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 2889 |
assert!(I8Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 2890 |
|
| 2891 |
assert_eq!( |
| 2892 |
I8Vec4::new(1, 2, 3, 4), |
| 2893 |
I8Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 2894 |
); |
| 2895 |
assert!(I8Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 2896 |
assert!(I8Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 2897 |
assert!(I8Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 2898 |
assert!(I8Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 2899 |
|
| 2900 |
assert_eq!( |
| 2901 |
I8Vec4::new(1, 2, 3, 4), |
| 2902 |
I8Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2903 |
); |
| 2904 |
assert!(I8Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2905 |
assert!(I8Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2906 |
assert!(I8Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2907 |
assert!(I8Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2908 |
|
| 2909 |
assert_eq!( |
| 2910 |
I8Vec4::new(1, 2, 3, 4), |
| 2911 |
I8Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2912 |
); |
| 2913 |
assert!(I8Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2914 |
assert!(I8Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2915 |
assert!(I8Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2916 |
assert!(I8Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2917 |
|
| 2918 |
assert_eq!( |
| 2919 |
I8Vec4::new(1, 2, 3, 4), |
| 2920 |
I8Vec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 2921 |
); |
| 2922 |
assert!(I8Vec4::try_from(USizeVec4::new(usize::MAX, 2, 3, 4)).is_err()); |
| 2923 |
assert!(I8Vec4::try_from(USizeVec4::new(1, usize::MAX, 3, 4)).is_err()); |
| 2924 |
assert!(I8Vec4::try_from(USizeVec4::new(1, 2, usize::MAX, 4)).is_err()); |
| 2925 |
assert!(I8Vec4::try_from(USizeVec4::new(1, 2, 3, usize::MAX)).is_err()); |
| 2926 |
}); |
| 2927 |
|
| 2928 |
glam_test!(test_wrapping_add, { |
| 2929 |
assert_eq!( |
| 2930 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_add(I8Vec4::new(1, 3, i8::MAX, 0)), |
| 2931 |
I8Vec4::new(i8::MIN, 8, -1, 0), |
| 2932 |
); |
| 2933 |
}); |
| 2934 |
|
| 2935 |
glam_test!(test_wrapping_sub, { |
| 2936 |
assert_eq!( |
| 2937 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_sub(I8Vec4::new(1, 3, i8::MAX, 0)), |
| 2938 |
I8Vec4::new(126, 2, 1, 0) |
| 2939 |
); |
| 2940 |
}); |
| 2941 |
|
| 2942 |
glam_test!(test_wrapping_mul, { |
| 2943 |
assert_eq!( |
| 2944 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_mul(I8Vec4::new(3, 3, 5, 1)), |
| 2945 |
I8Vec4::new(125, 15, -128, 0) |
| 2946 |
); |
| 2947 |
}); |
| 2948 |
|
| 2949 |
glam_test!(test_wrapping_div, { |
| 2950 |
assert_eq!( |
| 2951 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_div(I8Vec4::new(3, 3, 5, 1)), |
| 2952 |
I8Vec4::new(42, 1, -25, 0) |
| 2953 |
); |
| 2954 |
}); |
| 2955 |
|
| 2956 |
glam_test!(test_saturating_add, { |
| 2957 |
assert_eq!( |
| 2958 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0).saturating_add(I8Vec4::new(1, -1, 2, 3)), |
| 2959 |
I8Vec4::new(i8::MAX, i8::MIN, 2, 3) |
| 2960 |
); |
| 2961 |
}); |
| 2962 |
|
| 2963 |
glam_test!(test_saturating_sub, { |
| 2964 |
assert_eq!( |
| 2965 |
I8Vec4::new(i8::MIN, i8::MAX, 0, 0).saturating_sub(I8Vec4::new(1, -1, 2, 3)), |
| 2966 |
I8Vec4::new(i8::MIN, i8::MAX, -2, -3) |
| 2967 |
); |
| 2968 |
}); |
| 2969 |
|
| 2970 |
glam_test!(test_saturating_mul, { |
| 2971 |
assert_eq!( |
| 2972 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0).saturating_mul(I8Vec4::new(2, 2, 0, 0)), |
| 2973 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0) |
| 2974 |
); |
| 2975 |
}); |
| 2976 |
|
| 2977 |
glam_test!(test_saturating_div, { |
| 2978 |
assert_eq!( |
| 2979 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0).saturating_div(I8Vec4::new(2, 2, 3, 4)), |
| 2980 |
I8Vec4::new(63, -64, 0, 0) |
| 2981 |
); |
| 2982 |
}); |
| 2983 |
|
| 2984 |
glam_test!(test_checked_add_unsigned, { |
| 2985 |
assert_eq!(I8Vec4::MAX.checked_add_unsigned(U8Vec4::ONE), None); |
| 2986 |
assert_eq!( |
| 2987 |
I8Vec4::NEG_ONE.checked_add_unsigned(U8Vec4::ONE), |
| 2988 |
Some(I8Vec4::ZERO) |
| 2989 |
); |
| 2990 |
}); |
| 2991 |
|
| 2992 |
glam_test!(test_checked_sub_unsigned, { |
| 2993 |
assert_eq!(I8Vec4::MIN.checked_sub_unsigned(U8Vec4::ONE), None); |
| 2994 |
assert_eq!( |
| 2995 |
I8Vec4::ZERO.checked_sub_unsigned(U8Vec4::ONE), |
| 2996 |
Some(I8Vec4::NEG_ONE) |
| 2997 |
); |
| 2998 |
}); |
| 2999 |
|
| 3000 |
glam_test!(test_wrapping_add_unsigned, { |
| 3001 |
assert_eq!( |
| 3002 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 3003 |
.wrapping_add_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 3004 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 3005 |
); |
| 3006 |
}); |
| 3007 |
|
| 3008 |
glam_test!(test_wrapping_sub_unsigned, { |
| 3009 |
assert_eq!( |
| 3010 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 3011 |
.wrapping_sub_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 3012 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 3013 |
); |
| 3014 |
}); |
| 3015 |
|
| 3016 |
glam_test!(test_saturating_add_unsigned, { |
| 3017 |
assert_eq!( |
| 3018 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 3019 |
.saturating_add_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 3020 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 3021 |
); |
| 3022 |
}); |
| 3023 |
|
| 3024 |
glam_test!(test_saturating_sub_unsigned, { |
| 3025 |
assert_eq!( |
| 3026 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 3027 |
.saturating_sub_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 3028 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 3029 |
); |
| 3030 |
}); |
| 3031 |
|
| 3032 |
impl_vec4_signed_integer_tests!(i8, i8vec4, I8Vec4, I8Vec3, I8Vec2, BVec4); |
| 3033 |
impl_vec4_eq_hash_tests!(i8, i8vec4); |
| 3034 |
|
| 3035 |
impl_vec4_scalar_shift_op_tests!(I8Vec4, -2, 2); |
| 3036 |
impl_vec4_shift_op_tests!(I8Vec4); |
| 3037 |
|
| 3038 |
impl_vec4_scalar_bit_op_tests!(I8Vec4, -2, 2); |
| 3039 |
impl_vec4_bit_op_tests!(I8Vec4, -2, 2); |
| 3040 |
} |
| 3041 |
|
| 3042 |
mod u8vec4 { |
| 3043 |
use glam::{ |
| 3044 |
u8vec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec2, U8Vec3, U8Vec4, |
| 3045 |
USizeVec4, UVec4, |
| 3046 |
}; |
| 3047 |
|
| 3048 |
glam_test!(test_align, { |
| 3049 |
use std::mem; |
| 3050 |
assert_eq!(4, mem::size_of::<U8Vec4>()); |
| 3051 |
#[cfg(not(feature = "cuda"))] |
| 3052 |
assert_eq!(1, mem::align_of::<U8Vec4>()); |
| 3053 |
#[cfg(feature = "cuda")] |
| 3054 |
assert_eq!(4, mem::align_of::<U8Vec4>()); |
| 3055 |
}); |
| 3056 |
|
| 3057 |
glam_test!(test_try_from, { |
| 3058 |
assert_eq!( |
| 3059 |
U8Vec4::new(1, 2, 3, 4), |
| 3060 |
U8Vec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 3061 |
); |
| 3062 |
assert!(U8Vec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3063 |
assert!(U8Vec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 3064 |
assert!(U8Vec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 3065 |
assert!(U8Vec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 3066 |
|
| 3067 |
assert_eq!( |
| 3068 |
U8Vec4::new(1, 2, 3, 4), |
| 3069 |
U8Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 3070 |
); |
| 3071 |
assert!(U8Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3072 |
assert!(U8Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 3073 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 3074 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 3075 |
|
| 3076 |
assert!(U8Vec4::try_from(I16Vec4::new(i16::MAX, 2, 3, 4)).is_err()); |
| 3077 |
assert!(U8Vec4::try_from(I16Vec4::new(1, i16::MAX, 3, 4)).is_err()); |
| 3078 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, i16::MAX, 4)).is_err()); |
| 3079 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, 3, i16::MAX)).is_err()); |
| 3080 |
|
| 3081 |
assert_eq!( |
| 3082 |
U8Vec4::new(1, 2, 3, 4), |
| 3083 |
U8Vec4::try_from(U16Vec4::new(1, 2, 3, 4)).unwrap() |
| 3084 |
); |
| 3085 |
assert!(U8Vec4::try_from(U16Vec4::new(u16::MAX, 2, 3, 4)).is_err()); |
| 3086 |
assert!(U8Vec4::try_from(U16Vec4::new(1, u16::MAX, 3, 4)).is_err()); |
| 3087 |
assert!(U8Vec4::try_from(U16Vec4::new(1, 2, u16::MAX, 4)).is_err()); |
| 3088 |
assert!(U8Vec4::try_from(U16Vec4::new(1, 2, 3, u16::MAX)).is_err()); |
| 3089 |
|
| 3090 |
assert_eq!( |
| 3091 |
U8Vec4::new(1, 2, 3, 4), |
| 3092 |
U8Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 3093 |
); |
| 3094 |
assert!(U8Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 3095 |
assert!(U8Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 3096 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 3097 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 3098 |
|
| 3099 |
assert!(U8Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 3100 |
assert!(U8Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 3101 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 3102 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 3103 |
|
| 3104 |
assert_eq!( |
| 3105 |
U8Vec4::new(1, 2, 3, 4), |
| 3106 |
U8Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 3107 |
); |
| 3108 |
assert!(U8Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 3109 |
assert!(U8Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 3110 |
assert!(U8Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 3111 |
assert!(U8Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 3112 |
|
| 3113 |
assert_eq!( |
| 3114 |
U8Vec4::new(1, 2, 3, 4), |
| 3115 |
U8Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3116 |
); |
| 3117 |
assert!(U8Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3118 |
assert!(U8Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 3119 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 3120 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 3121 |
|
| 3122 |
assert!(U8Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 3123 |
assert!(U8Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 3124 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 3125 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 3126 |
|
| 3127 |
assert_eq!( |
| 3128 |
U8Vec4::new(1, 2, 3, 4), |
| 3129 |
U8Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3130 |
); |
| 3131 |
assert!(U8Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 3132 |
assert!(U8Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 3133 |
assert!(U8Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 3134 |
assert!(U8Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 3135 |
|
| 3136 |
assert_eq!( |
| 3137 |
U8Vec4::new(1, 2, 3, 4), |
| 3138 |
U8Vec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 3139 |
); |
| 3140 |
assert!(U8Vec4::try_from(USizeVec4::new(usize::MAX, 2, 3, 4)).is_err()); |
| 3141 |
assert!(U8Vec4::try_from(USizeVec4::new(1, usize::MAX, 3, 4)).is_err()); |
| 3142 |
assert!(U8Vec4::try_from(USizeVec4::new(1, 2, usize::MAX, 4)).is_err()); |
| 3143 |
assert!(U8Vec4::try_from(USizeVec4::new(1, 2, 3, usize::MAX)).is_err()); |
| 3144 |
}); |
| 3145 |
|
| 3146 |
glam_test!(test_wrapping_add, { |
| 3147 |
assert_eq!( |
| 3148 |
U8Vec4::new(u8::MAX, 5, u8::MAX, 0).wrapping_add(U8Vec4::new(1, 3, u8::MAX, 0)), |
| 3149 |
U8Vec4::new(0, 8, 254, 0), |
| 3150 |
); |
| 3151 |
}); |
| 3152 |
|
| 3153 |
glam_test!(test_wrapping_sub, { |
| 3154 |
assert_eq!( |
| 3155 |
U8Vec4::new(u8::MAX, 5, u8::MAX - 1, 0).wrapping_sub(U8Vec4::new(1, 3, u8::MAX, 0)), |
| 3156 |
U8Vec4::new(254, 2, 255, 0) |
| 3157 |
); |
| 3158 |
}); |
| 3159 |
|
| 3160 |
glam_test!(test_wrapping_mul, { |
| 3161 |
assert_eq!( |
| 3162 |
U8Vec4::new(u8::MAX, 5, u8::MAX, 0).wrapping_mul(U8Vec4::new(3, 3, 5, 1)), |
| 3163 |
U8Vec4::new(253, 15, 251, 0) |
| 3164 |
); |
| 3165 |
}); |
| 3166 |
|
| 3167 |
glam_test!(test_wrapping_div, { |
| 3168 |
assert_eq!( |
| 3169 |
U8Vec4::new(u8::MAX, 5, u8::MAX, 0).wrapping_div(U8Vec4::new(3, 3, 5, 1)), |
| 3170 |
U8Vec4::new(85, 1, 51, 0) |
| 3171 |
); |
| 3172 |
}); |
| 3173 |
|
| 3174 |
glam_test!(test_saturating_add, { |
| 3175 |
assert_eq!( |
| 3176 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0).saturating_add(U8Vec4::new(1, u8::MAX, 2, 3)), |
| 3177 |
U8Vec4::new(u8::MAX, u8::MAX, 2, 3) |
| 3178 |
); |
| 3179 |
}); |
| 3180 |
|
| 3181 |
glam_test!(test_saturating_sub, { |
| 3182 |
assert_eq!( |
| 3183 |
U8Vec4::new(0, u8::MAX, 0, 0).saturating_sub(U8Vec4::new(1, 1, 2, 3)), |
| 3184 |
U8Vec4::new(0, 254, 0, 0) |
| 3185 |
); |
| 3186 |
}); |
| 3187 |
|
| 3188 |
glam_test!(test_saturating_mul, { |
| 3189 |
assert_eq!( |
| 3190 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0).saturating_mul(U8Vec4::new(2, u8::MAX, 0, 0)), |
| 3191 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0) |
| 3192 |
); |
| 3193 |
}); |
| 3194 |
|
| 3195 |
glam_test!(test_saturating_div, { |
| 3196 |
assert_eq!( |
| 3197 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0).saturating_div(U8Vec4::new(2, u8::MAX, 3, 4)), |
| 3198 |
U8Vec4::new(127, 1, 0, 0) |
| 3199 |
); |
| 3200 |
}); |
| 3201 |
|
| 3202 |
glam_test!(test_checked_add_signed, { |
| 3203 |
assert_eq!(U8Vec4::MAX.checked_add_signed(I8Vec4::ONE), None); |
| 3204 |
assert_eq!( |
| 3205 |
U8Vec4::ONE.checked_add_signed(I8Vec4::NEG_ONE), |
| 3206 |
Some(U8Vec4::ZERO) |
| 3207 |
); |
| 3208 |
}); |
| 3209 |
|
| 3210 |
glam_test!(test_wrapping_add_signed, { |
| 3211 |
assert_eq!( |
| 3212 |
U8Vec4::new(u8::MAX, u8::MAX, u8::MAX, u8::MAX) |
| 3213 |
.wrapping_add_signed(I8Vec4::new(1, 1, 1, 1)), |
| 3214 |
U8Vec4::new(u8::MIN, u8::MIN, u8::MIN, u8::MIN) |
| 3215 |
); |
| 3216 |
}); |
| 3217 |
|
| 3218 |
glam_test!(test_saturating_add_signed, { |
| 3219 |
assert_eq!( |
| 3220 |
U8Vec4::new(u8::MAX, u8::MAX, u8::MAX, u8::MAX) |
| 3221 |
.saturating_add_signed(I8Vec4::new(1, 1, 1, 1)), |
| 3222 |
U8Vec4::new(u8::MAX, u8::MAX, u8::MAX, u8::MAX) |
| 3223 |
); |
| 3224 |
}); |
| 3225 |
|
| 3226 |
impl_vec4_unsigned_integer_tests!(u8, u8vec4, U8Vec4, U8Vec3, U8Vec2, BVec4); |
| 3227 |
impl_vec4_eq_hash_tests!(u8, u8vec4); |
| 3228 |
|
| 3229 |
impl_vec4_scalar_shift_op_tests!(U8Vec4, 0, 2); |
| 3230 |
impl_vec4_shift_op_tests!(U8Vec4); |
| 3231 |
|
| 3232 |
impl_vec4_scalar_bit_op_tests!(U8Vec4, 0, 2); |
| 3233 |
impl_vec4_bit_op_tests!(U8Vec4, 0, 2); |
| 3234 |
} |
| 3235 |
|
| 3236 |
mod i16vec4 { |
| 3237 |
use glam::{ |
| 3238 |
i16vec4, BVec4, I16Vec2, I16Vec3, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, |
| 3239 |
U8Vec4, USizeVec4, UVec4, |
| 3240 |
}; |
| 3241 |
|
| 3242 |
glam_test!(test_align, { |
| 3243 |
use std::mem; |
| 3244 |
assert_eq!(8, mem::size_of::<I16Vec4>()); |
| 3245 |
#[cfg(not(feature = "cuda"))] |
| 3246 |
assert_eq!(2, mem::align_of::<I16Vec4>()); |
| 3247 |
#[cfg(feature = "cuda")] |
| 3248 |
assert_eq!(8, mem::align_of::<I16Vec4>()); |
| 3249 |
}); |
| 3250 |
|
| 3251 |
glam_test!(test_try_from, { |
| 3252 |
assert_eq!( |
| 3253 |
I16Vec4::new(1, 2, 3, 4), |
| 3254 |
I16Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 3255 |
); |
| 3256 |
assert_eq!( |
| 3257 |
I16Vec4::new(1, 2, 3, 4), |
| 3258 |
I16Vec4::from(I8Vec4::new(1, 2, 3, 4)) |
| 3259 |
); |
| 3260 |
|
| 3261 |
assert_eq!( |
| 3262 |
I16Vec4::new(1, 2, 3, 4), |
| 3263 |
I16Vec4::try_from(U16Vec4::new(1, 2, 3, 4)).unwrap() |
| 3264 |
); |
| 3265 |
assert!(I16Vec4::try_from(U16Vec4::new(u16::MAX, 2, 3, 4)).is_err()); |
| 3266 |
assert!(I16Vec4::try_from(U16Vec4::new(1, u16::MAX, 3, 4)).is_err()); |
| 3267 |
assert!(I16Vec4::try_from(U16Vec4::new(1, 2, u16::MAX, 4)).is_err()); |
| 3268 |
assert!(I16Vec4::try_from(U16Vec4::new(1, 2, 3, u16::MAX)).is_err()); |
| 3269 |
|
| 3270 |
assert_eq!( |
| 3271 |
I16Vec4::new(1, 2, 3, 4), |
| 3272 |
I16Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 3273 |
); |
| 3274 |
assert!(I16Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 3275 |
assert!(I16Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 3276 |
assert!(I16Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 3277 |
assert!(I16Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 3278 |
|
| 3279 |
assert_eq!( |
| 3280 |
I16Vec4::new(1, 2, 3, 4), |
| 3281 |
I16Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 3282 |
); |
| 3283 |
assert!(I16Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 3284 |
assert!(I16Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 3285 |
assert!(I16Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 3286 |
assert!(I16Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 3287 |
|
| 3288 |
assert_eq!( |
| 3289 |
I16Vec4::new(1, 2, 3, 4), |
| 3290 |
I16Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3291 |
); |
| 3292 |
assert!(I16Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 3293 |
assert!(I16Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 3294 |
assert!(I16Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 3295 |
assert!(I16Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 3296 |
|
| 3297 |
assert_eq!( |
| 3298 |
I16Vec4::new(1, 2, 3, 4), |
| 3299 |
I16Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3300 |
); |
| 3301 |
assert!(I16Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 3302 |
assert!(I16Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 3303 |
assert!(I16Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 3304 |
assert!(I16Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 3305 |
|
| 3306 |
assert_eq!( |
| 3307 |
I16Vec4::new(1, 2, 3, 4), |
| 3308 |
I16Vec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 3309 |
); |
| 3310 |
assert!(I16Vec4::try_from(USizeVec4::new(usize::MAX, 2, 3, 4)).is_err()); |
| 3311 |
assert!(I16Vec4::try_from(USizeVec4::new(1, usize::MAX, 3, 4)).is_err()); |
| 3312 |
assert!(I16Vec4::try_from(USizeVec4::new(1, 2, usize::MAX, 4)).is_err()); |
| 3313 |
assert!(I16Vec4::try_from(USizeVec4::new(1, 2, 3, usize::MAX)).is_err()); |
| 3314 |
}); |
| 3315 |
|
| 3316 |
glam_test!(test_wrapping_add, { |
| 3317 |
assert_eq!( |
| 3318 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_add(I16Vec4::new(1, 3, i16::MAX, 0)), |
| 3319 |
I16Vec4::new(i16::MIN, 8, -1, 0), |
| 3320 |
); |
| 3321 |
}); |
| 3322 |
|
| 3323 |
glam_test!(test_wrapping_sub, { |
| 3324 |
assert_eq!( |
| 3325 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_sub(I16Vec4::new(1, 3, i16::MAX, 0)), |
| 3326 |
I16Vec4::new(32766, 2, 1, 0) |
| 3327 |
); |
| 3328 |
}); |
| 3329 |
|
| 3330 |
glam_test!(test_wrapping_mul, { |
| 3331 |
assert_eq!( |
| 3332 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_mul(I16Vec4::new(3, 3, 5, 1)), |
| 3333 |
I16Vec4::new(32765, 15, -32768, 0) |
| 3334 |
); |
| 3335 |
}); |
| 3336 |
|
| 3337 |
glam_test!(test_wrapping_div, { |
| 3338 |
assert_eq!( |
| 3339 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_div(I16Vec4::new(3, 3, 5, 1)), |
| 3340 |
I16Vec4::new(10922, 1, -6553, 0) |
| 3341 |
); |
| 3342 |
}); |
| 3343 |
|
| 3344 |
glam_test!(test_saturating_add, { |
| 3345 |
assert_eq!( |
| 3346 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_add(I16Vec4::new(1, -1, 2, 3)), |
| 3347 |
I16Vec4::new(i16::MAX, i16::MIN, 2, 3) |
| 3348 |
); |
| 3349 |
}); |
| 3350 |
|
| 3351 |
glam_test!(test_saturating_sub, { |
| 3352 |
assert_eq!( |
| 3353 |
I16Vec4::new(i16::MIN, i16::MAX, 0, 0).saturating_sub(I16Vec4::new(1, -1, 2, 3)), |
| 3354 |
I16Vec4::new(i16::MIN, i16::MAX, -2, -3) |
| 3355 |
); |
| 3356 |
}); |
| 3357 |
|
| 3358 |
glam_test!(test_saturating_mul, { |
| 3359 |
assert_eq!( |
| 3360 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_mul(I16Vec4::new(2, 2, 0, 0)), |
| 3361 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0) |
| 3362 |
); |
| 3363 |
}); |
| 3364 |
|
| 3365 |
glam_test!(test_saturating_div, { |
| 3366 |
assert_eq!( |
| 3367 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_div(I16Vec4::new(2, 2, 3, 4)), |
| 3368 |
I16Vec4::new(16383, -16384, 0, 0) |
| 3369 |
); |
| 3370 |
}); |
| 3371 |
|
| 3372 |
glam_test!(test_checked_add_unsigned, { |
| 3373 |
assert_eq!(I16Vec4::MAX.checked_add_unsigned(U16Vec4::ONE), None); |
| 3374 |
assert_eq!( |
| 3375 |
I16Vec4::NEG_ONE.checked_add_unsigned(U16Vec4::ONE), |
| 3376 |
Some(I16Vec4::ZERO) |
| 3377 |
); |
| 3378 |
}); |
| 3379 |
|
| 3380 |
glam_test!(test_checked_sub_unsigned, { |
| 3381 |
assert_eq!(I16Vec4::MIN.checked_sub_unsigned(U16Vec4::ONE), None); |
| 3382 |
assert_eq!( |
| 3383 |
I16Vec4::ZERO.checked_sub_unsigned(U16Vec4::ONE), |
| 3384 |
Some(I16Vec4::NEG_ONE) |
| 3385 |
); |
| 3386 |
}); |
| 3387 |
|
| 3388 |
glam_test!(test_wrapping_add_unsigned, { |
| 3389 |
assert_eq!( |
| 3390 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 3391 |
.wrapping_add_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 3392 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 3393 |
); |
| 3394 |
}); |
| 3395 |
|
| 3396 |
glam_test!(test_wrapping_sub_unsigned, { |
| 3397 |
assert_eq!( |
| 3398 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 3399 |
.wrapping_sub_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 3400 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 3401 |
); |
| 3402 |
}); |
| 3403 |
|
| 3404 |
glam_test!(test_saturating_add_unsigned, { |
| 3405 |
assert_eq!( |
| 3406 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 3407 |
.saturating_add_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 3408 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 3409 |
); |
| 3410 |
}); |
| 3411 |
|
| 3412 |
glam_test!(test_saturating_sub_unsigned, { |
| 3413 |
assert_eq!( |
| 3414 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 3415 |
.saturating_sub_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 3416 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 3417 |
); |
| 3418 |
}); |
| 3419 |
|
| 3420 |
impl_vec4_signed_integer_tests!(i16, i16vec4, I16Vec4, I16Vec3, I16Vec2, BVec4); |
| 3421 |
impl_vec4_eq_hash_tests!(i16, i16vec4); |
| 3422 |
|
| 3423 |
impl_vec4_scalar_shift_op_tests!(I16Vec4, -2, 2); |
| 3424 |
impl_vec4_shift_op_tests!(I16Vec4); |
| 3425 |
|
| 3426 |
impl_vec4_scalar_bit_op_tests!(I16Vec4, -2, 2); |
| 3427 |
impl_vec4_bit_op_tests!(I16Vec4, -2, 2); |
| 3428 |
} |
| 3429 |
|
| 3430 |
mod u16vec4 { |
| 3431 |
use glam::{ |
| 3432 |
u16vec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec2, U16Vec3, U16Vec4, U64Vec4, |
| 3433 |
U8Vec4, USizeVec4, UVec4, |
| 3434 |
}; |
| 3435 |
|
| 3436 |
glam_test!(test_align, { |
| 3437 |
use std::mem; |
| 3438 |
assert_eq!(8, mem::size_of::<U16Vec4>()); |
| 3439 |
#[cfg(not(feature = "cuda"))] |
| 3440 |
assert_eq!(2, mem::align_of::<U16Vec4>()); |
| 3441 |
#[cfg(feature = "cuda")] |
| 3442 |
assert_eq!(8, mem::align_of::<U16Vec4>()); |
| 3443 |
}); |
| 3444 |
|
| 3445 |
glam_test!(test_try_from, { |
| 3446 |
assert_eq!( |
| 3447 |
U16Vec4::new(1, 2, 3, 4), |
| 3448 |
U16Vec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 3449 |
); |
| 3450 |
assert!(U16Vec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3451 |
assert!(U16Vec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 3452 |
assert!(U16Vec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 3453 |
assert!(U16Vec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 3454 |
|
| 3455 |
assert_eq!( |
| 3456 |
U16Vec4::new(1, 2, 3, 4), |
| 3457 |
U16Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 3458 |
); |
| 3459 |
|
| 3460 |
assert_eq!( |
| 3461 |
U16Vec4::new(1, 2, 3, 4), |
| 3462 |
U16Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 3463 |
); |
| 3464 |
assert!(U16Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3465 |
assert!(U16Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 3466 |
assert!(U16Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 3467 |
assert!(U16Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 3468 |
|
| 3469 |
assert_eq!( |
| 3470 |
U16Vec4::new(1, 2, 3, 4), |
| 3471 |
U16Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 3472 |
); |
| 3473 |
assert!(U16Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 3474 |
assert!(U16Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 3475 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 3476 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 3477 |
|
| 3478 |
assert!(U16Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 3479 |
assert!(U16Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 3480 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 3481 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 3482 |
|
| 3483 |
assert_eq!( |
| 3484 |
U16Vec4::new(1, 2, 3, 4), |
| 3485 |
U16Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 3486 |
); |
| 3487 |
assert!(U16Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 3488 |
assert!(U16Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 3489 |
assert!(U16Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 3490 |
assert!(U16Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 3491 |
|
| 3492 |
assert_eq!( |
| 3493 |
U16Vec4::new(1, 2, 3, 4), |
| 3494 |
U16Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3495 |
); |
| 3496 |
assert!(U16Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3497 |
assert!(U16Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 3498 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 3499 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 3500 |
|
| 3501 |
assert!(U16Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 3502 |
assert!(U16Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 3503 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 3504 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 3505 |
|
| 3506 |
assert_eq!( |
| 3507 |
U16Vec4::new(1, 2, 3, 4), |
| 3508 |
U16Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3509 |
); |
| 3510 |
assert!(U16Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 3511 |
assert!(U16Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 3512 |
assert!(U16Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 3513 |
assert!(U16Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 3514 |
|
| 3515 |
assert_eq!( |
| 3516 |
U16Vec4::new(1, 2, 3, 4), |
| 3517 |
U16Vec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 3518 |
); |
| 3519 |
assert!(U16Vec4::try_from(USizeVec4::new(usize::MAX, 2, 3, 4)).is_err()); |
| 3520 |
assert!(U16Vec4::try_from(USizeVec4::new(1, usize::MAX, 3, 4)).is_err()); |
| 3521 |
assert!(U16Vec4::try_from(USizeVec4::new(1, 2, usize::MAX, 4)).is_err()); |
| 3522 |
assert!(U16Vec4::try_from(USizeVec4::new(1, 2, 3, usize::MAX)).is_err()); |
| 3523 |
}); |
| 3524 |
|
| 3525 |
glam_test!(test_wrapping_add, { |
| 3526 |
assert_eq!( |
| 3527 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_add(U16Vec4::new(1, 3, u16::MAX, 0)), |
| 3528 |
U16Vec4::new(0, 8, 65534, 0), |
| 3529 |
); |
| 3530 |
}); |
| 3531 |
|
| 3532 |
glam_test!(test_wrapping_sub, { |
| 3533 |
assert_eq!( |
| 3534 |
U16Vec4::new(u16::MAX, 5, u16::MAX - 1, 0).wrapping_sub(U16Vec4::new( |
| 3535 |
1, |
| 3536 |
3, |
| 3537 |
u16::MAX, |
| 3538 |
0 |
| 3539 |
)), |
| 3540 |
U16Vec4::new(65534, 2, 65535, 0) |
| 3541 |
); |
| 3542 |
}); |
| 3543 |
|
| 3544 |
glam_test!(test_wrapping_mul, { |
| 3545 |
assert_eq!( |
| 3546 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_mul(U16Vec4::new(3, 3, 5, 1)), |
| 3547 |
U16Vec4::new(65533, 15, 65531, 0) |
| 3548 |
); |
| 3549 |
}); |
| 3550 |
|
| 3551 |
glam_test!(test_wrapping_div, { |
| 3552 |
assert_eq!( |
| 3553 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_div(U16Vec4::new(3, 3, 5, 1)), |
| 3554 |
U16Vec4::new(21845, 1, 13107, 0) |
| 3555 |
); |
| 3556 |
}); |
| 3557 |
|
| 3558 |
glam_test!(test_saturating_add, { |
| 3559 |
assert_eq!( |
| 3560 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_add(U16Vec4::new(1, u16::MAX, 2, 3)), |
| 3561 |
U16Vec4::new(u16::MAX, u16::MAX, 2, 3) |
| 3562 |
); |
| 3563 |
}); |
| 3564 |
|
| 3565 |
glam_test!(test_saturating_sub, { |
| 3566 |
assert_eq!( |
| 3567 |
U16Vec4::new(0, u16::MAX, 0, 0).saturating_sub(U16Vec4::new(1, 1, 2, 3)), |
| 3568 |
U16Vec4::new(0, 65534, 0, 0) |
| 3569 |
); |
| 3570 |
}); |
| 3571 |
|
| 3572 |
glam_test!(test_saturating_mul, { |
| 3573 |
assert_eq!( |
| 3574 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_mul(U16Vec4::new(2, u16::MAX, 0, 0)), |
| 3575 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0) |
| 3576 |
); |
| 3577 |
}); |
| 3578 |
|
| 3579 |
glam_test!(test_saturating_div, { |
| 3580 |
assert_eq!( |
| 3581 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_div(U16Vec4::new(2, u16::MAX, 3, 4)), |
| 3582 |
U16Vec4::new(32767, 1, 0, 0) |
| 3583 |
); |
| 3584 |
}); |
| 3585 |
|
| 3586 |
glam_test!(test_checked_add_signed, { |
| 3587 |
assert_eq!(U16Vec4::MAX.checked_add_signed(I16Vec4::ONE), None); |
| 3588 |
assert_eq!( |
| 3589 |
U16Vec4::ONE.checked_add_signed(I16Vec4::NEG_ONE), |
| 3590 |
Some(U16Vec4::ZERO) |
| 3591 |
); |
| 3592 |
}); |
| 3593 |
|
| 3594 |
glam_test!(test_wrapping_add_signed, { |
| 3595 |
assert_eq!( |
| 3596 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 3597 |
.wrapping_add_signed(I16Vec4::new(1, 1, 1, 1)), |
| 3598 |
U16Vec4::new(u16::MIN, u16::MIN, u16::MIN, u16::MIN) |
| 3599 |
); |
| 3600 |
}); |
| 3601 |
|
| 3602 |
glam_test!(test_saturating_add_signed, { |
| 3603 |
assert_eq!( |
| 3604 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 3605 |
.saturating_add_signed(I16Vec4::new(1, 1, 1, 1)), |
| 3606 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 3607 |
); |
| 3608 |
}); |
| 3609 |
|
| 3610 |
impl_vec4_unsigned_integer_tests!(u16, u16vec4, U16Vec4, U16Vec3, U16Vec2, BVec4); |
| 3611 |
impl_vec4_eq_hash_tests!(u16, u16vec4); |
| 3612 |
|
| 3613 |
impl_vec4_scalar_shift_op_tests!(U16Vec4, 0, 2); |
| 3614 |
impl_vec4_shift_op_tests!(U16Vec4); |
| 3615 |
|
| 3616 |
impl_vec4_scalar_bit_op_tests!(U16Vec4, 0, 2); |
| 3617 |
impl_vec4_bit_op_tests!(U16Vec4, 0, 2); |
| 3618 |
} |
| 3619 |
|
| 3620 |
mod ivec4 { |
| 3621 |
use glam::{ |
| 3622 |
ivec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec2, IVec3, IVec4, U16Vec4, U64Vec4, U8Vec4, |
| 3623 |
USizeVec4, UVec4, |
| 3624 |
}; |
| 3625 |
|
| 3626 |
glam_test!(test_align, { |
| 3627 |
use std::mem; |
| 3628 |
assert_eq!(16, mem::size_of::<IVec4>()); |
| 3629 |
#[cfg(not(feature = "cuda"))] |
| 3630 |
assert_eq!(4, mem::align_of::<IVec4>()); |
| 3631 |
#[cfg(feature = "cuda")] |
| 3632 |
assert_eq!(16, mem::align_of::<IVec4>()); |
| 3633 |
}); |
| 3634 |
|
| 3635 |
glam_test!(test_try_from, { |
| 3636 |
assert_eq!(IVec4::new(1, 2, 3, 4), IVec4::from(U8Vec4::new(1, 2, 3, 4))); |
| 3637 |
assert_eq!(IVec4::new(1, 2, 3, 4), IVec4::from(I8Vec4::new(1, 2, 3, 4))); |
| 3638 |
|
| 3639 |
assert_eq!( |
| 3640 |
IVec4::new(1, 2, 3, 4), |
| 3641 |
IVec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 3642 |
); |
| 3643 |
assert_eq!( |
| 3644 |
IVec4::new(1, 2, 3, 4), |
| 3645 |
IVec4::from(I16Vec4::new(1, 2, 3, 4)) |
| 3646 |
); |
| 3647 |
|
| 3648 |
assert_eq!( |
| 3649 |
IVec4::new(1, 2, 3, 4), |
| 3650 |
IVec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 3651 |
); |
| 3652 |
assert!(IVec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 3653 |
assert!(IVec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 3654 |
assert!(IVec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 3655 |
assert!(IVec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 3656 |
|
| 3657 |
assert_eq!( |
| 3658 |
IVec4::new(1, 2, 3, 4), |
| 3659 |
IVec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3660 |
); |
| 3661 |
assert!(IVec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 3662 |
assert!(IVec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 3663 |
assert!(IVec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 3664 |
assert!(IVec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 3665 |
|
| 3666 |
assert_eq!( |
| 3667 |
IVec4::new(1, 2, 3, 4), |
| 3668 |
IVec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3669 |
); |
| 3670 |
assert!(IVec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 3671 |
assert!(IVec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 3672 |
assert!(IVec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 3673 |
assert!(IVec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 3674 |
|
| 3675 |
assert_eq!( |
| 3676 |
IVec4::new(1, 2, 3, 4), |
| 3677 |
IVec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 3678 |
); |
| 3679 |
assert!(IVec4::try_from(USizeVec4::new(usize::MAX, 2, 3, 4)).is_err()); |
| 3680 |
assert!(IVec4::try_from(USizeVec4::new(1, usize::MAX, 3, 4)).is_err()); |
| 3681 |
assert!(IVec4::try_from(USizeVec4::new(1, 2, usize::MAX, 4)).is_err()); |
| 3682 |
assert!(IVec4::try_from(USizeVec4::new(1, 2, 3, usize::MAX)).is_err()); |
| 3683 |
}); |
| 3684 |
|
| 3685 |
glam_test!(test_wrapping_add, { |
| 3686 |
assert_eq!( |
| 3687 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_add(IVec4::new(1, 3, i32::MAX, 0)), |
| 3688 |
IVec4::new(i32::MIN, 8, -1, 0), |
| 3689 |
); |
| 3690 |
}); |
| 3691 |
|
| 3692 |
glam_test!(test_wrapping_sub, { |
| 3693 |
assert_eq!( |
| 3694 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_sub(IVec4::new(1, 3, i32::MAX, 0)), |
| 3695 |
IVec4::new(2147483646, 2, 1, 0) |
| 3696 |
); |
| 3697 |
}); |
| 3698 |
|
| 3699 |
glam_test!(test_wrapping_mul, { |
| 3700 |
assert_eq!( |
| 3701 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_mul(IVec4::new(3, 3, 5, 1)), |
| 3702 |
IVec4::new(2147483645, 15, -2147483648, 0) |
| 3703 |
); |
| 3704 |
}); |
| 3705 |
|
| 3706 |
glam_test!(test_wrapping_div, { |
| 3707 |
assert_eq!( |
| 3708 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_div(IVec4::new(3, 3, 5, 1)), |
| 3709 |
IVec4::new(715827882, 1, -429496729, 0) |
| 3710 |
); |
| 3711 |
}); |
| 3712 |
|
| 3713 |
glam_test!(test_saturating_add, { |
| 3714 |
assert_eq!( |
| 3715 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_add(IVec4::new(1, -1, 2, 3)), |
| 3716 |
IVec4::new(i32::MAX, i32::MIN, 2, 3) |
| 3717 |
); |
| 3718 |
}); |
| 3719 |
|
| 3720 |
glam_test!(test_saturating_sub, { |
| 3721 |
assert_eq!( |
| 3722 |
IVec4::new(i32::MIN, i32::MAX, 0, 0).saturating_sub(IVec4::new(1, -1, 2, 3)), |
| 3723 |
IVec4::new(i32::MIN, i32::MAX, -2, -3) |
| 3724 |
); |
| 3725 |
}); |
| 3726 |
|
| 3727 |
glam_test!(test_saturating_mul, { |
| 3728 |
assert_eq!( |
| 3729 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_mul(IVec4::new(2, 2, 0, 0)), |
| 3730 |
IVec4::new(i32::MAX, i32::MIN, 0, 0) |
| 3731 |
); |
| 3732 |
}); |
| 3733 |
|
| 3734 |
glam_test!(test_saturating_div, { |
| 3735 |
assert_eq!( |
| 3736 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_div(IVec4::new(2, 2, 3, 4)), |
| 3737 |
IVec4::new(1073741823, -1073741824, 0, 0) |
| 3738 |
); |
| 3739 |
}); |
| 3740 |
|
| 3741 |
glam_test!(test_checked_add_unsigned, { |
| 3742 |
assert_eq!(IVec4::MAX.checked_add_unsigned(UVec4::ONE), None); |
| 3743 |
assert_eq!( |
| 3744 |
IVec4::NEG_ONE.checked_add_unsigned(UVec4::ONE), |
| 3745 |
Some(IVec4::ZERO) |
| 3746 |
); |
| 3747 |
}); |
| 3748 |
|
| 3749 |
glam_test!(test_checked_sub_unsigned, { |
| 3750 |
assert_eq!(IVec4::MIN.checked_sub_unsigned(UVec4::ONE), None); |
| 3751 |
assert_eq!( |
| 3752 |
IVec4::ZERO.checked_sub_unsigned(UVec4::ONE), |
| 3753 |
Some(IVec4::NEG_ONE) |
| 3754 |
); |
| 3755 |
}); |
| 3756 |
|
| 3757 |
glam_test!(test_wrapping_add_unsigned, { |
| 3758 |
assert_eq!( |
| 3759 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 3760 |
.wrapping_add_unsigned(UVec4::new(1, 1, 1, 1)), |
| 3761 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 3762 |
); |
| 3763 |
}); |
| 3764 |
|
| 3765 |
glam_test!(test_wrapping_sub_unsigned, { |
| 3766 |
assert_eq!( |
| 3767 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 3768 |
.wrapping_sub_unsigned(UVec4::new(1, 1, 1, 1)), |
| 3769 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 3770 |
); |
| 3771 |
}); |
| 3772 |
|
| 3773 |
glam_test!(test_saturating_add_unsigned, { |
| 3774 |
assert_eq!( |
| 3775 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 3776 |
.saturating_add_unsigned(UVec4::new(1, 1, 1, 1)), |
| 3777 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 3778 |
); |
| 3779 |
}); |
| 3780 |
|
| 3781 |
glam_test!(test_saturating_sub_unsigned, { |
| 3782 |
assert_eq!( |
| 3783 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 3784 |
.saturating_sub_unsigned(UVec4::new(1, 1, 1, 1)), |
| 3785 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 3786 |
); |
| 3787 |
}); |
| 3788 |
|
| 3789 |
impl_vec4_signed_integer_tests!(i32, ivec4, IVec4, IVec3, IVec2, BVec4); |
| 3790 |
impl_vec4_eq_hash_tests!(i32, ivec4); |
| 3791 |
|
| 3792 |
impl_vec4_scalar_shift_op_tests!(IVec4, -2, 2); |
| 3793 |
impl_vec4_shift_op_tests!(IVec4); |
| 3794 |
|
| 3795 |
impl_vec4_scalar_bit_op_tests!(IVec4, -2, 2); |
| 3796 |
impl_vec4_bit_op_tests!(IVec4, -2, 2); |
| 3797 |
} |
| 3798 |
|
| 3799 |
mod uvec4 { |
| 3800 |
use glam::{ |
| 3801 |
uvec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec4, USizeVec4, UVec2, |
| 3802 |
UVec3, UVec4, |
| 3803 |
}; |
| 3804 |
|
| 3805 |
glam_test!(test_align, { |
| 3806 |
use std::mem; |
| 3807 |
assert_eq!(16, mem::size_of::<UVec4>()); |
| 3808 |
#[cfg(not(feature = "cuda"))] |
| 3809 |
assert_eq!(4, mem::align_of::<UVec4>()); |
| 3810 |
#[cfg(feature = "cuda")] |
| 3811 |
assert_eq!(16, mem::align_of::<UVec4>()); |
| 3812 |
}); |
| 3813 |
|
| 3814 |
glam_test!(test_try_from, { |
| 3815 |
assert_eq!( |
| 3816 |
UVec4::new(1, 2, 3, 4), |
| 3817 |
UVec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 3818 |
); |
| 3819 |
assert!(UVec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3820 |
assert!(UVec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 3821 |
assert!(UVec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 3822 |
assert!(UVec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 3823 |
|
| 3824 |
assert_eq!(UVec4::new(1, 2, 3, 4), UVec4::from(U8Vec4::new(1, 2, 3, 4))); |
| 3825 |
|
| 3826 |
assert_eq!( |
| 3827 |
UVec4::new(1, 2, 3, 4), |
| 3828 |
UVec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 3829 |
); |
| 3830 |
assert!(UVec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3831 |
assert!(UVec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 3832 |
assert!(UVec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 3833 |
assert!(UVec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 3834 |
|
| 3835 |
assert_eq!( |
| 3836 |
UVec4::new(1, 2, 3, 4), |
| 3837 |
UVec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 3838 |
); |
| 3839 |
|
| 3840 |
assert_eq!( |
| 3841 |
UVec4::new(1, 2, 3, 4), |
| 3842 |
UVec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 3843 |
); |
| 3844 |
assert!(UVec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 3845 |
assert!(UVec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 3846 |
assert!(UVec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 3847 |
assert!(UVec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 3848 |
|
| 3849 |
assert_eq!( |
| 3850 |
UVec4::new(1, 2, 3, 4), |
| 3851 |
UVec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3852 |
); |
| 3853 |
assert!(UVec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3854 |
assert!(UVec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 3855 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 3856 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 3857 |
|
| 3858 |
assert!(UVec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 3859 |
assert!(UVec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 3860 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 3861 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 3862 |
|
| 3863 |
assert_eq!( |
| 3864 |
UVec4::new(1, 2, 3, 4), |
| 3865 |
UVec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3866 |
); |
| 3867 |
assert!(UVec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 3868 |
assert!(UVec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 3869 |
assert!(UVec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 3870 |
assert!(UVec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 3871 |
|
| 3872 |
assert_eq!( |
| 3873 |
UVec4::new(1, 2, 3, 4), |
| 3874 |
UVec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 3875 |
); |
| 3876 |
if core::mem::size_of::<usize>() > 4 { |
| 3877 |
assert!(UVec4::try_from(USizeVec4::new(usize::MAX, 2, 3, 4)).is_err()); |
| 3878 |
assert!(UVec4::try_from(USizeVec4::new(1, usize::MAX, 3, 4)).is_err()); |
| 3879 |
assert!(UVec4::try_from(USizeVec4::new(1, 2, usize::MAX, 4)).is_err()); |
| 3880 |
assert!(UVec4::try_from(USizeVec4::new(1, 2, 3, usize::MAX)).is_err()); |
| 3881 |
} |
| 3882 |
}); |
| 3883 |
|
| 3884 |
glam_test!(test_wrapping_add, { |
| 3885 |
assert_eq!( |
| 3886 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_add(UVec4::new(1, 3, u32::MAX, 0)), |
| 3887 |
UVec4::new(0, 8, 4294967294, 0), |
| 3888 |
); |
| 3889 |
}); |
| 3890 |
|
| 3891 |
glam_test!(test_wrapping_sub, { |
| 3892 |
assert_eq!( |
| 3893 |
UVec4::new(u32::MAX, 5, u32::MAX - 1, 0).wrapping_sub(UVec4::new(1, 3, u32::MAX, 0)), |
| 3894 |
UVec4::new(4294967294, 2, 4294967295, 0) |
| 3895 |
); |
| 3896 |
}); |
| 3897 |
|
| 3898 |
glam_test!(test_wrapping_mul, { |
| 3899 |
assert_eq!( |
| 3900 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_mul(UVec4::new(3, 3, 5, 1)), |
| 3901 |
UVec4::new(4294967293, 15, 4294967291, 0) |
| 3902 |
); |
| 3903 |
}); |
| 3904 |
|
| 3905 |
glam_test!(test_wrapping_div, { |
| 3906 |
assert_eq!( |
| 3907 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_div(UVec4::new(3, 3, 5, 1)), |
| 3908 |
UVec4::new(1431655765, 1, 858993459, 0) |
| 3909 |
); |
| 3910 |
}); |
| 3911 |
|
| 3912 |
glam_test!(test_saturating_add, { |
| 3913 |
assert_eq!( |
| 3914 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_add(UVec4::new(1, u32::MAX, 2, 3)), |
| 3915 |
UVec4::new(u32::MAX, u32::MAX, 2, 3) |
| 3916 |
); |
| 3917 |
}); |
| 3918 |
|
| 3919 |
glam_test!(test_saturating_sub, { |
| 3920 |
assert_eq!( |
| 3921 |
UVec4::new(0, u32::MAX, 0, 0).saturating_sub(UVec4::new(1, 1, 2, 3)), |
| 3922 |
UVec4::new(0, 4294967294, 0, 0) |
| 3923 |
); |
| 3924 |
}); |
| 3925 |
|
| 3926 |
glam_test!(test_saturating_mul, { |
| 3927 |
assert_eq!( |
| 3928 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_mul(UVec4::new(2, u32::MAX, 0, 0)), |
| 3929 |
UVec4::new(u32::MAX, u32::MAX, 0, 0) |
| 3930 |
); |
| 3931 |
}); |
| 3932 |
|
| 3933 |
glam_test!(test_saturating_div, { |
| 3934 |
assert_eq!( |
| 3935 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_div(UVec4::new(2, u32::MAX, 3, 4)), |
| 3936 |
UVec4::new(2147483647, 1, 0, 0) |
| 3937 |
); |
| 3938 |
}); |
| 3939 |
|
| 3940 |
glam_test!(test_checked_add_signed, { |
| 3941 |
assert_eq!(UVec4::MAX.checked_add_signed(IVec4::ONE), None); |
| 3942 |
assert_eq!( |
| 3943 |
UVec4::ONE.checked_add_signed(IVec4::NEG_ONE), |
| 3944 |
Some(UVec4::ZERO) |
| 3945 |
); |
| 3946 |
}); |
| 3947 |
|
| 3948 |
glam_test!(test_wrapping_add_signed, { |
| 3949 |
assert_eq!( |
| 3950 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 3951 |
.wrapping_add_signed(IVec4::new(1, 1, 1, 1)), |
| 3952 |
UVec4::new(u32::MIN, u32::MIN, u32::MIN, u32::MIN) |
| 3953 |
); |
| 3954 |
}); |
| 3955 |
|
| 3956 |
glam_test!(test_saturating_add_signed, { |
| 3957 |
assert_eq!( |
| 3958 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 3959 |
.saturating_add_signed(IVec4::new(1, 1, 1, 1)), |
| 3960 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 3961 |
); |
| 3962 |
}); |
| 3963 |
|
| 3964 |
impl_vec4_unsigned_integer_tests!(u32, uvec4, UVec4, UVec3, UVec2, BVec4); |
| 3965 |
impl_vec4_eq_hash_tests!(u32, uvec4); |
| 3966 |
|
| 3967 |
impl_vec4_scalar_shift_op_tests!(UVec4, 0, 2); |
| 3968 |
impl_vec4_shift_op_tests!(UVec4); |
| 3969 |
|
| 3970 |
impl_vec4_scalar_bit_op_tests!(UVec4, 0, 2); |
| 3971 |
impl_vec4_bit_op_tests!(UVec4, 0, 2); |
| 3972 |
} |
| 3973 |
|
| 3974 |
mod i64vec4 { |
| 3975 |
use glam::{ |
| 3976 |
i64vec4, BVec4, I16Vec4, I64Vec2, I64Vec3, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, |
| 3977 |
U8Vec4, USizeVec4, UVec4, |
| 3978 |
}; |
| 3979 |
|
| 3980 |
glam_test!(test_align, { |
| 3981 |
use std::mem; |
| 3982 |
assert_eq!(32, mem::size_of::<I64Vec4>()); |
| 3983 |
#[cfg(not(feature = "cuda"))] |
| 3984 |
assert_eq!(8, mem::align_of::<I64Vec4>()); |
| 3985 |
#[cfg(feature = "cuda")] |
| 3986 |
assert_eq!(16, mem::align_of::<I64Vec4>()); |
| 3987 |
}); |
| 3988 |
|
| 3989 |
glam_test!(test_try_from, { |
| 3990 |
assert_eq!( |
| 3991 |
I64Vec4::new(1, 2, 3, 4), |
| 3992 |
I64Vec4::from(I8Vec4::new(1, 2, 3, 4)) |
| 3993 |
); |
| 3994 |
assert_eq!( |
| 3995 |
I64Vec4::new(1, 2, 3, 4), |
| 3996 |
I64Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 3997 |
); |
| 3998 |
assert_eq!( |
| 3999 |
I64Vec4::new(1, 2, 3, 4), |
| 4000 |
I64Vec4::from(I16Vec4::new(1, 2, 3, 4)) |
| 4001 |
); |
| 4002 |
assert_eq!( |
| 4003 |
I64Vec4::new(1, 2, 3, 4), |
| 4004 |
I64Vec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 4005 |
); |
| 4006 |
assert_eq!( |
| 4007 |
I64Vec4::new(1, 2, 3, 4), |
| 4008 |
I64Vec4::from(IVec4::new(1, 2, 3, 4)) |
| 4009 |
); |
| 4010 |
assert_eq!( |
| 4011 |
I64Vec4::new(1, 2, 3, 4), |
| 4012 |
I64Vec4::from(UVec4::new(1, 2, 3, 4)) |
| 4013 |
); |
| 4014 |
|
| 4015 |
assert_eq!( |
| 4016 |
I64Vec4::new(1, 2, 3, 4), |
| 4017 |
I64Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 4018 |
); |
| 4019 |
assert!(I64Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 4020 |
assert!(I64Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 4021 |
assert!(I64Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 4022 |
assert!(I64Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 4023 |
|
| 4024 |
assert_eq!( |
| 4025 |
I64Vec4::new(1, 2, 3, 4), |
| 4026 |
I64Vec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 4027 |
); |
| 4028 |
if core::mem::size_of::<usize>() > 4 { |
| 4029 |
assert!(I64Vec4::try_from(USizeVec4::new(usize::MAX, 2, 3, 4)).is_err()); |
| 4030 |
assert!(I64Vec4::try_from(USizeVec4::new(1, usize::MAX, 3, 4)).is_err()); |
| 4031 |
assert!(I64Vec4::try_from(USizeVec4::new(1, 2, usize::MAX, 4)).is_err()); |
| 4032 |
assert!(I64Vec4::try_from(USizeVec4::new(1, 2, 3, usize::MAX)).is_err()); |
| 4033 |
} |
| 4034 |
}); |
| 4035 |
|
| 4036 |
glam_test!(test_wrapping_add, { |
| 4037 |
assert_eq!( |
| 4038 |
I64Vec4::new(i64::MAX, 5, i64::MIN, 0).wrapping_add(I64Vec4::new(1, 3, i64::MAX, 0)), |
| 4039 |
I64Vec4::new(i64::MIN, 8, -1, 0), |
| 4040 |
); |
| 4041 |
}); |
| 4042 |
|
| 4043 |
glam_test!(test_wrapping_sub, { |
| 4044 |
assert_eq!( |
| 4045 |
I64Vec4::new(i64::MAX, 5, i64::MIN, 0).wrapping_sub(I64Vec4::new(1, 3, i64::MAX, 0)), |
| 4046 |
I64Vec4::new(9223372036854775806, 2, 1, 0) |
| 4047 |
); |
| 4048 |
}); |
| 4049 |
|
| 4050 |
glam_test!(test_wrapping_mul, { |
| 4051 |
assert_eq!( |
| 4052 |
I64Vec4::new(i64::MAX, 5, i64::MIN, 0).wrapping_mul(I64Vec4::new(3, 3, 5, 1)), |
| 4053 |
I64Vec4::new(9223372036854775805, 15, -9223372036854775808, 0) |
| 4054 |
); |
| 4055 |
}); |
| 4056 |
|
| 4057 |
glam_test!(test_wrapping_div, { |
| 4058 |
assert_eq!( |
| 4059 |
I64Vec4::new(i64::MAX, 5, i64::MIN, 0).wrapping_div(I64Vec4::new(3, 3, 5, 1)), |
| 4060 |
I64Vec4::new(3074457345618258602, 1, -1844674407370955161, 0) |
| 4061 |
); |
| 4062 |
}); |
| 4063 |
|
| 4064 |
glam_test!(test_saturating_add, { |
| 4065 |
assert_eq!( |
| 4066 |
I64Vec4::new(i64::MAX, i64::MIN, 0, 0).saturating_add(I64Vec4::new(1, -1, 2, 3)), |
| 4067 |
I64Vec4::new(i64::MAX, i64::MIN, 2, 3) |
| 4068 |
); |
| 4069 |
}); |
| 4070 |
|
| 4071 |
glam_test!(test_saturating_sub, { |
| 4072 |
assert_eq!( |
| 4073 |
I64Vec4::new(i64::MIN, i64::MAX, 0, 0).saturating_sub(I64Vec4::new(1, -1, 2, 3)), |
| 4074 |
I64Vec4::new(i64::MIN, i64::MAX, -2, -3) |
| 4075 |
); |
| 4076 |
}); |
| 4077 |
|
| 4078 |
glam_test!(test_saturating_mul, { |
| 4079 |
assert_eq!( |
| 4080 |
I64Vec4::new(i64::MAX, i64::MIN, 0, 0).saturating_mul(I64Vec4::new(2, 2, 0, 0)), |
| 4081 |
I64Vec4::new(i64::MAX, i64::MIN, 0, 0) |
| 4082 |
); |
| 4083 |
}); |
| 4084 |
|
| 4085 |
glam_test!(test_saturating_div, { |
| 4086 |
assert_eq!( |
| 4087 |
I64Vec4::new(i64::MAX, i64::MIN, 0, 0).saturating_div(I64Vec4::new(2, 2, 3, 4)), |
| 4088 |
I64Vec4::new(4611686018427387903, -4611686018427387904, 0, 0) |
| 4089 |
); |
| 4090 |
}); |
| 4091 |
|
| 4092 |
glam_test!(test_checked_add_unsigned, { |
| 4093 |
assert_eq!(I64Vec4::MAX.checked_add_unsigned(U64Vec4::ONE), None); |
| 4094 |
assert_eq!( |
| 4095 |
I64Vec4::NEG_ONE.checked_add_unsigned(U64Vec4::ONE), |
| 4096 |
Some(I64Vec4::ZERO) |
| 4097 |
); |
| 4098 |
}); |
| 4099 |
|
| 4100 |
glam_test!(test_checked_sub_unsigned, { |
| 4101 |
assert_eq!(I64Vec4::MIN.checked_sub_unsigned(U64Vec4::ONE), None); |
| 4102 |
assert_eq!( |
| 4103 |
I64Vec4::ZERO.checked_sub_unsigned(U64Vec4::ONE), |
| 4104 |
Some(I64Vec4::NEG_ONE) |
| 4105 |
); |
| 4106 |
}); |
| 4107 |
|
| 4108 |
glam_test!(test_wrapping_add_unsigned, { |
| 4109 |
assert_eq!( |
| 4110 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 4111 |
.wrapping_add_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 4112 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 4113 |
); |
| 4114 |
}); |
| 4115 |
|
| 4116 |
glam_test!(test_wrapping_sub_unsigned, { |
| 4117 |
assert_eq!( |
| 4118 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 4119 |
.wrapping_sub_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 4120 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 4121 |
); |
| 4122 |
}); |
| 4123 |
|
| 4124 |
glam_test!(test_saturating_add_unsigned, { |
| 4125 |
assert_eq!( |
| 4126 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 4127 |
.saturating_add_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 4128 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 4129 |
); |
| 4130 |
}); |
| 4131 |
|
| 4132 |
glam_test!(test_saturating_sub_unsigned, { |
| 4133 |
assert_eq!( |
| 4134 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 4135 |
.saturating_sub_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 4136 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 4137 |
); |
| 4138 |
}); |
| 4139 |
|
| 4140 |
impl_vec4_signed_integer_tests!(i64, i64vec4, I64Vec4, I64Vec3, I64Vec2, BVec4); |
| 4141 |
impl_vec4_eq_hash_tests!(i64, i64vec4); |
| 4142 |
|
| 4143 |
impl_vec4_scalar_shift_op_tests!(I64Vec4, -2, 2); |
| 4144 |
impl_vec4_shift_op_tests!(I64Vec4); |
| 4145 |
|
| 4146 |
impl_vec4_scalar_bit_op_tests!(I64Vec4, -2, 2); |
| 4147 |
impl_vec4_bit_op_tests!(I64Vec4, -2, 2); |
| 4148 |
} |
| 4149 |
|
| 4150 |
mod u64vec4 { |
| 4151 |
use glam::{ |
| 4152 |
u64vec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec2, U64Vec3, U64Vec4, |
| 4153 |
U8Vec4, USizeVec4, UVec4, |
| 4154 |
}; |
| 4155 |
|
| 4156 |
glam_test!(test_align, { |
| 4157 |
use std::mem; |
| 4158 |
assert_eq!(32, mem::size_of::<U64Vec4>()); |
| 4159 |
#[cfg(not(feature = "cuda"))] |
| 4160 |
assert_eq!(8, mem::align_of::<U64Vec4>()); |
| 4161 |
#[cfg(feature = "cuda")] |
| 4162 |
assert_eq!(16, mem::align_of::<U64Vec4>()); |
| 4163 |
}); |
| 4164 |
|
| 4165 |
glam_test!(test_try_from, { |
| 4166 |
assert_eq!( |
| 4167 |
U64Vec4::new(1, 2, 3, 4), |
| 4168 |
U64Vec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 4169 |
); |
| 4170 |
assert!(U64Vec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 4171 |
assert!(U64Vec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 4172 |
assert!(U64Vec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 4173 |
assert!(U64Vec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 4174 |
|
| 4175 |
assert_eq!( |
| 4176 |
U64Vec4::new(1, 2, 3, 4), |
| 4177 |
U64Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 4178 |
); |
| 4179 |
|
| 4180 |
assert_eq!( |
| 4181 |
U64Vec4::new(1, 2, 3, 4), |
| 4182 |
U64Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 4183 |
); |
| 4184 |
assert!(U64Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 4185 |
assert!(U64Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 4186 |
assert!(U64Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 4187 |
assert!(U64Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 4188 |
|
| 4189 |
assert_eq!( |
| 4190 |
U64Vec4::new(1, 2, 3, 4), |
| 4191 |
U64Vec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 4192 |
); |
| 4193 |
|
| 4194 |
assert_eq!( |
| 4195 |
U64Vec4::new(1, 2, 3, 4), |
| 4196 |
U64Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 4197 |
); |
| 4198 |
assert!(U64Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 4199 |
assert!(U64Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 4200 |
assert!(U64Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 4201 |
assert!(U64Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 4202 |
|
| 4203 |
assert_eq!( |
| 4204 |
U64Vec4::new(1, 2, 3, 4), |
| 4205 |
U64Vec4::from(UVec4::new(1, 2, 3, 4)) |
| 4206 |
); |
| 4207 |
|
| 4208 |
assert_eq!( |
| 4209 |
U64Vec4::new(1, 2, 3, 4), |
| 4210 |
U64Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 4211 |
); |
| 4212 |
assert!(U64Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 4213 |
assert!(U64Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 4214 |
assert!(U64Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 4215 |
assert!(U64Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 4216 |
|
| 4217 |
assert_eq!( |
| 4218 |
U64Vec4::new(1, 2, 3, 4), |
| 4219 |
U64Vec4::try_from(USizeVec4::new(1, 2, 3, 4)).unwrap() |
| 4220 |
); |
| 4221 |
}); |
| 4222 |
|
| 4223 |
glam_test!(test_wrapping_add, { |
| 4224 |
assert_eq!( |
| 4225 |
U64Vec4::new(u64::MAX, 5, u64::MAX, 0).wrapping_add(U64Vec4::new(1, 3, u64::MAX, 0)), |
| 4226 |
U64Vec4::new(0, 8, u64::MAX.wrapping_add(u64::MAX), 0), |
| 4227 |
); |
| 4228 |
}); |
| 4229 |
|
| 4230 |
glam_test!(test_wrapping_sub, { |
| 4231 |
assert_eq!( |
| 4232 |
U64Vec4::new(u64::MAX, 5, u64::MAX - 1, 0).wrapping_sub(U64Vec4::new( |
| 4233 |
1, |
| 4234 |
3, |
| 4235 |
u64::MAX, |
| 4236 |
0 |
| 4237 |
)), |
| 4238 |
U64Vec4::new( |
| 4239 |
u64::MAX.wrapping_sub(1), |
| 4240 |
2, |
| 4241 |
(u64::MAX - 1).wrapping_sub(u64::MAX), |
| 4242 |
0 |
| 4243 |
) |
| 4244 |
); |
| 4245 |
}); |
| 4246 |
|
| 4247 |
glam_test!(test_wrapping_mul, { |
| 4248 |
assert_eq!( |
| 4249 |
U64Vec4::new(u64::MAX, 5, u64::MAX, 0).wrapping_mul(U64Vec4::new(3, 3, 5, 1)), |
| 4250 |
U64Vec4::new(u64::MAX.wrapping_mul(3), 15, u64::MAX.wrapping_mul(5), 0) |
| 4251 |
); |
| 4252 |
}); |
| 4253 |
|
| 4254 |
glam_test!(test_wrapping_div, { |
| 4255 |
assert_eq!( |
| 4256 |
U64Vec4::new(u64::MAX, 5, u64::MAX, 0).wrapping_div(U64Vec4::new(3, 3, 5, 1)), |
| 4257 |
U64Vec4::new(u64::MAX.wrapping_div(3), 1, u64::MAX.wrapping_div(5), 0) |
| 4258 |
); |
| 4259 |
}); |
| 4260 |
|
| 4261 |
glam_test!(test_saturating_add, { |
| 4262 |
assert_eq!( |
| 4263 |
U64Vec4::new(u64::MAX, u64::MAX, 0, 0).saturating_add(U64Vec4::new(1, u64::MAX, 2, 3)), |
| 4264 |
U64Vec4::new(u64::MAX, u64::MAX, 2, 3) |
| 4265 |
); |
| 4266 |
}); |
| 4267 |
|
| 4268 |
glam_test!(test_saturating_sub, { |
| 4269 |
assert_eq!( |
| 4270 |
U64Vec4::new(0, u64::MAX, 0, 0).saturating_sub(U64Vec4::new(1, 1, 2, 3)), |
| 4271 |
U64Vec4::new(0, u64::MAX.saturating_sub(1), 0, 0) |
| 4272 |
); |
| 4273 |
}); |
| 4274 |
|
| 4275 |
glam_test!(test_saturating_mul, { |
| 4276 |
assert_eq!( |
| 4277 |
U64Vec4::new(u64::MAX, u64::MAX, 0, 0).saturating_mul(U64Vec4::new(2, u64::MAX, 0, 0)), |
| 4278 |
U64Vec4::new(u64::MAX, u64::MAX, 0, 0) |
| 4279 |
); |
| 4280 |
}); |
| 4281 |
|
| 4282 |
glam_test!(test_saturating_div, { |
| 4283 |
assert_eq!( |
| 4284 |
U64Vec4::new(u64::MAX, u64::MAX, 0, 0).saturating_div(U64Vec4::new(2, u64::MAX, 3, 4)), |
| 4285 |
U64Vec4::new(u64::MAX.saturating_div(2), 1, 0, 0) |
| 4286 |
); |
| 4287 |
}); |
| 4288 |
|
| 4289 |
glam_test!(test_checked_add_signed, { |
| 4290 |
assert_eq!(U64Vec4::MAX.checked_add_signed(I64Vec4::ONE), None); |
| 4291 |
assert_eq!( |
| 4292 |
U64Vec4::ONE.checked_add_signed(I64Vec4::NEG_ONE), |
| 4293 |
Some(U64Vec4::ZERO) |
| 4294 |
); |
| 4295 |
}); |
| 4296 |
|
| 4297 |
glam_test!(test_wrapping_add_signed, { |
| 4298 |
assert_eq!( |
| 4299 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 4300 |
.wrapping_add_signed(I64Vec4::new(1, 1, 1, 1)), |
| 4301 |
U64Vec4::new(u64::MIN, u64::MIN, u64::MIN, u64::MIN) |
| 4302 |
); |
| 4303 |
}); |
| 4304 |
|
| 4305 |
glam_test!(test_saturating_add_signed, { |
| 4306 |
assert_eq!( |
| 4307 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 4308 |
.saturating_add_signed(I64Vec4::new(1, 1, 1, 1)), |
| 4309 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 4310 |
); |
| 4311 |
}); |
| 4312 |
|
| 4313 |
impl_vec4_unsigned_integer_tests!(u64, u64vec4, U64Vec4, U64Vec3, U64Vec2, BVec4); |
| 4314 |
impl_vec4_eq_hash_tests!(u64, u64vec4); |
| 4315 |
|
| 4316 |
impl_vec4_scalar_shift_op_tests!(U64Vec4, 0, 2); |
| 4317 |
impl_vec4_shift_op_tests!(U64Vec4); |
| 4318 |
|
| 4319 |
impl_vec4_scalar_bit_op_tests!(U64Vec4, 0, 2); |
| 4320 |
impl_vec4_bit_op_tests!(U64Vec4, 0, 2); |
| 4321 |
} |
| 4322 |
|
| 4323 |
mod usizevec4 { |
| 4324 |
use glam::{ |
| 4325 |
usizevec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec4, USizeVec2, |
| 4326 |
USizeVec3, USizeVec4, UVec4, |
| 4327 |
}; |
| 4328 |
|
| 4329 |
glam_test!(test_align, { |
| 4330 |
use std::mem; |
| 4331 |
assert_eq!(mem::size_of::<usize>() * 4, mem::size_of::<USizeVec4>()); |
| 4332 |
#[cfg(not(feature = "cuda"))] |
| 4333 |
assert_eq!(mem::align_of::<usize>(), mem::align_of::<USizeVec4>()); |
| 4334 |
#[cfg(feature = "cuda")] |
| 4335 |
assert_eq!(16, mem::align_of::<USizeVec4>()); |
| 4336 |
}); |
| 4337 |
|
| 4338 |
glam_test!(test_try_from, { |
| 4339 |
assert_eq!( |
| 4340 |
USizeVec4::new(1, 2, 3, 4), |
| 4341 |
USizeVec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 4342 |
); |
| 4343 |
assert!(USizeVec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 4344 |
assert!(USizeVec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 4345 |
assert!(USizeVec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 4346 |
assert!(USizeVec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 4347 |
|
| 4348 |
assert_eq!( |
| 4349 |
USizeVec4::new(1, 2, 3, 4), |
| 4350 |
USizeVec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 4351 |
); |
| 4352 |
|
| 4353 |
assert_eq!( |
| 4354 |
USizeVec4::new(1, 2, 3, 4), |
| 4355 |
USizeVec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 4356 |
); |
| 4357 |
assert!(USizeVec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 4358 |
assert!(USizeVec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 4359 |
assert!(USizeVec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 4360 |
assert!(USizeVec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 4361 |
|
| 4362 |
assert_eq!( |
| 4363 |
USizeVec4::new(1, 2, 3, 4), |
| 4364 |
USizeVec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 4365 |
); |
| 4366 |
|
| 4367 |
assert_eq!( |
| 4368 |
USizeVec4::new(1, 2, 3, 4), |
| 4369 |
USizeVec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 4370 |
); |
| 4371 |
assert!(USizeVec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 4372 |
assert!(USizeVec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 4373 |
assert!(USizeVec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 4374 |
assert!(USizeVec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 4375 |
|
| 4376 |
assert_eq!( |
| 4377 |
USizeVec4::new(1, 2, 3, 4), |
| 4378 |
USizeVec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 4379 |
); |
| 4380 |
assert_eq!( |
| 4381 |
USizeVec4::new(1, 2, 3, 4), |
| 4382 |
USizeVec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 4383 |
); |
| 4384 |
|
| 4385 |
assert_eq!( |
| 4386 |
USizeVec4::new(1, 2, 3, 4), |
| 4387 |
USizeVec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 4388 |
); |
| 4389 |
assert!(USizeVec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 4390 |
assert!(USizeVec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 4391 |
assert!(USizeVec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 4392 |
assert!(USizeVec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 4393 |
}); |
| 4394 |
|
| 4395 |
glam_test!(test_wrapping_add, { |
| 4396 |
assert_eq!( |
| 4397 |
USizeVec4::new(usize::MAX, 5, usize::MAX, 0).wrapping_add(USizeVec4::new( |
| 4398 |
1, |
| 4399 |
3, |
| 4400 |
usize::MAX, |
| 4401 |
0 |
| 4402 |
)), |
| 4403 |
USizeVec4::new(0, 8, usize::MAX.wrapping_add(usize::MAX), 0), |
| 4404 |
); |
| 4405 |
}); |
| 4406 |
|
| 4407 |
glam_test!(test_wrapping_sub, { |
| 4408 |
assert_eq!( |
| 4409 |
USizeVec4::new(usize::MAX, 5, usize::MAX - 1, 0).wrapping_sub(USizeVec4::new( |
| 4410 |
1, |
| 4411 |
3, |
| 4412 |
usize::MAX, |
| 4413 |
0 |
| 4414 |
)), |
| 4415 |
USizeVec4::new( |
| 4416 |
usize::MAX.wrapping_sub(1), |
| 4417 |
2, |
| 4418 |
(usize::MAX - 1).wrapping_sub(usize::MAX), |
| 4419 |
0 |
| 4420 |
) |
| 4421 |
); |
| 4422 |
}); |
| 4423 |
|
| 4424 |
glam_test!(test_wrapping_mul, { |
| 4425 |
assert_eq!( |
| 4426 |
USizeVec4::new(usize::MAX, 5, usize::MAX, 0).wrapping_mul(USizeVec4::new(3, 3, 5, 1)), |
| 4427 |
USizeVec4::new( |
| 4428 |
usize::MAX.wrapping_mul(3), |
| 4429 |
15, |
| 4430 |
usize::MAX.wrapping_mul(5), |
| 4431 |
0 |
| 4432 |
) |
| 4433 |
); |
| 4434 |
}); |
| 4435 |
|
| 4436 |
glam_test!(test_wrapping_div, { |
| 4437 |
assert_eq!( |
| 4438 |
USizeVec4::new(usize::MAX, 5, usize::MAX, 0).wrapping_div(USizeVec4::new(3, 3, 5, 1)), |
| 4439 |
USizeVec4::new(usize::MAX.wrapping_div(3), 1, usize::MAX.wrapping_div(5), 0) |
| 4440 |
); |
| 4441 |
}); |
| 4442 |
|
| 4443 |
glam_test!(test_saturating_add, { |
| 4444 |
assert_eq!( |
| 4445 |
USizeVec4::new(usize::MAX, usize::MAX, 0, 0).saturating_add(USizeVec4::new( |
| 4446 |
1, |
| 4447 |
usize::MAX, |
| 4448 |
2, |
| 4449 |
3 |
| 4450 |
)), |
| 4451 |
USizeVec4::new(usize::MAX, usize::MAX, 2, 3) |
| 4452 |
); |
| 4453 |
}); |
| 4454 |
|
| 4455 |
glam_test!(test_saturating_sub, { |
| 4456 |
assert_eq!( |
| 4457 |
USizeVec4::new(0, usize::MAX, 0, 0).saturating_sub(USizeVec4::new(1, 1, 2, 3)), |
| 4458 |
USizeVec4::new(0, usize::MAX.saturating_sub(1), 0, 0) |
| 4459 |
); |
| 4460 |
}); |
| 4461 |
|
| 4462 |
glam_test!(test_saturating_mul, { |
| 4463 |
assert_eq!( |
| 4464 |
USizeVec4::new(usize::MAX, usize::MAX, 0, 0).saturating_mul(USizeVec4::new( |
| 4465 |
2, |
| 4466 |
usize::MAX, |
| 4467 |
0, |
| 4468 |
0 |
| 4469 |
)), |
| 4470 |
USizeVec4::new(usize::MAX, usize::MAX, 0, 0) |
| 4471 |
); |
| 4472 |
}); |
| 4473 |
|
| 4474 |
glam_test!(test_saturating_div, { |
| 4475 |
assert_eq!( |
| 4476 |
USizeVec4::new(usize::MAX, usize::MAX, 0, 0).saturating_div(USizeVec4::new( |
| 4477 |
2, |
| 4478 |
usize::MAX, |
| 4479 |
3, |
| 4480 |
4 |
| 4481 |
)), |
| 4482 |
USizeVec4::new(usize::MAX.saturating_div(2), 1, 0, 0) |
| 4483 |
); |
| 4484 |
}); |
| 4485 |
|
| 4486 |
impl_vec4_unsigned_integer_tests!(usize, usizevec4, USizeVec4, USizeVec3, USizeVec2, BVec4); |
| 4487 |
impl_vec4_eq_hash_tests!(usize, usizevec4); |
| 4488 |
|
| 4489 |
impl_vec4_scalar_shift_op_tests!(USizeVec4, 0, 2); |
| 4490 |
impl_vec4_shift_op_tests!(USizeVec4); |
| 4491 |
|
| 4492 |
impl_vec4_scalar_bit_op_tests!(USizeVec4, 0, 2); |
| 4493 |
impl_vec4_bit_op_tests!(USizeVec4, 0, 2); |
| 4494 |
} |