• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bitshifter / glam-rs / 3617952136

pending completion
3617952136

push

github

GitHub
Vector mask type for scalar impl of `Vec3A` should be `BVec3A`. (#365)

18 of 18 new or added lines in 1 file covered. (100.0%)

17930 of 19133 relevant lines covered (93.71%)

3.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/bool/scalar/bvec4a.rs
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 `u32` vector mask.
8
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
9
#[repr(C, align(16))]
10
pub struct BVec4A {
11
    pub x: u32,
12
    pub y: u32,
13
    pub z: u32,
14
    pub w: u32,
15
}
16

17
const MASK: [u32; 2] = [0, 0xff_ff_ff_ff];
18

19
impl BVec4A {
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 {
30
            x: MASK[x as usize],
×
31
            y: MASK[y as usize],
×
32
            z: MASK[z as usize],
×
33
            w: MASK[w as usize],
×
34
        }
35
    }
36

37
    /// Creates a vector with all elements set to `v`.
38
    #[inline]
39
    pub const fn splat(v: bool) -> Self {
×
40
        Self::new(v, v, v, v)
×
41
    }
42

43
    /// Returns a bitmask with the lowest 4 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
    pub fn bitmask(self) -> u32 {
×
49
        (self.x & 0x1) | (self.y & 0x1) << 1 | (self.z & 0x1) << 2 | (self.w & 0x1) << 3
×
50
    }
51

52
    /// Returns true if any of the elements are true, false otherwise.
53
    #[inline]
54
    pub fn any(self) -> bool {
×
55
        ((self.x | self.y | self.z | self.w) & 0x1) != 0
×
56
    }
57

58
    /// Returns true if all the elements are true, false otherwise.
59
    #[inline]
60
    pub fn all(self) -> bool {
×
61
        ((self.x & self.y & self.z & self.w) & 0x1) != 0
×
62
    }
63

64
    #[inline]
65
    fn into_bool_array(self) -> [bool; 4] {
×
66
        [
67
            (self.x & 0x1) != 0,
×
68
            (self.y & 0x1) != 0,
×
69
            (self.z & 0x1) != 0,
×
70
            (self.w & 0x1) != 0,
×
71
        ]
72
    }
73

74
    #[inline]
75
    fn into_u32_array(self) -> [u32; 4] {
×
76
        [self.x, self.y, self.z, self.w]
×
77
    }
78
}
79

80
impl Default for BVec4A {
81
    #[inline]
82
    fn default() -> Self {
×
83
        Self::FALSE
×
84
    }
85
}
86

87
impl BitAnd for BVec4A {
88
    type Output = Self;
89
    #[inline]
90
    fn bitand(self, rhs: Self) -> Self {
×
91
        Self {
92
            x: self.x & rhs.x,
×
93
            y: self.y & rhs.y,
×
94
            z: self.z & rhs.z,
×
95
            w: self.w & rhs.w,
×
96
        }
97
    }
98
}
99

100
impl BitAndAssign for BVec4A {
101
    #[inline]
102
    fn bitand_assign(&mut self, rhs: Self) {
×
103
        *self = self.bitand(rhs);
×
104
    }
105
}
106

107
impl BitOr for BVec4A {
108
    type Output = Self;
109
    #[inline]
110
    fn bitor(self, rhs: Self) -> Self {
×
111
        Self {
112
            x: self.x | rhs.x,
×
113
            y: self.y | rhs.y,
×
114
            z: self.z | rhs.z,
×
115
            w: self.w | rhs.w,
×
116
        }
117
    }
118
}
119

120
impl BitOrAssign for BVec4A {
121
    #[inline]
122
    fn bitor_assign(&mut self, rhs: Self) {
×
123
        *self = self.bitor(rhs);
×
124
    }
125
}
126

127
impl BitXor for BVec4A {
128
    type Output = Self;
129
    #[inline]
130
    fn bitxor(self, rhs: Self) -> Self {
×
131
        Self {
132
            x: self.x ^ rhs.x,
×
133
            y: self.y ^ rhs.y,
×
134
            z: self.z ^ rhs.z,
×
135
            w: self.w ^ rhs.w,
×
136
        }
137
    }
138
}
139

140
impl BitXorAssign for BVec4A {
141
    #[inline]
142
    fn bitxor_assign(&mut self, rhs: Self) {
×
143
        *self = self.bitxor(rhs);
×
144
    }
145
}
146

147
impl Not for BVec4A {
148
    type Output = Self;
149
    #[inline]
150
    fn not(self) -> Self {
×
151
        Self {
152
            x: !self.x,
×
153
            y: !self.y,
×
154
            z: !self.z,
×
155
            w: !self.w,
×
156
        }
157
    }
158
}
159

160
#[cfg(not(target_arch = "spirv"))]
161
impl fmt::Debug for BVec4A {
162
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
163
        let arr = self.into_u32_array();
×
164
        write!(
×
165
            f,
166
            "{}({:#x}, {:#x}, {:#x}, {:#x})",
167
            stringify!(BVec4A),
168
            arr[0],
169
            arr[1],
170
            arr[2],
171
            arr[3]
172
        )
173
    }
174
}
175

176
#[cfg(not(target_arch = "spirv"))]
177
impl fmt::Display for BVec4A {
178
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
179
        let arr = self.into_bool_array();
×
180
        write!(f, "[{}, {}, {}, {}]", arr[0], arr[1], arr[2], arr[3])
×
181
    }
182
}
183

184
impl From<BVec4A> for [bool; 4] {
185
    #[inline]
186
    fn from(mask: BVec4A) -> Self {
×
187
        mask.into_bool_array()
×
188
    }
189
}
190

191
impl From<BVec4A> for [u32; 4] {
192
    #[inline]
193
    fn from(mask: BVec4A) -> Self {
×
194
        mask.into_u32_array()
×
195
    }
196
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc