aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-02-21 21:16:38 +0100
committerSébastien Crozet <developer@crozet.re>2022-02-21 21:16:38 +0100
commit19a00885d69dba87d9745edec1722513909e282a (patch)
tree8da8464e0cdb5dd68c3957d364d2482dc8e4e5d3
parentce3cf553c27d3fad6302dff7d196fccb953c2c33 (diff)
downloadrapier-19a00885d69dba87d9745edec1722513909e282a.tar.gz
rapier-19a00885d69dba87d9745edec1722513909e282a.tar.bz2
rapier-19a00885d69dba87d9745edec1722513909e282a.zip
Use a threshold for utils::inv and simd_inv
-rw-r--r--src/utils.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 9aa4bf2..07f0626 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -19,16 +19,19 @@ pub trait WReal: SimdRealField<Element = Real> + Copy {}
impl WReal for Real {}
impl WReal for SimdReal {}
+const INV_EPSILON: Real = 1.0e-20;
+
pub(crate) fn inv(val: Real) -> Real {
- if val == 0.0 {
+ if val >= -INV_EPSILON && val <= INV_EPSILON {
0.0
} else {
1.0 / val
}
}
-pub(crate) fn simd_inv<N: SimdRealField + Copy>(val: N) -> N {
- N::zero().select(val.simd_eq(N::zero()), N::one() / val)
+pub(crate) fn simd_inv<N: WReal>(val: N) -> N {
+ let eps = N::splat(INV_EPSILON);
+ N::zero().select(val.simd_gt(-eps) & val.simd_lt(eps), N::one() / val)
}
/// Trait to copy the sign of each component of one scalar/vector/matrix to another.