Debian Codegraph @

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