Debian Codegraph @

debian/missing-sources/glam-0.18.0/src/core/scalar/mask.rs

raw symbols SCIP
1 use crate::core::{
2 storage::{XY, XYZ, XYZW},
3 traits::{scalar::*, vector::*},
4 };
5
6 impl MaskConst for u32 {
7 const MASK: [u32; 2] = [0, 0xff_ff_ff_ff];
8 }
9
10 impl MaskConst for u64 {
11 const MASK: [u64; 2] = [0, 0xff_ff_ff_ff_ff_ff_ff_ff];
12 }
13
14 // u32 (currently unused)
15
16 /*
17 impl MaskVectorConst for XY<u32> {
18 const FALSE: Self = Self { x: 0, y: 0 };
19 }
20
21 impl MaskVectorConst for XYZ<u32> {
22 const FALSE: Self = Self { x: 0, y: 0, z: 0 };
23 }
24
25 impl MaskVectorConst for XYZW<u32> {
26 const FALSE: Self = Self {
27 x: 0,
28 y: 0,
29 z: 0,
30 w: 0,
31 };
32 }
33
34 impl MaskVector for XY<u32> {
35 #[inline]
36 fn bitand(self, other: Self) -> Self {
37 Self {
38 x: self.x & other.x,
39 y: self.y & other.y,
40 }
41 }
42
43 #[inline]
44 fn bitor(self, other: Self) -> Self {
45 Self {
46 x: self.x | other.x,
47 y: self.y | other.y,
48 }
49 }
50
51 #[inline]
52 fn not(self) -> Self {
53 Self {
54 x: !self.x,
55 y: !self.y,
56 }
57 }
58 }
59
60 impl MaskVector for XYZ<u32> {
61 #[inline]
62 fn bitand(self, other: Self) -> Self {
63 Self {
64 x: self.x & other.x,
65 y: self.y & other.y,
66 z: self.z & other.z,
67 }
68 }
69
70 #[inline]
71 fn bitor(self, other: Self) -> Self {
72 Self {
73 x: self.x | other.x,
74 y: self.y | other.y,
75 z: self.z | other.z,
76 }
77 }
78
79 #[inline]
80 fn not(self) -> Self {
81 Self {
82 x: !self.x,
83 y: !self.y,
84 z: !self.z,
85 }
86 }
87 }
88
89 impl MaskVector for XYZW<u32> {
90 #[inline]
91 fn bitand(self, other: Self) -> Self {
92 Self {
93 x: self.x & other.x,
94 y: self.y & other.y,
95 z: self.z & other.z,
96 w: self.w & other.w,
97 }
98 }
99
100 #[inline]
101 fn bitor(self, other: Self) -> Self {
102 Self {
103 x: self.x | other.x,
104 y: self.y | other.y,
105 z: self.z | other.z,
106 w: self.w | other.w,
107 }
108 }
109
110 #[inline]
111 fn not(self) -> Self {
112 Self {
113 x: !self.x,
114 y: !self.y,
115 z: !self.z,
116 w: !self.w,
117 }
118 }
119 }
120
121 impl MaskVector2 for XY<u32> {
122 #[inline(always)]
123 fn new(x: bool, y: bool) -> Self {
124 Self {
125 x: MaskConst::MASK[x as usize],
126 y: MaskConst::MASK[y as usize],
127 }
128 }
129
130 #[inline]
131 fn bitmask(self) -> u32 {
132 (self.x as u32 & 0x1) | (self.y as u32 & 0x1) << 1
133 }
134
135 #[inline]
136 fn any(self) -> bool {
137 ((self.x | self.y) & 0x1) != 0
138 }
139
140 #[inline]
141 fn all(self) -> bool {
142 ((self.x & self.y) & 0x1) != 0
143 }
144
145 #[inline]
146 fn into_bool_array(self) -> [bool; 2] {
147 [self.x != 0, self.y != 0]
148 }
149
150 #[inline]
151 fn into_u32_array(self) -> [u32; 2] {
152 [self.x, self.y]
153 }
154 }
155
156 impl MaskVector3 for XYZ<u32> {
157 #[inline(always)]
158 fn new(x: bool, y: bool, z: bool) -> Self {
159 // A SSE2 mask can be any bit pattern but for the `Vec3Mask` implementation of select
160 // we expect either 0 or 0xff_ff_ff_ff. This should be a safe assumption as this type
161 // can only be created via this function or by `Vec3` methods.
162 Self {
163 x: MaskConst::MASK[x as usize],
164 y: MaskConst::MASK[y as usize],
165 z: MaskConst::MASK[z as usize],
166 }
167 }
168
169 #[inline]
170 fn bitmask(self) -> u32 {
171 (self.x & 0x1) | (self.y & 0x1) << 1 | (self.z & 0x1) << 2
172 }
173
174 #[inline]
175 fn any(self) -> bool {
176 ((self.x | self.y | self.z) & 0x1) != 0
177 }
178
179 #[inline]
180 fn all(self) -> bool {
181 ((self.x & self.y & self.z) & 0x1) != 0
182 }
183
184 #[inline]
185 fn into_bool_array(self) -> [bool; 3] {
186 [self.x != 0, self.y != 0, self.z != 0]
187 }
188
189 #[inline]
190 fn into_u32_array(self) -> [u32; 3] {
191 [self.x, self.y, self.z]
192 }
193 }
194
195 impl MaskVector4 for XYZW<u32> {
196 #[inline(always)]
197 fn new(x: bool, y: bool, z: bool, w: bool) -> Self {
198 // A SSE2 mask can be any bit pattern but for the `Vec4Mask` implementation of select
199 // we expect either 0 or 0xff_ff_ff_ff. This should be a safe assumption as this type
200 // can only be created via this function or by `Vec4` methods.
201 Self {
202 x: MaskConst::MASK[x as usize],
203 y: MaskConst::MASK[y as usize],
204 z: MaskConst::MASK[z as usize],
205 w: MaskConst::MASK[w as usize],
206 }
207 }
208
209 #[inline]
210 fn bitmask(self) -> u32 {
211 (self.x & 0x1) | (self.y & 0x1) << 1 | (self.z & 0x1) << 2 | (self.w & 0x1) << 3
212 }
213
214 #[inline]
215 fn any(self) -> bool {
216 ((self.x | self.y | self.z | self.w) & 0x1) != 0
217 }
218
219 #[inline]
220 fn all(self) -> bool {
221 ((self.x & self.y & self.z & self.w) & 0x1) != 0
222 }
223
224 #[inline]
225 fn into_bool_array(self) -> [bool; 4] {
226 [self.x != 0, self.y != 0, self.z != 0, self.w != 0]
227 }
228
229 #[inline]
230 fn into_u32_array(self) -> [u32; 4] {
231 [self.x, self.y, self.z, self.w]
232 }
233 }
234 */
235
236 // bool
237
238 impl MaskVectorConst for XY<bool> {
239 const FALSE: Self = Self { x: false, y: false };
240 }
241
242 impl MaskVectorConst for XYZ<bool> {
243 const FALSE: Self = Self {
244 x: false,
245 y: false,
246 z: false,
247 };
248 }
249
250 impl MaskVectorConst for XYZW<bool> {
251 const FALSE: Self = Self {
252 x: false,
253 y: false,
254 z: false,
255 w: false,
256 };
257 }
258
259 impl MaskVector for XY<bool> {
260 #[inline]
261 fn bitand(self, other: Self) -> Self {
262 Self {
263 x: self.x && other.x,
264 y: self.y && other.y,
265 }
266 }
267
268 #[inline]
269 fn bitor(self, other: Self) -> Self {
270 Self {
271 x: self.x || other.x,
272 y: self.y || other.y,
273 }
274 }
275
276 #[inline]
277 fn not(self) -> Self {
278 Self {
279 x: !self.x,
280 y: !self.y,
281 }
282 }
283 }
284
285 impl MaskVector for XYZ<bool> {
286 #[inline]
287 fn bitand(self, other: Self) -> Self {
288 Self {
289 x: self.x && other.x,
290 y: self.y && other.y,
291 z: self.z && other.z,
292 }
293 }
294
295 #[inline]
296 fn bitor(self, other: Self) -> Self {
297 Self {
298 x: self.x || other.x,
299 y: self.y || other.y,
300 z: self.z || other.z,
301 }
302 }
303
304 #[inline]
305 fn not(self) -> Self {
306 Self {
307 x: !self.x,
308 y: !self.y,
309 z: !self.z,
310 }
311 }
312 }
313
314 impl MaskVector for XYZW<bool> {
315 #[inline]
316 fn bitand(self, other: Self) -> Self {
317 Self {
318 x: self.x && other.x,
319 y: self.y && other.y,
320 z: self.z && other.z,
321 w: self.w && other.w,
322 }
323 }
324
325 #[inline]
326 fn bitor(self, other: Self) -> Self {
327 Self {
328 x: self.x || other.x,
329 y: self.y || other.y,
330 z: self.z || other.z,
331 w: self.w || other.w,
332 }
333 }
334
335 #[inline]
336 fn not(self) -> Self {
337 Self {
338 x: !self.x,
339 y: !self.y,
340 z: !self.z,
341 w: !self.w,
342 }
343 }
344 }
345
346 impl MaskVector2 for XY<bool> {
347 #[inline(always)]
348 fn new(x: bool, y: bool) -> Self {
349 Self { x, y }
350 }
351
352 #[inline]
353 fn bitmask(self) -> u32 {
354 (self.x as u32) | (self.y as u32) << 1
355 }
356
357 #[inline]
358 fn any(self) -> bool {
359 self.x || self.y
360 }
361
362 #[inline]
363 fn all(self) -> bool {
364 self.x && self.y
365 }
366
367 #[inline]
368 fn into_bool_array(self) -> [bool; 2] {
369 [self.x, self.y]
370 }
371
372 #[inline]
373 fn into_u32_array(self) -> [u32; 2] {
374 [
375 MaskConst::MASK[self.x as usize],
376 MaskConst::MASK[self.y as usize],
377 ]
378 }
379 }
380
381 impl MaskVector3 for XYZ<bool> {
382 #[inline(always)]
383 fn new(x: bool, y: bool, z: bool) -> Self {
384 Self { x, y, z }
385 }
386
387 #[inline]
388 fn bitmask(self) -> u32 {
389 (self.x as u32) | (self.y as u32) << 1 | (self.z as u32) << 2
390 }
391
392 #[inline]
393 fn any(self) -> bool {
394 self.x || self.y || self.z
395 }
396
397 #[inline]
398 fn all(self) -> bool {
399 self.x && self.y && self.z
400 }
401
402 #[inline]
403 fn into_bool_array(self) -> [bool; 3] {
404 [self.x, self.y, self.z]
405 }
406
407 #[inline]
408 fn into_u32_array(self) -> [u32; 3] {
409 [
410 MaskConst::MASK[self.x as usize],
411 MaskConst::MASK[self.y as usize],
412 MaskConst::MASK[self.z as usize],
413 ]
414 }
415 }
416
417 impl MaskVector4 for XYZW<bool> {
418 #[inline(always)]
419 fn new(x: bool, y: bool, z: bool, w: bool) -> Self {
420 Self { x, y, z, w }
421 }
422
423 #[inline]
424 fn bitmask(self) -> u32 {
425 (self.x as u32) | (self.y as u32) << 1 | (self.z as u32) << 2 | (self.w as u32) << 3
426 }
427
428 #[inline]
429 fn any(self) -> bool {
430 self.x || self.y || self.z || self.w
431 }
432
433 #[inline]
434 fn all(self) -> bool {
435 self.x && self.y && self.z && self.w
436 }
437
438 #[inline]
439 fn into_bool_array(self) -> [bool; 4] {
440 [self.x, self.y, self.z, self.w]
441 }
442
443 #[inline]
444 fn into_u32_array(self) -> [u32; 4] {
445 [
446 MaskConst::MASK[self.x as usize],
447 MaskConst::MASK[self.y as usize],
448 MaskConst::MASK[self.z as usize],
449 MaskConst::MASK[self.w as usize],
450 ]
451 }
452 }