• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bitshifter / glam-rs / 9048315621

12 May 2024 02:44AM UTC coverage: 92.217% (-0.005%) from 92.222%
9048315621

push

github

bitshifter
Don't need to exclude iai from non-linux platforms.

28543 of 30952 relevant lines covered (92.22%)

3.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.61
/src/u32/uvec2.rs
1
// Generated from vec.rs.tera template. Edit the template, not the generated file.
2

3
use crate::{BVec2, I16Vec2, I64Vec2, IVec2, U16Vec2, U64Vec2, UVec3};
4

5
#[cfg(not(target_arch = "spirv"))]
6
use core::fmt;
7
use core::iter::{Product, Sum};
8
use core::{f32, ops::*};
9

10
/// Creates a 2-dimensional vector.
11
#[inline(always)]
12
#[must_use]
13
pub const fn uvec2(x: u32, y: u32) -> UVec2 {
×
14
    UVec2::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 UVec2 {
24
    pub x: u32,
25
    pub y: u32,
26
}
27

28
impl UVec2 {
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 `u32::MIN`.
36
    pub const MIN: Self = Self::splat(u32::MIN);
37

38
    /// All `u32::MAX`.
39
    pub const MAX: Self = Self::splat(u32::MAX);
40

41
    /// A unit vector pointing along the positive X axis.
42
    pub const X: Self = Self::new(1, 0);
43

44
    /// A unit vector pointing along the positive Y axis.
45
    pub const Y: Self = Self::new(0, 1);
46

47
    /// The unit axes.
48
    pub const AXES: [Self; 2] = [Self::X, Self::Y];
49

50
    /// Creates a new vector.
51
    #[inline(always)]
52
    #[must_use]
53
    pub const fn new(x: u32, y: u32) -> Self {
×
54
        Self { x, y }
55
    }
56

57
    /// Creates a vector with all elements set to `v`.
58
    #[inline]
59
    #[must_use]
60
    pub const fn splat(v: u32) -> Self {
3✔
61
        Self { x: v, y: v }
62
    }
63

64
    /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
65
    /// for each element of `self`.
66
    ///
67
    /// A true element in the mask uses the corresponding element from `if_true`, and false
68
    /// uses the element from `if_false`.
69
    #[inline]
70
    #[must_use]
71
    pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
3✔
72
        Self {
73
            x: if mask.test(0) { if_true.x } else { if_false.x },
3✔
74
            y: if mask.test(1) { if_true.y } else { if_false.y },
3✔
75
        }
76
    }
77

78
    /// Creates a new vector from an array.
79
    #[inline]
80
    #[must_use]
81
    pub const fn from_array(a: [u32; 2]) -> Self {
×
82
        Self::new(a[0], a[1])
×
83
    }
84

85
    /// `[x, y]`
86
    #[inline]
87
    #[must_use]
88
    pub const fn to_array(&self) -> [u32; 2] {
3✔
89
        [self.x, self.y]
3✔
90
    }
91

92
    /// Creates a vector from the first 2 values in `slice`.
93
    ///
94
    /// # Panics
95
    ///
96
    /// Panics if `slice` is less than 2 elements long.
97
    #[inline]
98
    #[must_use]
99
    pub const fn from_slice(slice: &[u32]) -> Self {
3✔
100
        Self::new(slice[0], slice[1])
6✔
101
    }
102

103
    /// Writes the elements of `self` to the first 2 elements in `slice`.
104
    ///
105
    /// # Panics
106
    ///
107
    /// Panics if `slice` is less than 2 elements long.
108
    #[inline]
109
    pub fn write_to_slice(self, slice: &mut [u32]) {
3✔
110
        slice[0] = self.x;
3✔
111
        slice[1] = self.y;
9✔
112
    }
113

114
    /// Creates a 3D vector from `self` and the given `z` value.
115
    #[inline]
116
    #[must_use]
117
    pub const fn extend(self, z: u32) -> UVec3 {
3✔
118
        UVec3::new(self.x, self.y, z)
×
119
    }
120

121
    /// Creates a 2D vector from `self` with the given value of `x`.
122
    #[inline]
123
    #[must_use]
124
    pub fn with_x(mut self, x: u32) -> Self {
3✔
125
        self.x = x;
3✔
126
        self
3✔
127
    }
128

129
    /// Creates a 2D vector from `self` with the given value of `y`.
130
    #[inline]
131
    #[must_use]
132
    pub fn with_y(mut self, y: u32) -> Self {
3✔
133
        self.y = y;
3✔
134
        self
3✔
135
    }
136

137
    /// Computes the dot product of `self` and `rhs`.
138
    #[inline]
139
    #[must_use]
140
    pub fn dot(self, rhs: Self) -> u32 {
3✔
141
        (self.x * rhs.x) + (self.y * rhs.y)
3✔
142
    }
143

144
    /// Returns a vector where every component is the dot product of `self` and `rhs`.
145
    #[inline]
146
    #[must_use]
147
    pub fn dot_into_vec(self, rhs: Self) -> Self {
3✔
148
        Self::splat(self.dot(rhs))
3✔
149
    }
150

151
    /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
152
    ///
153
    /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
154
    #[inline]
155
    #[must_use]
156
    pub fn min(self, rhs: Self) -> Self {
3✔
157
        Self {
158
            x: self.x.min(rhs.x),
3✔
159
            y: self.y.min(rhs.y),
3✔
160
        }
161
    }
162

163
    /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
164
    ///
165
    /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
166
    #[inline]
167
    #[must_use]
168
    pub fn max(self, rhs: Self) -> Self {
3✔
169
        Self {
170
            x: self.x.max(rhs.x),
3✔
171
            y: self.y.max(rhs.y),
3✔
172
        }
173
    }
174

175
    /// Component-wise clamping of values, similar to [`u32::clamp`].
176
    ///
177
    /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
178
    ///
179
    /// # Panics
180
    ///
181
    /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
182
    #[inline]
183
    #[must_use]
184
    pub fn clamp(self, min: Self, max: Self) -> Self {
3✔
185
        glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
3✔
186
        self.max(min).min(max)
3✔
187
    }
188

189
    /// Returns the horizontal minimum of `self`.
190
    ///
191
    /// In other words this computes `min(x, y, ..)`.
192
    #[inline]
193
    #[must_use]
194
    pub fn min_element(self) -> u32 {
3✔
195
        self.x.min(self.y)
3✔
196
    }
197

198
    /// Returns the horizontal maximum of `self`.
199
    ///
200
    /// In other words this computes `max(x, y, ..)`.
201
    #[inline]
202
    #[must_use]
203
    pub fn max_element(self) -> u32 {
3✔
204
        self.x.max(self.y)
3✔
205
    }
206

207
    /// Returns the sum of all elements of `self`.
208
    ///
209
    /// In other words, this computes `self.x + self.y + ..`.
210
    #[inline]
211
    #[must_use]
212
    pub fn element_sum(self) -> u32 {
3✔
213
        self.x + self.y
3✔
214
    }
215

216
    /// Returns the product 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_product(self) -> u32 {
3✔
222
        self.x * self.y
3✔
223
    }
224

225
    /// Returns a vector mask containing the result of a `==` comparison for each element of
226
    /// `self` and `rhs`.
227
    ///
228
    /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
229
    /// elements.
230
    #[inline]
231
    #[must_use]
232
    pub fn cmpeq(self, rhs: Self) -> BVec2 {
3✔
233
        BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
3✔
234
    }
235

236
    /// Returns a vector mask containing the result of a `!=` comparison for each element of
237
    /// `self` and `rhs`.
238
    ///
239
    /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
240
    /// elements.
241
    #[inline]
242
    #[must_use]
243
    pub fn cmpne(self, rhs: Self) -> BVec2 {
3✔
244
        BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
3✔
245
    }
246

247
    /// Returns a vector mask containing the result of a `>=` comparison for each element of
248
    /// `self` and `rhs`.
249
    ///
250
    /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
251
    /// elements.
252
    #[inline]
253
    #[must_use]
254
    pub fn cmpge(self, rhs: Self) -> BVec2 {
3✔
255
        BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
×
256
    }
257

258
    /// Returns a vector mask containing the result of a `>` comparison for each element of
259
    /// `self` and `rhs`.
260
    ///
261
    /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
262
    /// elements.
263
    #[inline]
264
    #[must_use]
265
    pub fn cmpgt(self, rhs: Self) -> BVec2 {
3✔
266
        BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
×
267
    }
268

269
    /// Returns a vector mask containing the result of a `<=` comparison for each element of
270
    /// `self` and `rhs`.
271
    ///
272
    /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
273
    /// elements.
274
    #[inline]
275
    #[must_use]
276
    pub fn cmple(self, rhs: Self) -> BVec2 {
3✔
277
        BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
×
278
    }
279

280
    /// Returns a vector mask containing the result of a `<` comparison for each element of
281
    /// `self` and `rhs`.
282
    ///
283
    /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
284
    /// elements.
285
    #[inline]
286
    #[must_use]
287
    pub fn cmplt(self, rhs: Self) -> BVec2 {
3✔
288
        BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
×
289
    }
290

291
    /// Computes the squared length of `self`.
292
    #[doc(alias = "magnitude2")]
293
    #[inline]
294
    #[must_use]
295
    pub fn length_squared(self) -> u32 {
3✔
296
        self.dot(self)
3✔
297
    }
298

299
    /// Casts all elements of `self` to `f32`.
300
    #[inline]
301
    #[must_use]
302
    pub fn as_vec2(&self) -> crate::Vec2 {
3✔
303
        crate::Vec2::new(self.x as f32, self.y as f32)
3✔
304
    }
