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

bitshifter / glam-rs / 13247972178

10 Feb 2025 06:36PM UTC coverage: 95.714% (-0.4%) from 96.156%
13247972178

push

github

web-flow
Remove `bytecheck` conditional testing in `rkyv` (#606)

39911 of 41698 relevant lines covered (95.71%)

3.61 hits per line

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

96.42
/src/u8/u8vec2.rs
1
// Generated from vec.rs.tera template. Edit the template, not the generated file.
2

3
use crate::{BVec2, I16Vec2, I64Vec2, I8Vec2, IVec2, U16Vec2, U64Vec2, U8Vec3, UVec2};
4

5
use core::fmt;
6
use core::iter::{Product, Sum};
7
use core::{f32, ops::*};
8

9
/// Creates a 2-dimensional vector.
10
#[inline(always)]
11
#[must_use]
12
pub const fn u8vec2(x: u8, y: u8) -> U8Vec2 {
6✔
13
    U8Vec2::new(x, y)
×
14
}
15

16
/// A 2-dimensional vector.
17
#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
18
#[derive(Clone, Copy, PartialEq, Eq)]
19
#[cfg_attr(feature = "cuda", repr(align(2)))]
20
#[cfg_attr(not(target_arch = "spirv"), repr(C))]
21
#[cfg_attr(target_arch = "spirv", repr(simd))]
22
pub struct U8Vec2 {
23
    pub x: u8,
24
    pub y: u8,
25
}
26

27
impl U8Vec2 {
28
    /// All zeroes.
29
    pub const ZERO: Self = Self::splat(0);
30

31
    /// All ones.
32
    pub const ONE: Self = Self::splat(1);
33

34
    /// All `u8::MIN`.
35
    pub const MIN: Self = Self::splat(u8::MIN);
36

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

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

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

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

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

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

63
    /// Returns a vector containing each element of `self` modified by a mapping function `f`.
64
    #[inline]
65
    #[must_use]
66
    pub fn map<F>(self, f: F) -> Self
6✔
67
    where
68
        F: Fn(u8) -> u8,
69
    {
70
        Self::new(f(self.x), f(self.y))
12✔
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 {
3✔
81
        Self {
82
            x: if mask.test(0) { if_true.x } else { if_false.x },
3✔
83
            y: if mask.test(1) { if_true.y } else { if_false.y },
3✔
84
        }
85
    }
86

87
    /// Creates a new vector from an array.
88
    #[inline]
89
    #[must_use]
90
    pub const fn from_array(a: [u8; 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) -> [u8; 2] {
3✔
98
        [self.x, self.y]
3✔
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: &[u8]) -> Self {
3✔
109
        assert!(slice.len() >= 2);
3✔
110
        Self::new(slice[0], slice[1])
3✔
111
    }
112

113
    /// Writes the elements of `self` to the first 2 elements in `slice`.
114
    ///
115
    /// # Panics
116
    ///
117
    /// Panics if `slice` is less than 2 elements long.
118
    #[inline]
119
    pub fn write_to_slice(self, slice: &mut [u8]) {
3✔
120
        slice[..2].copy_from_slice(&self.to_array());
3✔
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: u8) -> U8Vec3 {
3✔
127
        U8Vec3::new(self.x, self.y, z)
3✔
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: u8) -> Self {
3✔
134
        self.x = x;
3✔
135
        self
3✔
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: u8) -> Self {
3✔
142
        self.y = y;
3✔
143
        self
3✔
144
    }
145

146
    /// Computes the dot product of `self` and `rhs`.
147
    #[inline]
148
    #[must_use]
149
    pub fn dot(self, rhs: Self) -> u8 {
3✔
150
        (self.x * rhs.x) + (self.y * rhs.y)
3✔
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 {
3✔
157
        Self::splat(self.dot(rhs))
3✔
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 {
3✔
166
        Self {
167
            x: self.x.min(rhs.x),
3✔
168
            y: self.y.min(rhs.y),
3✔
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 {
3✔
178
        Self {
179
            x: self.x.max(rhs.x),
3✔
180
            y: self.y.max(rhs.y),
3✔
181
        }
182
    }
183

184
    /// Component-wise clamping of values, similar to [`u8::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 {
3✔
194
        glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
3✔
195
        self.max(min).min(max)
3✔
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) -> u8 {
3✔
204
        self.x.min(self.y)
3✔
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) -> u8 {
3✔
213
        self.x.max(self.y)
3✔
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) -> u8 {
3✔
222
        self.x + self.y
3✔
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) -> u8 {
3✔
231
        self.x * self.y
3✔
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 {
3✔
242
        BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
3✔
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 {
3✔
253
        BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
3✔
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 {
3✔
264
        BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
3✔
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 {
3✔
275
        BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
3✔
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 {
3✔
286
        BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
3✔
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 {
3✔
297
        BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
3✔
298
    }
299

300
    /// Computes the squared length of `self`.
301
    #[doc(alias = "magnitude2")]
302
    #[inline]
303
    #[must_use]
304
    pub fn length_squared(self) -> u8 {
3✔
305
        self.dot(self)
3✔
306
    }
307

308
    /// Computes the [manhattan distance] between two points.
309
    ///
310
    /// # Overflow
311
    /// This method may overflow if the result is greater than [`u8::MAX`].
312
    ///
313
    /// See also [`checked_manhattan_distance`][U8Vec2::checked_manhattan_distance].
314
    ///
315
    /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
316
    #[inline]
317
    #[must_use]
318
    pub fn manhattan_distance(self, other: Self) -> u8 {
3✔
319
        self.x.abs_diff(other.x) + self.y.abs_diff(other.y)
3✔
320
    }
321

322
    /// Computes the [manhattan distance] between two points.
323
    ///
324
    /// This will returns [`None`] if the result is greater than [`u8::MAX`].
325
    ///
326
    /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
327
    #[inline]
328
    #[must_use]
329
    pub fn checked_manhattan_distance(self, other: Self) -> Option<u8> {
3✔
330
        let d = self.x.abs_diff(other.x);
3✔
331
        d.checked_add(self.y.abs_diff(other.y))
3✔
332
    }
333

334
    /// Computes the [chebyshev distance] between two points.
335
    ///
336
    /// [chebyshev distance]: https://en.wikipedia.org/wiki/Chebyshev_distance
337
    #[inline]
338
    #[must_use]
339
    pub fn chebyshev_distance(self, other: Self) -> u8 {
3✔
340
        // Note: the compiler will eventually optimize out the loop
341
        [self.x.abs_diff(other.x), self.y.abs_diff(other.y)]
3✔
342
            .into_iter()
343
            .max()
344
            .unwrap()
345
    }
346

347
    /// Casts all elements of `self` to `f32`.
348
    #[inline]
349
    #[must_use]
350
    pub fn as_vec2(&self) -> crate::Vec2 {
3✔
351
        crate::Vec2::new(self.x as f32, self.y as f32)
3✔
352
    }
353

354
    /// Casts all elements of `self` to `f64`.
355
    #[inline]
356
    #[must_use]
357
    pub fn as_dvec2(&self) -> crate::DVec2 {
3✔
358
        crate::DVec2::new(self.x as f64, self.y as f64)
3✔
359
    }
360

361
    /// Casts all elements of `self` to `i8`.
362
    #[inline]
363
    #[must_use]
364
    pub fn as_i8vec2(&self) -> crate::I8Vec2 {
3✔
365
        crate::I8Vec2::new(self.x as i8, self.y as i8)
3✔
366
    }
367

368
    /// Casts all elements of `self` to `i16`.
369
    #[inline]
370
    #[must_use]
371
    pub fn as_i16vec2(&self) -> crate::I16Vec2 {
3✔
372
        crate::I16Vec2::new(self.x as i16, self.y as i16)
3✔
373
    }
374

375
    /// Casts all elements of `self` to `u16`.
376
    #[inline]
377
    #[must_use]
378
    pub fn as_u16vec2(&self) -> crate::U16Vec2 {
3✔
379
        crate::U16Vec2::new(self.x as u16, self.y as u16)
3✔
380
    }
381

382
    /// Casts all elements of `self` to `i32`.
383
    #[inline]
384
    #[must_use]
385
    pub fn as_ivec2(&self) -> crate::IVec2 {
3✔
386
        crate::IVec2::new(self.x as i32, self.y as i32)
3✔
387
    }
388

389
    /// Casts all elements of `self` to `u32`.
390
    #[inline]
391
    #[must_use]
392
    pub fn as_uvec2(&self) -> crate::UVec2 {
3✔
393
        crate::UVec2::new(self.x as u32, self.y as u32)
3✔
394
    }
395

396
    /// Casts all elements of `self` to `i64`.
397
    #[inline]
398
    #[must_use]
399
    pub fn as_i64vec2(&self) -> crate::I64Vec2 {
3✔
400
        crate::I64Vec2::new(self.x as i64, self.y as i64)
3✔
401
    }
402

403
    /// Casts all elements of `self` to `u64`.
404
    #[inline]
405
    #[must_use]
406
    pub fn as_u64vec2(&self) -> crate::U64Vec2 {
3✔
407
        crate::U64Vec2::new(self.x as u64, self.y as u64)
3✔
408
    }
409

410
    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
411
    ///
412
    /// In other words this computes `Some([self.x + rhs.x, self.y + rhs.y, ..])` but returns `None` on any overflow.
413
    #[inline]
414
    #[must_use]
415
    pub const fn checked_add(self, rhs: Self) -> Option<Self> {
3✔
416
        let x = match self.x.checked_add(rhs.x) {
3✔
417
            Some(v) => v,
3✔
418
            None => return None,
3✔
419
        };
420
        let y = match self.y.checked_add(rhs.y) {
3✔
421
            Some(v) => v,
3✔
422
            None => return None,
3✔
423
        };
424

425
        Some(Self { x, y })
3✔
426
    }
427

428
    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
429
    ///
430
    /// In other words this computes `Some([self.x - rhs.x, self.y - rhs.y, ..])` but returns `None` on any overflow.
431
    #[inline]
432
    #[must_use]
433
    pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
3✔
434
        let x = match self.x.checked_sub(rhs.x) {
3✔
435
            Some(v) => v,
3✔
436
            None => return None,
3✔
437
        };
438
        let y = match self.y.checked_sub(rhs.y) {
3✔
439
            Some(v) => v,
3✔
440
            None => return None,
3✔
441
        };
442

443
        Some(Self { x, y })
3✔
444
    }
445

446
    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
447
    ///
448
    /// In other words this computes `Some([self.x * rhs.x, self.y * rhs.y, ..])` but returns `None` on any overflow.
449
    #[inline]
450
    #[must_use]
451
    pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
3✔
452
        let x = match self.x.checked_mul(rhs.x) {
3✔
453
            Some(v) => v,
3✔
454
            None => return None,
3✔
455
        };
456
        let y = match self.y.checked_mul(rhs.y) {
3✔
457
            Some(v) => v,
3✔
458
            None => return None,
×
459
        };
460

461
        Some(Self { x, y })
3✔
462
    }
463

464
    /// Returns a vector containing the wrapping division of `self` and `rhs`.
465
    ///
466
    /// In other words this computes `Some([self.x / rhs.x, self.y / rhs.y, ..])` but returns `None` on any division by zero.
467
    #[inline]
468
    #[must_use]
469
    pub const fn checked_div(self, rhs: Self) -> Option<Self> {
3✔
470
        let x = match self.x.checked_div(rhs.x) {
3✔
471
            Some(v) => v,
3✔
472
            None => return None,
3✔
473
        };
474
        let y = match self.y.checked_div(rhs.y) {
3✔
475
            Some(v) => v,
3✔
476
            None => return None,
3✔
477
        };
478

479
        Some(Self { x, y })
3✔
480
    }
481

482
    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
483
    ///
484
    /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
485
    #[inline]
486
    #[must_use]
487
    pub const fn wrapping_add(self, rhs: Self) -> Self {
3✔
488
        Self {
489
            x: self.x.wrapping_add(rhs.x),
3✔
490
            y: self.y.wrapping_add(rhs.y),
3✔
491
        }
492
    }
493

494
    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
495
    ///
496
    /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
497
    #[inline]
498
    #[must_use]
499
    pub const fn wrapping_sub(self, rhs: Self) -> Self {
3✔
500
        Self {
501
            x: self.x.wrapping_sub(rhs.x),
3✔
502
            y: self.y.wrapping_sub(rhs.y),
3✔
503
        }
504
    }
505

506
    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
507
    ///
508
    /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
509
    #[inline]
510
    #[must_use]
511
    pub const fn wrapping_mul(self, rhs: Self) -> Self {
3✔
512
        Self {
513
            x: self.x.wrapping_mul(rhs.x),
3✔
514
            y: self.y.wrapping_mul(rhs.y),
3✔
515
        }
516
    }
517

518
    /// Returns a vector containing the wrapping division of `self` and `rhs`.
519
    ///
520
    /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
521
    #[inline]
522
    #[must_use]
523
    pub const fn wrapping_div(self, rhs: Self) -> Self {
3✔
524
        Self {
525
            x: self.x.wrapping_div(rhs.x),
3✔
526
            y: self.y.wrapping_div(rhs.y),
3✔
527
        }
528
    }
529

530
    /// Returns a vector containing the saturating addition of `self` and `rhs`.
531
    ///
532
    /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
533
    #[inline]
534
    #[must_use]
535
    pub const fn saturating_add(self, rhs: Self) -> Self {
3✔
536
        Self {
537
            x: self.x.saturating_add(rhs.x),
3✔
538
            y: self.y.saturating_add(rhs.y),
3✔
539
        }
540
    }
541

542
    /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
543
    ///
544
    /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
545
    #[inline]
546
    #[must_use]
547
    pub const fn saturating_sub(self, rhs: Self) -> Self {
3✔
548
        Self {
549
            x: self.x.saturating_sub(rhs.x),
3✔
550
            y: self.y.saturating_sub(rhs.y),
3✔
551
        }
552
    }
553

554
    /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
555
    ///
556
    /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
557
    #[inline]
558
    #[must_use]
559
    pub const fn saturating_mul(self, rhs: Self) -> Self {
3✔
560
        Self {
561
            x: self.x.saturating_mul(rhs.x),
3✔
562
            y: self.y.saturating_mul(rhs.y),
3✔
563
        }
564
    }
565

566
    /// Returns a vector containing the saturating division of `self` and `rhs`.
567
    ///
568
    /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
569
    #[inline]
570
    #[must_use]
571
    pub const fn saturating_div(self, rhs: Self) -> Self {
3✔
572
        Self {
573
            x: self.x.saturating_div(rhs.x),
3✔
574
            y: self.y.saturating_div(rhs.y),
3✔
575
        }
576
    }
577

578
    /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`.
579
    ///
580
    /// In other words this computes `Some([self.x + rhs.x, self.y + rhs.y, ..])` but returns `None` on any overflow.
581
    #[inline]
582
    #[must_use]
583
    pub const fn checked_add_signed(self, rhs: I8Vec2) -> Option<Self> {
×
584
        let x = match self.x.checked_add_signed(rhs.x) {
×
585
            Some(v) => v,
×
586
            None => return None,
×
587
        };
588
        let y = match self.y.checked_add_signed(rhs.y) {
×
589
            Some(v) => v,
×
590
            None => return None,
×
591
        };
592

593
        Some(Self { x, y })
×
594
    }
595

596
    /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`.
597
    ///
598
    /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`.
599
    #[inline]
600
    #[must_use]
601
    pub const fn wrapping_add_signed(self, rhs: I8Vec2) -> Self {
3✔
602
        Self {
603
            x: self.x.wrapping_add_signed(rhs.x),
3✔
604
            y: self.y.wrapping_add_signed(rhs.y),
3✔
605
        }
606
    }
607

608
    /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`.
609
    ///
610
    /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`.
611
    #[inline]
612
    #[must_use]
613
    pub const fn saturating_add_signed(self, rhs: I8Vec2) -> Self {
3✔
614
        Self {
615
            x: self.x.saturating_add_signed(rhs.x),
3✔
616
            y: self.y.saturating_add_signed(rhs.y),
3✔
617
        }
618
    }
619
}
620

621
impl Default for U8Vec2 {
622
    #[inline(always)]
623
    fn default() -> Self {
6✔
624
        Self::ZERO
×
625
    }
626
}
627

628
impl Div<U8Vec2> for U8Vec2 {
629
    type Output = Self;
630
    #[inline]
631
    fn div(self, rhs: Self) -> Self {
3✔
632
        Self {
633
            x: self.x.div(rhs.x),
3✔
634
            y: self.y.div(rhs.y),
3✔
635
        }
636
    }
637
}
638

639
impl Div<&U8Vec2> for U8Vec2 {
640
    type Output = U8Vec2;
641
    #[inline]
642
    fn div(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
643
        self.div(*rhs)
3✔
644
    }
645
}
646

647
impl Div<&U8Vec2> for &U8Vec2 {
648
    type Output = U8Vec2;
649
    #[inline]
650
    fn div(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
651
        (*self).div(*rhs)
3✔
652
    }
653
}
654

655
impl Div<U8Vec2> for &U8Vec2 {
656
    type Output = U8Vec2;
657
    #[inline]
658
    fn div(self, rhs: U8Vec2) -> U8Vec2 {
3✔
659
        (*self).div(rhs)
3✔
660
    }
661
}
662

663
impl DivAssign<U8Vec2> for U8Vec2 {
664
    #[inline]
665
    fn div_assign(&mut self, rhs: Self) {
3✔
666
        self.x.div_assign(rhs.x);
3✔
667
        self.y.div_assign(rhs.y);
4✔
668
    }
669
}
670

671
impl DivAssign<&U8Vec2> for U8Vec2 {
672
    #[inline]
673
    fn div_assign(&mut self, rhs: &U8Vec2) {
3✔
674
        self.div_assign(*rhs)
3✔
675
    }
676
}
677

678
impl Div<u8> for U8Vec2 {
679
    type Output = Self;
680
    #[inline]
681
    fn div(self, rhs: u8) -> Self {
6✔
682
        Self {
683
            x: self.x.div(rhs),
6✔
684
            y: self.y.div(rhs),
6✔
685
        }
686
    }
687
}
688

689
impl Div<&u8> for U8Vec2 {
690
    type Output = U8Vec2;
691
    #[inline]
692
    fn div(self, rhs: &u8) -> U8Vec2 {
3✔
693
        self.div(*rhs)
3✔
694
    }
695
}
696

697
impl Div<&u8> for &U8Vec2 {
698
    type Output = U8Vec2;
699
    #[inline]
700
    fn div(self, rhs: &u8) -> U8Vec2 {
3✔
701
        (*self).div(*rhs)
3✔
702
    }
703
}
704

705
impl Div<u8> for &U8Vec2 {
706
    type Output = U8Vec2;
707
    #[inline]
708
    fn div(self, rhs: u8) -> U8Vec2 {
3✔
709
        (*self).div(rhs)
3✔
710
    }
711
}
712

713
impl DivAssign<u8> for U8Vec2 {
714
    #[inline]
715
    fn div_assign(&mut self, rhs: u8) {
3✔
716
        self.x.div_assign(rhs);
3✔
717
        self.y.div_assign(rhs);
4✔
718
    }
719
}
720

721
impl DivAssign<&u8> for U8Vec2 {
722
    #[inline]
723
    fn div_assign(&mut self, rhs: &u8) {
3✔
724
        self.div_assign(*rhs)
3✔
725
    }
726
}
727

728
impl Div<U8Vec2> for u8 {
729
    type Output = U8Vec2;
730
    #[inline]
731
    fn div(self, rhs: U8Vec2) -> U8Vec2 {
3✔
732
        U8Vec2 {
733
            x: self.div(rhs.x),
3✔
734
            y: self.div(rhs.y),
3✔
735
        }
736
    }
737
}
738

739
impl Div<&U8Vec2> for u8 {
740
    type Output = U8Vec2;
741
    #[inline]
742
    fn div(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
743
        self.div(*rhs)
3✔
744
    }
745
}
746

747
impl Div<&U8Vec2> for &u8 {
748
    type Output = U8Vec2;
749
    #[inline]
750
    fn div(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
751
        (*self).div(*rhs)
3✔
752
    }
753
}
754

755
impl Div<U8Vec2> for &u8 {
756
    type Output = U8Vec2;
757
    #[inline]
758
    fn div(self, rhs: U8Vec2) -> U8Vec2 {
3✔
759
        (*self).div(rhs)
3✔
760
    }
761
}
762

763
impl Mul<U8Vec2> for U8Vec2 {
764
    type Output = Self;
765
    #[inline]
766
    fn mul(self, rhs: Self) -> Self {
4✔
767
        Self {
768
            x: self.x.mul(rhs.x),
4✔
769
            y: self.y.mul(rhs.y),
4✔
770
        }
771
    }
772
}
773

774
impl Mul<&U8Vec2> for U8Vec2 {
775
    type Output = U8Vec2;
776
    #[inline]
777
    fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
778
        self.mul(*rhs)
3✔
779
    }
780
}
781

782
impl Mul<&U8Vec2> for &U8Vec2 {
783
    type Output = U8Vec2;
784
    #[inline]
785
    fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
786
        (*self).mul(*rhs)
3✔
787
    }
788
}
789

790
impl Mul<U8Vec2> for &U8Vec2 {
791
    type Output = U8Vec2;
792
    #[inline]
793
    fn mul(self, rhs: U8Vec2) -> U8Vec2 {
3✔
794
        (*self).mul(rhs)
3✔
795
    }
796
}
797

798
impl MulAssign<U8Vec2> for U8Vec2 {
799
    #[inline]
800
    fn mul_assign(&mut self, rhs: Self) {
3✔
801
        self.x.mul_assign(rhs.x);
3✔
802
        self.y.mul_assign(rhs.y);
4✔
803
    }
804
}
805

806
impl MulAssign<&U8Vec2> for U8Vec2 {
807
    #[inline]
808
    fn mul_assign(&mut self, rhs: &U8Vec2) {
3✔
809
        self.mul_assign(*rhs)
3✔
810
    }
811
}
812

813
impl Mul<u8> for U8Vec2 {
814
    type Output = Self;
815
    #[inline]
816
    fn mul(self, rhs: u8) -> Self {
3✔
817
        Self {
818
            x: self.x.mul(rhs),
3✔
819
            y: self.y.mul(rhs),
3✔
820
        }
821
    }
822
}
823

824
impl Mul<&u8> for U8Vec2 {
825
    type Output = U8Vec2;
826
    #[inline]
827
    fn mul(self, rhs: &u8) -> U8Vec2 {
3✔
828
        self.mul(*rhs)
3✔
829
    }
830
}
831

832
impl Mul<&u8> for &U8Vec2 {
833
    type Output = U8Vec2;
834
    #[inline]
835
    fn mul(self, rhs: &u8) -> U8Vec2 {
3✔
836
        (*self).mul(*rhs)
3✔
837
    }
838
}
839

840
impl Mul<u8> for &U8Vec2 {
841
    type Output = U8Vec2;
842
    #[inline]
843
    fn mul(self, rhs: u8) -> U8Vec2 {
3✔
844
        (*self).mul(rhs)
3✔
845
    }
846
}
847

848
impl MulAssign<u8> for U8Vec2 {
849
    #[inline]
850
    fn mul_assign(&mut self, rhs: u8) {
3✔
851
        self.x.mul_assign(rhs);
3✔
852
        self.y.mul_assign(rhs);
4✔
853
    }
854
}
855

856
impl MulAssign<&u8> for U8Vec2 {
857
    #[inline]
858
    fn mul_assign(&mut self, rhs: &u8) {
3✔
859
        self.mul_assign(*rhs)
3✔
860
    }
861
}
862

863
impl Mul<U8Vec2> for u8 {
864
    type Output = U8Vec2;
865
    #[inline]
866
    fn mul(self, rhs: U8Vec2) -> U8Vec2 {
3✔
867
        U8Vec2 {
868
            x: self.mul(rhs.x),
3✔
869
            y: self.mul(rhs.y),
3✔
870
        }
871
    }
872
}
873

874
impl Mul<&U8Vec2> for u8 {
875
    type Output = U8Vec2;
876
    #[inline]
877
    fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
878
        self.mul(*rhs)
3✔
879
    }
880
}
881

882
impl Mul<&U8Vec2> for &u8 {
883
    type Output = U8Vec2;
884
    #[inline]
885
    fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
886
        (*self).mul(*rhs)
3✔
887
    }
888
}
889

890
impl Mul<U8Vec2> for &u8 {
891
    type Output = U8Vec2;
892
    #[inline]
893
    fn mul(self, rhs: U8Vec2) -> U8Vec2 {
3✔
894
        (*self).mul(rhs)
3✔
895
    }
896
}
897

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

909
impl Add<&U8Vec2> for U8Vec2 {
910
    type Output = U8Vec2;
911
    #[inline]
912
    fn add(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
913
        self.add(*rhs)
3✔
914
    }
915
}
916

917
impl Add<&U8Vec2> for &U8Vec2 {
918
    type Output = U8Vec2;
919
    #[inline]
920
    fn add(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
921
        (*self).add(*rhs)
3✔
922
    }
923
}
924

925
impl Add<U8Vec2> for &U8Vec2 {
926
    type Output = U8Vec2;
927
    #[inline]
928
    fn add(self, rhs: U8Vec2) -> U8Vec2 {
3✔
929
        (*self).add(rhs)
3✔
930
    }
931
}
932

933
impl AddAssign<U8Vec2> for U8Vec2 {
934
    #[inline]
935
    fn add_assign(&mut self, rhs: Self) {
3✔
936
        self.x.add_assign(rhs.x);
3✔
937
        self.y.add_assign(rhs.y);
4✔
938
    }
939
}
940

941
impl AddAssign<&U8Vec2> for U8Vec2 {
942
    #[inline]
943
    fn add_assign(&mut self, rhs: &U8Vec2) {
3✔
944
        self.add_assign(*rhs)
3✔
945
    }
946
}
947

948
impl Add<u8> for U8Vec2 {
949
    type Output = Self;
950
    #[inline]
951
    fn add(self, rhs: u8) -> Self {
3✔
952
        Self {
953
            x: self.x.add(rhs),
3✔
954
            y: self.y.add(rhs),
3✔
955
        }
956
    }
957
}
958

959
impl Add<&u8> for U8Vec2 {
960
    type Output = U8Vec2;
961
    #[inline]
962
    fn add(self, rhs: &u8) -> U8Vec2 {
3✔
963
        self.add(*rhs)
3✔
964
    }
965
}
966

967
impl Add<&u8> for &U8Vec2 {
968
    type Output = U8Vec2;
969
    #[inline]
970
    fn add(self, rhs: &u8) -> U8Vec2 {
3✔
971
        (*self).add(*rhs)
3✔
972
    }
973
}
974

975
impl Add<u8> for &U8Vec2 {
976
    type Output = U8Vec2;
977
    #[inline]
978
    fn add(self, rhs: u8) -> U8Vec2 {
3✔
979
        (*self).add(rhs)
3✔
980
    }
981
}
982

983
impl AddAssign<u8> for U8Vec2 {
984
    #[inline]
985
    fn add_assign(&mut self, rhs: u8) {
3✔
986
        self.x.add_assign(rhs);
3✔
987
        self.y.add_assign(rhs);
3✔
988
    }
989
}
990

991
impl AddAssign<&u8> for U8Vec2 {
992
    #[inline]
993
    fn add_assign(&mut self, rhs: &u8) {
3✔
994
        self.add_assign(*rhs)
3✔
995
    }
996
}
997

998
impl Add<U8Vec2> for u8 {
999
    type Output = U8Vec2;
1000
    #[inline]
1001
    fn add(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1002
        U8Vec2 {
1003
            x: self.add(rhs.x),
3✔
1004
            y: self.add(rhs.y),
3✔
1005
        }
1006
    }
1007
}
1008

1009
impl Add<&U8Vec2> for u8 {
1010
    type Output = U8Vec2;
1011
    #[inline]
1012
    fn add(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1013
        self.add(*rhs)
3✔
1014
    }
1015
}
1016

1017
impl Add<&U8Vec2> for &u8 {
1018
    type Output = U8Vec2;
1019
    #[inline]
1020
    fn add(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1021
        (*self).add(*rhs)
3✔
1022
    }
1023
}
1024

1025
impl Add<U8Vec2> for &u8 {
1026
    type Output = U8Vec2;
1027
    #[inline]
1028
    fn add(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1029
        (*self).add(rhs)
3✔
1030
    }
1031
}
1032

1033
impl Sub<U8Vec2> for U8Vec2 {
1034
    type Output = Self;
1035
    #[inline]
1036
    fn sub(self, rhs: Self) -> Self {
3✔
1037
        Self {
1038
            x: self.x.sub(rhs.x),
3✔
1039
            y: self.y.sub(rhs.y),
3✔
1040
        }
1041
    }
1042
}
1043

1044
impl Sub<&U8Vec2> for U8Vec2 {
1045
    type Output = U8Vec2;
1046
    #[inline]
1047
    fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1048
        self.sub(*rhs)
3✔
1049
    }
1050
}
1051

1052
impl Sub<&U8Vec2> for &U8Vec2 {
1053
    type Output = U8Vec2;
1054
    #[inline]
1055
    fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1056
        (*self).sub(*rhs)
3✔
1057
    }
1058
}
1059

1060
impl Sub<U8Vec2> for &U8Vec2 {
1061
    type Output = U8Vec2;
1062
    #[inline]
1063
    fn sub(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1064
        (*self).sub(rhs)
3✔
1065
    }
1066
}
1067

1068
impl SubAssign<U8Vec2> for U8Vec2 {
1069
    #[inline]
1070
    fn sub_assign(&mut self, rhs: U8Vec2) {
3✔
1071
        self.x.sub_assign(rhs.x);
3✔
1072
        self.y.sub_assign(rhs.y);
4✔
1073
    }
1074
}
1075

1076
impl SubAssign<&U8Vec2> for U8Vec2 {
1077
    #[inline]
1078
    fn sub_assign(&mut self, rhs: &U8Vec2) {
3✔
1079
        self.sub_assign(*rhs)
3✔
1080
    }
1081
}
1082

1083
impl Sub<u8> for U8Vec2 {
1084
    type Output = Self;
1085
    #[inline]
1086
    fn sub(self, rhs: u8) -> Self {
3✔
1087
        Self {
1088
            x: self.x.sub(rhs),
6✔
1089
            y: self.y.sub(rhs),
6✔
1090
        }
1091
    }
1092
}
1093

1094
impl Sub<&u8> for U8Vec2 {
1095
    type Output = U8Vec2;
1096
    #[inline]
1097
    fn sub(self, rhs: &u8) -> U8Vec2 {
3✔
1098
        self.sub(*rhs)
3✔
1099
    }
1100
}
1101

1102
impl Sub<&u8> for &U8Vec2 {
1103
    type Output = U8Vec2;
1104
    #[inline]
1105
    fn sub(self, rhs: &u8) -> U8Vec2 {
3✔
1106
        (*self).sub(*rhs)
3✔
1107
    }
1108
}
1109

1110
impl Sub<u8> for &U8Vec2 {
1111
    type Output = U8Vec2;
1112
    #[inline]
1113
    fn sub(self, rhs: u8) -> U8Vec2 {
3✔
1114
        (*self).sub(rhs)
3✔
1115
    }
1116
}
1117

1118
impl SubAssign<u8> for U8Vec2 {
1119
    #[inline]
1120
    fn sub_assign(&mut self, rhs: u8) {
3✔
1121
        self.x.sub_assign(rhs);
3✔
1122
        self.y.sub_assign(rhs);
3✔
1123
    }
1124
}
1125

1126
impl SubAssign<&u8> for U8Vec2 {
1127
    #[inline]
1128
    fn sub_assign(&mut self, rhs: &u8) {
3✔
1129
        self.sub_assign(*rhs)
3✔
1130
    }
1131
}
1132

1133
impl Sub<U8Vec2> for u8 {
1134
    type Output = U8Vec2;
1135
    #[inline]
1136
    fn sub(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1137
        U8Vec2 {
1138
            x: self.sub(rhs.x),
3✔
1139
            y: self.sub(rhs.y),
3✔
1140
        }
1141
    }
1142
}
1143

1144
impl Sub<&U8Vec2> for u8 {
1145
    type Output = U8Vec2;
1146
    #[inline]
1147
    fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1148
        self.sub(*rhs)
3✔
1149
    }
1150
}
1151

1152
impl Sub<&U8Vec2> for &u8 {
1153
    type Output = U8Vec2;
1154
    #[inline]
1155
    fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1156
        (*self).sub(*rhs)
3✔
1157
    }
1158
}
1159

1160
impl Sub<U8Vec2> for &u8 {
1161
    type Output = U8Vec2;
1162
    #[inline]
1163
    fn sub(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1164
        (*self).sub(rhs)
3✔
1165
    }
1166
}
1167

1168
impl Rem<U8Vec2> for U8Vec2 {
1169
    type Output = Self;
1170
    #[inline]
1171
    fn rem(self, rhs: Self) -> Self {
3✔
1172
        Self {
1173
            x: self.x.rem(rhs.x),
3✔
1174
            y: self.y.rem(rhs.y),
3✔
1175
        }
1176
    }
1177
}
1178

1179
impl Rem<&U8Vec2> for U8Vec2 {
1180
    type Output = U8Vec2;
1181
    #[inline]
1182
    fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1183
        self.rem(*rhs)
3✔
1184
    }
1185
}
1186

1187
impl Rem<&U8Vec2> for &U8Vec2 {
1188
    type Output = U8Vec2;
1189
    #[inline]
1190
    fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1191
        (*self).rem(*rhs)
3✔
1192
    }
1193
}
1194

1195
impl Rem<U8Vec2> for &U8Vec2 {
1196
    type Output = U8Vec2;
1197
    #[inline]
1198
    fn rem(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1199
        (*self).rem(rhs)
3✔
1200
    }
1201
}
1202

1203
impl RemAssign<U8Vec2> for U8Vec2 {
1204
    #[inline]
1205
    fn rem_assign(&mut self, rhs: Self) {
3✔
1206
        self.x.rem_assign(rhs.x);
4✔
1207
        self.y.rem_assign(rhs.y);
4✔
1208
    }
1209
}
1210

1211
impl RemAssign<&U8Vec2> for U8Vec2 {
1212
    #[inline]
1213
    fn rem_assign(&mut self, rhs: &U8Vec2) {
3✔
1214
        self.rem_assign(*rhs)
3✔
1215
    }
1216
}
1217

1218
impl Rem<u8> for U8Vec2 {
1219
    type Output = Self;
1220
    #[inline]
1221
    fn rem(self, rhs: u8) -> Self {
3✔
1222
        Self {
1223
            x: self.x.rem(rhs),
3✔
1224
            y: self.y.rem(rhs),
3✔
1225
        }
1226
    }
1227
}
1228

1229
impl Rem<&u8> for U8Vec2 {
1230
    type Output = U8Vec2;
1231
    #[inline]
1232
    fn rem(self, rhs: &u8) -> U8Vec2 {
3✔
1233
        self.rem(*rhs)
3✔
1234
    }
1235
}
1236

1237
impl Rem<&u8> for &U8Vec2 {
1238
    type Output = U8Vec2;
1239
    #[inline]
1240
    fn rem(self, rhs: &u8) -> U8Vec2 {
3✔
1241
        (*self).rem(*rhs)
3✔
1242
    }
1243
}
1244

1245
impl Rem<u8> for &U8Vec2 {
1246
    type Output = U8Vec2;
1247
    #[inline]
1248
    fn rem(self, rhs: u8) -> U8Vec2 {
3✔
1249
        (*self).rem(rhs)
3✔
1250
    }
1251
}
1252

1253
impl RemAssign<u8> for U8Vec2 {
1254
    #[inline]
1255
    fn rem_assign(&mut self, rhs: u8) {
3✔
1256
        self.x.rem_assign(rhs);
3✔
1257
        self.y.rem_assign(rhs);
4✔
1258
    }
1259
}
1260

1261
impl RemAssign<&u8> for U8Vec2 {
1262
    #[inline]
1263
    fn rem_assign(&mut self, rhs: &u8) {
3✔
1264
        self.rem_assign(*rhs)
3✔
1265
    }
1266
}
1267

1268
impl Rem<U8Vec2> for u8 {
1269
    type Output = U8Vec2;
1270
    #[inline]
1271
    fn rem(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1272
        U8Vec2 {
1273
            x: self.rem(rhs.x),
3✔
1274
            y: self.rem(rhs.y),
3✔
1275
        }
1276
    }
1277
}
1278

1279
impl Rem<&U8Vec2> for u8 {
1280
    type Output = U8Vec2;
1281
    #[inline]
1282
    fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1283
        self.rem(*rhs)
3✔
1284
    }
1285
}
1286

1287
impl Rem<&U8Vec2> for &u8 {
1288
    type Output = U8Vec2;
1289
    #[inline]
1290
    fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
3✔
1291
        (*self).rem(*rhs)
3✔
1292
    }
1293
}
1294

1295
impl Rem<U8Vec2> for &u8 {
1296
    type Output = U8Vec2;
1297
    #[inline]
1298
    fn rem(self, rhs: U8Vec2) -> U8Vec2 {
3✔
1299
        (*self).rem(rhs)
3✔
1300
    }
1301
}
1302

1303
#[cfg(not(target_arch = "spirv"))]
1304
impl AsRef<[u8; 2]> for U8Vec2 {
1305
    #[inline]
1306
    fn as_ref(&self) -> &[u8; 2] {
3✔
1307
        unsafe { &*(self as *const U8Vec2 as *const [u8; 2]) }
3✔
1308
    }
1309
}
1310

1311
#[cfg(not(target_arch = "spirv"))]
1312
impl AsMut<[u8; 2]> for U8Vec2 {
1313
    #[inline]
1314
    fn as_mut(&mut self) -> &mut [u8; 2] {
3✔
1315
        unsafe { &mut *(self as *mut U8Vec2 as *mut [u8; 2]) }
3✔
1316
    }
1317
}
1318

1319
impl Sum for U8Vec2 {
1320
    #[inline]
1321
    fn sum<I>(iter: I) -> Self
3✔
1322
    where
1323
        I: Iterator<Item = Self>,
1324
    {
1325
        iter.fold(Self::ZERO, Self::add)
3✔
1326
    }
1327
}
1328

1329
impl<'a> Sum<&'a Self> for U8Vec2 {
1330
    #[inline]
1331
    fn sum<I>(iter: I) -> Self
3✔
1332
    where
1333
        I: Iterator<Item = &'a Self>,
1334
    {
1335
        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
9✔
1336
    }
1337
}
1338

1339
impl Product for U8Vec2 {
1340
    #[inline]
1341
    fn product<I>(iter: I) -> Self
3✔
1342
    where
1343
        I: Iterator<Item = Self>,
1344
    {
1345
        iter.fold(Self::ONE, Self::mul)
3✔
1346
    }
1347
}
1348

1349
impl<'a> Product<&'a Self> for U8Vec2 {
1350
    #[inline]
1351
    fn product<I>(iter: I) -> Self
3✔
1352
    where
1353
        I: Iterator<Item = &'a Self>,
1354
    {
1355
        iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
9✔
1356
    }
1357
}
1358

1359
impl Not for U8Vec2 {
1360
    type Output = Self;
1361
    #[inline]
1362
    fn not(self) -> Self::Output {
3✔
1363
        Self {
1364
            x: self.x.not(),
3✔
1365
            y: self.y.not(),
3✔
1366
        }
1367
    }
1368
}
1369

1370
impl BitAnd for U8Vec2 {
1371
    type Output = Self;
1372
    #[inline]
1373
    fn bitand(self, rhs: Self) -> Self::Output {
3✔
1374
        Self {
1375
            x: self.x.bitand(rhs.x),
3✔
1376
            y: self.y.bitand(rhs.y),
3✔
1377
        }
1378
    }
1379
}
1380

1381
impl BitOr for U8Vec2 {
1382
    type Output = Self;
1383
    #[inline]
1384
    fn bitor(self, rhs: Self) -> Self::Output {
3✔
1385
        Self {
1386
            x: self.x.bitor(rhs.x),
3✔
1387
            y: self.y.bitor(rhs.y),
3✔
1388
        }
1389
    }
1390
}
1391

1392
impl BitXor for U8Vec2 {
1393
    type Output = Self;
1394
    #[inline]
1395
    fn bitxor(self, rhs: Self) -> Self::Output {
3✔
1396
        Self {
1397
            x: self.x.bitxor(rhs.x),
3✔
1398
            y: self.y.bitxor(rhs.y),
3✔
1399
        }
1400
    }
1401
}
1402

1403
impl BitAnd<u8> for U8Vec2 {
1404
    type Output = Self;
1405
    #[inline]
1406
    fn bitand(self, rhs: u8) -> Self::Output {
3✔
1407
        Self {
1408
            x: self.x.bitand(rhs),
3✔
1409
            y: self.y.bitand(rhs),
3✔
1410
        }
1411
    }
1412
}
1413

1414
impl BitOr<u8> for U8Vec2 {
1415
    type Output = Self;
1416
    #[inline]
1417
    fn bitor(self, rhs: u8) -> Self::Output {
3✔
1418
        Self {
1419
            x: self.x.bitor(rhs),
3✔
1420
            y: self.y.bitor(rhs),
3✔
1421
        }
1422
    }
1423
}
1424

1425
impl BitXor<u8> for U8Vec2 {
1426
    type Output = Self;
1427
    #[inline]
1428
    fn bitxor(self, rhs: u8) -> Self::Output {
3✔
1429
        Self {
1430
            x: self.x.bitxor(rhs),
3✔
1431
            y: self.y.bitxor(rhs),
3✔
1432
        }
1433
    }
1434
}
1435

1436
impl Shl<i8> for U8Vec2 {
1437
    type Output = Self;
1438
    #[inline]
1439
    fn shl(self, rhs: i8) -> Self::Output {
3✔
1440
        Self {
1441
            x: self.x.shl(rhs),
3✔
1442
            y: self.y.shl(rhs),
3✔
1443
        }
1444
    }
1445
}
1446

1447
impl Shr<i8> for U8Vec2 {
1448
    type Output = Self;
1449
    #[inline]
1450
    fn shr(self, rhs: i8) -> Self::Output {
3✔
1451
        Self {
1452
            x: self.x.shr(rhs),
3✔
1453
            y: self.y.shr(rhs),
3✔
1454
        }
1455
    }
1456
}
1457

1458
impl Shl<i16> for U8Vec2 {
1459
    type Output = Self;
1460
    #[inline]
1461
    fn shl(self, rhs: i16) -> Self::Output {
3✔
1462
        Self {
1463
            x: self.x.shl(rhs),
3✔
1464
            y: self.y.shl(rhs),
3✔
1465
        }
1466
    }
1467
}
1468

1469
impl Shr<i16> for U8Vec2 {
1470
    type Output = Self;
1471
    #[inline]
1472
    fn shr(self, rhs: i16) -> Self::Output {
3✔
1473
        Self {
1474
            x: self.x.shr(rhs),
3✔
1475
            y: self.y.shr(rhs),
3✔
1476
        }
1477
    }
1478
}
1479

1480
impl Shl<i32> for U8Vec2 {
1481
    type Output = Self;
1482
    #[inline]
1483
    fn shl(self, rhs: i32) -> Self::Output {
3✔
1484
        Self {
1485
            x: self.x.shl(rhs),
3✔
1486
            y: self.y.shl(rhs),
3✔
1487
        }
1488
    }
1489
}
1490

1491
impl Shr<i32> for U8Vec2 {
1492
    type Output = Self;
1493
    #[inline]
1494
    fn shr(self, rhs: i32) -> Self::Output {
3✔
1495
        Self {
1496
            x: self.x.shr(rhs),
3✔
1497
            y: self.y.shr(rhs),
3✔
1498
        }
1499
    }
1500
}
1501

1502
impl Shl<i64> for U8Vec2 {
1503
    type Output = Self;
1504
    #[inline]
1505
    fn shl(self, rhs: i64) -> Self::Output {
3✔
1506
        Self {
1507
            x: self.x.shl(rhs),
3✔
1508
            y: self.y.shl(rhs),
3✔
1509
        }
1510
    }
1511
}
1512

1513
impl Shr<i64> for U8Vec2 {
1514
    type Output = Self;
1515
    #[inline]
1516
    fn shr(self, rhs: i64) -> Self::Output {
3✔
1517
        Self {
1518
            x: self.x.shr(rhs),
3✔
1519
            y: self.y.shr(rhs),
3✔
1520
        }
1521
    }
1522
}
1523

1524
impl Shl<u8> for U8Vec2 {
1525
    type Output = Self;
1526
    #[inline]
1527
    fn shl(self, rhs: u8) -> Self::Output {
3✔
1528
        Self {
1529
            x: self.x.shl(rhs),
3✔
1530
            y: self.y.shl(rhs),
3✔
1531
        }
1532
    }
1533
}
1534

1535
impl Shr<u8> for U8Vec2 {
1536
    type Output = Self;
1537
    #[inline]
1538
    fn shr(self, rhs: u8) -> Self::Output {
3✔
1539
        Self {
1540
            x: self.x.shr(rhs),
3✔
1541
            y: self.y.shr(rhs),
3✔
1542
        }
1543
    }
1544
}
1545

1546
impl Shl<u16> for U8Vec2 {
1547
    type Output = Self;
1548
    #[inline]
1549
    fn shl(self, rhs: u16) -> Self::Output {
3✔
1550
        Self {
1551
            x: self.x.shl(rhs),
3✔
1552
            y: self.y.shl(rhs),
3✔
1553
        }
1554
    }
1555
}
1556

1557
impl Shr<u16> for U8Vec2 {
1558
    type Output = Self;
1559
    #[inline]
1560
    fn shr(self, rhs: u16) -> Self::Output {
3✔
1561
        Self {
1562
            x: self.x.shr(rhs),
3✔
1563
            y: self.y.shr(rhs),
3✔
1564
        }
1565
    }
1566
}
1567

1568
impl Shl<u32> for U8Vec2 {
1569
    type Output = Self;
1570
    #[inline]
1571
    fn shl(self, rhs: u32) -> Self::Output {
3✔
1572
        Self {
1573
            x: self.x.shl(rhs),
3✔
1574
            y: self.y.shl(rhs),
3✔
1575
        }
1576
    }
1577
}
1578

1579
impl Shr<u32> for U8Vec2 {
1580
    type Output = Self;
1581
    #[inline]
1582
    fn shr(self, rhs: u32) -> Self::Output {
3✔
1583
        Self {
1584
            x: self.x.shr(rhs),
3✔
1585
            y: self.y.shr(rhs),
3✔
1586
        }
1587
    }
1588
}
1589

1590
impl Shl<u64> for U8Vec2 {
1591
    type Output = Self;
1592
    #[inline]
1593
    fn shl(self, rhs: u64) -> Self::Output {
3✔
1594
        Self {
1595
            x: self.x.shl(rhs),
3✔
1596
            y: self.y.shl(rhs),
3✔
1597
        }
1598
    }
1599
}
1600

1601
impl Shr<u64> for U8Vec2 {
1602
    type Output = Self;
1603
    #[inline]
1604
    fn shr(self, rhs: u64) -> Self::Output {
3✔
1605
        Self {
1606
            x: self.x.shr(rhs),
3✔
1607
            y: self.y.shr(rhs),
3✔
1608
        }
1609
    }
1610
}
1611

1612
impl Shl<crate::IVec2> for U8Vec2 {
1613
    type Output = Self;
1614
    #[inline]
1615
    fn shl(self, rhs: crate::IVec2) -> Self::Output {
3✔
1616
        Self {
1617
            x: self.x.shl(rhs.x),
3✔
1618
            y: self.y.shl(rhs.y),
3✔
1619
        }
1620
    }
1621
}
1622

1623
impl Shr<crate::IVec2> for U8Vec2 {
1624
    type Output = Self;
1625
    #[inline]
1626
    fn shr(self, rhs: crate::IVec2) -> Self::Output {
3✔
1627
        Self {
1628
            x: self.x.shr(rhs.x),
3✔
1629
            y: self.y.shr(rhs.y),
3✔
1630
        }
1631
    }
1632
}
1633

1634
impl Shl<crate::UVec2> for U8Vec2 {
1635
    type Output = Self;
1636
    #[inline]
1637
    fn shl(self, rhs: crate::UVec2) -> Self::Output {
3✔
1638
        Self {
1639
            x: self.x.shl(rhs.x),
3✔
1640
            y: self.y.shl(rhs.y),
3✔
1641
        }
1642
    }
1643
}
1644

1645
impl Shr<crate::UVec2> for U8Vec2 {
1646
    type Output = Self;
1647
    #[inline]
1648
    fn shr(self, rhs: crate::UVec2) -> Self::Output {
3✔
1649
        Self {
1650
            x: self.x.shr(rhs.x),
3✔
1651
            y: self.y.shr(rhs.y),
3✔
1652
        }
1653
    }
1654
}
1655

1656
impl Index<usize> for U8Vec2 {
1657
    type Output = u8;
1658
    #[inline]
1659
    fn index(&self, index: usize) -> &Self::Output {
3✔
1660
        match index {
6✔
1661
            0 => &self.x,
3✔
1662
            1 => &self.y,
3✔
1663
            _ => panic!("index out of bounds"),
×
1664
        }
1665
    }
1666
}
1667

1668
impl IndexMut<usize> for U8Vec2 {
1669
    #[inline]
1670
    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
3✔
1671
        match index {
6✔
1672
            0 => &mut self.x,
3✔
1673
            1 => &mut self.y,
3✔
1674
            _ => panic!("index out of bounds"),
×
1675
        }
1676
    }
1677
}
1678

1679
impl fmt::Display for U8Vec2 {
1680
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
1681
        write!(f, "[{}, {}]", self.x, self.y)
3✔
1682
    }
1683
}
1684

1685
impl fmt::Debug for U8Vec2 {
1686
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
3✔
1687
        fmt.debug_tuple(stringify!(U8Vec2))
6✔
1688
            .field(&self.x)
1689
            .field(&self.y)
3✔
1690
            .finish()
1691
    }
1692
}
1693

1694
impl From<[u8; 2]> for U8Vec2 {
1695
    #[inline]
1696
    fn from(a: [u8; 2]) -> Self {
6✔
1697
        Self::new(a[0], a[1])
6✔
1698
    }
1699
}
1700

1701
impl From<U8Vec2> for [u8; 2] {
1702
    #[inline]
1703
    fn from(v: U8Vec2) -> Self {
3✔
1704
        [v.x, v.y]
3✔
1705
    }
1706
}
1707

1708
impl From<(u8, u8)> for U8Vec2 {
1709
    #[inline]
1710
    fn from(t: (u8, u8)) -> Self {
3✔
1711
        Self::new(t.0, t.1)
×
1712
    }
1713
}
1714

1715
impl From<U8Vec2> for (u8, u8) {
1716
    #[inline]
1717
    fn from(v: U8Vec2) -> Self {
6✔
1718
        (v.x, v.y)
×
1719
    }
1720
}
1721

1722
impl TryFrom<I8Vec2> for U8Vec2 {
1723
    type Error = core::num::TryFromIntError;
1724

1725
    #[inline]
1726
    fn try_from(v: I8Vec2) -> Result<Self, Self::Error> {
3✔
1727
        Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
6✔
1728
    }
1729
}
1730

1731
impl TryFrom<I16Vec2> for U8Vec2 {
1732
    type Error = core::num::TryFromIntError;
1733

1734
    #[inline]
1735
    fn try_from(v: I16Vec2) -> Result<Self, Self::Error> {
3✔
1736
        Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
6✔
1737
    }
1738
}
1739

1740
impl TryFrom<U16Vec2> for U8Vec2 {
1741
    type Error = core::num::TryFromIntError;
1742

1743
    #[inline]
1744
    fn try_from(v: U16Vec2) -> Result<Self, Self::Error> {
3✔
1745
        Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
6✔
1746
    }
1747
}
1748

1749
impl TryFrom<IVec2> for U8Vec2 {
1750
    type Error = core::num::TryFromIntError;
1751

1752
    #[inline]
1753
    fn try_from(v: IVec2) -> Result<Self, Self::Error> {
3✔
1754
        Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
6✔
1755
    }
1756
}
1757

1758
impl TryFrom<UVec2> for U8Vec2 {
1759
    type Error = core::num::TryFromIntError;
1760

1761
    #[inline]
1762
    fn try_from(v: UVec2) -> Result<Self, Self::Error> {
3✔
1763
        Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
6✔
1764
    }
1765
}
1766

1767
impl TryFrom<I64Vec2> for U8Vec2 {
1768
    type Error = core::num::TryFromIntError;
1769

1770
    #[inline]
1771
    fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
3✔
1772
        Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
6✔
1773
    }
1774
}
1775

1776
impl TryFrom<U64Vec2> for U8Vec2 {
1777
    type Error = core::num::TryFromIntError;
1778

1779
    #[inline]
1780
    fn try_from(v: U64Vec2) -> Result<Self, Self::Error> {
3✔
1781
        Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
6✔
1782
    }
1783
}
1784

1785
impl From<BVec2> for U8Vec2 {
1786
    #[inline]
1787
    fn from(v: BVec2) -> Self {
3✔
1788
        Self::new(u8::from(v.x), u8::from(v.y))
3✔
1789
    }
1790
}
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