Debian Codegraph @

debian/missing-sources/glam-0.23.0/src/bool/bvec3.rs

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