305

306
    /// Casts all elements of `self` to `f64`.
307
    #[inline]
308
    #[must_use]
309
    pub fn as_dvec2(&self) -> crate::DVec2 {
3✔
310
        crate::DVec2::new(self.x as f64, self.y as f64)
3✔
311
    }
312

313
    /// Casts all elements of `self` to `i16`.
314
    #[inline]
315
    #[must_use]
316
    pub fn as_i16vec2(&self) -> crate::I16Vec2 {
3✔
317
        crate::I16Vec2::new(self.x as i16, self.y as i16)
3✔
318
    }
319

320
    /// Casts all elements of `self` to `u16`.
321
    #[inline]
322
    #[must_use]
323
    pub fn as_u16vec2(&self) -> crate::U16Vec2 {
3✔
324
        crate::U16Vec2::new(self.x as u16, self.y as u16)
3✔
325
    }
326

327
    /// Casts all elements of `self` to `i32`.
328
    #[inline]
329
    #[must_use]
330
    pub fn as_ivec2(&self) -> crate::IVec2 {
3✔
331
        crate::IVec2::new(self.x as i32, self.y as i32)
3✔
332
    }
333

334
    /// Casts all elements of `self` to `i64`.
335
    #[inline]
336
    #[must_use]
337
    pub fn as_i64vec2(&self) -> crate::I64Vec2 {
3✔
338
        crate::I64Vec2::new(self.x as i64, self.y as i64)
3✔
339
    }
340

341
    /// Casts all elements of `self` to `u64`.
342
    #[inline]
343
    #[must_use]
344
    pub fn as_u64vec2(&self) -> crate::U64Vec2 {
3✔
345
        crate::U64Vec2::new(self.x as u64, self.y as u64)
3✔
346
    }
347

348
    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
349
    ///
350
    /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
351
    #[inline]
352
    #[must_use]
353
    pub const fn wrapping_add(self, rhs: Self) -> Self {
3✔
354
        Self {
355
            x: self.x.wrapping_add(rhs.x),
×
356
            y: self.y.wrapping_add(rhs.y),
×
357
        }
358
    }
359

360
    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
361
    ///
362
    /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
363
    #[inline]
364
    #[must_use]
365
    pub const fn wrapping_sub(self, rhs: Self) -> Self {
3✔
366
        Self {
367
            x: self.x.wrapping_sub(rhs.x),
×
368
            y: self.y.wrapping_sub(rhs.y),
×
369
        }
370
    }
371

372
    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
373
    ///
374
    /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
375
    #[inline]
376
    #[must_use]
377
    pub const fn wrapping_mul(self, rhs: Self) -> Self {
3✔
378
        Self {
379
            x: self.x.wrapping_mul(rhs.x),
×
380
            y: self.y.wrapping_mul(rhs.y),
×
381
        }
382
    }
383

384
    /// Returns a vector containing the wrapping division of `self` and `rhs`.
385
    ///
386
    /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
387
    #[inline]
388
    #[must_use]
389
    pub const fn wrapping_div(self, rhs: Self) -> Self {
3✔
390
        Self {
391
            x: self.x.wrapping_div(rhs.x),
×
392
            y: self.y.wrapping_div(rhs.y),
×
393
        }
394
    }
395

396
    /// Returns a vector containing the saturating addition of `self` and `rhs`.
397
    ///
398
    /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
399
    #[inline]
400
    #[must_use]
401
    pub const fn saturating_add(self, rhs: Self) -> Self {
3✔
402
        Self {
403
            x: self.x.saturating_add(rhs.x),
×
404
            y: self.y.saturating_add(rhs.y),
×
405
        }
406
    }
407

408
    /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
409
    ///
410
    /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
411
    #[inline]
412
    #[must_use]
413
    pub const fn saturating_sub(self, rhs: Self) -> Self {
3✔
414
        Self {
415
            x: self.x.saturating_sub(rhs.x),
×
416
            y: self.y.saturating_sub(rhs.y),
×
417
        }
418
    }
419

420
    /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
421
    ///
422
    /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
423
    #[inline]
424
    #[must_use]
425
    pub const fn saturating_mul(self, rhs: Self) -> Self {
3✔
426
        Self {
427
            x: self.x.saturating_mul(rhs.x),
3✔
428
            y: self.y.saturating_mul(rhs.y),
3✔
429
        }
430
    }
431

432
    /// Returns a vector containing the saturating division of `self` and `rhs`.
433
    ///
434
    /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
435
    #[inline]
436
    #[must_use]
437
    pub const fn saturating_div(self, rhs: Self) -> Self {
3✔
438
        Self {
439
            x: self.x.saturating_div(rhs.x),
3✔
440
            y: self.y.saturating_div(rhs.y),
3✔
441
        }
442
    }
443

444
    /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`.
445
    ///
446
    /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`.
447
    #[inline]
