Skip to content
Snippets Groups Projects

Feature/language

59 files
+ 2106
2846
Compare changes
  • Side-by-side
  • Inline

Files

+ 23
41
@@ -226,8 +226,7 @@ class TinyMatrix
constexpr TinyMatrix&
operator=(const ZeroType&) noexcept
{
static_assert(std::is_arithmetic<T>(),
"Cannot assign 'zero' value for non-arithmetic types");
static_assert(std::is_arithmetic<T>(), "Cannot assign 'zero' value for non-arithmetic types");
for (size_t i = 0; i < N * N; ++i) {
m_values[i] = 0;
}
@@ -238,8 +237,7 @@ class TinyMatrix
constexpr TinyMatrix&
operator=(const IdentityType&) noexcept
{
static_assert(std::is_arithmetic<T>(),
"Cannot assign 'identity' value for non-arithmetic types");
static_assert(std::is_arithmetic<T>(), "Cannot assign 'identity' value for non-arithmetic types");
for (size_t i = 0; i < N; ++i) {
for (size_t j = 0; j < N; ++j) {
m_values[_index(i, j)] = (i == j) ? 1 : 0;
@@ -269,9 +267,8 @@ class TinyMatrix
PUGS_INLINE
constexpr TinyMatrix(const ZeroType&) noexcept
{
static_assert(
std::is_arithmetic<T>(),
"Cannot construct from 'zero' value for non-arithmetic types");
static_assert(std::is_arithmetic<T>(), "Cannot construct from 'zero' value "
"for non-arithmetic types");
for (size_t i = 0; i < N * N; ++i) {
m_values[i] = 0;
}
@@ -280,9 +277,8 @@ class TinyMatrix
PUGS_INLINE
constexpr TinyMatrix(const IdentityType&) noexcept
{
static_assert(
std::is_arithmetic<T>(),
"Cannot construct from 'identity' value for non-arithmetic types");
static_assert(std::is_arithmetic<T>(), "Cannot construct from 'identity' "
"value for non-arithmetic types");
for (size_t i = 0; i < N; ++i) {
for (size_t j = 0; j < N; ++j) {
m_values[_index(i, j)] = (i == j) ? 1 : 0;
@@ -317,11 +313,9 @@ template <size_t N, typename T>
PUGS_INLINE constexpr T
det(const TinyMatrix<N, T>& A)
{
static_assert(std::is_arithmetic<T>::value,
"determinent is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value,
"determinent for arbitrary dimension N is defined for floating "
"point types only");
static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value, "determinent for arbitrary dimension N is defined for floating "
"point types only");
TinyMatrix<N, T> M = A;
TinyVector<N, size_t> index;
@@ -366,8 +360,7 @@ template <typename T>
PUGS_INLINE constexpr T
det(const TinyMatrix<1, T>& A)
{
static_assert(std::is_arithmetic<T>::value,
"determinent is not defined for non-arithmetic types");
static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types");
return A(0, 0);
}
@@ -375,8 +368,7 @@ template <typename T>
PUGS_INLINE constexpr T
det(const TinyMatrix<2, T>& A)
{
static_assert(std::is_arithmetic<T>::value,
"determinent is not defined for non-arithmetic types");
static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types");
return A(0, 0) * A(1, 1) - A(1, 0) * A(0, 1);
}
@@ -384,10 +376,8 @@ template <typename T>
PUGS_INLINE constexpr T
det(const TinyMatrix<3, T>& A)
{
static_assert(std::is_arithmetic<T>::value,
"determinent is not defined for non-arithmetic types");
return A(0, 0) * (A(1, 1) * A(2, 2) - A(2, 1) * A(1, 2)) -
A(1, 0) * (A(0, 1) * A(2, 2) - A(2, 1) * A(0, 2)) +
static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types");
return A(0, 0) * (A(1, 1) * A(2, 2) - A(2, 1) * A(1, 2)) - A(1, 0) * (A(0, 1) * A(2, 2) - A(2, 1) * A(0, 2)) +
A(2, 0) * (A(0, 1) * A(1, 2) - A(1, 1) * A(0, 2));
}
@@ -424,10 +414,8 @@ template <typename T>
PUGS_INLINE constexpr TinyMatrix<1, T>
inverse(const TinyMatrix<1, T>& A)
{
static_assert(std::is_arithmetic<T>::value,
"inverse is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value,
"inverse is defined for floating point types only");
static_assert(std::is_arithmetic<T>::value, "inverse is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value, "inverse is defined for floating point types only");
TinyMatrix<1, T> A_1(1. / A(0, 0));
return std::move(A_1);
@@ -437,8 +425,7 @@ template <size_t N, typename T>
PUGS_INLINE constexpr T
cofactor(const TinyMatrix<N, T>& A, const size_t& i, const size_t& j)
{
static_assert(std::is_arithmetic<T>::value,
"cofactor is not defined for non-arithmetic types");
static_assert(std::is_arithmetic<T>::value, "cofactor is not defined for non-arithmetic types");
const T sign = ((i + j) % 2) ? -1 : 1;
return sign * det(getMinor(A, i, j));
@@ -448,10 +435,8 @@ template <typename T>
PUGS_INLINE constexpr TinyMatrix<2, T>
inverse(const TinyMatrix<2, T>& A)
{
static_assert(std::is_arithmetic<T>::value,
"inverse is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value,
"inverse is defined for floating point types only");
static_assert(std::is_arithmetic<T>::value, "inverse is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value, "inverse is defined for floating point types only");
const T determinent = det(A);
const T inv_determinent = 1. / determinent;
@@ -464,17 +449,14 @@ template <typename T>
PUGS_INLINE constexpr TinyMatrix<3, T>
inverse(const TinyMatrix<3, T>& A)
{
static_assert(std::is_arithmetic<T>::value,
"inverse is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value,
"inverse is defined for floating point types only");
static_assert(std::is_arithmetic<T>::value, "inverse is not defined for non-arithmetic types");
static_assert(std::is_floating_point<T>::value, "inverse is defined for floating point types only");
const T determinent = det(A);
TinyMatrix<3, T> A_cofactors_T(
cofactor(A, 0, 0), cofactor(A, 1, 0), cofactor(A, 2, 0), cofactor(A, 0, 1),
cofactor(A, 1, 1), cofactor(A, 2, 1), cofactor(A, 0, 2), cofactor(A, 1, 2),
cofactor(A, 2, 2));
TinyMatrix<3, T> A_cofactors_T(cofactor(A, 0, 0), cofactor(A, 1, 0), cofactor(A, 2, 0), cofactor(A, 0, 1),
cofactor(A, 1, 1), cofactor(A, 2, 1), cofactor(A, 0, 2), cofactor(A, 1, 2),
cofactor(A, 2, 2));
return std::move(A_cofactors_T *= 1. / determinent);
}
Loading