1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{BVec2, I16Vec3, I64Vec2, IVec2, 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]
i16vec2(x: i16, y: i16) -> I16Vec213 pub const fn i16vec2(x: i16, y: i16) -> I16Vec2 {
14 I16Vec2::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(4)))]
21 #[cfg_attr(not(target_arch = "spirv"), repr(C))]
22 #[cfg_attr(target_arch = "spirv", repr(simd))]
23 pub struct I16Vec2 {
24 pub x: i16,
25 pub y: i16,
26 }
27
28 impl I16Vec2 {
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 `i16::MIN`.
39 pub const MIN: Self = Self::splat(i16::MIN);
40
41 /// All `i16::MAX`.
42 pub const MAX: Self = Self::splat(i16::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]
new(x: i16, y: i16) -> Self62 pub const fn new(x: i16, y: i16) -> Self {
63 Self { x, y }
64 }
65
66 /// Creates a vector with all elements set to `v`.
67 #[inline]
68 #[must_use]
splat(v: i16) -> Self69 pub const fn splat(v: i16) -> 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]
select(mask: BVec2, if_true: Self, if_false: Self) -> Self80 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]
from_array(a: [i16; 2]) -> Self90 pub const fn from_array(a: [i16; 2]) -> Self {
91 Self::new(a[0], a[1])
92 }
93
94 /// `[x, y]`
95 #[inline]
96 #[must_use]
to_array(&self) -> [i16; 2]97 pub const fn to_array(&self) -> [i16; 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]
from_slice(slice: &[i16]) -> Self108 pub const fn from_slice(slice: &[i16]) -> 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]
write_to_slice(self, slice: &mut [i16])118 pub fn write_to_slice(self, slice: &mut [i16]) {
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]
extend(self, z: i16) -> I16Vec3126 pub const fn extend(self, z: i16) -> I16Vec3 {
127 I16Vec3::new(self.x, self.y, z)
128 }
129
130 /// Computes the dot product of `self` and `rhs`.
131 #[inline]
132 #[must_use]
dot(self, rhs: Self) -> i16133 pub fn dot(self, rhs: Self) -> i16 {
134 (self.x * rhs.x) + (self.y * rhs.y)
135 }
136
137 /// Returns a vector where every component is the dot product of `self` and `rhs`.
138 #[inline]
139 #[must_use]
dot_into_vec(self, rhs: Self) -> Self140 pub fn dot_into_vec(self, rhs: Self) -> Self {
141 Self::splat(self.dot(rhs))
142 }
143
144 /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
145 ///
146 /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
147 #[inline]
148 #[must_use]
min(self, rhs: Self) -> Self149 pub fn min(self, rhs: Self) -> Self {
150 Self {
151 x: self.x.min(rhs.x),
152 y: self.y.min(rhs.y),
153 }
154 }
155
156 /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
157 ///
158 /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
159 #[inline]
160 #[must_use]
max(self, rhs: Self) -> Self161 pub fn max(self, rhs: Self) -> Self {
162 Self {
163 x: self.x.max(rhs.x),
164 y: self.y.max(rhs.y),
165 }
166 }
167
168 /// Component-wise clamping of values, similar to [`i16::clamp`].
169 ///
170 /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
171 ///
172 /// # Panics
173 ///
174 /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
175 #[inline]
176 #[must_use]
clamp(self, min: Self, max: Self) -> Self177 pub fn clamp(self, min: Self, max: Self) -> Self {
178 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
179 self.max(min).min(max)
180 }
181
182 /// Returns the horizontal minimum of `self`.
183 ///
184 /// In other words this computes `min(x, y, ..)`.
185 #[inline]
186 #[must_use]
min_element(self) -> i16187 pub fn min_element(self) -> i16 {
188 self.x.min(self.y)
189 }
190
191 /// Returns the horizontal maximum of `self`.
192 ///
193 /// In other words this computes `max(x, y, ..)`.
194 #[inline]
195 #[must_use]
max_element(self) -> i16196 pub fn max_element(self) -> i16 {
197 self.x.max(self.y)
198 }
199
200 /// Returns a vector mask containing the result of a `==` comparison for each element of
201 /// `self` and `rhs`.
202 ///
203 /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
204 /// elements.
205 #[inline]
206 #[must_use]
cmpeq(self, rhs: Self) -> BVec2207 pub fn cmpeq(self, rhs: Self) -> BVec2 {
208 BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
209 }
210
211 /// Returns a vector mask containing the result of a `!=` comparison for each element of
212 /// `self` and `rhs`.
213 ///
214 /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
215 /// elements.
216 #[inline]
217 #[must_use]
cmpne(self, rhs: Self) -> BVec2218 pub fn cmpne(self, rhs: Self) -> BVec2 {
219 BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
220 }
221
222 /// Returns a vector mask containing the result of a `>=` comparison for each element of
223 /// `self` and `rhs`.
224 ///
225 /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
226 /// elements.
227 #[inline]
228 #[must_use]
cmpge(self, rhs: Self) -> BVec2229 pub fn cmpge(self, rhs: Self) -> BVec2 {
230 BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
231 }
232
233 /// Returns a vector mask containing the result of a `>` comparison for each element of
234 /// `self` and `rhs`.
235 ///
236 /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
237 /// elements.
238 #[inline]
239 #[must_use]
cmpgt(self, rhs: Self) -> BVec2240 pub fn cmpgt(self, rhs: Self) -> BVec2 {
241 BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
242 }
243
244 /// Returns a vector mask containing the result of a `<=` comparison for each element of
245 /// `self` and `rhs`.
246 ///
247 /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
248 /// elements.
249 #[inline]
250 #[must_use]
cmple(self, rhs: Self) -> BVec2251 pub fn cmple(self, rhs: Self) -> BVec2 {
252 BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
253 }
254
255 /// Returns a vector mask containing the result of a `<` comparison for each element of
256 /// `self` and `rhs`.
257 ///
258 /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
259 /// elements.
260 #[inline]
261 #[must_use]
cmplt(self, rhs: Self) -> BVec2262 pub fn cmplt(self, rhs: Self) -> BVec2 {
263 BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
264 }
265
266 /// Returns a vector containing the absolute value of each element of `self`.
267 #[inline]
268 #[must_use]
abs(self) -> Self269 pub fn abs(self) -> Self {
270 Self {
271 x: self.x.abs(),
272 y: self.y.abs(),
273 }
274 }
275
276 /// Returns a vector with elements representing the sign of `self`.
277 ///
278 /// - `0` if the number is zero
279 /// - `1` if the number is positive
280 /// - `-1` if the number is negative
281 #[inline]
282 #[must_use]
signum(self) -> Self283 pub fn signum(self) -> Self {
284 Self {
285 x: self.x.signum(),
286 y: self.y.signum(),
287 }
288 }
289
290 /// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`.
291 ///
292 /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes
293 /// into the first lowest bit, element `y` into the second, etc.
294 #[inline]
295 #[must_use]
is_negative_bitmask(self) -> u32296 pub fn is_negative_bitmask(self) -> u32 {
297 (self.x.is_negative() as u32) | (self.y.is_negative() as u32) << 1
298 }
299
300 /// Computes the squared length of `self`.
301 #[doc(alias = "magnitude2")]
302 #[inline]
303 #[must_use]
length_squared(self) -> i16304 pub fn length_squared(self) -> i16 {
305 self.dot(self)
306 }
307
308 /// Compute the squared euclidean distance between two points in space.
309 #[inline]
310 #[must_use]
distance_squared(self, rhs: Self) -> i16311 pub fn distance_squared(self, rhs: Self) -> i16 {
312 (self - rhs).length_squared()
313 }
314
315 /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
316 ///
317 /// # Panics
318 /// This function will panic if any `rhs` element is 0 or the division results in overflow.
319 #[inline]
320 #[must_use]
div_euclid(self, rhs: Self) -> Self321 pub fn div_euclid(self, rhs: Self) -> Self {
322 Self::new(self.x.div_euclid(rhs.x), self.y.div_euclid(rhs.y))
323 }
324
325 /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
326 ///
327 /// # Panics
328 /// This function will panic if any `rhs` element is 0 or the division results in overflow.
329 ///
330 /// [Euclidean division]: i16::rem_euclid
331 #[inline]
332 #[must_use]
rem_euclid(self, rhs: Self) -> Self333 pub fn rem_euclid(self, rhs: Self) -> Self {
334 Self::new(self.x.rem_euclid(rhs.x), self.y.rem_euclid(rhs.y))
335 }
336
337 /// Returns a vector that is equal to `self` rotated by 90 degrees.
338 #[inline]
339 #[must_use]
perp(self) -> Self340 pub fn perp(self) -> Self {
341 Self {
342 x: -self.y,
343 y: self.x,
344 }
345 }
346
347 /// The perpendicular dot product of `self` and `rhs`.
348 /// Also known as the wedge product, 2D cross product, and determinant.
349 #[doc(alias = "wedge")]
350 #[doc(alias = "cross")]
351 #[doc(alias = "determinant")]
352 #[inline]
353 #[must_use]
perp_dot(self, rhs: Self) -> i16354 pub fn perp_dot(self, rhs: Self) -> i16 {
355 (self.x * rhs.y) - (self.y * rhs.x)
356 }
357
358 /// Returns `rhs` rotated by the angle of `self`. If `self` is normalized,
359 /// then this just rotation. This is what you usually want. Otherwise,
360 /// it will be like a rotation with a multiplication by `self`'s length.
361 #[inline]
362 #[must_use]
rotate(self, rhs: Self) -> Self363 pub fn rotate(self, rhs: Self) -> Self {
364 Self {
365 x: self.x * rhs.x - self.y * rhs.y,
366 y: self.y * rhs.x + self.x * rhs.y,
367 }
368 }
369
370 /// Casts all elements of `self` to `f32`.
371 #[inline]
372 #[must_use]
as_vec2(&self) -> crate::Vec2373 pub fn as_vec2(&self) -> crate::Vec2 {
374 crate::Vec2::new(self.x as f32, self.y as f32)
375 }
376
377 /// Casts all elements of `self` to `f64`.
378 #[inline]
379 #[must_use]
as_dvec2(&self) -> crate::DVec2380 pub fn as_dvec2(&self) -> crate::DVec2 {
381 crate::DVec2::new(self.x as f64, self.y as f64)
382 }
383
384 /// Casts all elements of `self` to `u16`.
385 #[inline]
386 #[must_use]
as_u16vec2(&self) -> crate::U16Vec2387 pub fn as_u16vec2(&self) -> crate::U16Vec2 {
388 crate::U16Vec2::new(self.x as u16, self.y as u16)
389 }
390
391 /// Casts all elements of `self` to `i32`.
392 #[inline]
393 #[must_use]
as_ivec2(&self) -> crate::IVec2394 pub fn as_ivec2(&self) -> crate::IVec2 {
395 crate::IVec2::new(self.x as i32, self.y as i32)
396 }
397
398 /// Casts all elements of `self` to `u32`.
399 #[inline]
400 #[must_use]
as_uvec2(&self) -> crate::UVec2401 pub fn as_uvec2(&self) -> crate::UVec2 {
402 crate::UVec2::new(self.x as u32, self.y as u32)
403 }
404
405 /// Casts all elements of `self` to `i64`.
406 #[inline]
407 #[must_use]
as_i64vec2(&self) -> crate::I64Vec2408 pub fn as_i64vec2(&self) -> crate::I64Vec2 {
409 crate::I64Vec2::new(self.x as i64, self.y as i64)
410 }
411
412 /// Casts all elements of `self` to `u64`.
413 #[inline]
414 #[must_use]
as_u64vec2(&self) -> crate::U64Vec2415 pub fn as_u64vec2(&self) -> crate::U64Vec2 {
416 crate::U64Vec2::new(self.x as u64, self.y as u64)
417 }
418
419 /// Returns a vector containing the wrapping addition of `self` and `rhs`.
420 ///
421 /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
422 #[inline]
423 #[must_use]
wrapping_add(self, rhs: Self) -> Self424 pub const fn wrapping_add(self, rhs: Self) -> Self {
425 Self {
426 x: self.x.wrapping_add(rhs.x),
427 y: self.y.wrapping_add(rhs.y),
428 }
429 }
430
431 /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
432 ///
433 /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
434 #[inline]
435 #[must_use]
wrapping_sub(self, rhs: Self) -> Self436 pub const fn wrapping_sub(self, rhs: Self) -> Self {
437 Self {
438 x: self.x.wrapping_sub(rhs.x),
439 y: self.y.wrapping_sub(rhs.y),
440 }
441 }
442
443 /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
444 ///
445 /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
446 #[inline]
447 #[must_use]
wrapping_mul(self, rhs: Self) -> Self448 pub const fn wrapping_mul(self, rhs: Self) -> Self {
449 Self {
450 x: self.x.wrapping_mul(rhs.x),
451 y: self.y.wrapping_mul(rhs.y),
452 }
453 }
454
455 /// Returns a vector containing the wrapping division of `self` and `rhs`.
456 ///
457 /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
458 #[inline]
459 #[must_use]
wrapping_div(self, rhs: Self) -> Self460 pub const fn wrapping_div(self, rhs: Self) -> Self {
461 Self {
462 x: self.x.wrapping_div(rhs.x),
463 y: self.y.wrapping_div(rhs.y),
464 }
465 }
466
467 /// Returns a vector containing the saturating addition of `self` and `rhs`.
468 ///
469 /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
470 #[inline]
471 #[must_use]
saturating_add(self, rhs: Self) -> Self472 pub const fn saturating_add(self, rhs: Self) -> Self {
473 Self {
474 x: self.x.saturating_add(rhs.x),
475 y: self.y.saturating_add(rhs.y),
476 }
477 }
478
479 /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
480 ///
481 /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
482 #[inline]
483 #[must_use]
saturating_sub(self, rhs: Self) -> Self484 pub const fn saturating_sub(self, rhs: Self) -> Self {
485 Self {
486 x: self.x.saturating_sub(rhs.x),
487 y: self.y.saturating_sub(rhs.y),
488 }
489 }
490
491 /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
492 ///
493 /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
494 #[inline]
495 #[must_use]
saturating_mul(self, rhs: Self) -> Self496 pub const fn saturating_mul(self, rhs: Self) -> Self {
497 Self {
498 x: self.x.saturating_mul(rhs.x),
499 y: self.y.saturating_mul(rhs.y),
500 }
501 }
502
503 /// Returns a vector containing the saturating division of `self` and `rhs`.
504 ///
505 /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
506 #[inline]
507 #[must_use]
saturating_div(self, rhs: Self) -> Self508 pub const fn saturating_div(self, rhs: Self) -> Self {
509 Self {
510 x: self.x.saturating_div(rhs.x),
511 y: self.y.saturating_div(rhs.y),
512 }
513 }
514 }
515
516 impl Default for I16Vec2 {
517 #[inline(always)]
default() -> Self518 fn default() -> Self {
519 Self::ZERO
520 }
521 }
522
523 impl Div<I16Vec2> for I16Vec2 {
524 type Output = Self;
525 #[inline]
div(self, rhs: Self) -> Self526 fn div(self, rhs: Self) -> Self {
527 Self {
528 x: self.x.div(rhs.x),
529 y: self.y.div(rhs.y),
530 }
531 }
532 }
533
534 impl DivAssign<I16Vec2> for I16Vec2 {
535 #[inline]
div_assign(&mut self, rhs: Self)536 fn div_assign(&mut self, rhs: Self) {
537 self.x.div_assign(rhs.x);
538 self.y.div_assign(rhs.y);
539 }
540 }
541
542 impl Div<i16> for I16Vec2 {
543 type Output = Self;
544 #[inline]
div(self, rhs: i16) -> Self545 fn div(self, rhs: i16) -> Self {
546 Self {
547 x: self.x.div(rhs),
548 y: self.y.div(rhs),
549 }
550 }
551 }
552
553 impl DivAssign<i16> for I16Vec2 {
554 #[inline]
div_assign(&mut self, rhs: i16)555 fn div_assign(&mut self, rhs: i16) {
556 self.x.div_assign(rhs);
557 self.y.div_assign(rhs);
558 }
559 }
560
561 impl Div<I16Vec2> for i16 {
562 type Output = I16Vec2;
563 #[inline]
div(self, rhs: I16Vec2) -> I16Vec2564 fn div(self, rhs: I16Vec2) -> I16Vec2 {
565 I16Vec2 {
566 x: self.div(rhs.x),
567 y: self.div(rhs.y),
568 }
569 }
570 }
571
572 impl Mul<I16Vec2> for I16Vec2 {
573 type Output = Self;
574 #[inline]
mul(self, rhs: Self) -> Self575 fn mul(self, rhs: Self) -> Self {
576 Self {
577 x: self.x.mul(rhs.x),
578 y: self.y.mul(rhs.y),
579 }
580 }
581 }
582
583 impl MulAssign<I16Vec2> for I16Vec2 {
584 #[inline]
mul_assign(&mut self, rhs: Self)585 fn mul_assign(&mut self, rhs: Self) {
586 self.x.mul_assign(rhs.x);
587 self.y.mul_assign(rhs.y);
588 }
589 }
590
591 impl Mul<i16> for I16Vec2 {
592 type Output = Self;
593 #[inline]
mul(self, rhs: i16) -> Self594 fn mul(self, rhs: i16) -> Self {
595 Self {
596 x: self.x.mul(rhs),
597 y: self.y.mul(rhs),
598 }
599 }
600 }
601
602 impl MulAssign<i16> for I16Vec2 {
603 #[inline]
mul_assign(&mut self, rhs: i16)604 fn mul_assign(&mut self, rhs: i16) {
605 self.x.mul_assign(rhs);
606 self.y.mul_assign(rhs);
607 }
608 }
609
610 impl Mul<I16Vec2> for i16 {
611 type Output = I16Vec2;
612 #[inline]
mul(self, rhs: I16Vec2) -> I16Vec2613 fn mul(self, rhs: I16Vec2) -> I16Vec2 {
614 I16Vec2 {
615 x: self.mul(rhs.x),
616 y: self.mul(rhs.y),
617 }
618 }
619 }
620
621 impl Add<I16Vec2> for I16Vec2 {
622 type Output = Self;
623 #[inline]
add(self, rhs: Self) -> Self624 fn add(self, rhs: Self) -> Self {
625 Self {
626 x: self.x.add(rhs.x),
627 y: self.y.add(rhs.y),
628 }
629 }
630 }
631
632 impl AddAssign<I16Vec2> for I16Vec2 {
633 #[inline]
add_assign(&mut self, rhs: Self)634 fn add_assign(&mut self, rhs: Self) {
635 self.x.add_assign(rhs.x);
636 self.y.add_assign(rhs.y);
637 }
638 }
639
640 impl Add<i16> for I16Vec2 {
641 type Output = Self;
642 #[inline]
add(self, rhs: i16) -> Self643 fn add(self, rhs: i16) -> Self {
644 Self {
645 x: self.x.add(rhs),
646 y: self.y.add(rhs),
647 }
648 }
649 }
650
651 impl AddAssign<i16> for I16Vec2 {
652 #[inline]
add_assign(&mut self, rhs: i16)653 fn add_assign(&mut self, rhs: i16) {
654 self.x.add_assign(rhs);
655 self.y.add_assign(rhs);
656 }
657 }
658
659 impl Add<I16Vec2> for i16 {
660 type Output = I16Vec2;
661 #[inline]
add(self, rhs: I16Vec2) -> I16Vec2662 fn add(self, rhs: I16Vec2) -> I16Vec2 {
663 I16Vec2 {
664 x: self.add(rhs.x),
665 y: self.add(rhs.y),
666 }
667 }
668 }
669
670 impl Sub<I16Vec2> for I16Vec2 {
671 type Output = Self;
672 #[inline]
sub(self, rhs: Self) -> Self673 fn sub(self, rhs: Self) -> Self {
674 Self {
675 x: self.x.sub(rhs.x),
676 y: self.y.sub(rhs.y),
677 }
678 }
679 }
680
681 impl SubAssign<I16Vec2> for I16Vec2 {
682 #[inline]
sub_assign(&mut self, rhs: I16Vec2)683 fn sub_assign(&mut self, rhs: I16Vec2) {
684 self.x.sub_assign(rhs.x);
685 self.y.sub_assign(rhs.y);
686 }
687 }
688
689 impl Sub<i16> for I16Vec2 {
690 type Output = Self;
691 #[inline]
sub(self, rhs: i16) -> Self692 fn sub(self, rhs: i16) -> Self {
693 Self {
694 x: self.x.sub(rhs),
695 y: self.y.sub(rhs),
696 }
697 }
698 }
699
700 impl SubAssign<i16> for I16Vec2 {
701 #[inline]
sub_assign(&mut self, rhs: i16)702 fn sub_assign(&mut self, rhs: i16) {
703 self.x.sub_assign(rhs);
704 self.y.sub_assign(rhs);
705 }
706 }
707
708 impl Sub<I16Vec2> for i16 {
709 type Output = I16Vec2;
710 #[inline]
sub(self, rhs: I16Vec2) -> I16Vec2711 fn sub(self, rhs: I16Vec2) -> I16Vec2 {
712 I16Vec2 {
713 x: self.sub(rhs.x),
714 y: self.sub(rhs.y),
715 }
716 }
717 }
718
719 impl Rem<I16Vec2> for I16Vec2 {
720 type Output = Self;
721 #[inline]
rem(self, rhs: Self) -> Self722 fn rem(self, rhs: Self) -> Self {
723 Self {
724 x: self.x.rem(rhs.x),
725 y: self.y.rem(rhs.y),
726 }
727 }
728 }
729
730 impl RemAssign<I16Vec2> for I16Vec2 {
731 #[inline]
rem_assign(&mut self, rhs: Self)732 fn rem_assign(&mut self, rhs: Self) {
733 self.x.rem_assign(rhs.x);
734 self.y.rem_assign(rhs.y);
735 }
736 }
737
738 impl Rem<i16> for I16Vec2 {
739 type Output = Self;
740 #[inline]
rem(self, rhs: i16) -> Self741 fn rem(self, rhs: i16) -> Self {
742 Self {
743 x: self.x.rem(rhs),
744 y: self.y.rem(rhs),
745 }
746 }
747 }
748
749 impl RemAssign<i16> for I16Vec2 {
750 #[inline]
rem_assign(&mut self, rhs: i16)751 fn rem_assign(&mut self, rhs: i16) {
752 self.x.rem_assign(rhs);
753 self.y.rem_assign(rhs);
754 }
755 }
756
757 impl Rem<I16Vec2> for i16 {
758 type Output = I16Vec2;
759 #[inline]
rem(self, rhs: I16Vec2) -> I16Vec2760 fn rem(self, rhs: I16Vec2) -> I16Vec2 {
761 I16Vec2 {
762 x: self.rem(rhs.x),
763 y: self.rem(rhs.y),
764 }
765 }
766 }
767
768 #[cfg(not(target_arch = "spirv"))]
769 impl AsRef<[i16; 2]> for I16Vec2 {
770 #[inline]
as_ref(&self) -> &[i16; 2]771 fn as_ref(&self) -> &[i16; 2] {
772 unsafe { &*(self as *const I16Vec2 as *const [i16; 2]) }
773 }
774 }
775
776 #[cfg(not(target_arch = "spirv"))]
777 impl AsMut<[i16; 2]> for I16Vec2 {
778 #[inline]
as_mut(&mut self) -> &mut [i16; 2]779 fn as_mut(&mut self) -> &mut [i16; 2] {
780 unsafe { &mut *(self as *mut I16Vec2 as *mut [i16; 2]) }
781 }
782 }
783
784 impl Sum for I16Vec2 {
785 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,786 fn sum<I>(iter: I) -> Self
787 where
788 I: Iterator<Item = Self>,
789 {
790 iter.fold(Self::ZERO, Self::add)
791 }
792 }
793
794 impl<'a> Sum<&'a Self> for I16Vec2 {
795 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,796 fn sum<I>(iter: I) -> Self
797 where
798 I: Iterator<Item = &'a Self>,
799 {
800 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
801 }
802 }
803
804 impl Product for I16Vec2 {
805 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,806 fn product<I>(iter: I) -> Self
807 where
808 I: Iterator<Item = Self>,
809 {
810 iter.fold(Self::ONE, Self::mul)
811 }
812 }
813
814 impl<'a> Product<&'a Self> for I16Vec2 {
815 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,816 fn product<I>(iter: I) -> Self
817 where
818 I: Iterator<Item = &'a Self>,
819 {
820 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
821 }
822 }
823
824 impl Neg for I16Vec2 {
825 type Output = Self;
826 #[inline]
neg(self) -> Self827 fn neg(self) -> Self {
828 Self {
829 x: self.x.neg(),
830 y: self.y.neg(),
831 }
832 }
833 }
834
835 impl Not for I16Vec2 {
836 type Output = Self;
837 #[inline]
not(self) -> Self::Output838 fn not(self) -> Self::Output {
839 Self {
840 x: self.x.not(),
841 y: self.y.not(),
842 }
843 }
844 }
845
846 impl BitAnd for I16Vec2 {
847 type Output = Self;
848 #[inline]
bitand(self, rhs: Self) -> Self::Output849 fn bitand(self, rhs: Self) -> Self::Output {
850 Self {
851 x: self.x.bitand(rhs.x),
852 y: self.y.bitand(rhs.y),
853 }
854 }
855 }
856
857 impl BitOr for I16Vec2 {
858 type Output = Self;
859 #[inline]
bitor(self, rhs: Self) -> Self::Output860 fn bitor(self, rhs: Self) -> Self::Output {
861 Self {
862 x: self.x.bitor(rhs.x),
863 y: self.y.bitor(rhs.y),
864 }
865 }
866 }
867
868 impl BitXor for I16Vec2 {
869 type Output = Self;
870 #[inline]
bitxor(self, rhs: Self) -> Self::Output871 fn bitxor(self, rhs: Self) -> Self::Output {
872 Self {
873 x: self.x.bitxor(rhs.x),
874 y: self.y.bitxor(rhs.y),
875 }
876 }
877 }
878
879 impl BitAnd<i16> for I16Vec2 {
880 type Output = Self;
881 #[inline]
bitand(self, rhs: i16) -> Self::Output882 fn bitand(self, rhs: i16) -> Self::Output {
883 Self {
884 x: self.x.bitand(rhs),
885 y: self.y.bitand(rhs),
886 }
887 }
888 }
889
890 impl BitOr<i16> for I16Vec2 {
891 type Output = Self;
892 #[inline]
bitor(self, rhs: i16) -> Self::Output893 fn bitor(self, rhs: i16) -> Self::Output {
894 Self {
895 x: self.x.bitor(rhs),
896 y: self.y.bitor(rhs),
897 }
898 }
899 }
900
901 impl BitXor<i16> for I16Vec2 {
902 type Output = Self;
903 #[inline]
bitxor(self, rhs: i16) -> Self::Output904 fn bitxor(self, rhs: i16) -> Self::Output {
905 Self {
906 x: self.x.bitxor(rhs),
907 y: self.y.bitxor(rhs),
908 }
909 }
910 }
911
912 impl Shl<i8> for I16Vec2 {
913 type Output = Self;
914 #[inline]
shl(self, rhs: i8) -> Self::Output915 fn shl(self, rhs: i8) -> Self::Output {
916 Self {
917 x: self.x.shl(rhs),
918 y: self.y.shl(rhs),
919 }
920 }
921 }
922
923 impl Shr<i8> for I16Vec2 {
924 type Output = Self;
925 #[inline]
shr(self, rhs: i8) -> Self::Output926 fn shr(self, rhs: i8) -> Self::Output {
927 Self {
928 x: self.x.shr(rhs),
929 y: self.y.shr(rhs),
930 }
931 }
932 }
933
934 impl Shl<i16> for I16Vec2 {
935 type Output = Self;
936 #[inline]
shl(self, rhs: i16) -> Self::Output937 fn shl(self, rhs: i16) -> Self::Output {
938 Self {
939 x: self.x.shl(rhs),
940 y: self.y.shl(rhs),
941 }
942 }
943 }
944
945 impl Shr<i16> for I16Vec2 {
946 type Output = Self;
947 #[inline]
shr(self, rhs: i16) -> Self::Output948 fn shr(self, rhs: i16) -> Self::Output {
949 Self {
950 x: self.x.shr(rhs),
951 y: self.y.shr(rhs),
952 }
953 }
954 }
955
956 impl Shl<i32> for I16Vec2 {
957 type Output = Self;
958 #[inline]
shl(self, rhs: i32) -> Self::Output959 fn shl(self, rhs: i32) -> Self::Output {
960 Self {
961 x: self.x.shl(rhs),
962 y: self.y.shl(rhs),
963 }
964 }
965 }
966
967 impl Shr<i32> for I16Vec2 {
968 type Output = Self;
969 #[inline]
shr(self, rhs: i32) -> Self::Output970 fn shr(self, rhs: i32) -> Self::Output {
971 Self {
972 x: self.x.shr(rhs),
973 y: self.y.shr(rhs),
974 }
975 }
976 }
977
978 impl Shl<i64> for I16Vec2 {
979 type Output = Self;
980 #[inline]
shl(self, rhs: i64) -> Self::Output981 fn shl(self, rhs: i64) -> Self::Output {
982 Self {
983 x: self.x.shl(rhs),
984 y: self.y.shl(rhs),
985 }
986 }
987 }
988
989 impl Shr<i64> for I16Vec2 {
990 type Output = Self;
991 #[inline]
shr(self, rhs: i64) -> Self::Output992 fn shr(self, rhs: i64) -> Self::Output {
993 Self {
994 x: self.x.shr(rhs),
995 y: self.y.shr(rhs),
996 }
997 }
998 }
999
1000 impl Shl<u8> for I16Vec2 {
1001 type Output = Self;
1002 #[inline]
shl(self, rhs: u8) -> Self::Output1003 fn shl(self, rhs: u8) -> Self::Output {
1004 Self {
1005 x: self.x.shl(rhs),
1006 y: self.y.shl(rhs),
1007 }
1008 }
1009 }
1010
1011 impl Shr<u8> for I16Vec2 {
1012 type Output = Self;
1013 #[inline]
shr(self, rhs: u8) -> Self::Output1014 fn shr(self, rhs: u8) -> Self::Output {
1015 Self {
1016 x: self.x.shr(rhs),
1017 y: self.y.shr(rhs),
1018 }
1019 }
1020 }
1021
1022 impl Shl<u16> for I16Vec2 {
1023 type Output = Self;
1024 #[inline]
shl(self, rhs: u16) -> Self::Output1025 fn shl(self, rhs: u16) -> Self::Output {
1026 Self {
1027 x: self.x.shl(rhs),
1028 y: self.y.shl(rhs),
1029 }
1030 }
1031 }
1032
1033 impl Shr<u16> for I16Vec2 {
1034 type Output = Self;
1035 #[inline]
shr(self, rhs: u16) -> Self::Output1036 fn shr(self, rhs: u16) -> Self::Output {
1037 Self {
1038 x: self.x.shr(rhs),
1039 y: self.y.shr(rhs),
1040 }
1041 }
1042 }
1043
1044 impl Shl<u32> for I16Vec2 {
1045 type Output = Self;
1046 #[inline]
shl(self, rhs: u32) -> Self::Output1047 fn shl(self, rhs: u32) -> Self::Output {
1048 Self {
1049 x: self.x.shl(rhs),
1050 y: self.y.shl(rhs),
1051 }
1052 }
1053 }
1054
1055 impl Shr<u32> for I16Vec2 {
1056 type Output = Self;
1057 #[inline]
shr(self, rhs: u32) -> Self::Output1058 fn shr(self, rhs: u32) -> Self::Output {
1059 Self {
1060 x: self.x.shr(rhs),
1061 y: self.y.shr(rhs),
1062 }
1063 }
1064 }
1065
1066 impl Shl<u64> for I16Vec2 {
1067 type Output = Self;
1068 #[inline]
shl(self, rhs: u64) -> Self::Output1069 fn shl(self, rhs: u64) -> Self::Output {
1070 Self {
1071 x: self.x.shl(rhs),
1072 y: self.y.shl(rhs),
1073 }
1074 }
1075 }
1076
1077 impl Shr<u64> for I16Vec2 {
1078 type Output = Self;
1079 #[inline]
shr(self, rhs: u64) -> Self::Output1080 fn shr(self, rhs: u64) -> Self::Output {
1081 Self {
1082 x: self.x.shr(rhs),
1083 y: self.y.shr(rhs),
1084 }
1085 }
1086 }
1087
1088 impl Shl<crate::IVec2> for I16Vec2 {
1089 type Output = Self;
1090 #[inline]
shl(self, rhs: crate::IVec2) -> Self::Output1091 fn shl(self, rhs: crate::IVec2) -> Self::Output {
1092 Self {
1093 x: self.x.shl(rhs.x),
1094 y: self.y.shl(rhs.y),
1095 }
1096 }
1097 }
1098
1099 impl Shr<crate::IVec2> for I16Vec2 {
1100 type Output = Self;
1101 #[inline]
shr(self, rhs: crate::IVec2) -> Self::Output1102 fn shr(self, rhs: crate::IVec2) -> Self::Output {
1103 Self {
1104 x: self.x.shr(rhs.x),
1105 y: self.y.shr(rhs.y),
1106 }
1107 }
1108 }
1109
1110 impl Shl<crate::UVec2> for I16Vec2 {
1111 type Output = Self;
1112 #[inline]
shl(self, rhs: crate::UVec2) -> Self::Output1113 fn shl(self, rhs: crate::UVec2) -> Self::Output {
1114 Self {
1115 x: self.x.shl(rhs.x),
1116 y: self.y.shl(rhs.y),
1117 }
1118 }
1119 }
1120
1121 impl Shr<crate::UVec2> for I16Vec2 {
1122 type Output = Self;
1123 #[inline]
shr(self, rhs: crate::UVec2) -> Self::Output1124 fn shr(self, rhs: crate::UVec2) -> Self::Output {
1125 Self {
1126 x: self.x.shr(rhs.x),
1127 y: self.y.shr(rhs.y),
1128 }
1129 }
1130 }
1131
1132 impl Index<usize> for I16Vec2 {
1133 type Output = i16;
1134 #[inline]
index(&self, index: usize) -> &Self::Output1135 fn index(&self, index: usize) -> &Self::Output {
1136 match index {
1137 0 => &self.x,
1138 1 => &self.y,
1139 _ => panic!("index out of bounds"),
1140 }
1141 }
1142 }
1143
1144 impl IndexMut<usize> for I16Vec2 {
1145 #[inline]
index_mut(&mut self, index: usize) -> &mut Self::Output1146 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1147 match index {
1148 0 => &mut self.x,
1149 1 => &mut self.y,
1150 _ => panic!("index out of bounds"),
1151 }
1152 }
1153 }
1154
1155 #[cfg(not(target_arch = "spirv"))]
1156 impl fmt::Display for I16Vec2 {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result1157 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1158 write!(f, "[{}, {}]", self.x, self.y)
1159 }
1160 }
1161
1162 #[cfg(not(target_arch = "spirv"))]
1163 impl fmt::Debug for I16Vec2 {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result1164 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1165 fmt.debug_tuple(stringify!(I16Vec2))
1166 .field(&self.x)
1167 .field(&self.y)
1168 .finish()
1169 }
1170 }
1171
1172 impl From<[i16; 2]> for I16Vec2 {
1173 #[inline]
from(a: [i16; 2]) -> Self1174 fn from(a: [i16; 2]) -> Self {
1175 Self::new(a[0], a[1])
1176 }
1177 }
1178
1179 impl From<I16Vec2> for [i16; 2] {
1180 #[inline]
from(v: I16Vec2) -> Self1181 fn from(v: I16Vec2) -> Self {
1182 [v.x, v.y]
1183 }
1184 }
1185
1186 impl From<(i16, i16)> for I16Vec2 {
1187 #[inline]
from(t: (i16, i16)) -> Self1188 fn from(t: (i16, i16)) -> Self {
1189 Self::new(t.0, t.1)
1190 }
1191 }
1192
1193 impl From<I16Vec2> for (i16, i16) {
1194 #[inline]
from(v: I16Vec2) -> Self1195 fn from(v: I16Vec2) -> Self {
1196 (v.x, v.y)
1197 }
1198 }
1199
1200 impl TryFrom<U16Vec2> for I16Vec2 {
1201 type Error = core::num::TryFromIntError;
1202
1203 #[inline]
try_from(v: U16Vec2) -> Result<Self, Self::Error>1204 fn try_from(v: U16Vec2) -> Result<Self, Self::Error> {
1205 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1206 }
1207 }
1208
1209 impl TryFrom<IVec2> for I16Vec2 {
1210 type Error = core::num::TryFromIntError;
1211
1212 #[inline]
try_from(v: IVec2) -> Result<Self, Self::Error>1213 fn try_from(v: IVec2) -> Result<Self, Self::Error> {
1214 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1215 }
1216 }
1217
1218 impl TryFrom<UVec2> for I16Vec2 {
1219 type Error = core::num::TryFromIntError;
1220
1221 #[inline]
try_from(v: UVec2) -> Result<Self, Self::Error>1222 fn try_from(v: UVec2) -> Result<Self, Self::Error> {
1223 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1224 }
1225 }
1226
1227 impl TryFrom<I64Vec2> for I16Vec2 {
1228 type Error = core::num::TryFromIntError;
1229
1230 #[inline]
try_from(v: I64Vec2) -> Result<Self, Self::Error>1231 fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
1232 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1233 }
1234 }
1235
1236 impl TryFrom<U64Vec2> for I16Vec2 {
1237 type Error = core::num::TryFromIntError;
1238
1239 #[inline]
try_from(v: U64Vec2) -> Result<Self, Self::Error>1240 fn try_from(v: U64Vec2) -> Result<Self, Self::Error> {
1241 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1242 }
1243 }
1244