Debian Codegraph @

debian/missing-sources/glam-0.25.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, PartialEq, Eq, Hash)]
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 #[must_use]
28 pub const fn new(x: bool, y: bool, z: bool) -> Self {
29 Self {
30 x: MASK[x as usize],
31 y: MASK[y as usize],
32 z: MASK[z as usize],
33 }
34 }
35
36 /// Creates a vector with all elements set to `v`.
37 #[inline]
38 #[must_use]
39 pub const fn splat(v: bool) -> Self {
40 Self::new(v, v, v)
41 }
42
43 /// Returns a bitmask with the lowest 3 bits set from the elements of `self`.
44 ///
45 /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes
46 /// into the first lowest bit, element `y` into the second, etc.
47 #[inline]
48 #[must_use]
49 pub fn bitmask(self) -> u32 {
50 (self.x & 0x1) | (self.y & 0x1) << 1 | (self.z & 0x1) << 2
51 }
52
53 /// Returns true if any of the elements are true, false otherwise.
54 #[inline]
55 #[must_use]
56 pub fn any(self) -> bool {
57 ((self.x | self.y | self.z) & 0x1) != 0
58 }
59
60 /// Returns true if all the elements are true, false otherwise.
61 #[inline]
62 #[must_use]
63 pub fn all(self) -> bool {
64 ((self.x & self.y & self.z) & 0x1) != 0
65 }
66
67 /// Tests the value at `index`.
68 ///
69 /// Panics if `index` is greater than 2.
70 #[inline]
71 #[must_use]
72 pub fn test(&self, index: usize) -> bool {
73 match index {
74 0 => (self.x & 0x1) != 0,
75 1 => (self.y & 0x1) != 0,
76 2 => (self.z & 0x1) != 0,
77 _ => panic!("index out of bounds"),
78 }
79 }
80
81 /// Sets the element at `index`.
82 ///
83 /// Panics if `index` is greater than 2.
84 #[inline]
85 pub fn set(&mut self, index: usize, value: bool) {
86 match index {
87 0 => self.x = MASK[value as usize],
88 1 => self.y = MASK[value as usize],
89 2 => self.z = MASK[value as usize],
90 _ => panic!("index out of bounds"),
91 }
92 }
93
94 #[inline]
95 #[must_use]
96 fn into_bool_array(self) -> [bool; 3] {
97 [
98 (self.x & 0x1) != 0,
99 (self.y & 0x1) != 0,
100 (self.z & 0x1) != 0,
101 ]
102 }
103
104 #[inline]
105 #[must_use]
106 fn into_u32_array(self) -> [u32; 3] {
107 [self.x, self.y, self.z]
108 }
109 }
110
111 impl Default for BVec3A {
112 #[inline]
113 fn default() -> Self {
114 Self::FALSE
115 }
116 }
117
118 impl BitAnd for BVec3A {
119 type Output = Self;
120 #[inline]
121 fn bitand(self, rhs: Self) -> Self {
122 Self {
123 x: self.x & rhs.x,
124 y: self.y & rhs.y,
125 z: self.z & rhs.z,
126 }
127 }
128 }
129
130 impl BitAndAssign for BVec3A {
131 #[inline]
132 fn bitand_assign(&mut self, rhs: Self) {
133 *self = self.bitand(rhs);
134 }
135 }
136
137 impl BitOr for BVec3A {
138 type Output = Self;
139 #[inline]
140 fn bitor(self, rhs: Self) -> Self {
141 Self {
142 x: self.x | rhs.x,
143 y: self.y | rhs.y,
144 z: self.z | rhs.z,
145 }
146 }
147 }
148
149 impl BitOrAssign for BVec3A {
150 #[inline]
151 fn bitor_assign(&mut self, rhs: Self) {
152 *self = self.bitor(rhs);
153 }
154 }
155
156 impl BitXor for BVec3A {
157 type Output = Self;
158 #[inline]
159 fn bitxor(self, rhs: Self) -> Self {
160 Self {
161 x: self.x ^ rhs.x,
162 y: self.y ^ rhs.y,
163 z: self.z ^ rhs.z,
164 }
165 }
166 }
167
168 impl BitXorAssign for BVec3A {
169 #[inline]
170 fn bitxor_assign(&mut self, rhs: Self) {
171 *self = self.bitxor(rhs);
172 }
173 }
174
175 impl Not for BVec3A {
176 type Output = Self;
177 #[inline]
178 fn not(self) -> Self {
179 Self {
180 x: !self.x,
181 y: !self.y,
182 z: !self.z,
183 }
184 }
185 }
186
187 #[cfg(not(target_arch = "spirv"))]
188 impl fmt::Debug for BVec3A {
189 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
190 let arr = self.into_u32_array();
191 write!(
192 f,
193 "{}({:#x}, {:#x}, {:#x})",
194 stringify!(BVec3A),
195 arr[0],
196 arr[1],
197 arr[2]
198 )
199 }
200 }
201
202 #[cfg(not(target_arch = "spirv"))]
203 impl fmt::Display for BVec3A {
204 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
205 let arr = self.into_bool_array();
206 write!(f, "[{}, {}, {}]", arr[0], arr[1], arr[2])
207 }
208 }
209
210 impl From<BVec3A> for [bool; 3] {
211 #[inline]
212 fn from(mask: BVec3A) -> Self {
213 mask.into_bool_array()
214 }
215 }
216
217 impl From<BVec3A> for [u32; 3] {
218 #[inline]
219 fn from(mask: BVec3A) -> Self {
220 mask.into_u32_array()
221 }
222 }