glam/i32/
ivec3.rs

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