Debian Codegraph @

debian/missing-sources/glam-0.28.0/src/i32/ivec2.rs

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