re_types/datatypes/
uvec2d_ext.rs1use super::UVec2D;
2
3impl UVec2D {
4 pub const ZERO: Self = Self([0; 2]);
6
7 pub const ONE: Self = Self([1; 2]);
9
10 #[inline]
12 pub const fn new(x: u32, y: u32) -> Self {
13 Self([x, y])
14 }
15
16 #[inline]
18 pub fn x(&self) -> u32 {
19 self.0[0]
20 }
21
22 #[inline]
24 pub fn y(&self) -> u32 {
25 self.0[1]
26 }
27
28 #[inline]
30 pub fn set_x(&mut self, x: u32) {
31 self.0[0] = x;
32 }
33
34 #[inline]
36 pub fn set_y(&mut self, y: u32) {
37 self.0[1] = y;
38 }
39}
40
41impl From<(u32, u32)> for UVec2D {
42 #[inline]
43 fn from((x, y): (u32, u32)) -> Self {
44 Self::new(x, y)
45 }
46}
47
48impl<'a> From<&'a Self> for UVec2D {
53 fn from(v: &'a Self) -> Self {
54 Self(v.0)
55 }
56}
57
58impl<'a> From<&'a (u32, u32)> for UVec2D {
59 #[inline]
60 fn from((x, y): &'a (u32, u32)) -> Self {
61 Self::new(*x, *y)
62 }
63}
64
65impl<'a> From<&'a [u32; 2]> for UVec2D {
66 #[inline]
67 fn from(v: &'a [u32; 2]) -> Self {
68 Self(*v)
69 }
70}
71
72impl<Idx> std::ops::Index<Idx> for UVec2D
73where
74 Idx: std::slice::SliceIndex<[u32]>,
75{
76 type Output = Idx::Output;
77
78 #[inline]
79 fn index(&self, index: Idx) -> &Self::Output {
80 &self.0[index]
81 }
82}
83
84#[cfg(feature = "glam")]
85impl From<UVec2D> for glam::UVec2 {
86 fn from(v: UVec2D) -> Self {
87 Self::from_slice(&v.0)
88 }
89}
90
91#[cfg(feature = "glam")]
92impl From<glam::UVec2> for UVec2D {
93 fn from(v: glam::UVec2) -> Self {
94 Self(v.to_array())
95 }
96}
97
98impl std::fmt::Display for UVec2D {
99 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100 write!(f, "[{}, {}]", self.x(), self.y())
101 }
102}