Debian Codegraph @

debian/missing-sources/glam-0.22.0/src/bool/scalar/bvec3a.rs

raw
1 // Generated from vec_mask.rs.tera template. Edit the template, not the generated file.
2
3 #[cfg(not(target_arch = "spirv"))]
4 use core::fmt;
5 use core::ops::*;
6
7 /// A 3-dimensional `u32` vector mask.
8 #[derive(Clone, Copy)]
9 #[repr(C, align(16))]
10 pub struct BVec3A {
11 pub x: u32,
12 pub y: u32,
13 pub z: u32,
14 }
15
16 const MASK: [u32; 2] = [0, 0xff_ff_ff_ff];
17
18 impl BVec3A {
19 /// All false.
20 pub const FALSE: Self = Self::splat(false);
21
22 /// All true.
23 pub const TRUE: Self = Self::splat(true);
24
25 /// Creates a new vector mask.
26 #[inline(always)]
27 pub const fn new(x: bool, y: bool, z: bool) -> Self {
28 Self {
29 x: MASK[x as usize],
30 y: MASK[y as usize],
31 z: MASK[z as usize],
32 }
33 }
34
35 /// Creates a vector with all elements set to `v`.
36 #[inline]
37 pub const fn splat(v: bool) -> Self {
38 Self::new(v, v, v)
39 }
40
41 /// Returns a bitmask with the lowest 3 bits set from the elements of `self`.
42 ///
43 /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes
44 /// into the first lowest bit, element `y` into the second, etc.
45 #[inline]
46 pub fn bitmask(self) -> u32 {
47 (self.x & 0x1) | (self.y & 0x1) << 1 | (self.z & 0x1) << 2
48 }
49
50 /// Returns true if any of the elements are true, false otherwise.
51 #[inline]
52 pub fn any(self) -> bool {
53 ((self.x | self.y | self.z) & 0x1) != 0
54 }
55
56 /// Returns true if all the elements are true, false otherwise.
57 #[inline]
58 pub fn all(self) -> bool {
59 ((self.x & self.y & self.z) & 0x1) != 0
60 }
61
62 #[inline]
63 fn into_bool_array(self) -> [bool; 3] {
64 [
65 (self.x & 0x1) != 0,
66 (self.y & 0x1) != 0,
67 (self.z & 0x1) != 0,
68 ]
69 }
70
71 #[inline]
72 fn into_u32_array(self) -> [u32; 3] {
73 [self.x, self.y, self.z]
74 }
75 }
76
77 impl Default for BVec3A {
78 #[inline]
79 fn default() -> Self {
80 Self::FALSE
81 }
82 }
83
84 impl BitAnd for BVec3A {
85 type Output = Self;
86 #[inline]
87 fn bitand(self, rhs: Self) -> Self {
88 Self {
89 x: self.x & rhs.x,
90 y: self.y & rhs.y,
91 z: self.z & rhs.z,
92 }
93 }
94 }
95
96 impl BitAndAssign for BVec3A {
97 #[inline]
98 fn bitand_assign(&mut self, rhs: Self) {
99 *self = self.bitand(rhs);
100 }
101 }
102
103 impl BitOr for BVec3A {
104 type Output = Self;
105 #[inline]
106 fn bitor(self, rhs: Self) -> Self {
107 Self {
108 x: self.x | rhs.x,
109 y: self.y | rhs.y,
110 z: self.z | rhs.z,
111 }
112 }
113 }
114
115 impl BitOrAssign for BVec3A {
116 #[inline]
117 fn bitor_assign(&mut self, rhs: Self) {
118 *self = self.bitor(rhs);
119 }
120 }
121
122 impl BitXor for BVec3A {
123 type Output = Self;
124 #[inline]
125 fn bitxor(self, rhs: Self) -> Self {
126 Self {
127 x: self.x ^ rhs.x,
128 y: self.y ^ rhs.y,
129 z: self.z ^ rhs.z,
130 }
131 }
132 }
133
134 impl BitXorAssign for BVec3A {
135 #[inline]
136 fn bitxor_assign(&mut self, rhs: Self) {
137 *self = self.bitxor(rhs);
138 }
139 }
140
141 impl Not for BVec3A {
142 type Output = Self;
143 #[inline]
144 fn not(self) -> Self {
145 Self {
146 x: !self.x,
147 y: !self.y,
148 z: !self.z,
149 }
150 }
151 }
152
153 #[cfg(not(target_arch = "spirv"))]
154 impl fmt::Debug for BVec3A {
155 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
156 let arr = self.into_u32_array();
157 write!(
158 f,
159 "{}({:#x}, {:#x}, {:#x})",
160 stringify!(BVec3A),
161 arr[0],
162 arr[1],
163 arr[2]
164 )
165 }
166 }
167
168 #[cfg(not(target_arch = "spirv"))]
169 impl fmt::Display for BVec3A {
170 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
171 let arr = self.into_bool_array();
172 write!(f, "[{}, {}, {}]", arr[0], arr[1], arr[2])
173 }
174 }
175
176 impl From<BVec3A> for [bool; 3] {
177 #[inline]
178 fn from(mask: BVec3A) -> Self {
179 mask.into_bool_array()
180 }
181 }
182
183 impl From<BVec3A> for [u32; 3] {
184 #[inline]
185 fn from(mask: BVec3A) -> Self {
186 mask.into_u32_array()
187 }
188 }