Skip to main content

rapier2d/utils/
simd_select.rs

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