Skip to main content

rapier2d_f64/utils/
simd_select.rs

1//! SimdSelect trait for conditional selection.
2
3use crate::math::SimdReal;
4use crate::math::{Real, Vector};
5use simba::simd::SimdValue;
6
7/// Trait for conditional selection between two values.
8pub trait SimdSelect<N: SimdValue> {
9    /// Select between `self` and `if_false` based on `condition`.
10    fn select(self, condition: N::SimdBool, if_false: Self) -> Self;
11}
12
13impl SimdSelect<Real> for Vector {
14    #[inline]
15    fn select(self, condition: bool, if_false: Self) -> Self {
16        if condition { self } else { if_false }
17    }
18}
19
20#[cfg(not(target_arch = "spirv"))]
21impl SimdSelect<SimdReal> for na::Vector3<SimdReal> {
22    #[inline]
23    fn select(self, condition: <SimdReal as SimdValue>::SimdBool, if_false: Self) -> Self {
24        SimdValue::select(self, condition, if_false)
25    }
26}