Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sofa/framework/Type/src/sofa/type/Mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace // anonymous
constexpr real rabs(const real r)
{
if constexpr (std::is_signed<real>())
return std::abs(r);
return r < 0 ? -r : r;
else
return r;
}
Expand Down
12 changes: 6 additions & 6 deletions Sofa/framework/Type/src/sofa/type/Vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace // anonymous
constexpr real rabs(const real r)
{
if constexpr (std::is_signed<real>())
return std::abs(r);
return r < 0 ? -r : r;
else
return r;
}
Expand Down Expand Up @@ -441,15 +441,15 @@ class Vec : public sofa::type::fixed_array<ValueType,size_t(N)>
}

/// Euclidean norm.
constexpr ValueType norm() const noexcept
ValueType norm() const noexcept
{
return ValueType(std::sqrt(norm2()));
}

/// l-norm of the vector
/// The type of norm is set by parameter l.
/// Use l<0 for the infinite norm.
constexpr ValueType lNorm( int l ) const
ValueType lNorm( int l ) const
{
if( l==2 ) return norm(); // euclidian norm
else if( l<0 ) // infinite norm
Expand Down Expand Up @@ -504,21 +504,21 @@ class Vec : public sofa::type::fixed_array<ValueType,size_t(N)>

/// Normalize the vector.
/// returns false iff the norm is too small
constexpr bool normalize(ValueType threshold=std::numeric_limits<ValueType>::epsilon()) noexcept
bool normalize(ValueType threshold=std::numeric_limits<ValueType>::epsilon()) noexcept
{
return normalizeWithNorm(norm(),threshold);
}

/// Normalize the vector with a failsafe.
/// If the norm is too small, the vector becomes the failsafe.
constexpr void normalize(Vec<N,ValueType> failsafe, ValueType threshold=std::numeric_limits<ValueType>::epsilon()) noexcept
void normalize(Vec<N,ValueType> failsafe, ValueType threshold=std::numeric_limits<ValueType>::epsilon()) noexcept
{
if( !normalize(threshold) ) *this=failsafe;
}

/// Return the normalized vector.
/// @warning 'this' is not normalized.
constexpr Vec<N,ValueType> normalized() const noexcept
Vec<N,ValueType> normalized() const noexcept
{
Vec<N,ValueType> r(*this);
r.normalize();
Expand Down