| 1 | // Generated from vec.rs.tera template. Edit the template, not the generated file. |
| 2 | |
| 3 | use crate::{BVec4, UVec2, UVec3}; |
| 4 | |
| 5 | #[cfg(not(target_arch = "spirv"))] |
| 6 | use core::fmt; |
| 7 | use core::iter::{Product, Sum}; |
| 8 | use core::{f32, ops::*}; |
| 9 | |
| 10 | /// Creates a 4-dimensional vector. |
| 11 | #[inline(always)] |
| 12 | pub const fn uvec4(x: u32, y: u32, z: u32, w: u32) -> UVec4 { |
| 13 | UVec4::new(x, y, z, w) |
| 14 | } |
| 15 | |
| 16 | /// A 4-dimensional vector. |
| 17 | #[cfg_attr(not(target_arch = "spirv"), derive(Hash))] |
| 18 | #[derive(Clone, Copy, PartialEq, Eq)] |
| 19 | #[cfg_attr(feature = "cuda", repr(align(16)))] |
| 20 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 21 | #[cfg_attr(target_arch = "spirv", repr(simd))] |
| 22 | pub struct UVec4 { |
| 23 | pub x: u32, |
| 24 | pub y: u32, |
| 25 | pub z: u32, |
| 26 | pub w: u32, |
| 27 | } |
| 28 | |
| 29 | impl UVec4 { |
| 30 | /// All zeroes. |
| 31 | pub const ZERO: Self = Self::splat(0); |
| 32 | |
| 33 | /// All ones. |
| 34 | pub const ONE: Self = Self::splat(1); |
| 35 | |
| 36 | /// A unit-length vector pointing along the positive X axis. |
| 37 | pub const X: Self = Self::new(1, 0, 0, 0); |
| 38 | |
| 39 | /// A unit-length vector pointing along the positive Y axis. |
| 40 | pub const Y: Self = Self::new(0, 1, 0, 0); |
| 41 | |
| 42 | /// A unit-length vector pointing along the positive Z axis. |
| 43 | pub const Z: Self = Self::new(0, 0, 1, 0); |
| 44 | |
| 45 | /// A unit-length vector pointing along the positive W axis. |
| 46 | pub const W: Self = Self::new(0, 0, 0, 1); |
| 47 | |
| 48 | /// The unit axes. |
| 49 | pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W]; |
| 50 | |
| 51 | /// Creates a new vector. |
| 52 | #[inline(always)] |
| 53 | pub const fn new(x: u32, y: u32, z: u32, w: u32) -> Self { |
| 54 | Self { x, y, z, w } |
| 55 | } |
| 56 | |
| 57 | /// Creates a vector with all elements set to `v`. |
| 58 | #[inline] |
| 59 | pub const fn splat(v: u32) -> Self { |
| 60 | Self { |
| 61 | x: v, |
| 62 | |
| 63 | y: v, |
| 64 | |
| 65 | z: v, |
| 66 | |
| 67 | w: v, |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use |
| 72 | /// for each element of `self`. |
| 73 | /// |
| 74 | /// A true element in the mask uses the corresponding element from `if_true`, and false |
| 75 | /// uses the element from `if_false`. |
| 76 | #[inline] |
| 77 | pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self { |
| 78 | Self { |
| 79 | x: if mask.x { if_true.x } else { if_false.x }, |
| 80 | y: if mask.y { if_true.y } else { if_false.y }, |
| 81 | z: if mask.z { if_true.z } else { if_false.z }, |
| 82 | w: if mask.w { if_true.w } else { if_false.w }, |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /// Creates a new vector from an array. |
| 87 | #[inline] |
| 88 | pub const fn from_array(a: [u32; 4]) -> Self { |
| 89 | Self::new(a[0], a[1], a[2], a[3]) |
| 90 | } |
| 91 | |
| 92 | /// `[x, y, z, w]` |
| 93 | #[inline] |
| 94 | pub const fn to_array(&self) -> [u32; 4] { |
| 95 | [self.x, self.y, self.z, self.w] |
| 96 | } |
| 97 | |
| 98 | /// Creates a vector from the first 4 values in `slice`. |
| 99 | /// |
| 100 | /// # Panics |
| 101 | /// |
| 102 | /// Panics if `slice` is less than 4 elements long. |
| 103 | #[inline] |
| 104 | pub const fn from_slice(slice: &[u32]) -> Self { |
| 105 | Self::new(slice[0], slice[1], slice[2], slice[3]) |
| 106 | } |
| 107 | |
| 108 | /// Writes the elements of `self` to the first 4 elements in `slice`. |
| 109 | /// |
| 110 | /// # Panics |
| 111 | /// |
| 112 | /// Panics if `slice` is less than 4 elements long. |
| 113 | #[inline] |
| 114 | pub fn write_to_slice(self, slice: &mut [u32]) { |
| 115 | slice[0] = self.x; |
| 116 | slice[1] = self.y; |
| 117 | slice[2] = self.z; |
| 118 | slice[3] = self.w; |
| 119 | } |
| 120 | |
| 121 | /// Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. |
| 122 | /// |
| 123 | /// Truncation to `UVec3` may also be performed by using `self.xyz()` or `UVec3::from()`. |
| 124 | #[inline] |
| 125 | pub fn truncate(self) -> UVec3 { |
| 126 | use crate::swizzles::Vec4Swizzles; |
| 127 | self.xyz() |
| 128 | } |
| 129 | |
| 130 | /// Computes the dot product of `self` and `rhs`. |
| 131 | #[inline] |
| 132 | pub fn dot(self, rhs: Self) -> u32 { |
| 133 | (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w) |
| 134 | } |
| 135 | |
| 136 | /// Returns a vector where every component is the dot product of `self` and `rhs`. |
| 137 | #[inline] |
| 138 | pub fn dot_into_vec(self, rhs: Self) -> Self { |
| 139 | Self::splat(self.dot(rhs)) |
| 140 | } |
| 141 | |
| 142 | /// Returns a vector containing the minimum values for each element of `self` and `rhs`. |
| 143 | /// |
| 144 | /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. |
| 145 | #[inline] |
| 146 | pub fn min(self, rhs: Self) -> Self { |
| 147 | Self { |
| 148 | x: self.x.min(rhs.x), |
| 149 | y: self.y.min(rhs.y), |
| 150 | z: self.z.min(rhs.z), |
| 151 | w: self.w.min(rhs.w), |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /// Returns a vector containing the maximum values for each element of `self` and `rhs`. |
| 156 | /// |
| 157 | /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. |
| 158 | #[inline] |
| 159 | pub fn max(self, rhs: Self) -> Self { |
| 160 | Self { |
| 161 | x: self.x.max(rhs.x), |
| 162 | y: self.y.max(rhs.y), |
| 163 | z: self.z.max(rhs.z), |
| 164 | w: self.w.max(rhs.w), |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /// Component-wise clamping of values, similar to [`u32::clamp`]. |
| 169 | /// |
| 170 | /// Each element in `min` must be less-or-equal to the corresponding element in `max`. |
| 171 | /// |
| 172 | /// # Panics |
| 173 | /// |
| 174 | /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. |
| 175 | #[inline] |
| 176 | pub fn clamp(self, min: Self, max: Self) -> Self { |
| 177 | glam_assert!(min.cmple(max).all(), "clamp: expected min <= max"); |
| 178 | self.max(min).min(max) |
| 179 | } |
| 180 | |
| 181 | /// Returns the horizontal minimum of `self`. |
| 182 | /// |
| 183 | /// In other words this computes `min(x, y, ..)`. |
| 184 | #[inline] |
| 185 | pub fn min_element(self) -> u32 { |
| 186 | self.x.min(self.y.min(self.z.min(self.w))) |
| 187 | } |
| 188 | |
| 189 | /// Returns the horizontal maximum of `self`. |
| 190 | /// |
| 191 | /// In other words this computes `max(x, y, ..)`. |
| 192 | #[inline] |
| 193 | pub fn max_element(self) -> u32 { |
| 194 | self.x.max(self.y.max(self.z.max(self.w))) |
| 195 | } |
| 196 | |
| 197 | /// Returns a vector mask containing the result of a `==` comparison for each element of |
| 198 | /// `self` and `rhs`. |
| 199 | /// |
| 200 | /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all |
| 201 | /// elements. |
| 202 | #[inline] |
| 203 | pub fn cmpeq(self, rhs: Self) -> BVec4 { |
| 204 | BVec4::new( |
| 205 | self.x.eq(&rhs.x), |
| 206 | self.y.eq(&rhs.y), |
| 207 | self.z.eq(&rhs.z), |
| 208 | self.w.eq(&rhs.w), |
| 209 | ) |
| 210 | } |
| 211 | |
| 212 | /// Returns a vector mask containing the result of a `!=` comparison for each element of |
| 213 | /// `self` and `rhs`. |
| 214 | /// |
| 215 | /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all |
| 216 | /// elements. |
| 217 | #[inline] |
| 218 | pub fn cmpne(self, rhs: Self) -> BVec4 { |
| 219 | BVec4::new( |
| 220 | self.x.ne(&rhs.x), |
| 221 | self.y.ne(&rhs.y), |
| 222 | self.z.ne(&rhs.z), |
| 223 | self.w.ne(&rhs.w), |
| 224 | ) |
| 225 | } |
| 226 | |
| 227 | /// Returns a vector mask containing the result of a `>=` comparison for each element of |
| 228 | /// `self` and `rhs`. |
| 229 | /// |
| 230 | /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all |
| 231 | /// elements. |
| 232 | #[inline] |
| 233 | pub fn cmpge(self, rhs: Self) -> BVec4 { |
| 234 | BVec4::new( |
| 235 | self.x.ge(&rhs.x), |
| 236 | self.y.ge(&rhs.y), |
| 237 | self.z.ge(&rhs.z), |
| 238 | self.w.ge(&rhs.w), |
| 239 | ) |
| 240 | } |
| 241 | |
| 242 | /// Returns a vector mask containing the result of a `>` comparison for each element of |
| 243 | /// `self` and `rhs`. |
| 244 | /// |
| 245 | /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all |
| 246 | /// elements. |
| 247 | #[inline] |
| 248 | pub fn cmpgt(self, rhs: Self) -> BVec4 { |
| 249 | BVec4::new( |
| 250 | self.x.gt(&rhs.x), |
| 251 | self.y.gt(&rhs.y), |
| 252 | self.z.gt(&rhs.z), |
| 253 | self.w.gt(&rhs.w), |
| 254 | ) |
| 255 | } |
| 256 | |
| 257 | /// Returns a vector mask containing the result of a `<=` comparison for each element of |
| 258 | /// `self` and `rhs`. |
| 259 | /// |
| 260 | /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all |
| 261 | /// elements. |
| 262 | #[inline] |
| 263 | pub fn cmple(self, rhs: Self) -> BVec4 { |
| 264 | BVec4::new( |
| 265 | self.x.le(&rhs.x), |
| 266 | self.y.le(&rhs.y), |
| 267 | self.z.le(&rhs.z), |
| 268 | self.w.le(&rhs.w), |
| 269 | ) |
| 270 | } |
| 271 | |
| 272 | /// Returns a vector mask containing the result of a `<` comparison for each element of |
| 273 | /// `self` and `rhs`. |
| 274 | /// |
| 275 | /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all |
| 276 | /// elements. |
| 277 | #[inline] |
| 278 | pub fn cmplt(self, rhs: Self) -> BVec4 { |
| 279 | BVec4::new( |
| 280 | self.x.lt(&rhs.x), |
| 281 | self.y.lt(&rhs.y), |
| 282 | self.z.lt(&rhs.z), |
| 283 | self.w.lt(&rhs.w), |
| 284 | ) |
| 285 | } |
| 286 | |
| 287 | /// Casts all elements of `self` to `f32`. |
| 288 | #[inline] |
| 289 | pub fn as_vec4(&self) -> crate::Vec4 { |
| 290 | crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32) |
| 291 | } |
| 292 | |
| 293 | /// Casts all elements of `self` to `f64`. |
| 294 | #[inline] |
| 295 | pub fn as_dvec4(&self) -> crate::DVec4 { |
| 296 | crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64) |
| 297 | } |
| 298 | |
| 299 | /// Casts all elements of `self` to `i32`. |
| 300 | #[inline] |
| 301 | pub fn as_ivec4(&self) -> crate::IVec4 { |
| 302 | crate::IVec4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | impl Default for UVec4 { |
| 307 | #[inline(always)] |
| 308 | fn default() -> Self { |
| 309 | Self::ZERO |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | impl Div<UVec4> for UVec4 { |
| 314 | type Output = Self; |
| 315 | #[inline] |
| 316 | fn div(self, rhs: Self) -> Self { |
| 317 | Self { |
| 318 | x: self.x.div(rhs.x), |
| 319 | y: self.y.div(rhs.y), |
| 320 | z: self.z.div(rhs.z), |
| 321 | w: self.w.div(rhs.w), |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | impl DivAssign<UVec4> for UVec4 { |
| 327 | #[inline] |
| 328 | fn div_assign(&mut self, rhs: Self) { |
| 329 | self.x.div_assign(rhs.x); |
| 330 | self.y.div_assign(rhs.y); |
| 331 | self.z.div_assign(rhs.z); |
| 332 | self.w.div_assign(rhs.w); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | impl Div<u32> for UVec4 { |
| 337 | type Output = Self; |
| 338 | #[inline] |
| 339 | fn div(self, rhs: u32) -> Self { |
| 340 | Self { |
| 341 | x: self.x.div(rhs), |
| 342 | y: self.y.div(rhs), |
| 343 | z: self.z.div(rhs), |
| 344 | w: self.w.div(rhs), |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | impl DivAssign<u32> for UVec4 { |
| 350 | #[inline] |
| 351 | fn div_assign(&mut self, rhs: u32) { |
| 352 | self.x.div_assign(rhs); |
| 353 | self.y.div_assign(rhs); |
| 354 | self.z.div_assign(rhs); |
| 355 | self.w.div_assign(rhs); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | impl Div<UVec4> for u32 { |
| 360 | type Output = UVec4; |
| 361 | #[inline] |
| 362 | fn div(self, rhs: UVec4) -> UVec4 { |
| 363 | UVec4 { |
| 364 | x: self.div(rhs.x), |
| 365 | y: self.div(rhs.y), |
| 366 | z: self.div(rhs.z), |
| 367 | w: self.div(rhs.w), |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | impl Mul<UVec4> for UVec4 { |
| 373 | type Output = Self; |
| 374 | #[inline] |
| 375 | fn mul(self, rhs: Self) -> Self { |
| 376 | Self { |
| 377 | x: self.x.mul(rhs.x), |
| 378 | y: self.y.mul(rhs.y), |
| 379 | z: self.z.mul(rhs.z), |
| 380 | w: self.w.mul(rhs.w), |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | impl MulAssign<UVec4> for UVec4 { |
| 386 | #[inline] |
| 387 | fn mul_assign(&mut self, rhs: Self) { |
| 388 | self.x.mul_assign(rhs.x); |
| 389 | self.y.mul_assign(rhs.y); |
| 390 | self.z.mul_assign(rhs.z); |
| 391 | self.w.mul_assign(rhs.w); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | impl Mul<u32> for UVec4 { |
| 396 | type Output = Self; |
| 397 | #[inline] |
| 398 | fn mul(self, rhs: u32) -> Self { |
| 399 | Self { |
| 400 | x: self.x.mul(rhs), |
| 401 | y: self.y.mul(rhs), |
| 402 | z: self.z.mul(rhs), |
| 403 | w: self.w.mul(rhs), |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | impl MulAssign<u32> for UVec4 { |
| 409 | #[inline] |
| 410 | fn mul_assign(&mut self, rhs: u32) { |
| 411 | self.x.mul_assign(rhs); |
| 412 | self.y.mul_assign(rhs); |
| 413 | self.z.mul_assign(rhs); |
| 414 | self.w.mul_assign(rhs); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | impl Mul<UVec4> for u32 { |
| 419 | type Output = UVec4; |
| 420 | #[inline] |
| 421 | fn mul(self, rhs: UVec4) -> UVec4 { |
| 422 | UVec4 { |
| 423 | x: self.mul(rhs.x), |
| 424 | y: self.mul(rhs.y), |
| 425 | z: self.mul(rhs.z), |
| 426 | w: self.mul(rhs.w), |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | impl Add<UVec4> for UVec4 { |
| 432 | type Output = Self; |
| 433 | #[inline] |
| 434 | fn add(self, rhs: Self) -> Self { |
| 435 | Self { |
| 436 | x: self.x.add(rhs.x), |
| 437 | y: self.y.add(rhs.y), |
| 438 | z: self.z.add(rhs.z), |
| 439 | w: self.w.add(rhs.w), |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | impl AddAssign<UVec4> for UVec4 { |
| 445 | #[inline] |
| 446 | fn add_assign(&mut self, rhs: Self) { |
| 447 | self.x.add_assign(rhs.x); |
| 448 | self.y.add_assign(rhs.y); |
| 449 | self.z.add_assign(rhs.z); |
| 450 | self.w.add_assign(rhs.w); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | impl Add<u32> for UVec4 { |
| 455 | type Output = Self; |
| 456 | #[inline] |
| 457 | fn add(self, rhs: u32) -> Self { |
| 458 | Self { |
| 459 | x: self.x.add(rhs), |
| 460 | y: self.y.add(rhs), |
| 461 | z: self.z.add(rhs), |
| 462 | w: self.w.add(rhs), |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | impl AddAssign<u32> for UVec4 { |
| 468 | #[inline] |
| 469 | fn add_assign(&mut self, rhs: u32) { |
| 470 | self.x.add_assign(rhs); |
| 471 | self.y.add_assign(rhs); |
| 472 | self.z.add_assign(rhs); |
| 473 | self.w.add_assign(rhs); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | impl Add<UVec4> for u32 { |
| 478 | type Output = UVec4; |
| 479 | #[inline] |
| 480 | fn add(self, rhs: UVec4) -> UVec4 { |
| 481 | UVec4 { |
| 482 | x: self.add(rhs.x), |
| 483 | y: self.add(rhs.y), |
| 484 | z: self.add(rhs.z), |
| 485 | w: self.add(rhs.w), |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | impl Sub<UVec4> for UVec4 { |
| 491 | type Output = Self; |
| 492 | #[inline] |
| 493 | fn sub(self, rhs: Self) -> Self { |
| 494 | Self { |
| 495 | x: self.x.sub(rhs.x), |
| 496 | y: self.y.sub(rhs.y), |
| 497 | z: self.z.sub(rhs.z), |
| 498 | w: self.w.sub(rhs.w), |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | impl SubAssign<UVec4> for UVec4 { |
| 504 | #[inline] |
| 505 | fn sub_assign(&mut self, rhs: UVec4) { |
| 506 | self.x.sub_assign(rhs.x); |
| 507 | self.y.sub_assign(rhs.y); |
| 508 | self.z.sub_assign(rhs.z); |
| 509 | self.w.sub_assign(rhs.w); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | impl Sub<u32> for UVec4 { |
| 514 | type Output = Self; |
| 515 | #[inline] |
| 516 | fn sub(self, rhs: u32) -> Self { |
| 517 | Self { |
| 518 | x: self.x.sub(rhs), |
| 519 | y: self.y.sub(rhs), |
| 520 | z: self.z.sub(rhs), |
| 521 | w: self.w.sub(rhs), |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | impl SubAssign<u32> for UVec4 { |
| 527 | #[inline] |
| 528 | fn sub_assign(&mut self, rhs: u32) { |
| 529 | self.x.sub_assign(rhs); |
| 530 | self.y.sub_assign(rhs); |
| 531 | self.z.sub_assign(rhs); |
| 532 | self.w.sub_assign(rhs); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | impl Sub<UVec4> for u32 { |
| 537 | type Output = UVec4; |
| 538 | #[inline] |
| 539 | fn sub(self, rhs: UVec4) -> UVec4 { |
| 540 | UVec4 { |
| 541 | x: self.sub(rhs.x), |
| 542 | y: self.sub(rhs.y), |
| 543 | z: self.sub(rhs.z), |
| 544 | w: self.sub(rhs.w), |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | impl Rem<UVec4> for UVec4 { |
| 550 | type Output = Self; |
| 551 | #[inline] |
| 552 | fn rem(self, rhs: Self) -> Self { |
| 553 | Self { |
| 554 | x: self.x.rem(rhs.x), |
| 555 | y: self.y.rem(rhs.y), |
| 556 | z: self.z.rem(rhs.z), |
| 557 | w: self.w.rem(rhs.w), |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | impl RemAssign<UVec4> for UVec4 { |
| 563 | #[inline] |
| 564 | fn rem_assign(&mut self, rhs: Self) { |
| 565 | self.x.rem_assign(rhs.x); |
| 566 | self.y.rem_assign(rhs.y); |
| 567 | self.z.rem_assign(rhs.z); |
| 568 | self.w.rem_assign(rhs.w); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | impl Rem<u32> for UVec4 { |
| 573 | type Output = Self; |
| 574 | #[inline] |
| 575 | fn rem(self, rhs: u32) -> Self { |
| 576 | Self { |
| 577 | x: self.x.rem(rhs), |
| 578 | y: self.y.rem(rhs), |
| 579 | z: self.z.rem(rhs), |
| 580 | w: self.w.rem(rhs), |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | impl RemAssign<u32> for UVec4 { |
| 586 | #[inline] |
| 587 | fn rem_assign(&mut self, rhs: u32) { |
| 588 | self.x.rem_assign(rhs); |
| 589 | self.y.rem_assign(rhs); |
| 590 | self.z.rem_assign(rhs); |
| 591 | self.w.rem_assign(rhs); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | impl Rem<UVec4> for u32 { |
| 596 | type Output = UVec4; |
| 597 | #[inline] |
| 598 | fn rem(self, rhs: UVec4) -> UVec4 { |
| 599 | UVec4 { |
| 600 | x: self.rem(rhs.x), |
| 601 | y: self.rem(rhs.y), |
| 602 | z: self.rem(rhs.z), |
| 603 | w: self.rem(rhs.w), |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | #[cfg(not(target_arch = "spirv"))] |
| 609 | impl AsRef<[u32; 4]> for UVec4 { |
| 610 | #[inline] |
| 611 | fn as_ref(&self) -> &[u32; 4] { |
| 612 | unsafe { &*(self as *const UVec4 as *const [u32; 4]) } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | #[cfg(not(target_arch = "spirv"))] |
| 617 | impl AsMut<[u32; 4]> for UVec4 { |
| 618 | #[inline] |
| 619 | fn as_mut(&mut self) -> &mut [u32; 4] { |
| 620 | unsafe { &mut *(self as *mut UVec4 as *mut [u32; 4]) } |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | impl Sum for UVec4 { |
| 625 | #[inline] |
| 626 | fn sum<I>(iter: I) -> Self |
| 627 | where |
| 628 | I: Iterator<Item = Self>, |
| 629 | { |
| 630 | iter.fold(Self::ZERO, Self::add) |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | impl<'a> Sum<&'a Self> for UVec4 { |
| 635 | #[inline] |
| 636 | fn sum<I>(iter: I) -> Self |
| 637 | where |
| 638 | I: Iterator<Item = &'a Self>, |
| 639 | { |
| 640 | iter.fold(Self::ZERO, |a, &b| Self::add(a, b)) |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | impl Product for UVec4 { |
| 645 | #[inline] |
| 646 | fn product<I>(iter: I) -> Self |
| 647 | where |
| 648 | I: Iterator<Item = Self>, |
| 649 | { |
| 650 | iter.fold(Self::ONE, Self::mul) |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | impl<'a> Product<&'a Self> for UVec4 { |
| 655 | #[inline] |
| 656 | fn product<I>(iter: I) -> Self |
| 657 | where |
| 658 | I: Iterator<Item = &'a Self>, |
| 659 | { |
| 660 | iter.fold(Self::ONE, |a, &b| Self::mul(a, b)) |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | impl Not for UVec4 { |
| 665 | type Output = Self; |
| 666 | #[inline] |
| 667 | fn not(self) -> Self::Output { |
| 668 | Self { |
| 669 | x: self.x.not(), |
| 670 | y: self.y.not(), |
| 671 | z: self.z.not(), |
| 672 | w: self.w.not(), |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | impl BitAnd for UVec4 { |
| 678 | type Output = Self; |
| 679 | #[inline] |
| 680 | fn bitand(self, rhs: Self) -> Self::Output { |
| 681 | Self { |
| 682 | x: self.x.bitand(rhs.x), |
| 683 | y: self.y.bitand(rhs.y), |
| 684 | z: self.z.bitand(rhs.z), |
| 685 | w: self.w.bitand(rhs.w), |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | impl BitOr for UVec4 { |
| 691 | type Output = Self; |
| 692 | #[inline] |
| 693 | fn bitor(self, rhs: Self) -> Self::Output { |
| 694 | Self { |
| 695 | x: self.x.bitor(rhs.x), |
| 696 | y: self.y.bitor(rhs.y), |
| 697 | z: self.z.bitor(rhs.z), |
| 698 | w: self.w.bitor(rhs.w), |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | impl BitXor for UVec4 { |
| 704 | type Output = Self; |
| 705 | #[inline] |
| 706 | fn bitxor(self, rhs: Self) -> Self::Output { |
| 707 | Self { |
| 708 | x: self.x.bitxor(rhs.x), |
| 709 | y: self.y.bitxor(rhs.y), |
| 710 | z: self.z.bitxor(rhs.z), |
| 711 | w: self.w.bitxor(rhs.w), |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | impl BitAnd<u32> for UVec4 { |
| 717 | type Output = Self; |
| 718 | #[inline] |
| 719 | fn bitand(self, rhs: u32) -> Self::Output { |
| 720 | Self { |
| 721 | x: self.x.bitand(rhs), |
| 722 | y: self.y.bitand(rhs), |
| 723 | z: self.z.bitand(rhs), |
| 724 | w: self.w.bitand(rhs), |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | impl BitOr<u32> for UVec4 { |
| 730 | type Output = Self; |
| 731 | #[inline] |
| 732 | fn bitor(self, rhs: u32) -> Self::Output { |
| 733 | Self { |
| 734 | x: self.x.bitor(rhs), |
| 735 | y: self.y.bitor(rhs), |
| 736 | z: self.z.bitor(rhs), |
| 737 | w: self.w.bitor(rhs), |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | impl BitXor<u32> for UVec4 { |
| 743 | type Output = Self; |
| 744 | #[inline] |
| 745 | fn bitxor(self, rhs: u32) -> Self::Output { |
| 746 | Self { |
| 747 | x: self.x.bitxor(rhs), |
| 748 | y: self.y.bitxor(rhs), |
| 749 | z: self.z.bitxor(rhs), |
| 750 | w: self.w.bitxor(rhs), |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | impl Shl<i8> for UVec4 { |
| 756 | type Output = Self; |
| 757 | #[inline] |
| 758 | fn shl(self, rhs: i8) -> Self::Output { |
| 759 | Self { |
| 760 | x: self.x.shl(rhs), |
| 761 | y: self.y.shl(rhs), |
| 762 | z: self.z.shl(rhs), |
| 763 | w: self.w.shl(rhs), |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | impl Shr<i8> for UVec4 { |
| 769 | type Output = Self; |
| 770 | #[inline] |
| 771 | fn shr(self, rhs: i8) -> Self::Output { |
| 772 | Self { |
| 773 | x: self.x.shr(rhs), |
| 774 | y: self.y.shr(rhs), |
| 775 | z: self.z.shr(rhs), |
| 776 | w: self.w.shr(rhs), |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | impl Shl<i16> for UVec4 { |
| 782 | type Output = Self; |
| 783 | #[inline] |
| 784 | fn shl(self, rhs: i16) -> Self::Output { |
| 785 | Self { |
| 786 | x: self.x.shl(rhs), |
| 787 | y: self.y.shl(rhs), |
| 788 | z: self.z.shl(rhs), |
| 789 | w: self.w.shl(rhs), |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | impl Shr<i16> for UVec4 { |
| 795 | type Output = Self; |
| 796 | #[inline] |
| 797 | fn shr(self, rhs: i16) -> Self::Output { |
| 798 | Self { |
| 799 | x: self.x.shr(rhs), |
| 800 | y: self.y.shr(rhs), |
| 801 | z: self.z.shr(rhs), |
| 802 | w: self.w.shr(rhs), |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | impl Shl<i32> for UVec4 { |
| 808 | type Output = Self; |
| 809 | #[inline] |
| 810 | fn shl(self, rhs: i32) -> Self::Output { |
| 811 | Self { |
| 812 | x: self.x.shl(rhs), |
| 813 | y: self.y.shl(rhs), |
| 814 | z: self.z.shl(rhs), |
| 815 | w: self.w.shl(rhs), |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | impl Shr<i32> for UVec4 { |
| 821 | type Output = Self; |
| 822 | #[inline] |
| 823 | fn shr(self, rhs: i32) -> Self::Output { |
| 824 | Self { |
| 825 | x: self.x.shr(rhs), |
| 826 | y: self.y.shr(rhs), |
| 827 | z: self.z.shr(rhs), |
| 828 | w: self.w.shr(rhs), |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | impl Shl<u8> for UVec4 { |
| 834 | type Output = Self; |
| 835 | #[inline] |
| 836 | fn shl(self, rhs: u8) -> Self::Output { |
| 837 | Self { |
| 838 | x: self.x.shl(rhs), |
| 839 | y: self.y.shl(rhs), |
| 840 | z: self.z.shl(rhs), |
| 841 | w: self.w.shl(rhs), |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | impl Shr<u8> for UVec4 { |
| 847 | type Output = Self; |
| 848 | #[inline] |
| 849 | fn shr(self, rhs: u8) -> Self::Output { |
| 850 | Self { |
| 851 | x: self.x.shr(rhs), |
| 852 | y: self.y.shr(rhs), |
| 853 | z: self.z.shr(rhs), |
| 854 | w: self.w.shr(rhs), |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | impl Shl<u16> for UVec4 { |
| 860 | type Output = Self; |
| 861 | #[inline] |
| 862 | fn shl(self, rhs: u16) -> Self::Output { |
| 863 | Self { |
| 864 | x: self.x.shl(rhs), |
| 865 | y: self.y.shl(rhs), |
| 866 | z: self.z.shl(rhs), |
| 867 | w: self.w.shl(rhs), |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | impl Shr<u16> for UVec4 { |
| 873 | type Output = Self; |
| 874 | #[inline] |
| 875 | fn shr(self, rhs: u16) -> Self::Output { |
| 876 | Self { |
| 877 | x: self.x.shr(rhs), |
| 878 | y: self.y.shr(rhs), |
| 879 | z: self.z.shr(rhs), |
| 880 | w: self.w.shr(rhs), |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | impl Shl<u32> for UVec4 { |
| 886 | type Output = Self; |
| 887 | #[inline] |
| 888 | fn shl(self, rhs: u32) -> Self::Output { |
| 889 | Self { |
| 890 | x: self.x.shl(rhs), |
| 891 | y: self.y.shl(rhs), |
| 892 | z: self.z.shl(rhs), |
| 893 | w: self.w.shl(rhs), |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | impl Shr<u32> for UVec4 { |
| 899 | type Output = Self; |
| 900 | #[inline] |
| 901 | fn shr(self, rhs: u32) -> Self::Output { |
| 902 | Self { |
| 903 | x: self.x.shr(rhs), |
| 904 | y: self.y.shr(rhs), |
| 905 | z: self.z.shr(rhs), |
| 906 | w: self.w.shr(rhs), |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | impl Shl<crate::IVec4> for UVec4 { |
| 912 | type Output = Self; |
| 913 | #[inline] |
| 914 | fn shl(self, rhs: crate::IVec4) -> Self::Output { |
| 915 | Self { |
| 916 | x: self.x.shl(rhs.x), |
| 917 | y: self.y.shl(rhs.y), |
| 918 | z: self.z.shl(rhs.z), |
| 919 | w: self.w.shl(rhs.w), |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | impl Shr<crate::IVec4> for UVec4 { |
| 925 | type Output = Self; |
| 926 | #[inline] |
| 927 | fn shr(self, rhs: crate::IVec4) -> Self::Output { |
| 928 | Self { |
| 929 | x: self.x.shr(rhs.x), |
| 930 | y: self.y.shr(rhs.y), |
| 931 | z: self.z.shr(rhs.z), |
| 932 | w: self.w.shr(rhs.w), |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | impl Shl<crate::UVec4> for UVec4 { |
| 938 | type Output = Self; |
| 939 | #[inline] |
| 940 | fn shl(self, rhs: crate::UVec4) -> Self::Output { |
| 941 | Self { |
| 942 | x: self.x.shl(rhs.x), |
| 943 | y: self.y.shl(rhs.y), |
| 944 | z: self.z.shl(rhs.z), |
| 945 | w: self.w.shl(rhs.w), |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | impl Shr<crate::UVec4> for UVec4 { |
| 951 | type Output = Self; |
| 952 | #[inline] |
| 953 | fn shr(self, rhs: crate::UVec4) -> Self::Output { |
| 954 | Self { |
| 955 | x: self.x.shr(rhs.x), |
| 956 | y: self.y.shr(rhs.y), |
| 957 | z: self.z.shr(rhs.z), |
| 958 | w: self.w.shr(rhs.w), |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | impl Index<usize> for UVec4 { |
| 964 | type Output = u32; |
| 965 | #[inline] |
| 966 | fn index(&self, index: usize) -> &Self::Output { |
| 967 | match index { |
| 968 | 0 => &self.x, |
| 969 | 1 => &self.y, |
| 970 | 2 => &self.z, |
| 971 | 3 => &self.w, |
| 972 | _ => panic!("index out of bounds"), |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | impl IndexMut<usize> for UVec4 { |
| 978 | #[inline] |
| 979 | fn index_mut(&mut self, index: usize) -> &mut Self::Output { |
| 980 | match index { |
| 981 | 0 => &mut self.x, |
| 982 | 1 => &mut self.y, |
| 983 | 2 => &mut self.z, |
| 984 | 3 => &mut self.w, |
| 985 | _ => panic!("index out of bounds"), |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | #[cfg(not(target_arch = "spirv"))] |
| 991 | impl fmt::Display for UVec4 { |
| 992 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 993 | write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w) |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | #[cfg(not(target_arch = "spirv"))] |
| 998 | impl fmt::Debug for UVec4 { |
| 999 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1000 | fmt.debug_tuple(stringify!(UVec4)) |
| 1001 | .field(&self.x) |
| 1002 | .field(&self.y) |
| 1003 | .field(&self.z) |
| 1004 | .field(&self.w) |
| 1005 | .finish() |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | impl From<[u32; 4]> for UVec4 { |
| 1010 | #[inline] |
| 1011 | fn from(a: [u32; 4]) -> Self { |
| 1012 | Self::new(a[0], a[1], a[2], a[3]) |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | impl From<UVec4> for [u32; 4] { |
| 1017 | #[inline] |
| 1018 | fn from(v: UVec4) -> Self { |
| 1019 | [v.x, v.y, v.z, v.w] |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | impl From<(u32, u32, u32, u32)> for UVec4 { |
| 1024 | #[inline] |
| 1025 | fn from(t: (u32, u32, u32, u32)) -> Self { |
| 1026 | Self::new(t.0, t.1, t.2, t.3) |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | impl From<UVec4> for (u32, u32, u32, u32) { |
| 1031 | #[inline] |
| 1032 | fn from(v: UVec4) -> Self { |
| 1033 | (v.x, v.y, v.z, v.w) |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | impl From<(UVec3, u32)> for UVec4 { |
| 1038 | #[inline] |
| 1039 | fn from((v, w): (UVec3, u32)) -> Self { |
| 1040 | Self::new(v.x, v.y, v.z, w) |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | impl From<(u32, UVec3)> for UVec4 { |
| 1045 | #[inline] |
| 1046 | fn from((x, v): (u32, UVec3)) -> Self { |
| 1047 | Self::new(x, v.x, v.y, v.z) |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | impl From<(UVec2, u32, u32)> for UVec4 { |
| 1052 | #[inline] |
| 1053 | fn from((v, z, w): (UVec2, u32, u32)) -> Self { |
| 1054 | Self::new(v.x, v.y, z, w) |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | impl From<(UVec2, UVec2)> for UVec4 { |
| 1059 | #[inline] |
| 1060 | fn from((v, u): (UVec2, UVec2)) -> Self { |
| 1061 | Self::new(v.x, v.y, u.x, u.y) |
| 1062 | } |
| 1063 | } |