448
    #[must_use]
449
    pub const fn wrapping_add_signed(self, rhs: IVec2) -> Self {
3✔
450
        Self {
451
            x: self.x.wrapping_add_signed(rhs.x),
3✔
452
            y: self.y.wrapping_add_signed(rhs.y),
3✔
453
        }
454
    }
455

456
    /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`.
457
    ///
458
    /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`.
459
    #[inline]
460
    #[must_use]
461
    pub const fn saturating_add_signed(self, rhs: IVec2) -> Self {
3✔
462
        Self {
463
            x: self.x.saturating_add_signed(rhs.x),
3✔
464
            y: self.y.saturating_add_signed(rhs.y),
3✔
465
        }
466
    }
467
}
468

469
impl Default for UVec2 {
470
    #[inline(always)]
471
    fn default() -> Self {
×
472
        Self::ZERO
×
473
    }
474
}
475

476
impl Div<UVec2> for UVec2 {
477
    type Output = Self;
478
    #[inline]
479
    fn div(self, rhs: Self) -> Self {
3✔
480
        Self {
481
            x: self.x.div(rhs.x),
3✔
482
            y: self.y.div(rhs.y),
3✔
483
        }
484
    }
485
}
486

487
impl DivAssign<UVec2> for UVec2 {
488
    #[inline]
489
    fn div_assign(&mut self, rhs: Self) {
3✔
490
        self.x.div_assign(rhs.x);
3✔
491
        self.y.div_assign(rhs.y);
3✔
492
    }
493
}
494

495
impl Div<u32> for UVec2 {
496
    type Output = Self;
497
    #[inline]
498
    fn div(self, rhs: u32) -> Self {
3✔
499
        Self {
500
            x: self.x.div(rhs),
3✔
501
            y: self.y.div(rhs),
3✔
502
        }
503
    }
504
}
505

506
impl DivAssign<u32> for UVec2 {
507
    #[inline]
508
    fn div_assign(&mut self, rhs: u32) {
3✔
509
        self.x.div_assign(rhs);
3✔
510
        self.y.div_assign(rhs);
3✔
511
    }
512
}
513

514
impl Div<UVec2> for u32 {
515
    type Output = UVec2;
516
    #[inline]
517
    fn div(self, rhs: UVec2) -> UVec2 {
3✔
518
        UVec2 {
519
            x: self.div(rhs.x),
3✔
520
            y: self.div(rhs.y),
3✔
521
        }
522
    }
523
}
524

525
impl Mul<UVec2> for UVec2 {
526
    type Output = Self;
527
    #[inline]
528
    fn mul(self, rhs: Self) -> Self {
3✔
529
        Self {
530
            x: self.x.mul(rhs.x),
3✔
531
            y: self.y.mul(rhs.y),
3✔
532
        }
533
    }
534
}
535

536
impl MulAssign<UVec2> for UVec2 {
537
    #[inline]
538
    fn mul_assign(&mut self, rhs: Self) {
3✔
539
        self.x.mul_assign(rhs.x);
3✔
540
        self.y.mul_assign(rhs.y);
3✔
541
    }
542
}
543

544
impl Mul<u32> for UVec2 {
545
    type Output = Self;
546
    #[inline]
547
    fn mul(self, rhs: u32) -> Self {
3✔
548
        Self {
549
            x: self.x.mul(rhs),
3✔
550
            y: self.y.mul(rhs),
3✔
551
        }
552
    }
553
}
554

555
impl MulAssign<u32> for UVec2 {
556
    #[inline]
557
    fn mul_assign(&mut self, rhs: u32) {
3✔
558
        self.x.mul_assign(rhs);
3✔
559
        self.y.mul_assign(rhs);
3✔
560
    }
561
}
562

563
impl Mul<UVec2> for u32 {
564
    type Output = UVec2;
565
    #[inline]
566
    fn mul(self, rhs: UVec2) -> UVec2 {
3✔
567
        UVec2 {
568
            x: self.mul(rhs.x),
3✔
569
            y: self.mul(rhs.y),
3✔
570
        }
571
    }
572
}
573

574
impl Add<UVec2> for UVec2 {
575
    type Output = Self;
576
    #[inline]
577
    fn add(self, rhs: Self) -> Self {
3✔
578
        Self {
579
            x: self.x.add(rhs.x),
3✔
580
            y: self.y.add(rhs.y),
3✔
581
        }
582
    }
583
}
584

585
impl AddAssign<UVec2> for UVec2 {
586
    #[inline]
587
    fn add_assign(&mut self, rhs: Self) {
3✔
588
        self.x.add_assign(rhs.x);
3✔
589
        self.y.add_assign(rhs.y);
3✔
590
    }
591
}
592

593
impl Add<u32> for UVec2 {
594
    type Output = Self;
595
    #[inline]
596
    fn add(self, rhs: u32) -> Self {
3✔
597
        Self {
598
            x: self.x.add(rhs),
3✔
599
            y: self.y.add(rhs),
3✔
600
        }
601
    }
602
}
603

