| 1 | // Generated from vec.rs.tera template. Edit the template, not the generated file. |
| 2 | |
| 3 | #[cfg(not(feature = "scalar-math"))] |
| 4 | use crate::BVec4A; |
| 5 | use crate::{BVec4, I16Vec4, I64Vec4, IVec2, IVec3, U16Vec4, U64Vec4, UVec4}; |
| 6 | |
| 7 | #[cfg(not(target_arch = "spirv"))] |
| 8 | use core::fmt; |
| 9 | use core::iter::{Product, Sum}; |
| 10 | use core::{f32, ops::*}; |
| 11 | |
| 12 | /// Creates a 4-dimensional vector. |
| 13 | #[inline(always)] |
| 14 | #[must_use] |
| 15 | pub const fn ivec4(x: i32, y: i32, z: i32, w: i32) -> IVec4 { |
| 16 | IVec4::new(x, y, z, w) |
| 17 | } |
| 18 | |
| 19 | /// A 4-dimensional vector. |
| 20 | #[cfg_attr(not(target_arch = "spirv"), derive(Hash))] |
| 21 | #[derive(Clone, Copy, PartialEq, Eq)] |
| 22 | #[cfg_attr(feature = "cuda", repr(align(16)))] |
| 23 | #[cfg_attr(not(target_arch = "spirv"), repr(C))] |
| 24 | #[cfg_attr(target_arch = "spirv", repr(simd))] |
| 25 | pub struct IVec4 { |
| 26 | pub x: i32, |
| 27 | pub y: i32, |
| 28 | pub z: i32, |
| 29 | pub w: i32, |
| 30 | } |
| 31 | |
| 32 | impl IVec4 { |
| 33 | /// All zeroes. |
| 34 | pub const ZERO: Self = Self::splat(0); |
| 35 | |
| 36 | /// All ones. |
| 37 | pub const ONE: Self = Self::splat(1); |
| 38 | |
| 39 | /// All negative ones. |
| 40 | pub const NEG_ONE: Self = Self::splat(-1); |
| 41 | |
| 42 | /// All `i32::MIN`. |
| 43 | pub const MIN: Self = Self::splat(i32::MIN); |
| 44 | |
| 45 | /// All `i32::MAX`. |
| 46 | pub const MAX: Self = Self::splat(i32::MAX); |
| 47 | |
| 48 | /// A unit vector pointing along the positive X axis. |
| 49 | pub const X: Self = Self::new(1, 0, 0, 0); |
| 50 | |
| 51 | /// A unit vector pointing along the positive Y axis. |
| 52 | pub const Y: Self = Self::new(0, 1, 0, 0); |
| 53 | |
| 54 | /// A unit vector pointing along the positive Z axis. |
| 55 | pub const Z: Self = Self::new(0, 0, 1, 0); |
| 56 | |
| 57 | /// A unit vector pointing along the positive W axis. |
| 58 | pub const W: Self = Self::new(0, 0, 0, 1); |
| 59 | |
| 60 | /// A unit vector pointing along the negative X axis. |
| 61 | pub const NEG_X: Self = Self::new(-1, 0, 0, 0); |
| 62 | |
| 63 | /// A unit vector pointing along the negative Y axis. |
| 64 | pub const NEG_Y: Self = Self::new(0, -1, 0, 0); |
| 65 | |
| 66 | /// A unit vector pointing along the negative Z axis. |
| 67 | pub const NEG_Z: Self = Self::new(0, 0, -1, 0); |
| 68 | |
| 69 | /// A unit vector pointing along the negative W axis. |
| 70 | pub const NEG_W: Self = Self::new(0, 0, 0, -1); |
| 71 | |
| 72 | /// The unit axes. |
| 73 | pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W]; |
| 74 | |
| 75 | /// Creates a new vector. |
| 76 | #[inline(always)] |
| 77 | #[must_use] |
| 78 | pub const fn new(x: i32, y: i32, z: i32, w: i32) -> Self { |
| 79 | Self { x, y, z, w } |
| 80 | } |
| 81 | |
| 82 | /// Creates a vector with all elements set to `v`. |
| 83 | #[inline] |
| 84 | #[must_use] |
| 85 | pub const fn splat(v: i32) -> Self { |
| 86 | Self { |
| 87 | x: v, |
| 88 | |
| 89 | y: v, |
| 90 | |
| 91 | z: v, |
| 92 | |
| 93 | w: v, |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use |
| 98 | /// for each element of `self`. |
| 99 | /// |
| 100 | /// A true element in the mask uses the corresponding element from `if_true`, and false |
| 101 | /// uses the element from `if_false`. |
| 102 | #[inline] |
| 103 | #[must_use] |
| 104 | pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self { |
| 105 | Self { |
| 106 | x: if mask.test(0) { if_true.x } else { if_false.x }, |
| 107 | y: if mask.test(1) { if_true.y } else { if_false.y }, |
| 108 | z: if mask.test(2) { if_true.z } else { if_false.z }, |
| 109 | w: if mask.test(3) { if_true.w } else { if_false.w }, |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /// Creates a new vector from an array. |
| 114 | #[inline] |
| 115 | #[must_use] |
| 116 | pub const fn from_array(a: [i32; 4]) -> Self { |
| 117 | Self::new(a[0], a[1], a[2], a[3]) |
| 118 | } |
| 119 | |
| 120 | /// `[x, y, z, w]` |
| 121 | #[inline] |
| 122 | #[must_use] |
| 123 | pub const fn to_array(&self) -> [i32; 4] { |
| 124 | [self.x, self.y, self.z, self.w] |
| 125 | } |
| 126 | |
| 127 | /// Creates a vector from the first 4 values in `slice`. |
| 128 | /// |
| 129 | /// # Panics |
| 130 | /// |
| 131 | /// Panics if `slice` is less than 4 elements long. |
| 132 | #[inline] |
| 133 | #[must_use] |
| 134 | pub const fn from_slice(slice: &[i32]) -> Self { |
| 135 | Self::new(slice[0], slice[1], slice[2], slice[3]) |
| 136 | } |
| 137 | |
| 138 | /// Writes the elements of `self` to the first 4 elements in `slice`. |
| 139 | /// |
| 140 | /// # Panics |
| 141 | /// |
| 142 | /// Panics if `slice` is less than 4 elements long. |
| 143 | #[inline] |
| 144 | pub fn write_to_slice(self, slice: &mut [i32]) { |
| 145 | slice[0] = self.x; |
| 146 | slice[1] = self.y; |
| 147 | slice[2] = self.z; |
| 148 | slice[3] = self.w; |
| 149 | } |
| 150 | |
| 151 | /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. |
| 152 | /// |
| 153 | /// Truncation to [`IVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. |
| 154 | #[inline] |
| 155 | #[must_use] |
| 156 | pub fn truncate(self) -> IVec3 { |
| 157 | use crate::swizzles::Vec4Swizzles; |
| 158 | self.xyz() |
| 159 | } |
| 160 | |
| 161 | /// Creates a 4D vector from `self` with the given value of `x`. |
| 162 | #[inline] |
| 163 | #[must_use] |
| 164 | pub fn with_x(mut self, x: i32) -> Self { |
| 165 | self.x = x; |
| 166 | self |
| 167 | } |
| 168 | |
| 169 | /// Creates a 4D vector from `self` with the given value of `y`. |
| 170 | #[inline] |
| 171 | #[must_use] |
| 172 | pub fn with_y(mut self, y: i32) -> Self { |
| 173 | self.y = y; |
| 174 | self |
| 175 | } |
| 176 | |
| 177 | /// Creates a 4D vector from `self` with the given value of `z`. |
| 178 | #[inline] |
| 179 | #[must_use] |
| 180 | pub fn with_z(mut self, z: i32) -> Self { |
| 181 | self.z = z; |
| 182 | self |
| 183 | } |
| 184 | |
| 185 | /// Creates a 4D vector from `self` with the given value of `w`. |
| 186 | #[inline] |
| 187 | #[must_use] |
| 188 | pub fn with_w(mut self, w: i32) -> Self { |
| 189 | self.w = w; |
| 190 | self |
| 191 | } |
| 192 | |
| 193 | /// Computes the dot product of `self` and `rhs`. |
| 194 | #[inline] |
| 195 | #[must_use] |
| 196 | pub fn dot(self, rhs: Self) -> i32 { |
| 197 | (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w) |
| 198 | } |
| 199 | |
| 200 | /// Returns a vector where every component is the dot product of `self` and `rhs`. |
| 201 | #[inline] |
| 202 | #[must_use] |
| 203 | pub fn dot_into_vec(self, rhs: Self) -> Self { |
| 204 | Self::splat(self.dot(rhs)) |
| 205 | } |
| 206 | |
| 207 | /// Returns a vector containing the minimum values for each element of `self` and `rhs`. |
| 208 | /// |
| 209 | /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. |
| 210 | #[inline] |
| 211 | #[must_use] |
| 212 | pub fn min(self, rhs: Self) -> Self { |
| 213 | Self { |
| 214 | x: self.x.min(rhs.x), |
| 215 | y: self.y.min(rhs.y), |
| 216 | z: self.z.min(rhs.z), |
| 217 | w: self.w.min(rhs.w), |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /// Returns a vector containing the maximum values for each element of `self` and `rhs`. |
| 222 | /// |
| 223 | /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. |
| 224 | #[inline] |
| 225 | #[must_use] |
| 226 | pub fn max(self, rhs: Self) -> Self { |
| 227 | Self { |
| 228 | x: self.x.max(rhs.x), |
| 229 | y: self.y.max(rhs.y), |
| 230 | z: self.z.max(rhs.z), |
| 231 | w: self.w.max(rhs.w), |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /// Component-wise clamping of values, similar to [`i32::clamp`]. |
| 236 | /// |
| 237 | /// Each element in `min` must be less-or-equal to the corresponding element in `max`. |
| 238 | /// |
| 239 | /// # Panics |
| 240 | /// |
| 241 | /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. |
| 242 | #[inline] |
| 243 | #[must_use] |
| 244 | pub fn clamp(self, min: Self, max: Self) -> Self { |
| 245 | glam_assert!(min.cmple(max).all(), "clamp: expected min <= max"); |
| 246 | self.max(min).min(max) |
| 247 | } |
| 248 | |
| 249 | /// Returns the horizontal minimum of `self`. |
| 250 | /// |
| 251 | /// In other words this computes `min(x, y, ..)`. |
| 252 | #[inline] |
| 253 | #[must_use] |
| 254 | pub fn min_element(self) -> i32 { |
| 255 | self.x.min(self.y.min(self.z.min(self.w))) |
| 256 | } |
| 257 | |
| 258 | /// Returns the horizontal maximum of `self`. |
| 259 | /// |
| 260 | /// In other words this computes `max(x, y, ..)`. |
| 261 | #[inline] |
| 262 | #[must_use] |
| 263 | pub fn max_element(self) -> i32 { |
| 264 | self.x.max(self.y.max(self.z.max(self.w))) |
| 265 | } |
| 266 | |
| 267 | /// Returns the sum of all elements of `self`. |
| 268 | /// |
| 269 | /// In other words, this computes `self.x + self.y + ..`. |
| 270 | #[inline] |
| 271 | #[must_use] |
| 272 | pub fn element_sum(self) -> i32 { |
| 273 | self.x + self.y + self.z + self.w |
| 274 | } |
| 275 | |
| 276 | /// Returns the product of all elements of `self`. |
| 277 | /// |
| 278 | /// In other words, this computes `self.x * self.y * ..`. |
| 279 | #[inline] |
| 280 | #[must_use] |
| 281 | pub fn element_product(self) -> i32 { |
| 282 | self.x * self.y * self.z * self.w |
| 283 | } |
| 284 | |
| 285 | /// Returns a vector mask containing the result of a `==` comparison for each element of |
| 286 | /// `self` and `rhs`. |
| 287 | /// |
| 288 | /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all |
| 289 | /// elements. |
| 290 | #[inline] |
| 291 | #[must_use] |
| 292 | pub fn cmpeq(self, rhs: Self) -> BVec4 { |
| 293 | BVec4::new( |
| 294 | self.x.eq(&rhs.x), |
| 295 | self.y.eq(&rhs.y), |
| 296 | self.z.eq(&rhs.z), |
| 297 | self.w.eq(&rhs.w), |
| 298 | ) |
| 299 | } |
| 300 | |
| 301 | /// Returns a vector mask containing the result of a `!=` comparison for each element of |
| 302 | /// `self` and `rhs`. |
| 303 | /// |
| 304 | /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all |
| 305 | /// elements. |
| 306 | #[inline] |
| 307 | #[must_use] |
| 308 | pub fn cmpne(self, rhs: Self) -> BVec4 { |
| 309 | BVec4::new( |
| 310 | self.x.ne(&rhs.x), |
| 311 | self.y.ne(&rhs.y), |
| 312 | self.z.ne(&rhs.z), |
| 313 | self.w.ne(&rhs.w), |
| 314 | ) |
| 315 | } |
| 316 | |
| 317 | /// Returns a vector mask containing the result of a `>=` comparison for each element of |
| 318 | /// `self` and `rhs`. |
| 319 | /// |
| 320 | /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all |
| 321 | /// elements. |
| 322 | #[inline] |
| 323 | #[must_use] |
| 324 | pub fn cmpge(self, rhs: Self) -> BVec4 { |
| 325 | BVec4::new( |
| 326 | self.x.ge(&rhs.x), |
| 327 | self.y.ge(&rhs.y), |
| 328 | self.z.ge(&rhs.z), |
| 329 | self.w.ge(&rhs.w), |
| 330 | ) |
| 331 | } |
| 332 | |
| 333 | /// Returns a vector mask containing the result of a `>` comparison for each element of |
| 334 | /// `self` and `rhs`. |
| 335 | /// |
| 336 | /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all |
| 337 | /// elements. |
| 338 | #[inline] |
| 339 | #[must_use] |
| 340 | pub fn cmpgt(self, rhs: Self) -> BVec4 { |
| 341 | BVec4::new( |
| 342 | self.x.gt(&rhs.x), |
| 343 | self.y.gt(&rhs.y), |
| 344 | self.z.gt(&rhs.z), |
| 345 | self.w.gt(&rhs.w), |
| 346 | ) |
| 347 | } |
| 348 | |
| 349 | /// Returns a vector mask containing the result of a `<=` comparison for each element of |
| 350 | /// `self` and `rhs`. |
| 351 | /// |
| 352 | /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all |
| 353 | /// elements. |
| 354 | #[inline] |
| 355 | #[must_use] |
| 356 | pub fn cmple(self, rhs: Self) -> BVec4 { |
| 357 | BVec4::new( |
| 358 | self.x.le(&rhs.x), |
| 359 | self.y.le(&rhs.y), |
| 360 | self.z.le(&rhs.z), |
| 361 | self.w.le(&rhs.w), |
| 362 | ) |
| 363 | } |
| 364 | |
| 365 | /// Returns a vector mask containing the result of a `<` comparison for each element of |
| 366 | /// `self` and `rhs`. |
| 367 | /// |
| 368 | /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all |
| 369 | /// elements. |
| 370 | #[inline] |
| 371 | #[must_use] |
| 372 | pub fn cmplt(self, rhs: Self) -> BVec4 { |
| 373 | BVec4::new( |
| 374 | self.x.lt(&rhs.x), |
| 375 | self.y.lt(&rhs.y), |
| 376 | self.z.lt(&rhs.z), |
| 377 | self.w.lt(&rhs.w), |
| 378 | ) |
| 379 | } |
| 380 | |
| 381 | /// Returns a vector containing the absolute value of each element of `self`. |
| 382 | #[inline] |
| 383 | #[must_use] |
| 384 | pub fn abs(self) -> Self { |
| 385 | Self { |
| 386 | x: self.x.abs(), |
| 387 | y: self.y.abs(), |
| 388 | z: self.z.abs(), |
| 389 | w: self.w.abs(), |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /// Returns a vector with elements representing the sign of `self`. |
| 394 | /// |
| 395 | /// - `0` if the number is zero |
| 396 | /// - `1` if the number is positive |
| 397 | /// - `-1` if the number is negative |
| 398 | #[inline] |
| 399 | #[must_use] |
| 400 | pub fn signum(self) -> Self { |
| 401 | Self { |
| 402 | x: self.x.signum(), |
| 403 | y: self.y.signum(), |
| 404 | z: self.z.signum(), |
| 405 | w: self.w.signum(), |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. |
| 410 | /// |
| 411 | /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes |
| 412 | /// into the first lowest bit, element `y` into the second, etc. |
| 413 | #[inline] |
| 414 | #[must_use] |
| 415 | pub fn is_negative_bitmask(self) -> u32 { |
| 416 | (self.x.is_negative() as u32) |
| 417 | | (self.y.is_negative() as u32) << 1 |
| 418 | | (self.z.is_negative() as u32) << 2 |
| 419 | | (self.w.is_negative() as u32) << 3 |
| 420 | } |
| 421 | |
| 422 | /// Computes the squared length of `self`. |
| 423 | #[doc(alias = "magnitude2")] |
| 424 | #[inline] |
| 425 | #[must_use] |
| 426 | pub fn length_squared(self) -> i32 { |
| 427 | self.dot(self) |
| 428 | } |
| 429 | |
| 430 | /// Compute the squared euclidean distance between two points in space. |
| 431 | #[inline] |
| 432 | #[must_use] |
| 433 | pub fn distance_squared(self, rhs: Self) -> i32 { |
| 434 | (self - rhs).length_squared() |
| 435 | } |
| 436 | |
| 437 | /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. |
| 438 | /// |
| 439 | /// # Panics |
| 440 | /// This function will panic if any `rhs` element is 0 or the division results in overflow. |
| 441 | #[inline] |
| 442 | #[must_use] |
| 443 | pub fn div_euclid(self, rhs: Self) -> Self { |
| 444 | Self::new( |
| 445 | self.x.div_euclid(rhs.x), |
| 446 | self.y.div_euclid(rhs.y), |
| 447 | self.z.div_euclid(rhs.z), |
| 448 | self.w.div_euclid(rhs.w), |
| 449 | ) |
| 450 | } |
| 451 | |
| 452 | /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. |
| 453 | /// |
| 454 | /// # Panics |
| 455 | /// This function will panic if any `rhs` element is 0 or the division results in overflow. |
| 456 | /// |
| 457 | /// [Euclidean division]: i32::rem_euclid |
| 458 | #[inline] |
| 459 | #[must_use] |
| 460 | pub fn rem_euclid(self, rhs: Self) -> Self { |
| 461 | Self::new( |
| 462 | self.x.rem_euclid(rhs.x), |
| 463 | self.y.rem_euclid(rhs.y), |
| 464 | self.z.rem_euclid(rhs.z), |
| 465 | self.w.rem_euclid(rhs.w), |
| 466 | ) |
| 467 | } |
| 468 | |
| 469 | /// Casts all elements of `self` to `f32`. |
| 470 | #[inline] |
| 471 | #[must_use] |
| 472 | pub fn as_vec4(&self) -> crate::Vec4 { |
| 473 | crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32) |
| 474 | } |
| 475 | |
| 476 | /// Casts all elements of `self` to `f64`. |
| 477 | #[inline] |
| 478 | #[must_use] |
| 479 | pub fn as_dvec4(&self) -> crate::DVec4 { |
| 480 | crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64) |
| 481 | } |
| 482 | |
| 483 | /// Casts all elements of `self` to `i16`. |
| 484 | #[inline] |
| 485 | #[must_use] |
| 486 | pub fn as_i16vec4(&self) -> crate::I16Vec4 { |
| 487 | crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16) |
| 488 | } |
| 489 | |
| 490 | /// Casts all elements of `self` to `u16`. |
| 491 | #[inline] |
| 492 | #[must_use] |
| 493 | pub fn as_u16vec4(&self) -> crate::U16Vec4 { |
| 494 | crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16) |
| 495 | } |
| 496 | |
| 497 | /// Casts all elements of `self` to `u32`. |
| 498 | #[inline] |
| 499 | #[must_use] |
| 500 | pub fn as_uvec4(&self) -> crate::UVec4 { |
| 501 | crate::UVec4::new(self.x as u32, self.y as u32, self.z as u32, self.w as u32) |
| 502 | } |
| 503 | |
| 504 | /// Casts all elements of `self` to `i64`. |
| 505 | #[inline] |
| 506 | #[must_use] |
| 507 | pub fn as_i64vec4(&self) -> crate::I64Vec4 { |
| 508 | crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64) |
| 509 | } |
| 510 | |
| 511 | /// Casts all elements of `self` to `u64`. |
| 512 | #[inline] |
| 513 | #[must_use] |
| 514 | pub fn as_u64vec4(&self) -> crate::U64Vec4 { |
| 515 | crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64) |
| 516 | } |
| 517 | |
| 518 | /// Returns a vector containing the wrapping addition of `self` and `rhs`. |
| 519 | /// |
| 520 | /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. |
| 521 | #[inline] |
| 522 | #[must_use] |
| 523 | pub const fn wrapping_add(self, rhs: Self) -> Self { |
| 524 | Self { |
| 525 | x: self.x.wrapping_add(rhs.x), |
| 526 | y: self.y.wrapping_add(rhs.y), |
| 527 | z: self.z.wrapping_add(rhs.z), |
| 528 | w: self.w.wrapping_add(rhs.w), |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. |
| 533 | /// |
| 534 | /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. |
| 535 | #[inline] |
| 536 | #[must_use] |
| 537 | pub const fn wrapping_sub(self, rhs: Self) -> Self { |
| 538 | Self { |
| 539 | x: self.x.wrapping_sub(rhs.x), |
| 540 | y: self.y.wrapping_sub(rhs.y), |
| 541 | z: self.z.wrapping_sub(rhs.z), |
| 542 | w: self.w.wrapping_sub(rhs.w), |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. |
| 547 | /// |
| 548 | /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. |
| 549 | #[inline] |
| 550 | #[must_use] |
| 551 | pub const fn wrapping_mul(self, rhs: Self) -> Self { |
| 552 | Self { |
| 553 | x: self.x.wrapping_mul(rhs.x), |
| 554 | y: self.y.wrapping_mul(rhs.y), |
| 555 | z: self.z.wrapping_mul(rhs.z), |
| 556 | w: self.w.wrapping_mul(rhs.w), |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /// Returns a vector containing the wrapping division of `self` and `rhs`. |
| 561 | /// |
| 562 | /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. |
| 563 | #[inline] |
| 564 | #[must_use] |
| 565 | pub const fn wrapping_div(self, rhs: Self) -> Self { |
| 566 | Self { |
| 567 | x: self.x.wrapping_div(rhs.x), |
| 568 | y: self.y.wrapping_div(rhs.y), |
| 569 | z: self.z.wrapping_div(rhs.z), |
| 570 | w: self.w.wrapping_div(rhs.w), |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | /// Returns a vector containing the saturating addition of `self` and `rhs`. |
| 575 | /// |
| 576 | /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. |
| 577 | #[inline] |
| 578 | #[must_use] |
| 579 | pub const fn saturating_add(self, rhs: Self) -> Self { |
| 580 | Self { |
| 581 | x: self.x.saturating_add(rhs.x), |
| 582 | y: self.y.saturating_add(rhs.y), |
| 583 | z: self.z.saturating_add(rhs.z), |
| 584 | w: self.w.saturating_add(rhs.w), |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | /// Returns a vector containing the saturating subtraction of `self` and `rhs`. |
| 589 | /// |
| 590 | /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. |
| 591 | #[inline] |
| 592 | #[must_use] |
| 593 | pub const fn saturating_sub(self, rhs: Self) -> Self { |
| 594 | Self { |
| 595 | x: self.x.saturating_sub(rhs.x), |
| 596 | y: self.y.saturating_sub(rhs.y), |
| 597 | z: self.z.saturating_sub(rhs.z), |
| 598 | w: self.w.saturating_sub(rhs.w), |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | /// Returns a vector containing the saturating multiplication of `self` and `rhs`. |
| 603 | /// |
| 604 | /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. |
| 605 | #[inline] |
| 606 | #[must_use] |
| 607 | pub const fn saturating_mul(self, rhs: Self) -> Self { |
| 608 | Self { |
| 609 | x: self.x.saturating_mul(rhs.x), |
| 610 | y: self.y.saturating_mul(rhs.y), |
| 611 | z: self.z.saturating_mul(rhs.z), |
| 612 | w: self.w.saturating_mul(rhs.w), |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | /// Returns a vector containing the saturating division of `self` and `rhs`. |
| 617 | /// |
| 618 | /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. |
| 619 | #[inline] |
| 620 | #[must_use] |
| 621 | pub const fn saturating_div(self, rhs: Self) -> Self { |
| 622 | Self { |
| 623 | x: self.x.saturating_div(rhs.x), |
| 624 | y: self.y.saturating_div(rhs.y), |
| 625 | z: self.z.saturating_div(rhs.z), |
| 626 | w: self.w.saturating_div(rhs.w), |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. |
| 631 | /// |
| 632 | /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. |
| 633 | #[inline] |
| 634 | #[must_use] |
| 635 | pub const fn wrapping_add_unsigned(self, rhs: UVec4) -> Self { |
| 636 | Self { |
| 637 | x: self.x.wrapping_add_unsigned(rhs.x), |
| 638 | y: self.y.wrapping_add_unsigned(rhs.y), |
| 639 | z: self.z.wrapping_add_unsigned(rhs.z), |
| 640 | w: self.w.wrapping_add_unsigned(rhs.w), |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. |
| 645 | /// |
| 646 | /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. |
| 647 | #[inline] |
| 648 | #[must_use] |
| 649 | pub const fn wrapping_sub_unsigned(self, rhs: UVec4) -> Self { |
| 650 | Self { |
| 651 | x: self.x.wrapping_sub_unsigned(rhs.x), |
| 652 | y: self.y.wrapping_sub_unsigned(rhs.y), |
| 653 | z: self.z.wrapping_sub_unsigned(rhs.z), |
| 654 | w: self.w.wrapping_sub_unsigned(rhs.w), |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | // Returns a vector containing the saturating addition of `self` and unsigned vector `rhs`. |
| 659 | /// |
| 660 | /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. |
| 661 | #[inline] |
| 662 | #[must_use] |
| 663 | pub const fn saturating_add_unsigned(self, rhs: UVec4) -> Self { |
| 664 | Self { |
| 665 | x: self.x.saturating_add_unsigned(rhs.x), |
| 666 | y: self.y.saturating_add_unsigned(rhs.y), |
| 667 | z: self.z.saturating_add_unsigned(rhs.z), |
| 668 | w: self.w.saturating_add_unsigned(rhs.w), |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. |
| 673 | /// |
| 674 | /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. |
| 675 | #[inline] |
| 676 | #[must_use] |
| 677 | pub const fn saturating_sub_unsigned(self, rhs: UVec4) -> Self { |
| 678 | Self { |
| 679 | x: self.x.saturating_sub_unsigned(rhs.x), |
| 680 | y: self.y.saturating_sub_unsigned(rhs.y), |
| 681 | z: self.z.saturating_sub_unsigned(rhs.z), |
| 682 | w: self.w.saturating_sub_unsigned(rhs.w), |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | impl Default for IVec4 { |
| 688 | #[inline(always)] |
| 689 | fn default() -> Self { |
| 690 | Self::ZERO |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | impl Div<IVec4> for IVec4 { |
| 695 | type Output = Self; |
| 696 | #[inline] |
| 697 | fn div(self, rhs: Self) -> Self { |
| 698 | Self { |
| 699 | x: self.x.div(rhs.x), |
| 700 | y: self.y.div(rhs.y), |
| 701 | z: self.z.div(rhs.z), |
| 702 | w: self.w.div(rhs.w), |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | impl DivAssign<IVec4> for IVec4 { |
| 708 | #[inline] |
| 709 | fn div_assign(&mut self, rhs: Self) { |
| 710 | self.x.div_assign(rhs.x); |
| 711 | self.y.div_assign(rhs.y); |
| 712 | self.z.div_assign(rhs.z); |
| 713 | self.w.div_assign(rhs.w); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | impl Div<i32> for IVec4 { |
| 718 | type Output = Self; |
| 719 | #[inline] |
| 720 | fn div(self, rhs: i32) -> Self { |
| 721 | Self { |
| 722 | x: self.x.div(rhs), |
| 723 | y: self.y.div(rhs), |
| 724 | z: self.z.div(rhs), |
| 725 | w: self.w.div(rhs), |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | impl DivAssign<i32> for IVec4 { |
| 731 | #[inline] |
| 732 | fn div_assign(&mut self, rhs: i32) { |
| 733 | self.x.div_assign(rhs); |
| 734 | self.y.div_assign(rhs); |
| 735 | self.z.div_assign(rhs); |
| 736 | self.w.div_assign(rhs); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | impl Div<IVec4> for i32 { |
| 741 | type Output = IVec4; |
| 742 | #[inline] |
| 743 | fn div(self, rhs: IVec4) -> IVec4 { |
| 744 | IVec4 { |
| 745 | x: self.div(rhs.x), |
| 746 | y: self.div(rhs.y), |
| 747 | z: self.div(rhs.z), |
| 748 | w: self.div(rhs.w), |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | impl Mul<IVec4> for IVec4 { |
| 754 | type Output = Self; |
| 755 | #[inline] |
| 756 | fn mul(self, rhs: Self) -> Self { |
| 757 | Self { |
| 758 | x: self.x.mul(rhs.x), |
| 759 | y: self.y.mul(rhs.y), |
| 760 | z: self.z.mul(rhs.z), |
| 761 | w: self.w.mul(rhs.w), |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | impl MulAssign<IVec4> for IVec4 { |
| 767 | #[inline] |
| 768 | fn mul_assign(&mut self, rhs: Self) { |
| 769 | self.x.mul_assign(rhs.x); |
| 770 | self.y.mul_assign(rhs.y); |
| 771 | self.z.mul_assign(rhs.z); |
| 772 | self.w.mul_assign(rhs.w); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | impl Mul<i32> for IVec4 { |
| 777 | type Output = Self; |
| 778 | #[inline] |
| 779 | fn mul(self, rhs: i32) -> Self { |
| 780 | Self { |
| 781 | x: self.x.mul(rhs), |
| 782 | y: self.y.mul(rhs), |
| 783 | z: self.z.mul(rhs), |
| 784 | w: self.w.mul(rhs), |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | impl MulAssign<i32> for IVec4 { |
| 790 | #[inline] |
| 791 | fn mul_assign(&mut self, rhs: i32) { |
| 792 | self.x.mul_assign(rhs); |
| 793 | self.y.mul_assign(rhs); |
| 794 | self.z.mul_assign(rhs); |
| 795 | self.w.mul_assign(rhs); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | impl Mul<IVec4> for i32 { |
| 800 | type Output = IVec4; |
| 801 | #[inline] |
| 802 | fn mul(self, rhs: IVec4) -> IVec4 { |
| 803 | IVec4 { |
| 804 | x: self.mul(rhs.x), |
| 805 | y: self.mul(rhs.y), |
| 806 | z: self.mul(rhs.z), |
| 807 | w: self.mul(rhs.w), |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | impl Add<IVec4> for IVec4 { |
| 813 | type Output = Self; |
| 814 | #[inline] |
| 815 | fn add(self, rhs: Self) -> Self { |
| 816 | Self { |
| 817 | x: self.x.add(rhs.x), |
| 818 | y: self.y.add(rhs.y), |
| 819 | z: self.z.add(rhs.z), |
| 820 | w: self.w.add(rhs.w), |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | impl AddAssign<IVec4> for IVec4 { |
| 826 | #[inline] |
| 827 | fn add_assign(&mut self, rhs: Self) { |
| 828 | self.x.add_assign(rhs.x); |
| 829 | self.y.add_assign(rhs.y); |
| 830 | self.z.add_assign(rhs.z); |
| 831 | self.w.add_assign(rhs.w); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | impl Add<i32> for IVec4 { |
| 836 | type Output = Self; |
| 837 | #[inline] |
| 838 | fn add(self, rhs: i32) -> Self { |
| 839 | Self { |
| 840 | x: self.x.add(rhs), |
| 841 | y: self.y.add(rhs), |
| 842 | z: self.z.add(rhs), |
| 843 | w: self.w.add(rhs), |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | impl AddAssign<i32> for IVec4 { |
| 849 | #[inline] |
| 850 | fn add_assign(&mut self, rhs: i32) { |
| 851 | self.x.add_assign(rhs); |
| 852 | self.y.add_assign(rhs); |
| 853 | self.z.add_assign(rhs); |
| 854 | self.w.add_assign(rhs); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | impl Add<IVec4> for i32 { |
| 859 | type Output = IVec4; |
| 860 | #[inline] |
| 861 | fn add(self, rhs: IVec4) -> IVec4 { |
| 862 | IVec4 { |
| 863 | x: self.add(rhs.x), |
| 864 | y: self.add(rhs.y), |
| 865 | z: self.add(rhs.z), |
| 866 | w: self.add(rhs.w), |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | impl Sub<IVec4> for IVec4 { |
| 872 | type Output = Self; |
| 873 | #[inline] |
| 874 | fn sub(self, rhs: Self) -> Self { |
| 875 | Self { |
| 876 | x: self.x.sub(rhs.x), |
| 877 | y: self.y.sub(rhs.y), |
| 878 | z: self.z.sub(rhs.z), |
| 879 | w: self.w.sub(rhs.w), |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | impl SubAssign<IVec4> for IVec4 { |
| 885 | #[inline] |
| 886 | fn sub_assign(&mut self, rhs: IVec4) { |
| 887 | self.x.sub_assign(rhs.x); |
| 888 | self.y.sub_assign(rhs.y); |
| 889 | self.z.sub_assign(rhs.z); |
| 890 | self.w.sub_assign(rhs.w); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | impl Sub<i32> for IVec4 { |
| 895 | type Output = Self; |
| 896 | #[inline] |
| 897 | fn sub(self, rhs: i32) -> Self { |
| 898 | Self { |
| 899 | x: self.x.sub(rhs), |
| 900 | y: self.y.sub(rhs), |
| 901 | z: self.z.sub(rhs), |
| 902 | w: self.w.sub(rhs), |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | impl SubAssign<i32> for IVec4 { |
| 908 | #[inline] |
| 909 | fn sub_assign(&mut self, rhs: i32) { |
| 910 | self.x.sub_assign(rhs); |
| 911 | self.y.sub_assign(rhs); |
| 912 | self.z.sub_assign(rhs); |
| 913 | self.w.sub_assign(rhs); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | impl Sub<IVec4> for i32 { |
| 918 | type Output = IVec4; |
| 919 | #[inline] |
| 920 | fn sub(self, rhs: IVec4) -> IVec4 { |
| 921 | IVec4 { |
| 922 | x: self.sub(rhs.x), |
| 923 | y: self.sub(rhs.y), |
| 924 | z: self.sub(rhs.z), |
| 925 | w: self.sub(rhs.w), |
| 926 | } |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | impl Rem<IVec4> for IVec4 { |
| 931 | type Output = Self; |
| 932 | #[inline] |
| 933 | fn rem(self, rhs: Self) -> Self { |
| 934 | Self { |
| 935 | x: self.x.rem(rhs.x), |
| 936 | y: self.y.rem(rhs.y), |
| 937 | z: self.z.rem(rhs.z), |
| 938 | w: self.w.rem(rhs.w), |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | impl RemAssign<IVec4> for IVec4 { |
| 944 | #[inline] |
| 945 | fn rem_assign(&mut self, rhs: Self) { |
| 946 | self.x.rem_assign(rhs.x); |
| 947 | self.y.rem_assign(rhs.y); |
| 948 | self.z.rem_assign(rhs.z); |
| 949 | self.w.rem_assign(rhs.w); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | impl Rem<i32> for IVec4 { |
| 954 | type Output = Self; |
| 955 | #[inline] |
| 956 | fn rem(self, rhs: i32) -> Self { |
| 957 | Self { |
| 958 | x: self.x.rem(rhs), |
| 959 | y: self.y.rem(rhs), |
| 960 | z: self.z.rem(rhs), |
| 961 | w: self.w.rem(rhs), |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | impl RemAssign<i32> for IVec4 { |
| 967 | #[inline] |
| 968 | fn rem_assign(&mut self, rhs: i32) { |
| 969 | self.x.rem_assign(rhs); |
| 970 | self.y.rem_assign(rhs); |
| 971 | self.z.rem_assign(rhs); |
| 972 | self.w.rem_assign(rhs); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | impl Rem<IVec4> for i32 { |
| 977 | type Output = IVec4; |
| 978 | #[inline] |
| 979 | fn rem(self, rhs: IVec4) -> IVec4 { |
| 980 | IVec4 { |
| 981 | x: self.rem(rhs.x), |
| 982 | y: self.rem(rhs.y), |
| 983 | z: self.rem(rhs.z), |
| 984 | w: self.rem(rhs.w), |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | #[cfg(not(target_arch = "spirv"))] |
| 990 | impl AsRef<[i32; 4]> for IVec4 { |
| 991 | #[inline] |
| 992 | fn as_ref(&self) -> &[i32; 4] { |
| 993 | unsafe { &*(self as *const IVec4 as *const [i32; 4]) } |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | #[cfg(not(target_arch = "spirv"))] |
| 998 | impl AsMut<[i32; 4]> for IVec4 { |
| 999 | #[inline] |
| 1000 | fn as_mut(&mut self) -> &mut [i32; 4] { |
| 1001 | unsafe { &mut *(self as *mut IVec4 as *mut [i32; 4]) } |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | impl Sum for IVec4 { |
| 1006 | #[inline] |
| 1007 | fn sum<I>(iter: I) -> Self |
| 1008 | where |
| 1009 | I: Iterator<Item = Self>, |
| 1010 | { |
| 1011 | iter.fold(Self::ZERO, Self::add) |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | impl<'a> Sum<&'a Self> for IVec4 { |
| 1016 | #[inline] |
| 1017 | fn sum<I>(iter: I) -> Self |
| 1018 | where |
| 1019 | I: Iterator<Item = &'a Self>, |
| 1020 | { |
| 1021 | iter.fold(Self::ZERO, |a, &b| Self::add(a, b)) |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | impl Product for IVec4 { |
| 1026 | #[inline] |
| 1027 | fn product<I>(iter: I) -> Self |
| 1028 | where |
| 1029 | I: Iterator<Item = Self>, |
| 1030 | { |
| 1031 | iter.fold(Self::ONE, Self::mul) |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | impl<'a> Product<&'a Self> for IVec4 { |
| 1036 | #[inline] |
| 1037 | fn product<I>(iter: I) -> Self |
| 1038 | where |
| 1039 | I: Iterator<Item = &'a Self>, |
| 1040 | { |
| 1041 | iter.fold(Self::ONE, |a, &b| Self::mul(a, b)) |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | impl Neg for IVec4 { |
| 1046 | type Output = Self; |
| 1047 | #[inline] |
| 1048 | fn neg(self) -> Self { |
| 1049 | Self { |
| 1050 | x: self.x.neg(), |
| 1051 | y: self.y.neg(), |
| 1052 | z: self.z.neg(), |
| 1053 | w: self.w.neg(), |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | impl Not for IVec4 { |
| 1059 | type Output = Self; |
| 1060 | #[inline] |
| 1061 | fn not(self) -> Self::Output { |
| 1062 | Self { |
| 1063 | x: self.x.not(), |
| 1064 | y: self.y.not(), |
| 1065 | z: self.z.not(), |
| 1066 | w: self.w.not(), |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | impl BitAnd for IVec4 { |
| 1072 | type Output = Self; |
| 1073 | #[inline] |
| 1074 | fn bitand(self, rhs: Self) -> Self::Output { |
| 1075 | Self { |
| 1076 | x: self.x.bitand(rhs.x), |
| 1077 | y: self.y.bitand(rhs.y), |
| 1078 | z: self.z.bitand(rhs.z), |
| 1079 | w: self.w.bitand(rhs.w), |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | impl BitOr for IVec4 { |
| 1085 | type Output = Self; |
| 1086 | #[inline] |
| 1087 | fn bitor(self, rhs: Self) -> Self::Output { |
| 1088 | Self { |
| 1089 | x: self.x.bitor(rhs.x), |
| 1090 | y: self.y.bitor(rhs.y), |
| 1091 | z: self.z.bitor(rhs.z), |
| 1092 | w: self.w.bitor(rhs.w), |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | impl BitXor for IVec4 { |
| 1098 | type Output = Self; |
| 1099 | #[inline] |
| 1100 | fn bitxor(self, rhs: Self) -> Self::Output { |
| 1101 | Self { |
| 1102 | x: self.x.bitxor(rhs.x), |
| 1103 | y: self.y.bitxor(rhs.y), |
| 1104 | z: self.z.bitxor(rhs.z), |
| 1105 | w: self.w.bitxor(rhs.w), |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | impl BitAnd<i32> for IVec4 { |
| 1111 | type Output = Self; |
| 1112 | #[inline] |
| 1113 | fn bitand(self, rhs: i32) -> Self::Output { |
| 1114 | Self { |
| 1115 | x: self.x.bitand(rhs), |
| 1116 | y: self.y.bitand(rhs), |
| 1117 | z: self.z.bitand(rhs), |
| 1118 | w: self.w.bitand(rhs), |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | impl BitOr<i32> for IVec4 { |
| 1124 | type Output = Self; |
| 1125 | #[inline] |
| 1126 | fn bitor(self, rhs: i32) -> Self::Output { |
| 1127 | Self { |
| 1128 | x: self.x.bitor(rhs), |
| 1129 | y: self.y.bitor(rhs), |
| 1130 | z: self.z.bitor(rhs), |
| 1131 | w: self.w.bitor(rhs), |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | impl BitXor<i32> for IVec4 { |
| 1137 | type Output = Self; |
| 1138 | #[inline] |
| 1139 | fn bitxor(self, rhs: i32) -> Self::Output { |
| 1140 | Self { |
| 1141 | x: self.x.bitxor(rhs), |
| 1142 | y: self.y.bitxor(rhs), |
| 1143 | z: self.z.bitxor(rhs), |
| 1144 | w: self.w.bitxor(rhs), |
| 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | impl Shl<i8> for IVec4 { |
| 1150 | type Output = Self; |
| 1151 | #[inline] |
| 1152 | fn shl(self, rhs: i8) -> Self::Output { |
| 1153 | Self { |
| 1154 | x: self.x.shl(rhs), |
| 1155 | y: self.y.shl(rhs), |
| 1156 | z: self.z.shl(rhs), |
| 1157 | w: self.w.shl(rhs), |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | impl Shr<i8> for IVec4 { |
| 1163 | type Output = Self; |
| 1164 | #[inline] |
| 1165 | fn shr(self, rhs: i8) -> Self::Output { |
| 1166 | Self { |
| 1167 | x: self.x.shr(rhs), |
| 1168 | y: self.y.shr(rhs), |
| 1169 | z: self.z.shr(rhs), |
| 1170 | w: self.w.shr(rhs), |
| 1171 | } |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | impl Shl<i16> for IVec4 { |
| 1176 | type Output = Self; |
| 1177 | #[inline] |
| 1178 | fn shl(self, rhs: i16) -> Self::Output { |
| 1179 | Self { |
| 1180 | x: self.x.shl(rhs), |
| 1181 | y: self.y.shl(rhs), |
| 1182 | z: self.z.shl(rhs), |
| 1183 | w: self.w.shl(rhs), |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | impl Shr<i16> for IVec4 { |
| 1189 | type Output = Self; |
| 1190 | #[inline] |
| 1191 | fn shr(self, rhs: i16) -> Self::Output { |
| 1192 | Self { |
| 1193 | x: self.x.shr(rhs), |
| 1194 | y: self.y.shr(rhs), |
| 1195 | z: self.z.shr(rhs), |
| 1196 | w: self.w.shr(rhs), |
| 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | impl Shl<i32> for IVec4 { |
| 1202 | type Output = Self; |
| 1203 | #[inline] |
| 1204 | fn shl(self, rhs: i32) -> Self::Output { |
| 1205 | Self { |
| 1206 | x: self.x.shl(rhs), |
| 1207 | y: self.y.shl(rhs), |
| 1208 | z: self.z.shl(rhs), |
| 1209 | w: self.w.shl(rhs), |
| 1210 | } |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | impl Shr<i32> for IVec4 { |
| 1215 | type Output = Self; |
| 1216 | #[inline] |
| 1217 | fn shr(self, rhs: i32) -> Self::Output { |
| 1218 | Self { |
| 1219 | x: self.x.shr(rhs), |
| 1220 | y: self.y.shr(rhs), |
| 1221 | z: self.z.shr(rhs), |
| 1222 | w: self.w.shr(rhs), |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | impl Shl<i64> for IVec4 { |
| 1228 | type Output = Self; |
| 1229 | #[inline] |
| 1230 | fn shl(self, rhs: i64) -> Self::Output { |
| 1231 | Self { |
| 1232 | x: self.x.shl(rhs), |
| 1233 | y: self.y.shl(rhs), |
| 1234 | z: self.z.shl(rhs), |
| 1235 | w: self.w.shl(rhs), |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | impl Shr<i64> for IVec4 { |
| 1241 | type Output = Self; |
| 1242 | #[inline] |
| 1243 | fn shr(self, rhs: i64) -> Self::Output { |
| 1244 | Self { |
| 1245 | x: self.x.shr(rhs), |
| 1246 | y: self.y.shr(rhs), |
| 1247 | z: self.z.shr(rhs), |
| 1248 | w: self.w.shr(rhs), |
| 1249 | } |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | impl Shl<u8> for IVec4 { |
| 1254 | type Output = Self; |
| 1255 | #[inline] |
| 1256 | fn shl(self, rhs: u8) -> Self::Output { |
| 1257 | Self { |
| 1258 | x: self.x.shl(rhs), |
| 1259 | y: self.y.shl(rhs), |
| 1260 | z: self.z.shl(rhs), |
| 1261 | w: self.w.shl(rhs), |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | impl Shr<u8> for IVec4 { |
| 1267 | type Output = Self; |
| 1268 | #[inline] |
| 1269 | fn shr(self, rhs: u8) -> Self::Output { |
| 1270 | Self { |
| 1271 | x: self.x.shr(rhs), |
| 1272 | y: self.y.shr(rhs), |
| 1273 | z: self.z.shr(rhs), |
| 1274 | w: self.w.shr(rhs), |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | impl Shl<u16> for IVec4 { |
| 1280 | type Output = Self; |
| 1281 | #[inline] |
| 1282 | fn shl(self, rhs: u16) -> Self::Output { |
| 1283 | Self { |
| 1284 | x: self.x.shl(rhs), |
| 1285 | y: self.y.shl(rhs), |
| 1286 | z: self.z.shl(rhs), |
| 1287 | w: self.w.shl(rhs), |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | impl Shr<u16> for IVec4 { |
| 1293 | type Output = Self; |
| 1294 | #[inline] |
| 1295 | fn shr(self, rhs: u16) -> Self::Output { |
| 1296 | Self { |
| 1297 | x: self.x.shr(rhs), |
| 1298 | y: self.y.shr(rhs), |
| 1299 | z: self.z.shr(rhs), |
| 1300 | w: self.w.shr(rhs), |
| 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | impl Shl<u32> for IVec4 { |
| 1306 | type Output = Self; |
| 1307 | #[inline] |
| 1308 | fn shl(self, rhs: u32) -> Self::Output { |
| 1309 | Self { |
| 1310 | x: self.x.shl(rhs), |
| 1311 | y: self.y.shl(rhs), |
| 1312 | z: self.z.shl(rhs), |
| 1313 | w: self.w.shl(rhs), |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | impl Shr<u32> for IVec4 { |
| 1319 | type Output = Self; |
| 1320 | #[inline] |
| 1321 | fn shr(self, rhs: u32) -> Self::Output { |
| 1322 | Self { |
| 1323 | x: self.x.shr(rhs), |
| 1324 | y: self.y.shr(rhs), |
| 1325 | z: self.z.shr(rhs), |
| 1326 | w: self.w.shr(rhs), |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | impl Shl<u64> for IVec4 { |
| 1332 | type Output = Self; |
| 1333 | #[inline] |
| 1334 | fn shl(self, rhs: u64) -> Self::Output { |
| 1335 | Self { |
| 1336 | x: self.x.shl(rhs), |
| 1337 | y: self.y.shl(rhs), |
| 1338 | z: self.z.shl(rhs), |
| 1339 | w: self.w.shl(rhs), |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | impl Shr<u64> for IVec4 { |
| 1345 | type Output = Self; |
| 1346 | #[inline] |
| 1347 | fn shr(self, rhs: u64) -> Self::Output { |
| 1348 | Self { |
| 1349 | x: self.x.shr(rhs), |
| 1350 | y: self.y.shr(rhs), |
| 1351 | z: self.z.shr(rhs), |
| 1352 | w: self.w.shr(rhs), |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | impl Shl<crate::IVec4> for IVec4 { |
| 1358 | type Output = Self; |
| 1359 | #[inline] |
| 1360 | fn shl(self, rhs: crate::IVec4) -> Self::Output { |
| 1361 | Self { |
| 1362 | x: self.x.shl(rhs.x), |
| 1363 | y: self.y.shl(rhs.y), |
| 1364 | z: self.z.shl(rhs.z), |
| 1365 | w: self.w.shl(rhs.w), |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | impl Shr<crate::IVec4> for IVec4 { |
| 1371 | type Output = Self; |
| 1372 | #[inline] |
| 1373 | fn shr(self, rhs: crate::IVec4) -> Self::Output { |
| 1374 | Self { |
| 1375 | x: self.x.shr(rhs.x), |
| 1376 | y: self.y.shr(rhs.y), |
| 1377 | z: self.z.shr(rhs.z), |
| 1378 | w: self.w.shr(rhs.w), |
| 1379 | } |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | impl Shl<crate::UVec4> for IVec4 { |
| 1384 | type Output = Self; |
| 1385 | #[inline] |
| 1386 | fn shl(self, rhs: crate::UVec4) -> Self::Output { |
| 1387 | Self { |
| 1388 | x: self.x.shl(rhs.x), |
| 1389 | y: self.y.shl(rhs.y), |
| 1390 | z: self.z.shl(rhs.z), |
| 1391 | w: self.w.shl(rhs.w), |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | impl Shr<crate::UVec4> for IVec4 { |
| 1397 | type Output = Self; |
| 1398 | #[inline] |
| 1399 | fn shr(self, rhs: crate::UVec4) -> Self::Output { |
| 1400 | Self { |
| 1401 | x: self.x.shr(rhs.x), |
| 1402 | y: self.y.shr(rhs.y), |
| 1403 | z: self.z.shr(rhs.z), |
| 1404 | w: self.w.shr(rhs.w), |
| 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | impl Index<usize> for IVec4 { |
| 1410 | type Output = i32; |
| 1411 | #[inline] |
| 1412 | fn index(&self, index: usize) -> &Self::Output { |
| 1413 | match index { |
| 1414 | 0 => &self.x, |
| 1415 | 1 => &self.y, |
| 1416 | 2 => &self.z, |
| 1417 | 3 => &self.w, |
| 1418 | _ => panic!("index out of bounds"), |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | impl IndexMut<usize> for IVec4 { |
| 1424 | #[inline] |
| 1425 | fn index_mut(&mut self, index: usize) -> &mut Self::Output { |
| 1426 | match index { |
| 1427 | 0 => &mut self.x, |
| 1428 | 1 => &mut self.y, |
| 1429 | 2 => &mut self.z, |
| 1430 | 3 => &mut self.w, |
| 1431 | _ => panic!("index out of bounds"), |
| 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | #[cfg(not(target_arch = "spirv"))] |
| 1437 | impl fmt::Display for IVec4 { |
| 1438 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1439 | write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w) |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | #[cfg(not(target_arch = "spirv"))] |
| 1444 | impl fmt::Debug for IVec4 { |
| 1445 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1446 | fmt.debug_tuple(stringify!(IVec4)) |
| 1447 | .field(&self.x) |
| 1448 | .field(&self.y) |
| 1449 | .field(&self.z) |
| 1450 | .field(&self.w) |
| 1451 | .finish() |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | impl From<[i32; 4]> for IVec4 { |
| 1456 | #[inline] |
| 1457 | fn from(a: [i32; 4]) -> Self { |
| 1458 | Self::new(a[0], a[1], a[2], a[3]) |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | impl From<IVec4> for [i32; 4] { |
| 1463 | #[inline] |
| 1464 | fn from(v: IVec4) -> Self { |
| 1465 | [v.x, v.y, v.z, v.w] |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | impl From<(i32, i32, i32, i32)> for IVec4 { |
| 1470 | #[inline] |
| 1471 | fn from(t: (i32, i32, i32, i32)) -> Self { |
| 1472 | Self::new(t.0, t.1, t.2, t.3) |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | impl From<IVec4> for (i32, i32, i32, i32) { |
| 1477 | #[inline] |
| 1478 | fn from(v: IVec4) -> Self { |
| 1479 | (v.x, v.y, v.z, v.w) |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | impl From<(IVec3, i32)> for IVec4 { |
| 1484 | #[inline] |
| 1485 | fn from((v, w): (IVec3, i32)) -> Self { |
| 1486 | Self::new(v.x, v.y, v.z, w) |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | impl From<(i32, IVec3)> for IVec4 { |
| 1491 | #[inline] |
| 1492 | fn from((x, v): (i32, IVec3)) -> Self { |
| 1493 | Self::new(x, v.x, v.y, v.z) |
| 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | impl From<(IVec2, i32, i32)> for IVec4 { |
| 1498 | #[inline] |
| 1499 | fn from((v, z, w): (IVec2, i32, i32)) -> Self { |
| 1500 | Self::new(v.x, v.y, z, w) |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | impl From<(IVec2, IVec2)> for IVec4 { |
| 1505 | #[inline] |
| 1506 | fn from((v, u): (IVec2, IVec2)) -> Self { |
| 1507 | Self::new(v.x, v.y, u.x, u.y) |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | impl From<I16Vec4> for IVec4 { |
| 1512 | #[inline] |
| 1513 | fn from(v: I16Vec4) -> Self { |
| 1514 | Self::new( |
| 1515 | i32::from(v.x), |
| 1516 | i32::from(v.y), |
| 1517 | i32::from(v.z), |
| 1518 | i32::from(v.w), |
| 1519 | ) |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | impl From<U16Vec4> for IVec4 { |
| 1524 | #[inline] |
| 1525 | fn from(v: U16Vec4) -> Self { |
| 1526 | Self::new( |
| 1527 | i32::from(v.x), |
| 1528 | i32::from(v.y), |
| 1529 | i32::from(v.z), |
| 1530 | i32::from(v.w), |
| 1531 | ) |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | impl TryFrom<UVec4> for IVec4 { |
| 1536 | type Error = core::num::TryFromIntError; |
| 1537 | |
| 1538 | #[inline] |
| 1539 | fn try_from(v: UVec4) -> Result<Self, Self::Error> { |
| 1540 | Ok(Self::new( |
| 1541 | i32::try_from(v.x)?, |
| 1542 | i32::try_from(v.y)?, |
| 1543 | i32::try_from(v.z)?, |
| 1544 | i32::try_from(v.w)?, |
| 1545 | )) |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | impl TryFrom<I64Vec4> for IVec4 { |
| 1550 | type Error = core::num::TryFromIntError; |
| 1551 | |
| 1552 | #[inline] |
| 1553 | fn try_from(v: I64Vec4) -> Result<Self, Self::Error> { |
| 1554 | Ok(Self::new( |
| 1555 | i32::try_from(v.x)?, |
| 1556 | i32::try_from(v.y)?, |
| 1557 | i32::try_from(v.z)?, |
| 1558 | i32::try_from(v.w)?, |
| 1559 | )) |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | impl TryFrom<U64Vec4> for IVec4 { |
| 1564 | type Error = core::num::TryFromIntError; |
| 1565 | |
| 1566 | #[inline] |
| 1567 | fn try_from(v: U64Vec4) -> Result<Self, Self::Error> { |
| 1568 | Ok(Self::new( |
| 1569 | i32::try_from(v.x)?, |
| 1570 | i32::try_from(v.y)?, |
| 1571 | i32::try_from(v.z)?, |
| 1572 | i32::try_from(v.w)?, |
| 1573 | )) |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | impl From<BVec4> for IVec4 { |
| 1578 | #[inline] |
| 1579 | fn from(v: BVec4) -> Self { |
| 1580 | Self::new( |
| 1581 | i32::from(v.x), |
| 1582 | i32::from(v.y), |
| 1583 | i32::from(v.z), |
| 1584 | i32::from(v.w), |
| 1585 | ) |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | #[cfg(not(feature = "scalar-math"))] |
| 1590 | |
| 1591 | impl From<BVec4A> for IVec4 { |
| 1592 | #[inline] |
| 1593 | fn from(v: BVec4A) -> Self { |
| 1594 | let bool_array: [bool; 4] = v.into(); |
| 1595 | Self::new( |
| 1596 | i32::from(bool_array[0]), |
| 1597 | i32::from(bool_array[1]), |
| 1598 | i32::from(bool_array[2]), |
| 1599 | i32::from(bool_array[3]), |
| 1600 | ) |
| 1601 | } |
| 1602 | } |