Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions Sofa/framework/Type/src/sofa/type/Mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace // anonymous
{
template<typename real>
constexpr real rabs(const real r)
real rabs(const real r)
{
if constexpr (std::is_signed<real>())
return std::abs(r);
Expand All @@ -41,7 +41,7 @@ namespace // anonymous
}

template<typename real>
constexpr real equalsZero(const real r, const real epsilon = std::numeric_limits<real>::epsilon())
real equalsZero(const real r, const real epsilon = std::numeric_limits<real>::epsilon())
{
return rabs(r) <= epsilon;
}
Expand All @@ -65,8 +65,8 @@ class Mat : public fixed_array<VecNoInit<C,real>, L>
typedef VecNoInit<C,real> LineNoInit;
typedef Vec<L,real> Col;

static const Size nbLines = L;
static const Size nbCols = C;
static constexpr Size nbLines = L;
static constexpr Size nbCols = C;

constexpr Mat() noexcept
{
Expand Down Expand Up @@ -389,15 +389,15 @@ class Mat : public fixed_array<VecNoInit<C,real>, L>
}


constexpr bool isSymmetric() const
bool isSymmetric() const
{
for (Size i=0; i<L; i++)
for (Size j=i+1; j<C; j++)
if( rabs( this->elems[i][j] - this->elems[j][i] ) > EQUALITY_THRESHOLD ) return false;
return true;
}

constexpr bool isDiagonal() const noexcept
bool isDiagonal() const noexcept
{
for (Size i=0; i<L; i++)
{
Expand Down Expand Up @@ -799,7 +799,7 @@ constexpr real determinant(const Mat<3,2,real>& m) noexcept

// one-norm of a 3 x 3 matrix
template<class real>
constexpr real oneNorm(const Mat<3,3,real>& A)
real oneNorm(const Mat<3,3,real>& A)
{
real norm = 0.0;
for (sofa::Size i=0; i<3; i++)
Expand All @@ -813,7 +813,7 @@ constexpr real oneNorm(const Mat<3,3,real>& A)

// inf-norm of a 3 x 3 matrix
template<class real>
constexpr real infNorm(const Mat<3,3,real>& A)
real infNorm(const Mat<3,3,real>& A)
{
real norm = 0.0;
for (sofa::Size i=0; i<3; i++)
Expand Down Expand Up @@ -847,7 +847,7 @@ constexpr Vec<N,real> diagonal(const Mat<N,N,real>& m)

/// Matrix inversion (general case).
template<sofa::Size S, class real>
[[nodiscard]] constexpr bool invertMatrix(Mat<S,S,real>& dest, const Mat<S,S,real>& from)
[[nodiscard]] bool invertMatrix(Mat<S,S,real>& dest, const Mat<S,S,real>& from)
{
sofa::Size i{0}, j{0}, k{0};
Vec<S, sofa::Size> r, c, row, col;
Expand Down
14 changes: 7 additions & 7 deletions Sofa/framework/Type/src/sofa/type/Vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace sofa::type
namespace // anonymous
{
template<typename real>
constexpr real rabs(const real r)
real rabs(const real r)
{
if constexpr (std::is_signed<real>())
return std::abs(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,29 +504,29 @@ 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();
return r;
}

/// return true if norm()==1
constexpr bool isNormalized( ValueType threshold=std::numeric_limits<ValueType>::epsilon()*(ValueType)10 ) const
bool isNormalized( ValueType threshold=std::numeric_limits<ValueType>::epsilon()*(ValueType)10 ) const
{
return rabs( norm2() - static_cast<ValueType>(1) ) <= threshold;
}
Expand Down