604
impl AddAssign<u32> for UVec2 {
605
    #[inline]
606
    fn add_assign(&mut self, rhs: u32) {
3✔
607
        self.x.add_assign(rhs);
3✔
608
        self.y.add_assign(rhs);
3✔
609
    }
610
}
611

612
impl Add<UVec2> for u32 {
613
    type Output = UVec2;
614
    #[inline]
615
    fn add(self, rhs: UVec2) -> UVec2 {
3✔
616
        UVec2 {
617
            x: self.add(rhs.x),
3✔
618
            y: self.add(rhs.y),
3✔
619
        }
620
    }
621
}
622

623
impl Sub<UVec2> for UVec2 {
624
    type Output = Self;
625
    #[inline]
626
    fn sub(self, rhs: Self) -> Self {
3✔
627
        Self {
628
            x: self.x.sub(rhs.x),
3✔
629
            y: self.y.sub(rhs.y),
3✔
630
        }
631
    }
632
}
633

634
impl SubAssign<UVec2> for UVec2 {
635
    #[inline]
636
    fn sub_assign(&mut self, rhs: UVec2) {
3✔
637
        self.x.sub_assign(rhs.x);
3✔
638
        self.y.sub_assign(rhs.y);
3✔
639
    }
640
}
641

642
impl Sub<u32> for UVec2 {
643
    type Output = Self;
644
    #[inline]
645
    fn sub(self, rhs: u32) -> Self {
3✔
646
        Self {
647
            x: self.x.sub(rhs),
3✔
648
            y: self.y.sub(rhs),
3✔
649
        }
650
    }
651
}
652

653
impl SubAssign<u32> for UVec2 {
654
    #[inline]
655
    fn sub_assign(&mut self, rhs: u32) {
3✔
656
        self.x.sub_assign(rhs);
3✔
657
        self.y.sub_assign(rhs);
3✔
658
    }
659
}
660

661
impl Sub<UVec2> for u32 {
662
    type Output = UVec2;
663
    #[inline]
664
    fn sub(self, rhs: UVec2) -> UVec2 {
3✔
665
        UVec2 {
666
            x: self.sub(rhs.x),
3✔
667
            y: self.sub(rhs.y),
3✔
668
        }
669
    }
670
}
671

672
impl Rem<UVec2> for UVec2 {
673
    type Output = Self;
674
    #[inline]
675
    fn rem(self, rhs: Self) -> Self {
3✔
676
        Self {
677
            x: self.x.rem(rhs.x),
3✔
678
            y: self.y.rem(rhs.y),
3✔
679
        }
680
    }
681
}
682

683
impl RemAssign<UVec2> for UVec2 {
684
    #[inline]
685
    fn rem_assign(&mut self, rhs: Self) {
3✔
686
        self.x.rem_assign(rhs.x);
3✔
687
        self.y.rem_assign(rhs.y);
3✔
688
    }
689
}
690

691
impl Rem<u32> for UVec2 {
692
    type Output = Self;
693
    #[inline]
694
    fn rem(self, rhs: u32) -> Self {
3✔
695
        Self {
696
            x: self.x.rem(rhs),
3✔
697
            y: self.y.rem(rhs),
3✔
698
        }
699
    }
700
}
701

702
impl RemAssign<u32> for UVec2 {
703
    #[inline]
704
    fn rem_assign(&mut self, rhs: u32) {
3✔
705
        self.x.rem_assign(rhs);
3✔
706
        self.y.rem_assign(rhs);
3✔
707
    }
708
}
709

710
impl Rem<UVec2> for u32 {
711
    type Output = UVec2;
712
    #[inline]
713
    fn rem(self, rhs: UVec2) -> UVec2 {
3✔
714
        UVec2 {
715
            x: self.rem(rhs.x),
3✔
716
            y: self.rem(rhs.y),
3✔
717
        }
718
    }
719
}
720

721
#[cfg(not(target_arch = "spirv"))]
722
impl AsRef<[u32; 2]> for UVec2 {
723
    #[inline]
724
    fn as_ref(&self) -> &[u32; 2] {
3✔
725
        unsafe { &*(self as *const UVec2 as *const [u32; 2]) }
×
726
    }
727
}
728

729
#[cfg(not(target_arch = "spirv"))]
730
impl AsMut<[u32; 2]> for UVec2 {
731
    #[inline]
732
    fn as_mut(&mut self) -> &mut [u32; 2] {
3✔
733
        unsafe { &mut *(self as *mut UVec2 as *mut [u32; 2]) }
×
734
    }
735
}
736

737
impl Sum for UVec2 {
738
    #[inline]
739
    fn sum<I>(iter: I) -> Self
3✔
740
    where
741
        I: Iterator<Item = Self>,
742
    {
743
        iter.fold(Self::ZERO, Self::add)
3✔
744
    }
745
}
746

