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