re_types/datatypes/
uvec3d_ext.rs1use super::UVec3D;
2
3impl UVec3D {
4 pub const ZERO: Self = Self([0; 3]);
6
7 pub const ONE: Self = Self([1; 3]);
9
10 #[inline]
12 pub const fn new(x: u32, y: u32, z: u32) -> Self {
13 Self([x, y, z])
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 z(&self) -> u32 {
31 self.0[2]
32 }
33}
34
35impl From<(u32, u32, u32)> for UVec3D {
36 #[inline]
37 fn from((x, y, z): (u32, u32, u32)) -> Self {
38 Self::new(x, y, z)
39 }
40}
41
42impl<'a> From<&'a Self> for UVec3D {
47 fn from(v: &'a Self) -> Self {
48 Self(v.0)
49 }
50}
51
52impl<'a> From<&'a (u32, u32, u32)> for UVec3D {
53 #[inline]
54 fn from((x, y, z): &'a (u32, u32, u32)) -> Self {
55 Self::new(*x, *y, *z)
56 }
57}
58
59impl<'a> From<&'a [u32; 3]> for UVec3D {
60 #[inline]
61 fn from(v: &'a [u32; 3]) -> Self {
62 Self(*v)
63 }
64}
65
66impl<Idx> std::ops::Index<Idx> for UVec3D
67where
68 Idx: std::slice::SliceIndex<[u32]>,
69{
70 type Output = Idx::Output;
71
72 #[inline]
73 fn index(&self, index: Idx) -> &Self::Output {
74 &self.0[index]
75 }
76}
77
78#[cfg(feature = "glam")]
79impl From<UVec3D> for glam::UVec3 {
80 #[inline]
81 fn from(v: UVec3D) -> Self {
82 Self::from_slice(&v.0)
83 }
84}
85
86#[cfg(feature = "glam")]
87impl From<glam::UVec3> for UVec3D {
88 #[inline]
89 fn from(v: glam::UVec3) -> Self {
90 Self(v.to_array())
91 }
92}
93
94impl std::fmt::Display for UVec3D {
95 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96 write!(f, "[{}, {}, {}]", self.x(), self.y(), self.z(),)
97 }
98}