747
impl<'a> Sum<&'a Self> for UVec2 {
748
    #[inline]
749
    fn sum<I>(iter: I) -> Self
3✔
750
    where
751
        I: Iterator<Item = &'a Self>,
752
    {
753
        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
9✔
754
    }
755
}
756

757
impl Product for UVec2 {
758
    #[inline]
759
    fn product<I>(iter: I) -> Self
3✔
760
    where
761
        I: Iterator<Item = Self>,
762
    {
763
        iter.fold(Self::ONE, Self::mul)
3✔
764
    }
765
}
766

767
impl<'a> Product<&'a Self> for UVec2 {
768
    #[inline]
769
    fn product<I>(iter: I) -> Self
3✔
770
    where
771
        I: Iterator<Item = &'a Self>,
772
    {
773
        iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
9✔
774
    }
775
}
776

777
impl Not for UVec2 {
778
    type Output = Self;
779
    #[inline]
780
    fn not(self) -> Self::Output {
3✔
781
        Self {
782
            x: self.x.not(),
3✔
783
            y: self.y.not(),
3✔
784
        }
785
    }
786
}
787

788
impl BitAnd for UVec2 {
789
    type Output = Self;
790
    #[inline]
791
    fn bitand(self, rhs: Self) -> Self::Output {
3✔
792
        Self {
793
            x: self.x.bitand(rhs.x),
3✔
794
            y: self.y.bitand(rhs.y),
3✔
795
        }
796
    }
797
}
798

799
impl BitOr for UVec2 {
800
    type Output = Self;
801
    #[inline]
802
    fn bitor(self, rhs: Self) -> Self::Output {
3✔
803
        Self {
804
            x: self.x.bitor(rhs.x),
3✔
805
            y: self.y.bitor(rhs.y),
3✔
806
        }
807
    }
808
}
809

810
impl BitXor for UVec2 {
811
    type Output = Self;
812
    #[inline]
813
    fn bitxor(self, rhs: Self) -> Self::Output {
3✔
814
        Self {
815
            x: self.x.bitxor(rhs.x),
3✔
816
            y: self.y.bitxor(rhs.y),
3✔
817
        }
818
    }
819
}
820

821
impl BitAnd<u32> for UVec2 {
822
    type Output = Self;
823
    #[inline]
824
    fn bitand(self, rhs: u32) -> Self::Output {
3✔
825
        Self {
826
            x: self.x.bitand(rhs),
3✔
827
            y: self.y.bitand(rhs),
3✔
828
        }
829
    }
830
}
831

832
impl BitOr<u32> for UVec2 {
833
    type Output = Self;
834
    #[inline]
835
    fn bitor(self, rhs: u32) -> Self::Output {
3✔
836
        Self {
837
            x: self.x.bitor(rhs),
3✔
838
            y: self.y.bitor(rhs),
3✔
839
        }
840
    }
841
}
842

843
impl BitXor<u32> for UVec2 {
844
    type Output = Self;
845
    #[inline]
846
    fn bitxor(self, rhs: u32) -> Self::Output {
3✔
847
        Self {
848
            x: self.x.bitxor(rhs),
3✔
849
            y: self.y.bitxor(rhs),
3✔
850
        }
851
    }
852
}
853

854
impl Shl<i8> for UVec2 {
855
    type Output = Self;
856
    #[inline]
857
    fn shl(self, rhs: i8) -> Self::Output {
3✔
858
        Self {
859
            x: self.x.shl(rhs),
3✔
860
            y: self.y.shl(rhs),
3✔
861
        }
862
    }
863
}
864

865
impl Shr<i8> for UVec2 {
866
    type Output = Self;
867
    #[inline]
868
    fn shr(self, rhs: i8) -> Self::Output {
3✔
869
        Self {
870
            x: self.x.shr(rhs),
3✔
871
            y: self.y.shr(rhs),
3✔
872
        }
873
    }
874
}
875

876
impl Shl<i16> for UVec2 {
877
    type Output = Self;
878
    #[inline]
879
    fn shl(self, rhs: i16) -> Self::Output {
3✔
880
        Self {
881
            x: self.x.shl(rhs),
3✔
882
            y: self.y.shl(rhs),
3✔
883
        }
884
    }
885
}
886

887
impl Shr<i16> for UVec2 {
888
    type Output = Self;
889
    #[inline]
890
    fn shr(self, rhs: i16) -> Self::Output {
3✔
891
        Self {
892
            x: self.x.shr(rhs),
3✔
893
            y: self.y.shr(rhs),
3✔
894
        }
895
    }
896
}
897

898
impl Shl<i32> for UVec2 {
899
    type Output = Self;
900
    #[inline]
901
    fn shl(self, rhs: i32) -> Self::Output {
3✔
902
        Self {
903
            x: self.x.shl(rhs),
3✔
904
            y: self.y.shl(rhs),
3✔
905
        }
906
    }
907
}
908

