Debian Codegraph @

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