diff options
Diffstat (limited to 'src/bool/scalar/bvec4a.rs')
-rw-r--r-- | src/bool/scalar/bvec4a.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/bool/scalar/bvec4a.rs b/src/bool/scalar/bvec4a.rs index 28b0066..bdf8884 100644 --- a/src/bool/scalar/bvec4a.rs +++ b/src/bool/scalar/bvec4a.rs @@ -25,6 +25,7 @@ impl BVec4A { /// Creates a new vector mask. #[inline(always)] + #[must_use] pub const fn new(x: bool, y: bool, z: bool, w: bool) -> Self { Self { x: MASK[x as usize], @@ -36,6 +37,7 @@ impl BVec4A { /// Creates a vector with all elements set to `v`. #[inline] + #[must_use] pub const fn splat(v: bool) -> Self { Self::new(v, v, v, v) } @@ -45,23 +47,56 @@ impl BVec4A { /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. #[inline] + #[must_use] pub fn bitmask(self) -> u32 { (self.x & 0x1) | (self.y & 0x1) << 1 | (self.z & 0x1) << 2 | (self.w & 0x1) << 3 } /// Returns true if any of the elements are true, false otherwise. #[inline] + #[must_use] pub fn any(self) -> bool { ((self.x | self.y | self.z | self.w) & 0x1) != 0 } /// Returns true if all the elements are true, false otherwise. #[inline] + #[must_use] pub fn all(self) -> bool { ((self.x & self.y & self.z & self.w) & 0x1) != 0 } + /// Tests the value at `index`. + /// + /// Panics if `index` is greater than 3. + #[inline] + #[must_use] + pub fn test(&self, index: usize) -> bool { + match index { + 0 => (self.x & 0x1) != 0, + 1 => (self.y & 0x1) != 0, + 2 => (self.z & 0x1) != 0, + 3 => (self.w & 0x1) != 0, + _ => panic!("index out of bounds"), + } + } + + /// Sets the element at `index`. + /// + /// Panics if `index` is greater than 3. + #[inline] + pub fn set(&mut self, index: usize, value: bool) { + match index { + 0 => self.x = MASK[value as usize], + 1 => self.y = MASK[value as usize], + 2 => self.z = MASK[value as usize], + 3 => self.w = MASK[value as usize], + _ => panic!("index out of bounds"), + } + } + #[inline] + #[must_use] fn into_bool_array(self) -> [bool; 4] { [ (self.x & 0x1) != 0, @@ -72,6 +107,7 @@ impl BVec4A { } #[inline] + #[must_use] fn into_u32_array(self) -> [u32; 4] { [self.x, self.y, self.z, self.w] } |