909
impl Shr<i32> for UVec2 {
910
    type Output = Self;
911
    #[inline]
912
    fn shr(self, rhs: i32) -> Self::Output {
3✔
913
        Self {
914
            x: self.x.shr(rhs),
3✔
915
            y: self.y.shr(rhs),
3✔
916
        }
917
    }
918
}
919

920
impl Shl<i64> for UVec2 {
921
    type Output = Self;
922
    #[inline]
923
    fn shl(self, rhs: i64) -> Self::Output {
3✔
924
        Self {
925
            x: self.x.shl(rhs),
3✔
926
            y: self.y.shl(rhs),
3✔
927
        }
928
    }
929
}
930

931
impl Shr<i64> for UVec2 {
932
    type Output = Self;
933
    #[inline]
934
    fn shr(self, rhs: i64) -> Self::Output {
3✔
935
        Self {
936
            x: self.x.shr(rhs),
3✔
937
            y: self.y.shr(rhs),
3✔
938
        }
939
    }
940
}
941

942
impl Shl<u8> for UVec2 {
943
    type Output = Self;
944
    #[inline]
945
    fn shl(self, rhs: u8) -> Self::Output {
3✔
946
        Self {
947
            x: self.x.shl(rhs),
3✔
948
            y: self.y.shl(rhs),
3✔
949
        }
950
    }
951
}
952

953
impl Shr<u8> for UVec2 {
954
    type Output = Self;
955
    #[inline]
956
    fn shr(self, rhs: u8) -> Self::Output {
3✔
957
        Self {
958
            x: self.x.shr(rhs),
3✔
959
            y: self.y.shr(rhs),
3✔
960
        }
961
    }
962
}
963

964
impl Shl<u16> for UVec2 {
965
    type Output = Self;
966
    #[inline]
967
    fn shl(self, rhs: u16) -> Self::Output {
3✔
968
        Self {
969
            x: self.x.shl(rhs),
3✔
970
            y: self.y.shl(rhs),
3✔
971
        }
972
    }
973
}
974

975
impl Shr<u16> for UVec2 {
976
    type Output = Self;
977
    #[inline]
978
    fn shr(self, rhs: u16) -> Self::Output {
3✔
979
        Self {
980
            x: self.x.shr(rhs),
3✔
981
            y: self.y.shr(rhs),
3✔
982
        }
983
    }
984
}
985

986
impl Shl<u32> for UVec2 {
987
    type Output = Self;
988
    #[inline]
989
    fn shl(self, rhs: u32) -> Self::Output {
3✔
990
        Self {
991
            x: self.x.shl(rhs),
3✔
992
            y: self.y.shl(rhs),
3✔
993
        }
994
    }
995
}
996

997
impl Shr<u32> for UVec2 {
998
    type Output = Self;
999
    #[inline]
1000
    fn shr(self, rhs: u32) -> Self::Output {
3✔
1001
        Self {
1002
            x: self.x.shr(rhs),
3✔
1003
            y: self.y.shr(rhs),
3✔
1004
        }
1005
    }
1006
}
1007

1008
impl Shl<u64> for UVec2 {
1009
    type Output = Self;
1010
    #[inline]
1011
    fn shl(self, rhs: u64) -> Self::Output {
3✔
1012
        Self {
1013
            x: self.x.shl(rhs),
3✔
1014
            y: self.y.shl(rhs),
3✔
1015
        }
1016
    }
1017
}
1018

1019
impl Shr<u64> for UVec2 {
1020
    type Output = Self;
1021
    #[inline]
1022
    fn shr(self, rhs: u64) -> Self::Output {
3✔
1023
        Self {
1024
            x: self.x.shr(rhs),
3✔
1025
            y: self.y.shr(rhs),
3✔
1026
        }
1027
    }
1028
}
1029

1030
impl Shl<crate::IVec2> for UVec2 {
1031
    type Output = Self;
1032
    #[inline]
1033
    fn shl(self, rhs: crate::IVec2) -> Self::Output {
3✔
1034
        Self {
1035
            x: self.x.shl(rhs.x),
3✔
1036
            y: self.y.shl(rhs.y),
3✔
1037
        }
1038
    }
1039
}
1040

1041
impl Shr<crate::IVec2> for UVec2 {
1042
    type Output = Self;
1043
    #[inline]
1044
    fn shr(self, rhs: crate::IVec2) -> Self::Output {
3✔
1045
        Self {
1046
            x: self.x.shr(rhs.x),
3✔
1047
            y: self.y.shr(rhs.y),
3✔
1048
        }
1049
    }
1050
}
1051

1052
impl Shl<crate::UVec2> for UVec2 {
1053
    type Output = Self;
1054
    #[inline]
1055
    fn shl(self, rhs: crate::UVec2) -> Self::Output {
3✔
1056
        Self {
1057
            x: self.x.shl(rhs.x),
3✔
1058
            y: self.y.shl(rhs.y),
3✔
1059
        }
1060
    }
1061
}
1062

1063
impl Shr<crate::UVec2> for UVec2 {
1064
    type Output = Self;
1065
    #[inline]
1066
    fn shr(self, rhs: crate::UVec2) -> Self::Output {
3✔
1067
        Self {
1068
            x: self.x.shr(rhs.x),
3✔
1069
            y: self.y.shr(rhs.y),
3✔
1070
        }
1071
    }
1072
}
1073

1074
impl Index<usize> for UVec2 {
1075
    type Output = u32;
1076
    #[inline]
1077
    fn index(&self, index: usize) -> &Self::Output {
3✔
1078
        match index {
6✔
1079
            0 => &self.x,
3✔
1080
            1 => &self.y,
3✔
1081
            _ => panic!("index out of bounds"),
×
1082
        }
1083
    }
1084
}
1085

1086
impl IndexMut<usize> for UVec2 {
1087
    #[inline]
1088
    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
3✔
1089
        match index {
6✔
1090
            0 => &mut self.x,
3✔
1091
            1 => &mut self.y,
3✔
1092
            _ => panic!("index out of bounds"),
×
1093
        }
1094
    }
1095
}
1096

1097
#[cfg(not(target_arch = "spirv"))]
1098
impl fmt::Display for UVec2 {
1099
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
1100
        write!(f, "[{}, {}]", self.x, self.y)
6✔
1101
    }
1102
}
1103

1104
#[cfg(not(target_arch = "spirv"))]
1105
impl fmt::Debug for UVec2 {
1106
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
1107
        fmt.debug_tuple(stringify!(UVec2))
6✔
1108
            .field(&self.x)
1109
            .field(&self.y)
3✔
1110
            .finish()
1111
    }
1112
}
1113

1114
impl From<[u32; 2]> for UVec2 {
1115
    #[inline]
1116
    fn from(a: [u32; 2]) -> Self {
6✔
1117
        Self::new(a[0], a[1])
6✔
1118
    }
1119
}
1120

1121
impl From<UVec2> for [u32; 2] {
1122
    #[inline]
1123
    fn from(v: UVec2) -> Self {
3✔
1124
        [v.x, v.y]
3✔
1125
    }
1126
}
1127

1128
impl From<(u32, u32)> for UVec2 {
1129
    #[inline]
1130
    fn from(t: (u32, u32)) -> Self {
3✔
1131
        Self::new(t.0, t.1)
×
1132
    }
1133
}
1134

1135
impl From<UVec2> for (u32, u32) {
1136
    #[inline]
1137
    fn from(v: UVec2) -> Self {
6✔
1138
        (v.x, v.y)
×
1139
    }
1140
}
1141

1142
impl From<U16Vec2> for UVec2 {
1143
    #[inline]
1144
    fn from(v: U16Vec2) -> Self {
3✔
1145
        Self::new(u32::from(v.x), u32::from(v.y))
×
1146
    }
1147
}
1148

1149
impl TryFrom<I16Vec2> for UVec2 {
1150
    type Error = core::num::TryFromIntError;
1151

1152
    #[inline]
1153
    fn try_from(v: I16Vec2) -> Result<Self, Self::Error> {
3✔
1154
        Ok(Self::new(u32::try_from(v.x)?, u32::try_from(v.y)?))
6✔
1155
    }
1156
}
1157

1158
impl TryFrom<IVec2> for UVec2 {
1159
    type Error = core::num::TryFromIntError;
1160

1161
    #[inline]
1162
    fn try_from(v: IVec2) -> Result<Self, Self::Error> {
3✔
1163
        Ok(Self::new(u32::try_from(v.x)?, u32::try_from(v.y)?))
6✔
1164
    }
1165
}
1166

1167
impl TryFrom<I64Vec2> for UVec2 {
1168
    type Error = core::num::TryFromIntError;
1169

1170
    #[inline]
1171
    fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
3✔
1172
        Ok(Self::new(u32::try_from(v.x)?, u32::try_from(v.y)?))
6✔
1173
    }
1174
}
1175

1176
impl TryFrom<U64Vec2> for UVec2 {
1177
    type Error = core::num::TryFromIntError;
1178

1179
    #[inline]
1180
    fn try_from(v: U64Vec2) -> Result<Self, Self::Error> {
3✔
1181
        Ok(Self::new(u32::try_from(v.x)?, u32::try_from(v.y)?))
6✔
1182
    }
1183
}
1184

1185
impl From<BVec2> for UVec2 {
1186
    #[inline]
1187
    fn from(v: BVec2) -> Self {
3✔
1188
        Self::new(u32::from(v.x), u32::from(v.y))
×
1189
    }
1190
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc