| 1 | use crate::core::{ |
| 2 | storage::{XY, XYZ, XYZF32A16, XYZW}, |
| 3 | traits::{scalar::*, vector::*}, |
| 4 | }; |
| 5 | |
| 6 | impl<T: NumEx> VectorConst for XY<T> { |
| 7 | const ZERO: Self = Self { |
| 8 | x: <T as NumConstEx>::ZERO, |
| 9 | y: <T as NumConstEx>::ZERO, |
| 10 | }; |
| 11 | const ONE: Self = Self { |
| 12 | x: <T as NumConstEx>::ONE, |
| 13 | y: <T as NumConstEx>::ONE, |
| 14 | }; |
| 15 | } |
| 16 | |
| 17 | impl<T: NanConstEx> NanConstEx for XY<T> { |
| 18 | const NAN: Self = Self { |
| 19 | x: <T as NanConstEx>::NAN, |
| 20 | y: <T as NanConstEx>::NAN, |
| 21 | }; |
| 22 | } |
| 23 | |
| 24 | impl<T: NumEx> Vector2Const for XY<T> { |
| 25 | const X: Self = Self { |
| 26 | x: <T as NumConstEx>::ONE, |
| 27 | y: <T as NumConstEx>::ZERO, |
| 28 | }; |
| 29 | const Y: Self = Self { |
| 30 | x: <T as NumConstEx>::ZERO, |
| 31 | y: <T as NumConstEx>::ONE, |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | impl<T: NumEx> VectorConst for XYZ<T> { |
| 36 | const ZERO: Self = Self { |
| 37 | x: <T as NumConstEx>::ZERO, |
| 38 | y: <T as NumConstEx>::ZERO, |
| 39 | z: <T as NumConstEx>::ZERO, |
| 40 | }; |
| 41 | const ONE: Self = Self { |
| 42 | x: <T as NumConstEx>::ONE, |
| 43 | y: <T as NumConstEx>::ONE, |
| 44 | z: <T as NumConstEx>::ONE, |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | impl<T: NanConstEx> NanConstEx for XYZ<T> { |
| 49 | const NAN: Self = Self { |
| 50 | x: <T as NanConstEx>::NAN, |
| 51 | y: <T as NanConstEx>::NAN, |
| 52 | z: <T as NanConstEx>::NAN, |
| 53 | }; |
| 54 | } |
| 55 | |
| 56 | impl<T: NumEx> Vector3Const for XYZ<T> { |
| 57 | const X: Self = Self { |
| 58 | x: <T as NumConstEx>::ONE, |
| 59 | y: <T as NumConstEx>::ZERO, |
| 60 | z: <T as NumConstEx>::ZERO, |
| 61 | }; |
| 62 | const Y: Self = Self { |
| 63 | x: <T as NumConstEx>::ZERO, |
| 64 | y: <T as NumConstEx>::ONE, |
| 65 | z: <T as NumConstEx>::ZERO, |
| 66 | }; |
| 67 | const Z: Self = Self { |
| 68 | x: <T as NumConstEx>::ZERO, |
| 69 | y: <T as NumConstEx>::ZERO, |
| 70 | z: <T as NumConstEx>::ONE, |
| 71 | }; |
| 72 | } |
| 73 | |
| 74 | impl<T: NumEx> VectorConst for XYZW<T> { |
| 75 | const ZERO: Self = Self { |
| 76 | x: <T as NumConstEx>::ZERO, |
| 77 | y: <T as NumConstEx>::ZERO, |
| 78 | z: <T as NumConstEx>::ZERO, |
| 79 | w: <T as NumConstEx>::ZERO, |
| 80 | }; |
| 81 | const ONE: Self = Self { |
| 82 | x: <T as NumConstEx>::ONE, |
| 83 | y: <T as NumConstEx>::ONE, |
| 84 | z: <T as NumConstEx>::ONE, |
| 85 | w: <T as NumConstEx>::ONE, |
| 86 | }; |
| 87 | } |
| 88 | |
| 89 | impl<T: NanConstEx> NanConstEx for XYZW<T> { |
| 90 | const NAN: Self = Self { |
| 91 | x: <T as NanConstEx>::NAN, |
| 92 | y: <T as NanConstEx>::NAN, |
| 93 | z: <T as NanConstEx>::NAN, |
| 94 | w: <T as NanConstEx>::NAN, |
| 95 | }; |
| 96 | } |
| 97 | |
| 98 | impl<T: NumEx> Vector4Const for XYZW<T> { |
| 99 | const X: Self = Self { |
| 100 | x: <T as NumConstEx>::ONE, |
| 101 | y: <T as NumConstEx>::ZERO, |
| 102 | z: <T as NumConstEx>::ZERO, |
| 103 | w: <T as NumConstEx>::ZERO, |
| 104 | }; |
| 105 | const Y: Self = Self { |
| 106 | x: <T as NumConstEx>::ZERO, |
| 107 | y: <T as NumConstEx>::ONE, |
| 108 | z: <T as NumConstEx>::ZERO, |
| 109 | w: <T as NumConstEx>::ZERO, |
| 110 | }; |
| 111 | const Z: Self = Self { |
| 112 | x: <T as NumConstEx>::ZERO, |
| 113 | y: <T as NumConstEx>::ZERO, |
| 114 | z: <T as NumConstEx>::ONE, |
| 115 | w: <T as NumConstEx>::ZERO, |
| 116 | }; |
| 117 | const W: Self = Self { |
| 118 | x: <T as NumConstEx>::ZERO, |
| 119 | y: <T as NumConstEx>::ZERO, |
| 120 | z: <T as NumConstEx>::ZERO, |
| 121 | w: <T as NumConstEx>::ONE, |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | impl<T: NumEx> Vector<T> for XY<T> { |
| 126 | type Mask = XY<bool>; |
| 127 | |
| 128 | #[inline] |
| 129 | fn splat(s: T) -> Self { |
| 130 | Self { x: s, y: s } |
| 131 | } |
| 132 | |
| 133 | #[inline] |
| 134 | fn select(mask: Self::Mask, if_true: Self, if_false: Self) -> Self { |
| 135 | Self { |
| 136 | x: if mask.x { if_true.x } else { if_false.x }, |
| 137 | y: if mask.y { if_true.y } else { if_false.y }, |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | #[inline] |
| 142 | fn cmpeq(self, other: Self) -> Self::Mask { |
| 143 | Self::Mask { |
| 144 | x: self.x.eq(&other.x), |
| 145 | y: self.y.eq(&other.y), |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #[inline] |
| 150 | fn cmpne(self, other: Self) -> Self::Mask { |
| 151 | Self::Mask { |
| 152 | x: self.x.ne(&other.x), |
| 153 | y: self.y.ne(&other.y), |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | #[inline] |
| 158 | fn cmpge(self, other: Self) -> Self::Mask { |
| 159 | Self::Mask { |
| 160 | x: self.x.ge(&other.x), |
| 161 | y: self.y.ge(&other.y), |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | #[inline] |
| 166 | fn cmpgt(self, other: Self) -> Self::Mask { |
| 167 | Self::Mask { |
| 168 | x: self.x.gt(&other.x), |
| 169 | y: self.y.gt(&other.y), |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | #[inline] |
| 174 | fn cmple(self, other: Self) -> Self::Mask { |
| 175 | Self::Mask { |
| 176 | x: self.x.le(&other.x), |
| 177 | y: self.y.le(&other.y), |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | #[inline] |
| 182 | fn cmplt(self, other: Self) -> Self::Mask { |
| 183 | Self::Mask { |
| 184 | x: self.x.lt(&other.x), |
| 185 | y: self.y.lt(&other.y), |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | #[inline] |
| 190 | fn add(self, other: Self) -> Self { |
| 191 | Self { |
| 192 | x: self.x + other.x, |
| 193 | y: self.y + other.y, |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | #[inline] |
| 198 | fn div(self, other: Self) -> Self { |
| 199 | Self { |
| 200 | x: self.x / other.x, |
| 201 | y: self.y / other.y, |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | #[inline] |
| 206 | fn mul(self, other: Self) -> Self { |
| 207 | Self { |
| 208 | x: self.x * other.x, |
| 209 | y: self.y * other.y, |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | #[inline] |
| 214 | fn sub(self, other: Self) -> Self { |
| 215 | Self { |
| 216 | x: self.x - other.x, |
| 217 | y: self.y - other.y, |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | #[inline] |
| 222 | fn add_scalar(self, other: T) -> Self { |
| 223 | Self { |
| 224 | x: self.x + other, |
| 225 | y: self.y + other, |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | #[inline] |
| 230 | fn sub_scalar(self, other: T) -> Self { |
| 231 | Self { |
| 232 | x: self.x - other, |
| 233 | y: self.y - other, |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | #[inline] |
| 238 | fn mul_scalar(self, other: T) -> Self { |
| 239 | Self { |
| 240 | x: self.x * other, |
| 241 | y: self.y * other, |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | #[inline] |
| 246 | fn div_scalar(self, other: T) -> Self { |
| 247 | Self { |
| 248 | x: self.x / other, |
| 249 | y: self.y / other, |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | #[inline] |
| 254 | fn rem(self, other: Self) -> Self { |
| 255 | Self { |
| 256 | x: self.x % other.x, |
| 257 | y: self.y % other.y, |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | #[inline] |
| 262 | fn rem_scalar(self, other: T) -> Self { |
| 263 | Self { |
| 264 | x: self.x % other, |
| 265 | y: self.y % other, |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | #[inline] |
| 270 | fn min(self, other: Self) -> Self { |
| 271 | Self { |
| 272 | x: self.x.min(other.x), |
| 273 | y: self.y.min(other.y), |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | #[inline] |
| 278 | fn max(self, other: Self) -> Self { |
| 279 | Self { |
| 280 | x: self.x.max(other.x), |
| 281 | y: self.y.max(other.y), |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | impl<T: NumEx> Vector<T> for XYZ<T> { |
| 287 | type Mask = XYZ<bool>; |
| 288 | |
| 289 | #[inline] |
| 290 | fn splat(s: T) -> Self { |
| 291 | Self { x: s, y: s, z: s } |
| 292 | } |
| 293 | |
| 294 | #[inline] |
| 295 | fn select(mask: Self::Mask, if_true: Self, if_false: Self) -> Self { |
| 296 | Self { |
| 297 | x: if mask.x { if_true.x } else { if_false.x }, |
| 298 | y: if mask.y { if_true.y } else { if_false.y }, |
| 299 | z: if mask.z { if_true.z } else { if_false.z }, |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | #[inline] |
| 304 | fn cmpeq(self, other: Self) -> Self::Mask { |
| 305 | Self::Mask { |
| 306 | x: self.x.eq(&other.x), |
| 307 | y: self.y.eq(&other.y), |
| 308 | z: self.z.eq(&other.z), |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | #[inline] |
| 313 | fn cmpne(self, other: Self) -> Self::Mask { |
| 314 | Self::Mask { |
| 315 | x: self.x.ne(&other.x), |
| 316 | y: self.y.ne(&other.y), |
| 317 | z: self.z.ne(&other.z), |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | #[inline] |
| 322 | fn cmpge(self, other: Self) -> Self::Mask { |
| 323 | Self::Mask { |
| 324 | x: self.x.ge(&other.x), |
| 325 | y: self.y.ge(&other.y), |
| 326 | z: self.z.ge(&other.z), |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | #[inline] |
| 331 | fn cmpgt(self, other: Self) -> Self::Mask { |
| 332 | Self::Mask { |
| 333 | x: self.x.gt(&other.x), |
| 334 | y: self.y.gt(&other.y), |
| 335 | z: self.z.gt(&other.z), |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | #[inline] |
| 340 | fn cmple(self, other: Self) -> Self::Mask { |
| 341 | Self::Mask { |
| 342 | x: self.x.le(&other.x), |
| 343 | y: self.y.le(&other.y), |
| 344 | z: self.z.le(&other.z), |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | #[inline] |
| 349 | fn cmplt(self, other: Self) -> Self::Mask { |
| 350 | Self::Mask { |
| 351 | x: self.x.lt(&other.x), |
| 352 | y: self.y.lt(&other.y), |
| 353 | z: self.z.lt(&other.z), |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | #[inline] |
| 358 | fn add(self, other: Self) -> Self { |
| 359 | Self { |
| 360 | x: self.x + other.x, |
| 361 | y: self.y + other.y, |
| 362 | z: self.z + other.z, |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | #[inline] |
| 367 | fn div(self, other: Self) -> Self { |
| 368 | Self { |
| 369 | x: self.x / other.x, |
| 370 | y: self.y / other.y, |
| 371 | z: self.z / other.z, |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | #[inline] |
| 376 | fn mul(self, other: Self) -> Self { |
| 377 | Self { |
| 378 | x: self.x * other.x, |
| 379 | y: self.y * other.y, |
| 380 | z: self.z * other.z, |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | #[inline] |
| 385 | fn sub(self, other: Self) -> Self { |
| 386 | Self { |
| 387 | x: self.x - other.x, |
| 388 | y: self.y - other.y, |
| 389 | z: self.z - other.z, |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | fn add_scalar(self, other: T) -> Self { |
| 394 | Self { |
| 395 | x: self.x + other, |
| 396 | y: self.y + other, |
| 397 | z: self.z + other, |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | fn sub_scalar(self, other: T) -> Self { |
| 402 | Self { |
| 403 | x: self.x - other, |
| 404 | y: self.y - other, |
| 405 | z: self.z - other, |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | #[inline] |
| 410 | fn mul_scalar(self, other: T) -> Self { |
| 411 | Self { |
| 412 | x: self.x * other, |
| 413 | y: self.y * other, |
| 414 | z: self.z * other, |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | #[inline] |
| 419 | fn div_scalar(self, other: T) -> Self { |
| 420 | Self { |
| 421 | x: self.x / other, |
| 422 | y: self.y / other, |
| 423 | z: self.z / other, |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | #[inline] |
| 428 | fn rem(self, other: Self) -> Self { |
| 429 | Self { |
| 430 | x: self.x % other.x, |
| 431 | y: self.y % other.y, |
| 432 | z: self.z % other.z, |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | #[inline] |
| 437 | fn rem_scalar(self, other: T) -> Self { |
| 438 | Self { |
| 439 | x: self.x % other, |
| 440 | y: self.y % other, |
| 441 | z: self.z % other, |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | #[inline] |
| 446 | fn min(self, other: Self) -> Self { |
| 447 | Self { |
| 448 | x: self.x.min(other.x), |
| 449 | y: self.y.min(other.y), |
| 450 | z: self.z.min(other.z), |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | #[inline] |
| 455 | fn max(self, other: Self) -> Self { |
| 456 | Self { |
| 457 | x: self.x.max(other.x), |
| 458 | y: self.y.max(other.y), |
| 459 | z: self.z.max(other.z), |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | impl<T: NumEx> Vector<T> for XYZW<T> { |
| 465 | type Mask = XYZW<bool>; |
| 466 | |
| 467 | #[inline] |
| 468 | fn splat(s: T) -> Self { |
| 469 | Self { |
| 470 | x: s, |
| 471 | y: s, |
| 472 | z: s, |
| 473 | w: s, |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | #[inline] |
| 478 | fn select(mask: Self::Mask, if_true: Self, if_false: Self) -> Self { |
| 479 | Self { |
| 480 | x: if mask.x { if_true.x } else { if_false.x }, |
| 481 | y: if mask.y { if_true.y } else { if_false.y }, |
| 482 | z: if mask.z { if_true.z } else { if_false.z }, |
| 483 | w: if mask.w { if_true.w } else { if_false.w }, |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | #[inline] |
| 488 | fn cmpeq(self, other: Self) -> Self::Mask { |
| 489 | Self::Mask { |
| 490 | x: self.x.eq(&other.x), |
| 491 | y: self.y.eq(&other.y), |
| 492 | z: self.z.eq(&other.z), |
| 493 | w: self.w.eq(&other.w), |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | #[inline] |
| 498 | fn cmpne(self, other: Self) -> Self::Mask { |
| 499 | Self::Mask { |
| 500 | x: self.x.ne(&other.x), |
| 501 | y: self.y.ne(&other.y), |
| 502 | z: self.z.ne(&other.z), |
| 503 | w: self.w.ne(&other.w), |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | #[inline] |
| 508 | fn cmpge(self, other: Self) -> Self::Mask { |
| 509 | Self::Mask { |
| 510 | x: self.x.ge(&other.x), |
| 511 | y: self.y.ge(&other.y), |
| 512 | z: self.z.ge(&other.z), |
| 513 | w: self.w.ge(&other.w), |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | #[inline] |
| 518 | fn cmpgt(self, other: Self) -> Self::Mask { |
| 519 | Self::Mask { |
| 520 | x: self.x.gt(&other.x), |
| 521 | y: self.y.gt(&other.y), |
| 522 | z: self.z.gt(&other.z), |
| 523 | w: self.w.gt(&other.w), |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | #[inline] |
| 528 | fn cmple(self, other: Self) -> Self::Mask { |
| 529 | Self::Mask { |
| 530 | x: self.x.le(&other.x), |
| 531 | y: self.y.le(&other.y), |
| 532 | z: self.z.le(&other.z), |
| 533 | w: self.w.le(&other.w), |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | #[inline] |
| 538 | fn cmplt(self, other: Self) -> Self::Mask { |
| 539 | Self::Mask { |
| 540 | x: self.x.lt(&other.x), |
| 541 | y: self.y.lt(&other.y), |
| 542 | z: self.z.lt(&other.z), |
| 543 | w: self.w.lt(&other.w), |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | #[inline] |
| 548 | fn add(self, other: Self) -> Self { |
| 549 | Self { |
| 550 | x: self.x + other.x, |
| 551 | y: self.y + other.y, |
| 552 | z: self.z + other.z, |
| 553 | w: self.w + other.w, |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | #[inline] |
| 558 | fn div(self, other: Self) -> Self { |
| 559 | Self { |
| 560 | x: self.x / other.x, |
| 561 | y: self.y / other.y, |
| 562 | z: self.z / other.z, |
| 563 | w: self.w / other.w, |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | #[inline] |
| 568 | fn mul(self, other: Self) -> Self { |
| 569 | Self { |
| 570 | x: self.x * other.x, |
| 571 | y: self.y * other.y, |
| 572 | z: self.z * other.z, |
| 573 | w: self.w * other.w, |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | #[inline] |
| 578 | fn sub(self, other: Self) -> Self { |
| 579 | Self { |
| 580 | x: self.x - other.x, |
| 581 | y: self.y - other.y, |
| 582 | z: self.z - other.z, |
| 583 | w: self.w - other.w, |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | fn add_scalar(self, other: T) -> Self { |
| 588 | Self { |
| 589 | x: self.x + other, |
| 590 | y: self.y + other, |
| 591 | z: self.z + other, |
| 592 | w: self.w + other, |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | fn sub_scalar(self, other: T) -> Self { |
| 597 | Self { |
| 598 | x: self.x - other, |
| 599 | y: self.y - other, |
| 600 | z: self.z - other, |
| 601 | w: self.w - other, |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | #[inline] |
| 606 | fn mul_scalar(self, other: T) -> Self { |
| 607 | Self { |
| 608 | x: self.x * other, |
| 609 | y: self.y * other, |
| 610 | z: self.z * other, |
| 611 | w: self.w * other, |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | #[inline] |
| 616 | fn div_scalar(self, other: T) -> Self { |
| 617 | Self { |
| 618 | x: self.x / other, |
| 619 | y: self.y / other, |
| 620 | z: self.z / other, |
| 621 | w: self.w / other, |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | #[inline] |
| 626 | fn rem(self, other: Self) -> Self { |
| 627 | Self { |
| 628 | x: self.x % other.x, |
| 629 | y: self.y % other.y, |
| 630 | z: self.z % other.z, |
| 631 | w: self.w % other.w, |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | #[inline] |
| 636 | fn rem_scalar(self, other: T) -> Self { |
| 637 | Self { |
| 638 | x: self.x % other, |
| 639 | y: self.y % other, |
| 640 | z: self.z % other, |
| 641 | w: self.w % other, |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | #[inline] |
| 646 | fn min(self, other: Self) -> Self { |
| 647 | Self { |
| 648 | x: self.x.min(other.x), |
| 649 | y: self.y.min(other.y), |
| 650 | z: self.z.min(other.z), |
| 651 | w: self.w.min(other.w), |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | #[inline] |
| 656 | fn max(self, other: Self) -> Self { |
| 657 | Self { |
| 658 | x: self.x.max(other.x), |
| 659 | y: self.y.max(other.y), |
| 660 | z: self.z.max(other.z), |
| 661 | w: self.w.max(other.w), |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | impl<T: NumEx> Vector2<T> for XY<T> { |
| 667 | #[inline(always)] |
| 668 | fn new(x: T, y: T) -> Self { |
| 669 | Self { x, y } |
| 670 | } |
| 671 | |
| 672 | #[inline(always)] |
| 673 | fn x(self) -> T { |
| 674 | self.x |
| 675 | } |
| 676 | |
| 677 | #[inline(always)] |
| 678 | fn y(self) -> T { |
| 679 | self.y |
| 680 | } |
| 681 | |
| 682 | #[inline(always)] |
| 683 | fn as_ref_xy(&self) -> &XY<T> { |
| 684 | self |
| 685 | } |
| 686 | |
| 687 | #[inline(always)] |
| 688 | fn as_mut_xy(&mut self) -> &mut XY<T> { |
| 689 | self |
| 690 | } |
| 691 | |
| 692 | #[inline] |
| 693 | fn min_element(self) -> T { |
| 694 | self.x.min(self.y) |
| 695 | } |
| 696 | |
| 697 | #[inline] |
| 698 | fn max_element(self) -> T { |
| 699 | self.x.max(self.y) |
| 700 | } |
| 701 | |
| 702 | #[inline] |
| 703 | fn clamp(self, min: Self, max: Self) -> Self { |
| 704 | glam_assert!(min.x <= max.x); |
| 705 | glam_assert!(min.y <= max.y); |
| 706 | // we intentionally do not use `f32::clamp` because we don't |
| 707 | // want panics unless `glam-assert` feature is on. |
| 708 | Self { |
| 709 | x: self.x.max(min.x).min(max.x), |
| 710 | y: self.y.max(min.y).min(max.y), |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | impl<T: NumEx> Vector3<T> for XYZ<T> { |
| 716 | #[inline(always)] |
| 717 | fn new(x: T, y: T, z: T) -> Self { |
| 718 | Self { x, y, z } |
| 719 | } |
| 720 | |
| 721 | #[inline(always)] |
| 722 | fn x(self) -> T { |
| 723 | self.x |
| 724 | } |
| 725 | |
| 726 | #[inline(always)] |
| 727 | fn y(self) -> T { |
| 728 | self.y |
| 729 | } |
| 730 | |
| 731 | #[inline(always)] |
| 732 | fn z(self) -> T { |
| 733 | self.z |
| 734 | } |
| 735 | |
| 736 | #[inline(always)] |
| 737 | fn as_ref_xyz(&self) -> &XYZ<T> { |
| 738 | self |
| 739 | } |
| 740 | |
| 741 | #[inline(always)] |
| 742 | fn as_mut_xyz(&mut self) -> &mut XYZ<T> { |
| 743 | self |
| 744 | } |
| 745 | |
| 746 | #[inline] |
| 747 | fn min_element(self) -> T { |
| 748 | self.x.min(self.y.min(self.z)) |
| 749 | } |
| 750 | |
| 751 | #[inline] |
| 752 | fn max_element(self) -> T { |
| 753 | self.x.max(self.y.max(self.z)) |
| 754 | } |
| 755 | |
| 756 | #[inline] |
| 757 | fn clamp(self, min: Self, max: Self) -> Self { |
| 758 | glam_assert!(min.x <= max.x); |
| 759 | glam_assert!(min.y <= max.y); |
| 760 | glam_assert!(min.z <= max.z); |
| 761 | // we intentionally do not use `f32::clamp` because we don't |
| 762 | // want panics unless `glam-assert` feature is on. |
| 763 | Self::new( |
| 764 | self.x.max(min.x).min(max.x), |
| 765 | self.y.max(min.y).min(max.y), |
| 766 | self.z.max(min.z).min(max.z), |
| 767 | ) |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | impl<T: NumEx> Vector4<T> for XYZW<T> { |
| 772 | #[inline(always)] |
| 773 | fn new(x: T, y: T, z: T, w: T) -> Self { |
| 774 | Self { x, y, z, w } |
| 775 | } |
| 776 | |
| 777 | #[inline(always)] |
| 778 | fn x(self) -> T { |
| 779 | self.x |
| 780 | } |
| 781 | |
| 782 | #[inline(always)] |
| 783 | fn y(self) -> T { |
| 784 | self.y |
| 785 | } |
| 786 | |
| 787 | #[inline(always)] |
| 788 | fn z(self) -> T { |
| 789 | self.z |
| 790 | } |
| 791 | |
| 792 | #[inline(always)] |
| 793 | fn w(self) -> T { |
| 794 | self.w |
| 795 | } |
| 796 | |
| 797 | #[inline(always)] |
| 798 | fn as_ref_xyzw(&self) -> &XYZW<T> { |
| 799 | self |
| 800 | } |
| 801 | |
| 802 | #[inline(always)] |
| 803 | fn as_mut_xyzw(&mut self) -> &mut XYZW<T> { |
| 804 | self |
| 805 | } |
| 806 | |
| 807 | #[inline] |
| 808 | fn min_element(self) -> T { |
| 809 | self.x.min(self.y.min(self.z.min(self.w))) |
| 810 | } |
| 811 | |
| 812 | #[inline] |
| 813 | fn max_element(self) -> T { |
| 814 | self.x.max(self.y.max(self.z.max(self.w))) |
| 815 | } |
| 816 | |
| 817 | #[inline] |
| 818 | fn clamp(self, min: Self, max: Self) -> Self { |
| 819 | glam_assert!(min.x <= max.x); |
| 820 | glam_assert!(min.y <= max.y); |
| 821 | glam_assert!(min.z <= max.z); |
| 822 | glam_assert!(min.w <= max.w); |
| 823 | // we intentionally do not use `f32::clamp` because we don't |
| 824 | // want panics unless `glam-assert` feature is on. |
| 825 | Self { |
| 826 | x: self.x.max(min.x).min(max.x), |
| 827 | y: self.y.max(min.y).min(max.y), |
| 828 | z: self.z.max(min.z).min(max.z), |
| 829 | w: self.w.max(min.w).min(max.w), |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | impl<T: SignedEx> SignedVector<T> for XY<T> { |
| 835 | #[inline] |
| 836 | fn neg(self) -> Self { |
| 837 | Self { |
| 838 | x: self.x.neg(), |
| 839 | y: self.y.neg(), |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | impl<T: SignedEx> SignedVector2<T> for XY<T> {} |
| 845 | |
| 846 | impl<T: SignedEx> SignedVector<T> for XYZ<T> { |
| 847 | #[inline] |
| 848 | fn neg(self) -> Self { |
| 849 | Self { |
| 850 | x: self.x.neg(), |
| 851 | y: self.y.neg(), |
| 852 | z: self.z.neg(), |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | impl<T: SignedEx> SignedVector<T> for XYZW<T> { |
| 858 | #[inline] |
| 859 | fn neg(self) -> Self { |
| 860 | Self { |
| 861 | x: self.x.neg(), |
| 862 | y: self.y.neg(), |
| 863 | z: self.z.neg(), |
| 864 | w: self.w.neg(), |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | impl<T: SignedEx> SignedVector3<T> for XYZ<T> {} |
| 870 | impl<T: SignedEx> SignedVector4<T> for XYZW<T> {} |
| 871 | |
| 872 | impl<T: FloatEx> FloatVector2<T> for XY<T> {} |
| 873 | impl<T: FloatEx> FloatVector3<T> for XYZ<T> {} |
| 874 | impl<T: FloatEx> FloatVector4<T> for XYZW<T> {} |
| 875 | |
| 876 | impl<T> From<XYZ<T>> for XY<T> { |
| 877 | #[inline(always)] |
| 878 | fn from(v: XYZ<T>) -> Self { |
| 879 | Self { x: v.x, y: v.y } |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | impl<T> From<XYZW<T>> for XY<T> { |
| 884 | #[inline(always)] |
| 885 | fn from(v: XYZW<T>) -> Self { |
| 886 | Self { x: v.x, y: v.y } |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | impl<T> From<XYZW<T>> for XYZ<T> { |
| 891 | #[inline(always)] |
| 892 | fn from(v: XYZW<T>) -> Self { |
| 893 | Self { |
| 894 | x: v.x, |
| 895 | y: v.y, |
| 896 | z: v.z, |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | impl VectorConst for XYZF32A16 { |
| 902 | const ZERO: Self = Self { |
| 903 | x: 0.0, |
| 904 | y: 0.0, |
| 905 | z: 0.0, |
| 906 | }; |
| 907 | const ONE: Self = Self { |
| 908 | x: 1.0, |
| 909 | y: 1.0, |
| 910 | z: 1.0, |
| 911 | }; |
| 912 | } |
| 913 | |
| 914 | impl NanConstEx for XYZF32A16 { |
| 915 | const NAN: Self = Self { |
| 916 | x: f32::NAN, |
| 917 | y: f32::NAN, |
| 918 | z: f32::NAN, |
| 919 | }; |
| 920 | } |
| 921 | |
| 922 | impl Vector3Const for XYZF32A16 { |
| 923 | const X: Self = Self { |
| 924 | x: 1.0, |
| 925 | y: 0.0, |
| 926 | z: 0.0, |
| 927 | }; |
| 928 | const Y: Self = Self { |
| 929 | x: 0.0, |
| 930 | y: 1.0, |
| 931 | z: 0.0, |
| 932 | }; |
| 933 | const Z: Self = Self { |
| 934 | x: 0.0, |
| 935 | y: 0.0, |
| 936 | z: 1.0, |
| 937 | }; |
| 938 | } |
| 939 | |
| 940 | impl Vector<f32> for XYZF32A16 { |
| 941 | type Mask = XYZ<bool>; |
| 942 | |
| 943 | #[inline] |
| 944 | fn splat(s: f32) -> Self { |
| 945 | Self { x: s, y: s, z: s } |
| 946 | } |
| 947 | |
| 948 | #[inline] |
| 949 | fn select(mask: Self::Mask, if_true: Self, if_false: Self) -> Self { |
| 950 | XYZ::select(mask, if_true.into(), if_false.into()).into() |
| 951 | } |
| 952 | |
| 953 | #[inline] |
| 954 | fn cmpeq(self, other: Self) -> Self::Mask { |
| 955 | XYZ::cmpeq(self.into(), other.into()) |
| 956 | } |
| 957 | |
| 958 | #[inline] |
| 959 | fn cmpne(self, other: Self) -> Self::Mask { |
| 960 | XYZ::cmpne(self.into(), other.into()) |
| 961 | } |
| 962 | |
| 963 | #[inline] |
| 964 | fn cmpge(self, other: Self) -> Self::Mask { |
| 965 | XYZ::cmpge(self.into(), other.into()) |
| 966 | } |
| 967 | |
| 968 | #[inline] |
| 969 | fn cmpgt(self, other: Self) -> Self::Mask { |
| 970 | XYZ::cmpgt(self.into(), other.into()) |
| 971 | } |
| 972 | |
| 973 | #[inline] |
| 974 | fn cmple(self, other: Self) -> Self::Mask { |
| 975 | XYZ::cmple(self.into(), other.into()) |
| 976 | } |
| 977 | |
| 978 | #[inline] |
| 979 | fn cmplt(self, other: Self) -> Self::Mask { |
| 980 | XYZ::cmplt(self.into(), other.into()) |
| 981 | } |
| 982 | |
| 983 | #[inline] |
| 984 | fn add(self, other: Self) -> Self { |
| 985 | XYZ::add(self.into(), other.into()).into() |
| 986 | } |
| 987 | |
| 988 | #[inline] |
| 989 | fn div(self, other: Self) -> Self { |
| 990 | XYZ::div(self.into(), other.into()).into() |
| 991 | } |
| 992 | |
| 993 | #[inline] |
| 994 | fn mul(self, other: Self) -> Self { |
| 995 | XYZ::mul(self.into(), other.into()).into() |
| 996 | } |
| 997 | |
| 998 | #[inline] |
| 999 | fn rem(self, other: Self) -> Self { |
| 1000 | XYZ::rem(self.into(), other.into()).into() |
| 1001 | } |
| 1002 | |
| 1003 | #[inline] |
| 1004 | fn sub(self, other: Self) -> Self { |
| 1005 | XYZ::sub(self.into(), other.into()).into() |
| 1006 | } |
| 1007 | |
| 1008 | #[inline] |
| 1009 | fn add_scalar(self, other: f32) -> Self { |
| 1010 | XYZ::add_scalar(self.into(), other).into() |
| 1011 | } |
| 1012 | |
| 1013 | #[inline] |
| 1014 | fn sub_scalar(self, other: f32) -> Self { |
| 1015 | XYZ::sub_scalar(self.into(), other).into() |
| 1016 | } |
| 1017 | |
| 1018 | #[inline] |
| 1019 | fn mul_scalar(self, other: f32) -> Self { |
| 1020 | XYZ::mul_scalar(self.into(), other).into() |
| 1021 | } |
| 1022 | |
| 1023 | #[inline] |
| 1024 | fn div_scalar(self, other: f32) -> Self { |
| 1025 | XYZ::div_scalar(self.into(), other).into() |
| 1026 | } |
| 1027 | |
| 1028 | #[inline] |
| 1029 | fn rem_scalar(self, other: f32) -> Self { |
| 1030 | XYZ::rem_scalar(self.into(), other).into() |
| 1031 | } |
| 1032 | |
| 1033 | #[inline] |
| 1034 | fn min(self, other: Self) -> Self { |
| 1035 | XYZ::min(self.into(), other.into()).into() |
| 1036 | } |
| 1037 | |
| 1038 | #[inline] |
| 1039 | fn max(self, other: Self) -> Self { |
| 1040 | XYZ::max(self.into(), other.into()).into() |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | impl Vector3<f32> for XYZF32A16 { |
| 1045 | #[inline(always)] |
| 1046 | fn new(x: f32, y: f32, z: f32) -> Self { |
| 1047 | XYZF32A16 { x, y, z } |
| 1048 | } |
| 1049 | |
| 1050 | #[inline(always)] |
| 1051 | fn x(self) -> f32 { |
| 1052 | self.x |
| 1053 | } |
| 1054 | |
| 1055 | #[inline(always)] |
| 1056 | fn y(self) -> f32 { |
| 1057 | self.y |
| 1058 | } |
| 1059 | |
| 1060 | #[inline(always)] |
| 1061 | fn z(self) -> f32 { |
| 1062 | self.z |
| 1063 | } |
| 1064 | |
| 1065 | #[inline(always)] |
| 1066 | fn as_ref_xyz(&self) -> &XYZ<f32> { |
| 1067 | unsafe { &*(self as *const Self).cast() } |
| 1068 | } |
| 1069 | |
| 1070 | #[inline(always)] |
| 1071 | fn as_mut_xyz(&mut self) -> &mut XYZ<f32> { |
| 1072 | unsafe { &mut *(self as *mut Self).cast() } |
| 1073 | } |
| 1074 | |
| 1075 | #[inline(always)] |
| 1076 | fn min_element(self) -> f32 { |
| 1077 | XYZ::min_element(self.into()) |
| 1078 | } |
| 1079 | |
| 1080 | #[inline(always)] |
| 1081 | fn max_element(self) -> f32 { |
| 1082 | XYZ::max_element(self.into()) |
| 1083 | } |
| 1084 | |
| 1085 | #[inline(always)] |
| 1086 | fn clamp(self, min: Self, max: Self) -> Self { |
| 1087 | XYZ::clamp(self.into(), min.into(), max.into()).into() |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | impl SignedVector<f32> for XYZF32A16 { |
| 1092 | #[inline(always)] |
| 1093 | fn neg(self) -> Self { |
| 1094 | XYZ::neg(self.into()).into() |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | impl SignedVector3<f32> for XYZF32A16 {} |
| 1099 | impl FloatVector3<f32> for XYZF32A16 {} |
| 1100 | |
| 1101 | // 2D bitwise and shifting |
| 1102 | |
| 1103 | impl<T, Rhs> ScalarShiftOps<Rhs> for XY<T> |
| 1104 | where |
| 1105 | T: IntegerShiftOps<Rhs>, |
| 1106 | Rhs: Copy, |
| 1107 | { |
| 1108 | #[inline(always)] |
| 1109 | fn scalar_shl(self, rhs: Rhs) -> Self { |
| 1110 | Self { |
| 1111 | x: self.x << rhs, |
| 1112 | y: self.y << rhs, |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | #[inline(always)] |
| 1117 | fn scalar_shr(self, rhs: Rhs) -> Self { |
| 1118 | Self { |
| 1119 | x: self.x >> rhs, |
| 1120 | y: self.y >> rhs, |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | impl<T> ScalarBitOps<T> for XY<T> |
| 1126 | where |
| 1127 | T: Copy + IntegerBitOps, |
| 1128 | { |
| 1129 | #[inline(always)] |
| 1130 | fn scalar_bitand(self, rhs: T) -> Self { |
| 1131 | Self { |
| 1132 | x: self.x & rhs, |
| 1133 | y: self.y & rhs, |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | #[inline(always)] |
| 1138 | fn scalar_bitor(self, rhs: T) -> Self { |
| 1139 | Self { |
| 1140 | x: self.x | rhs, |
| 1141 | y: self.y | rhs, |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | #[inline(always)] |
| 1146 | fn scalar_bitxor(self, rhs: T) -> Self { |
| 1147 | Self { |
| 1148 | x: self.x ^ rhs, |
| 1149 | y: self.y ^ rhs, |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | impl<T, Rhs> VectorShiftOps<XY<Rhs>> for XY<T> |
| 1155 | where |
| 1156 | T: Copy + IntegerShiftOps<Rhs>, |
| 1157 | { |
| 1158 | #[inline(always)] |
| 1159 | fn vector_shl(self, rhs: XY<Rhs>) -> Self { |
| 1160 | Self { |
| 1161 | x: self.x << rhs.x, |
| 1162 | y: self.y << rhs.y, |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | #[inline(always)] |
| 1167 | fn vector_shr(self, rhs: XY<Rhs>) -> Self { |
| 1168 | Self { |
| 1169 | x: self.x >> rhs.x, |
| 1170 | y: self.y >> rhs.y, |
| 1171 | } |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | impl<T> VectorBitOps<XY<T>> for XY<T> |
| 1176 | where |
| 1177 | T: Copy + IntegerBitOps, |
| 1178 | { |
| 1179 | #[inline(always)] |
| 1180 | fn not(self) -> Self { |
| 1181 | Self { |
| 1182 | x: !self.x, |
| 1183 | y: !self.y, |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | #[inline(always)] |
| 1188 | fn vector_bitand(self, rhs: Self) -> Self { |
| 1189 | Self { |
| 1190 | x: self.x & rhs.x, |
| 1191 | y: self.y & rhs.y, |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | #[inline(always)] |
| 1196 | fn vector_bitor(self, rhs: Self) -> Self { |
| 1197 | Self { |
| 1198 | x: self.x | rhs.x, |
| 1199 | y: self.y | rhs.y, |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | #[inline(always)] |
| 1204 | fn vector_bitxor(self, rhs: Self) -> Self { |
| 1205 | Self { |
| 1206 | x: self.x ^ rhs.x, |
| 1207 | y: self.y ^ rhs.y, |
| 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | // 3D bitwise and shifting |
| 1213 | |
| 1214 | impl<T, Rhs> ScalarShiftOps<Rhs> for XYZ<T> |
| 1215 | where |
| 1216 | T: IntegerShiftOps<Rhs>, |
| 1217 | Rhs: Copy, |
| 1218 | { |
| 1219 | #[inline(always)] |
| 1220 | fn scalar_shl(self, rhs: Rhs) -> Self { |
| 1221 | Self { |
| 1222 | x: self.x << rhs, |
| 1223 | y: self.y << rhs, |
| 1224 | z: self.z << rhs, |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | #[inline(always)] |
| 1229 | fn scalar_shr(self, rhs: Rhs) -> Self { |
| 1230 | Self { |
| 1231 | x: self.x >> rhs, |
| 1232 | y: self.y >> rhs, |
| 1233 | z: self.z >> rhs, |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | impl<T> ScalarBitOps<T> for XYZ<T> |
| 1239 | where |
| 1240 | T: Copy + IntegerBitOps, |
| 1241 | { |
| 1242 | #[inline(always)] |
| 1243 | fn scalar_bitand(self, rhs: T) -> Self { |
| 1244 | Self { |
| 1245 | x: self.x & rhs, |
| 1246 | y: self.y & rhs, |
| 1247 | z: self.z & rhs, |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | #[inline(always)] |
| 1252 | fn scalar_bitor(self, rhs: T) -> Self { |
| 1253 | Self { |
| 1254 | x: self.x | rhs, |
| 1255 | y: self.y | rhs, |
| 1256 | z: self.z | rhs, |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | #[inline(always)] |
| 1261 | fn scalar_bitxor(self, rhs: T) -> Self { |
| 1262 | Self { |
| 1263 | x: self.x ^ rhs, |
| 1264 | y: self.y ^ rhs, |
| 1265 | z: self.z ^ rhs, |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | impl<T, Rhs> VectorShiftOps<XYZ<Rhs>> for XYZ<T> |
| 1271 | where |
| 1272 | T: Copy + IntegerShiftOps<Rhs>, |
| 1273 | { |
| 1274 | #[inline(always)] |
| 1275 | fn vector_shl(self, rhs: XYZ<Rhs>) -> Self { |
| 1276 | Self { |
| 1277 | x: self.x << rhs.x, |
| 1278 | y: self.y << rhs.y, |
| 1279 | z: self.z << rhs.z, |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | #[inline(always)] |
| 1284 | fn vector_shr(self, rhs: XYZ<Rhs>) -> Self { |
| 1285 | Self { |
| 1286 | x: self.x >> rhs.x, |
| 1287 | y: self.y >> rhs.y, |
| 1288 | z: self.z >> rhs.z, |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | impl<T> VectorBitOps<XYZ<T>> for XYZ<T> |
| 1294 | where |
| 1295 | T: Copy + IntegerBitOps, |
| 1296 | { |
| 1297 | #[inline(always)] |
| 1298 | fn not(self) -> Self { |
| 1299 | Self { |
| 1300 | x: !self.x, |
| 1301 | y: !self.y, |
| 1302 | z: !self.z, |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | #[inline(always)] |
| 1307 | fn vector_bitand(self, rhs: Self) -> Self { |
| 1308 | Self { |
| 1309 | x: self.x & rhs.x, |
| 1310 | y: self.y & rhs.y, |
| 1311 | z: self.z & rhs.z, |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | #[inline(always)] |
| 1316 | fn vector_bitor(self, rhs: Self) -> Self { |
| 1317 | Self { |
| 1318 | x: self.x | rhs.x, |
| 1319 | y: self.y | rhs.y, |
| 1320 | z: self.z | rhs.z, |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | #[inline(always)] |
| 1325 | fn vector_bitxor(self, rhs: Self) -> Self { |
| 1326 | Self { |
| 1327 | x: self.x ^ rhs.x, |
| 1328 | y: self.y ^ rhs.y, |
| 1329 | z: self.z ^ rhs.z, |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | // 4D bitwise and shifting |
| 1335 | |
| 1336 | impl<T, Rhs> ScalarShiftOps<Rhs> for XYZW<T> |
| 1337 | where |
| 1338 | T: IntegerShiftOps<Rhs>, |
| 1339 | Rhs: Copy, |
| 1340 | { |
| 1341 | #[inline(always)] |
| 1342 | fn scalar_shl(self, rhs: Rhs) -> Self { |
| 1343 | Self { |
| 1344 | x: self.x << rhs, |
| 1345 | y: self.y << rhs, |
| 1346 | z: self.z << rhs, |
| 1347 | w: self.w << rhs, |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | #[inline(always)] |
| 1352 | fn scalar_shr(self, rhs: Rhs) -> Self { |
| 1353 | Self { |
| 1354 | x: self.x >> rhs, |
| 1355 | y: self.y >> rhs, |
| 1356 | z: self.z >> rhs, |
| 1357 | w: self.w >> rhs, |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | impl<T> ScalarBitOps<T> for XYZW<T> |
| 1363 | where |
| 1364 | T: Copy + IntegerBitOps, |
| 1365 | { |
| 1366 | #[inline(always)] |
| 1367 | fn scalar_bitand(self, rhs: T) -> Self { |
| 1368 | Self { |
| 1369 | x: self.x & rhs, |
| 1370 | y: self.y & rhs, |
| 1371 | z: self.z & rhs, |
| 1372 | w: self.w & rhs, |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | #[inline(always)] |
| 1377 | fn scalar_bitor(self, rhs: T) -> Self { |
| 1378 | Self { |
| 1379 | x: self.x | rhs, |
| 1380 | y: self.y | rhs, |
| 1381 | z: self.z | rhs, |
| 1382 | w: self.w | rhs, |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | #[inline(always)] |
| 1387 | fn scalar_bitxor(self, rhs: T) -> Self { |
| 1388 | Self { |
| 1389 | x: self.x ^ rhs, |
| 1390 | y: self.y ^ rhs, |
| 1391 | z: self.z ^ rhs, |
| 1392 | w: self.w ^ rhs, |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | impl<T, Rhs> VectorShiftOps<XYZW<Rhs>> for XYZW<T> |
| 1398 | where |
| 1399 | T: Copy + IntegerShiftOps<Rhs>, |
| 1400 | { |
| 1401 | #[inline(always)] |
| 1402 | fn vector_shl(self, rhs: XYZW<Rhs>) -> Self { |
| 1403 | Self { |
| 1404 | x: self.x << rhs.x, |
| 1405 | y: self.y << rhs.y, |
| 1406 | z: self.z << rhs.z, |
| 1407 | w: self.w << rhs.w, |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | #[inline(always)] |
| 1412 | fn vector_shr(self, rhs: XYZW<Rhs>) -> Self { |
| 1413 | Self { |
| 1414 | x: self.x >> rhs.x, |
| 1415 | y: self.y >> rhs.y, |
| 1416 | z: self.z >> rhs.z, |
| 1417 | w: self.w >> rhs.w, |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | impl<T> VectorBitOps<XYZW<T>> for XYZW<T> |
| 1423 | where |
| 1424 | T: Copy + IntegerBitOps, |
| 1425 | { |
| 1426 | #[inline(always)] |
| 1427 | fn not(self) -> Self { |
| 1428 | Self { |
| 1429 | x: !self.x, |
| 1430 | y: !self.y, |
| 1431 | z: !self.z, |
| 1432 | w: !self.w, |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | #[inline(always)] |
| 1437 | fn vector_bitand(self, rhs: Self) -> Self { |
| 1438 | Self { |
| 1439 | x: self.x & rhs.x, |
| 1440 | y: self.y & rhs.y, |
| 1441 | z: self.z & rhs.z, |
| 1442 | w: self.w & rhs.w, |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | #[inline(always)] |
| 1447 | fn vector_bitor(self, rhs: Self) -> Self { |
| 1448 | Self { |
| 1449 | x: self.x | rhs.x, |
| 1450 | y: self.y | rhs.y, |
| 1451 | z: self.z | rhs.z, |
| 1452 | w: self.w | rhs.w, |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | #[inline(always)] |
| 1457 | fn vector_bitxor(self, rhs: Self) -> Self { |
| 1458 | Self { |
| 1459 | x: self.x ^ rhs.x, |
| 1460 | y: self.y ^ rhs.y, |
| 1461 | z: self.z ^ rhs.z, |
| 1462 | w: self.w ^ rhs.w, |
| 1463 | } |
| 1464 | } |
| 1465 | } |