-Removed lambda expansions due to gcc generating call instructions

This commit is contained in:
2025-06-28 12:09:59 -04:00
parent 37fba8faad
commit 1573033b52
10 changed files with 298 additions and 67 deletions

View File

@@ -120,15 +120,16 @@ struct array
/// ///
/// \brief /// \brief
friend constexpr bool_t operator==(const array& lhs, const array& rhs) friend constexpr bool_t operator==(const array& lhs, const array& rhs)
{ return [lhs, rhs]<size_t...i>(index_sequence<i...>) -> bool_t // Lambda Declaration, Creates Indices at Compile Time { return array::__compare(lhs, rhs, make_index_sequence<ElemV>{}); }
{ return ((lhs[i] == rhs[i]) && ...); }(make_index_sequence<ElemV>{}); } // Lambda Implementation,
friend constexpr bool_t operator!=(const array& lhs, const array& rhs) friend constexpr bool_t operator!=(const array& lhs, const array& rhs)
{ return [lhs, rhs]<size_t...i>(index_sequence<i...>) -> bool_t { return not array::__compare(lhs, rhs, make_index_sequence<ElemV>{}); }
{ return ((lhs[i] != rhs[i]) || ...); }(make_index_sequence<ElemV>{}); }
/// @} /// @}
private:
template<size_t...i>
static bool __compare(const array& lhs, const array& rhs, index_sequence<i...>) { return ((lhs[i] == rhs[i]) && ...); }
}; };
} }

View File

@@ -22,6 +22,7 @@
using assert_handler = void (*)(const char *, const char *, int , const char *); using assert_handler = void (*)(const char *, const char *, int , const char *);
extern void __assert_impl(const char* expression, const char* file, int line, const char* function); extern void __assert_impl(const char* expression, const char* file, int line, const char* function);
#define assert(expression) if(not(expression)) { __assert_impl(#expression, __FILE__, __LINE__, __PRETTY_FUNCTION__); } #define assert(expression) if(not(expression)) { __assert_impl(#expression, __FILE__, __LINE__, __PRETTY_FUNCTION__); }
#endif // FENNEC_LANG_ASSERT_H #endif // FENNEC_LANG_ASSERT_H

View File

@@ -561,7 +561,7 @@ constexpr vector<genType, i...> modf(const vector<genType, i...>& x, vector<genT
/// \param x input value /// \param x input value
template<typename genType, typename genBType = bool_t> requires(is_bool_v<genBType>) template<typename genType, typename genBType = bool_t> requires(is_bool_v<genBType>)
constexpr genBType isnan(genType x) constexpr genBType isnan(genType x)
{ return ::isnan(x); } { return ::isnanf(x); }
// Vector Specializations ---------------------------------------------------------------------------------------------- // Vector Specializations ----------------------------------------------------------------------------------------------
@@ -584,7 +584,7 @@ constexpr vector<genBType, i...> isnan(const vector<genType, i...>& x)
/// \param x input value /// \param x input value
template<typename genType, typename genBType = bool_t> requires(is_bool_v<genBType>) template<typename genType, typename genBType = bool_t> requires(is_bool_v<genBType>)
constexpr genBType isinf(genType x) constexpr genBType isinf(genType x)
{ return ::isinf(x); } { return ::isinff(x); }
// Vector Specializations ---------------------------------------------------------------------------------------------- // Vector Specializations ----------------------------------------------------------------------------------------------

View File

@@ -141,6 +141,7 @@ constexpr matrix<scalar, rows, cols...> inverse(const matrix<scalar, rows, cols.
return i; return i;
} }
} }

View File

@@ -109,6 +109,7 @@
/// ///
#include <fennec/math/vector.h> #include <fennec/math/vector.h>
#include <fennec/math/common.h>
#include <fennec/math/exponential.h> #include <fennec/math/exponential.h>
namespace fennec namespace fennec

View File

@@ -154,11 +154,7 @@ constexpr matrix<scalar, sizeof...(s0), s1...> outerProduct(const vector<scalar,
/// \details The input matrix m is not modified. /// \details The input matrix m is not modified.
template<typename scalar, size_t rows, size_t...cols> template<typename scalar, size_t rows, size_t...cols>
constexpr mat<scalar, rows, sizeof...(cols)> transpose(const matrix<scalar, rows, cols...>& m) noexcept constexpr mat<scalar, rows, sizeof...(cols)> transpose(const matrix<scalar, rows, cols...>& m) noexcept
{ { return mat<scalar, rows, sizeof...(cols)>::transpose(m); }
return [m]<size_t...i>(index_sequence<i...>) -> mat<scalar, rows, sizeof...(cols)> {
return mat<scalar, rows, sizeof...(cols)>(fennec::row(m, i) ...);
}(make_index_sequence<rows>{});
}
/// ///
/// \brief Returns the determinant of m. /// \brief Returns the determinant of m.
@@ -225,7 +221,7 @@ struct matrix
/// ///
/// \brief alias for the transpose matrix type /// \brief alias for the transpose matrix type
using transpose_t = mat<ScalarT, columns, rows>; using transpose_t = mat<ScalarT, rows, columns>;
/// ///
@@ -244,8 +240,7 @@ struct matrix
/// \brief default constructor, initializes elements with 0 /// \brief default constructor, initializes elements with 0
/// ///
/// \details /// \details
constexpr matrix() constexpr matrix() = default;
: data{ scalar_t(0) }{}
/// ///
@@ -329,7 +324,7 @@ struct matrix
/// ///
/// \copydetails matrix::operator[](size_t) const /// \copydetails matrix::operator[](size_t) const
constexpr column_t& operator[](size_t i) constexpr column_t& operator[](size_t i)
{ assert(i < rows); return data[i]; } { assert(i < columns); return data[i]; }
/// ///
/// \brief returns the column at index \f$i\f$ /// \brief returns the column at index \f$i\f$
@@ -367,9 +362,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been added by the scalar /// \returns a copy of the matrix with each component having been added by the scalar
constexpr friend matrix_t operator+(const matrix_t& lhs, scalar_t rhs) constexpr friend matrix_t operator+(const matrix_t& lhs, scalar_t rhs)
{ {
matrix_t retval = lhs; return matrix_t(lhs[ColIndicesV] + rhs ...);
((retval[ColIndicesV] += rhs), ...);
return retval;
} }
/// ///
@@ -379,9 +372,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been added by the scalar /// \returns a copy of the matrix with each component having been added by the scalar
constexpr friend matrix_t operator+(scalar_t lhs, const matrix_t& rhs) constexpr friend matrix_t operator+(scalar_t lhs, const matrix_t& rhs)
{ {
matrix_t retval = rhs; return matrix_t(lhs + rhs[ColIndicesV] ...);
((retval[ColIndicesV] += lhs), ...);
return retval;
} }
/// ///
@@ -391,9 +382,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been subtracted by the scalar /// \returns a copy of the matrix with each component having been subtracted by the scalar
constexpr friend matrix_t operator-(const matrix_t& lhs, scalar_t rhs) constexpr friend matrix_t operator-(const matrix_t& lhs, scalar_t rhs)
{ {
matrix_t retval = lhs; return matrix_t(lhs[ColIndicesV] - rhs ...);
((retval[ColIndicesV] -= rhs), ...);
return retval;
} }
/// ///
@@ -403,9 +392,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been subtracted by the scalar /// \returns a copy of the matrix with each component having been subtracted by the scalar
constexpr friend matrix_t operator-(scalar_t lhs, const matrix_t& rhs) constexpr friend matrix_t operator-(scalar_t lhs, const matrix_t& rhs)
{ {
matrix_t retval = rhs; return matrix_t(lhs - rhs[ColIndicesV] ...);
((retval[ColIndicesV] -= lhs), ...);
return retval;
} }
/// ///
@@ -415,9 +402,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been multiplied by the scalar /// \returns a copy of the matrix with each component having been multiplied by the scalar
constexpr friend matrix_t operator*(const matrix_t& lhs, scalar_t rhs) constexpr friend matrix_t operator*(const matrix_t& lhs, scalar_t rhs)
{ {
matrix_t retval = lhs; return matrix_t(lhs[ColIndicesV] * rhs ...);
((retval[ColIndicesV] *= rhs), ...);
return retval;
} }
/// ///
@@ -427,9 +412,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been multiplied by the scalar /// \returns a copy of the matrix with each component having been multiplied by the scalar
constexpr friend matrix_t operator*(scalar_t lhs, const matrix_t& rhs) constexpr friend matrix_t operator*(scalar_t lhs, const matrix_t& rhs)
{ {
matrix_t retval = rhs; return matrix_t(lhs * rhs[ColIndicesV] ...);
((retval[ColIndicesV] *= lhs), ...);
return retval;
} }
/// ///
@@ -439,9 +422,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been divided by the scalar /// \returns a copy of the matrix with each component having been divided by the scalar
constexpr friend matrix_t operator/(const matrix_t& lhs, scalar_t rhs) constexpr friend matrix_t operator/(const matrix_t& lhs, scalar_t rhs)
{ {
matrix_t retval = lhs; return matrix_t(lhs[ColIndicesV] / rhs ...);
((retval[ColIndicesV] /= rhs), ...);
return retval;
} }
/// ///
@@ -451,9 +432,7 @@ struct matrix
/// \returns a copy of the matrix with each component having been divided by the scalar /// \returns a copy of the matrix with each component having been divided by the scalar
constexpr friend matrix_t operator/(scalar_t lhs, const matrix_t& rhs) constexpr friend matrix_t operator/(scalar_t lhs, const matrix_t& rhs)
{ {
matrix_t retval = rhs; return matrix_t(lhs / rhs[ColIndicesV] ...);
((retval[ColIndicesV] /= lhs), ...);
return retval;
} }
@@ -607,8 +586,9 @@ struct matrix
/// \param rhs the vector /// \param rhs the vector
/// \returns a vector containing the dot products of \f$rhs\f$ with each row of \f$lhs\f$ /// \returns a vector containing the dot products of \f$rhs\f$ with each row of \f$lhs\f$
constexpr friend column_t operator*(const matrix_t& lhs, const row_t& rhs) constexpr friend column_t operator*(const matrix_t& lhs, const row_t& rhs)
{ return [lhs, rhs]<size_t...i>(index_sequence<i...>) -> column_t {
{ return column_t(fennec::dot(fennec::row(lhs, i), rhs) ...); }(make_index_sequence<rows>{}); } return __mul(lhs, rhs);
}
/// ///
/// \brief performs a linear algebraic multiply /// \brief performs a linear algebraic multiply
@@ -616,7 +596,7 @@ struct matrix
/// \param rhs the matrix /// \param rhs the matrix
/// \returns a vector containing the dot products of \f$lhs\f$ with each column of \f$rhs\f$ /// \returns a vector containing the dot products of \f$lhs\f$ with each column of \f$rhs\f$
constexpr friend row_t operator*(const column_t& lhs, const matrix_t& rhs) constexpr friend row_t operator*(const column_t& lhs, const matrix_t& rhs)
{ return row_t(fennec::dot(fennec::column(rhs, ColIndicesV), lhs) ...); } { return row_t(fennec::dot(fennec::column(rhs, ColIndicesV), lhs) ...); }
/// @} /// @}
@@ -647,11 +627,12 @@ struct matrix
/// \brief performs a linear algebraic matrix multiplication /// \brief performs a linear algebraic matrix multiplication
/// \param lhs the rows to multiply with /// \param lhs the rows to multiply with
/// \param rhs the columns to multiply with /// \param rhs the columns to multiply with
constexpr friend matrix_t operator*(const matrix_t& lhs, const transpose_t& rhs) template<size_t ORowsV, size_t...OColIndicesV> requires(columns == ORowsV)
constexpr friend matrix<scalar_t, RowsV, OColIndicesV...> operator*(const matrix_t& lhs, const matrix<scalar_t, ORowsV, OColIndicesV...>& rhs)
{ {
return [lhs, rhs]<size_t...i>(index_sequence<i...>) -> matrix_t { return matrix<scalar_t, RowsV, OColIndicesV...>(
return matrix_t(rhs * fennec::row(lhs, i)...); matrix::__mul(lhs, rhs[OColIndicesV])...
}(make_index_sequence<rows>{}); );
} }
/// @} /// @}
@@ -660,36 +641,53 @@ struct matrix
// Helpers ============================================================================================================= // Helpers =============================================================================================================
public:
static constexpr matrix_t transpose(const transpose_t& mat)
{ return matrix_t(fennec::row(mat, ColIndicesV)...); }
private: private:
// ReSharper disable once CppMemberFunctionMayBeStatic
template<size_t i0 = 0> template<size_t i0 = 0>
constexpr void __construct() { } constexpr void __construct() { } // base case, does nothing, this will get optimized away
template<size_t i0 = 0, typename HeadT, typename...ArgsT> // helper for parsing parameter packs
constexpr void __construct(HeadT&& head, ArgsT&&...args) template<size_t i0 = 0, typename HeadT, typename...RestT>
constexpr void __construct(HeadT&& head, RestT&&...rest)
{ {
matrix::__insert<i0>(head); matrix::__insert<i0>(head); // insert the head element
matrix::__construct<i0 + component_count_v<HeadT>>(std::forward<ArgsT>(args)...); matrix::__construct<i0 + component_count_v<HeadT>>(std::forward<RestT>(rest)...); // propagate to the rest of the arguments
} }
// helper for inserting a scalar value
template<size_t i0 = 0> template<size_t i0 = 0>
constexpr void __insert(scalar_t s) constexpr void __insert(scalar_t s)
{ data[i0 / rows][i0 % rows] = s; } { data[i0 / rows][i0 % rows] = s; }
// helper for inserting a scalar value of differing type
template<size_t i0 = 0, typename OScalarT> requires(is_arithmetic_v<OScalarT>) template<size_t i0 = 0, typename OScalarT> requires(is_arithmetic_v<OScalarT>)
constexpr void __insert(OScalarT s) constexpr void __insert(OScalarT s)
{ data[i0 / rows][i0 % rows] = scalar_t(s); } { data[i0 / rows][i0 % rows] = scalar_t(s); }
// helper for inserting a vector
template<size_t i0 = 0, size_t...i> template<size_t i0 = 0, size_t...i>
constexpr void __insert(const vector<scalar_t, i...>& v) constexpr void __insert(const vector<scalar_t, i...>& v)
{ (matrix::__insert<i0 + i>(v[i]), ...); } { (matrix::__insert<i0 + i>(v[i]), ...); }
// helper for inserting a vector of differing type
template<size_t i0 = 0, typename OScalarT, size_t...i> template<size_t i0 = 0, typename OScalarT, size_t...i>
constexpr void __insert(const vector<OScalarT, i...>& v) constexpr void __insert(const vector<OScalarT, i...>& v)
{ (matrix::__insert<i0 + i>(v[i]), ...); } { (matrix::__insert<i0 + i>(v[i]), ...); }
// helper for a linear algebraic multiply
static constexpr column_t __mul(const matrix_t& lhs, const row_t& rhs)
{
// the compiler will optimize this better than writing out a specific definition
// when compared to glm or CxxSwizzle, this is faster by a significant margin
// all implementations provide 7 decimal places of precision
return ((lhs[ColIndicesV] * rhs[ColIndicesV]) + ...);
}
}; };

View File

@@ -631,6 +631,15 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
/// \name \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" Arithmetic operators /// \name \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" Arithmetic operators
/// @{ /// @{
///
/// \brief negation operator
///
/// \details
/// \param x the vector
/// \returns A \ref fennec_math_vector "vector" \a v such that, \f$v_i=-x_i\f$
constexpr friend vector_t operator-(const vector_t& x)
{ return vector((-x[IndicesV]) ...); }
/// ///
/// \brief \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" addition operator /// \brief \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" addition operator
/// ///
@@ -743,6 +752,15 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
/// \name Boolean Operators /// \name Boolean Operators
/// @{ /// @{
///
/// \brief unary boolean not operator
///
/// \details
/// \param v the vector
/// \returns A \ref fennec_math_vector "vector" \a v such that, \f$v_i=!x_i\f$
constexpr friend vector_t operator!(const vector_t& x)
{ return vector_t(!x[IndicesV] ...); }
/// ///
/// \brief \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" logical and operator /// \brief \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" logical and operator
/// ///

View File

@@ -26,5 +26,7 @@ void __assert_impl(const char* expression, const char* file, int line, const cha
{ {
__assert_callback(expression, file, line, function); __assert_callback(expression, file, line, function);
#ifndef NDEBUG
abort(); abort();
#endif
} }

View File

@@ -34,6 +34,207 @@ namespace test
inline void fennec_test_math_matrix() inline void fennec_test_math_matrix()
{ {
fennec_test_section("component_count");
fennec_test_spacer(1);
fennec_test_run((component_count_v<mat2x2> == 4), true);
fennec_test_run((component_count_v<mat2x3> == 6), true);
fennec_test_run((component_count_v<mat3x2> == 6), true);
fennec_test_run((component_count_v<mat3x3> == 9), true);
fennec_test_run((component_count_v<mat3x4> == 12), true);
fennec_test_run((component_count_v<mat4x3> == 12), true);
fennec_test_run((component_count_v<mat4x4> == 16), true);
fennec_test_spacer(1);
fennec_test_run((component_count_v<mat2x2&> == 4), true);
fennec_test_run((component_count_v<mat2x3&> == 6), true);
fennec_test_run((component_count_v<mat3x2&> == 6), true);
fennec_test_run((component_count_v<mat3x3&> == 9), true);
fennec_test_run((component_count_v<mat3x4&> == 12), true);
fennec_test_run((component_count_v<mat4x3&> == 12), true);
fennec_test_run((component_count_v<mat4x4&> == 16), true);
fennec_test_spacer(1);
fennec_test_run((component_count_v<mat2x2&&> == 4), true);
fennec_test_run((component_count_v<mat2x3&&> == 6), true);
fennec_test_run((component_count_v<mat3x2&&> == 6), true);
fennec_test_run((component_count_v<mat3x3&&> == 9), true);
fennec_test_run((component_count_v<mat3x4&&> == 12), true);
fennec_test_run((component_count_v<mat4x3&&> == 12), true);
fennec_test_run((component_count_v<mat4x4&&> == 16), true);
fennec_test_spacer(1);
fennec_test_run((component_count_v<const mat2x2&> == 4), true);
fennec_test_run((component_count_v<const mat2x3&> == 6), true);
fennec_test_run((component_count_v<const mat3x2&> == 6), true);
fennec_test_run((component_count_v<const mat3x3&> == 9), true);
fennec_test_run((component_count_v<const mat3x4&> == 12), true);
fennec_test_run((component_count_v<const mat4x3&> == 12), true);
fennec_test_run((component_count_v<const mat4x4&> == 16), true);
fennec_test_spacer(2);
fennec_test_run((component_count_v<dmat2x2> == 4), true);
fennec_test_run((component_count_v<dmat2x3> == 6), true);
fennec_test_run((component_count_v<dmat3x2> == 6), true);
fennec_test_run((component_count_v<dmat3x3> == 9), true);
fennec_test_run((component_count_v<dmat3x4> == 12), true);
fennec_test_run((component_count_v<dmat4x3> == 12), true);
fennec_test_run((component_count_v<dmat4x4> == 16), true);
fennec_test_spacer(1);
fennec_test_run((component_count_v<dmat2x2&> == 4), true);
fennec_test_run((component_count_v<dmat2x3&> == 6), true);
fennec_test_run((component_count_v<dmat3x2&> == 6), true);
fennec_test_run((component_count_v<dmat3x3&> == 9), true);
fennec_test_run((component_count_v<dmat3x4&> == 12), true);
fennec_test_run((component_count_v<dmat4x3&> == 12), true);
fennec_test_run((component_count_v<dmat4x4&> == 16), true);
fennec_test_spacer(1);
fennec_test_run((component_count_v<dmat2x2&&> == 4), true);
fennec_test_run((component_count_v<dmat2x3&&> == 6), true);
fennec_test_run((component_count_v<dmat3x2&&> == 6), true);
fennec_test_run((component_count_v<dmat3x3&&> == 9), true);
fennec_test_run((component_count_v<dmat3x4&&> == 12), true);
fennec_test_run((component_count_v<dmat4x3&&> == 12), true);
fennec_test_run((component_count_v<dmat4x4&&> == 16), true);
fennec_test_spacer(1);
fennec_test_run((component_count_v<const dmat2x2&> == 4), true);
fennec_test_run((component_count_v<const dmat2x3&> == 6), true);
fennec_test_run((component_count_v<const dmat3x2&> == 6), true);
fennec_test_run((component_count_v<const dmat3x3&> == 9), true);
fennec_test_run((component_count_v<const dmat3x4&> == 12), true);
fennec_test_run((component_count_v<const dmat4x3&> == 12), true);
fennec_test_run((component_count_v<const dmat4x4&> == 16), true);
fennec_test_spacer(2);
fennec_test_header("matrix equality operators");
fennec_test_spacer(1);
fennec_test_run(mat2() == mat2(), true);
fennec_test_run(mat3() == mat3(), true);
fennec_test_run(mat4() == mat4(), true);
fennec_test_spacer(1);
fennec_test_run(mat2() != mat2(), false);
fennec_test_run(mat3() != mat3(), false);
fennec_test_run(mat4() != mat4(), false);
fennec_test_spacer(2);
fennec_test_header("matrix constructors");
fennec_test_spacer(1);
fennec_test_run(mat2(), mat2(0));
fennec_test_run(mat3(), mat3(0));
fennec_test_run(mat4(), mat4(0));
fennec_test_spacer(1);
fennec_test_run(mat2(1), mat2(1, 0, 0, 1));
fennec_test_run(mat3(1), mat3(1, 0, 0, 0, 1, 0, 0, 0, 1));
fennec_test_run(mat4(1), mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1));
fennec_test_spacer(2);
fennec_test_header("matrix-scalar operators");
fennec_test_spacer(1);
fennec_test_run(mat2x2(1, 2, 3, 4) * 2, mat2x2(2, 4, 6, 8));
fennec_test_run(mat2x3(1, 2, 3, 4, 5, 6) * 2, mat2x3(2, 4, 6, 8, 10, 12));
fennec_test_run(mat3x2(1, 2, 3, 4, 5, 6) * 2, mat3x2(2, 4, 6, 8, 10, 12));
fennec_test_run(mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9) * 2, mat3x3(2, 4, 6, 8, 10, 12, 14, 16, 18));
fennec_test_spacer(2);
fennec_test_header("matrix-vector operators");
fennec_test_spacer(1);
fennec_test_run(vec2(1, 2) * mat2x2(1, 2, 3, 4), vec2(5, 11));
fennec_test_run(vec2(1, 2) * mat3x2(1, 2, 3, 4, 5, 6), vec3(5, 11, 17));
fennec_test_run(vec2(1, 2) * mat4x2(1, 2, 3, 4, 5, 6, 7, 8), vec4(5, 11, 17, 23));
fennec_test_spacer(1);
fennec_test_run(vec3(1, 2, 3) * mat2x3(1, 2, 3, 4, 5, 6), vec2(14, 32));
fennec_test_run(vec3(1, 2, 3) * mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9), vec3(14, 32, 50));
fennec_test_run(vec3(1, 2, 3) * mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), vec4(14, 32, 50, 68));
fennec_test_spacer(2);
fennec_test_header("matrix-matrix operators");
fennec_test_spacer(1);
fennec_test_run(mat2x2(1, 2, 3, 4) * mat2x2(1, 2, 3, 4), mat2x2(7, 10, 15, 22));
fennec_test_run(mat2x2(1, 2, 3, 4) * mat3x2(1, 2, 3, 4, 5, 6), mat3x2(7, 10, 15, 22, 23, 34));
fennec_test_run(mat2x2(1, 2, 3, 4) * mat4x2(1, 2, 3, 4, 5, 6, 7, 8), mat4x2(7, 10, 15, 22, 23, 34, 31, 46));
fennec_test_spacer(1);
fennec_test_run(mat2x3(1, 2, 3, 4, 5, 6) * mat2x2(1, 2, 3, 4), mat2x3(9, 12, 15, 19, 26, 33));
fennec_test_run(mat2x3(1, 2, 3, 4, 5, 6) * mat3x2(1, 2, 3, 4, 5, 6), mat3x3(9, 12, 15, 19, 26, 33, 29, 40, 51));
fennec_test_run(mat2x3(1, 2, 3, 4, 5, 6) * mat4x2(1, 2, 3, 4, 5, 6, 7, 8), mat4x3(9, 12, 15, 19, 26, 33, 29, 40, 51, 39, 54, 69));
fennec_test_spacer(1);
fennec_test_run(mat3x2(1, 2, 3, 4, 5, 6) * mat2x3(1, 2, 3, 4, 5, 6), mat2x2(22, 28, 49, 64));
fennec_test_run(mat3x2(1, 2, 3, 4, 5, 6) * mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9), mat3x2(22, 28, 49, 64, 76, 100));
fennec_test_run(mat3x2(1, 2, 3, 4, 5, 6) * mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), mat4x2(22, 28, 49, 64, 76, 100, 103, 136));
fennec_test_spacer(1);
fennec_test_run(mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9) * mat2x3(1, 2, 3, 4, 5, 6), mat2x3(30, 36, 42, 66, 81, 96));
fennec_test_run(mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9) * mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9), mat3x3(30, 36, 42, 66, 81, 96, 102, 126, 150));
fennec_test_run(mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9) * mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), mat4x3(30, 36, 42, 66, 81, 96, 102, 126, 150, 138, 171, 204));
fennec_test_spacer(1);
fennec_test_run(mat3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) * mat2x3(1, 2, 3, 4, 5, 6), mat2x4(38, 44, 50, 56, 83, 98, 113, 128));
fennec_test_run(mat3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) * mat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9), mat3x4(38, 44, 50, 56, 83, 98, 113, 128, 128, 152, 176, 200));
fennec_test_run(mat3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) * mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), mat4x4(38, 44, 50, 56, 83, 98, 113, 128, 128, 152, 176, 200, 173, 206, 239, 272));
fennec_test_spacer(1);
fennec_test_run(mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) * mat2x4(1, 2, 3, 4, 5, 6, 7, 8), mat2x3(70, 80, 90, 158, 184, 210));
fennec_test_run(mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) * mat3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), mat3x3(70, 80, 90, 158, 184, 210, 246, 288, 330));
fennec_test_run(mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) * mat4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), mat4x3(70, 80, 90, 158, 184, 210, 246, 288, 330, 334, 392, 450));
fennec_test_spacer(1);
fennec_test_run(mat4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) * mat2x4(1, 2, 3, 4, 5, 6, 7, 8), mat2x4(90, 100, 110, 120, 202, 228, 254, 280));
fennec_test_run(mat4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) * mat3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), mat3x4(90, 100, 110, 120, 202, 228, 254, 280, 314,356,398,440));
fennec_test_run(mat4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) * mat4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), mat4x4(90, 100, 110, 120, 202, 228, 254, 280, 314, 356, 398, 440, 426, 484, 542, 600));
fennec_test_spacer(2);
fennec_test_section("matrixCompMult"); fennec_test_section("matrixCompMult");
fennec_test_spacer(1); fennec_test_spacer(1);
@@ -42,7 +243,7 @@ inline void fennec_test_math_matrix()
fennec_test_run(fennec::matrixCompMult(mat3(1, 4, 8, 6, 2, 5, 9, 7, 3), mat3(1)), mat3(1, 0, 0, 0, 2, 0, 0, 0, 3)); fennec_test_run(fennec::matrixCompMult(mat3(1, 4, 8, 6, 2, 5, 9, 7, 3), mat3(1)), mat3(1, 0, 0, 0, 2, 0, 0, 0, 3));
fennec_test_run(fennec::matrixCompMult(mat4(2, 1, -3, 4, -1, 0, 2, 5, 3, 2, 1, 0, 4, -2, 3, 1), mat4(1)), mat4(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)); fennec_test_run(fennec::matrixCompMult(mat4(2, 1, -3, 4, -1, 0, 2, 5, 3, 2, 1, 0, 4, -2, 3, 1), mat4(1)), mat4(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1));
fennec_test_spacer(1); fennec_test_spacer(2);
@@ -51,25 +252,25 @@ inline void fennec_test_math_matrix()
fennec_test_spacer(1); fennec_test_spacer(1);
fennec_test_run(fennec::outerProduct(vec2(1, 2), vec2(3, 4)), mat2(3, 6, 4, 8)); fennec_test_run(fennec::outerProduct(vec2(1, 2), vec2(3, 4)), mat2(3, 6, 4, 8));
fennec_test_run(fennec::outerProduct(vec3(1, 2, 3), vec3(4, 5, 6)), mat3(4, 8, 12, 5, 10, 15, 6, 12, 18)); fennec_test_run(fennec::outerProduct(vec3(1, 2, 3), vec3(4, 5, 6)), mat3(4, 8, 12, 5, 10, 15, 6, 12, 18));
fennec_test_run(fennec::outerProduct(vec4(1, 2, 3, 4), vec4(5, 6, 7, 8)), mat4(5, 10, 15, 20, 6, 12, 18, 24, 7, 14, 21, 28, 8, 16, 24, 32)); fennec_test_run(fennec::outerProduct(vec4(1, 2, 3, 4), vec4(5, 6, 7, 8)), mat4(5, 10, 15, 20, 6, 12, 18, 24, 7, 14, 21, 28, 8, 16, 24, 32));
fennec_test_spacer(1); fennec_test_spacer(1);
fennec_test_run(fennec::outerProduct(vec3(1, 2, 3), vec2(4, 5)), mat2x3(4, 8, 12, 5, 10, 15)); fennec_test_run(fennec::outerProduct(vec3(1, 2, 3), vec2(4, 5)), mat2x3(4, 8, 12, 5, 10, 15));
fennec_test_run(fennec::outerProduct(vec2(1, 2), vec3(3, 4, 5)), mat3x2(3, 6, 4, 8, 5, 10)); fennec_test_run(fennec::outerProduct(vec2(1, 2), vec3(3, 4, 5)), mat3x2(3, 6, 4, 8, 5, 10));
fennec_test_spacer(1); fennec_test_spacer(1);
fennec_test_run(fennec::outerProduct(vec4(1, 2, 3, 4), vec2(5, 6)), mat2x4(5, 10, 15, 20, 6, 12, 18, 24)); fennec_test_run(fennec::outerProduct(vec4(1, 2, 3, 4), vec2(5, 6)), mat2x4(5, 10, 15, 20, 6, 12, 18, 24));
fennec_test_run(fennec::outerProduct(vec2(1, 2), vec4(3, 4, 5, 6)), mat4x2(3, 6, 4, 8, 5, 10, 6, 12)); fennec_test_run(fennec::outerProduct(vec2(1, 2), vec4(3, 4, 5, 6)), mat4x2(3, 6, 4, 8, 5, 10, 6, 12));
fennec_test_spacer(1); fennec_test_spacer(1);
fennec_test_run(fennec::outerProduct(vec4(1, 2, 3, 4), vec3(5, 6, 7)), mat3x4(5, 10, 15, 20, 6, 12, 18, 24, 7, 14, 21, 28)); fennec_test_run(fennec::outerProduct(vec4(1, 2, 3, 4), vec3(5, 6, 7)), mat3x4(5, 10, 15, 20, 6, 12, 18, 24, 7, 14, 21, 28));
fennec_test_run(fennec::outerProduct(vec3(1, 2, 3), vec4(4, 5, 6, 7)), mat4x3(4, 8, 12, 5, 10, 15, 6, 12, 18, 7, 14, 21)); fennec_test_run(fennec::outerProduct(vec3(1, 2, 3), vec4(4, 5, 6, 7)), mat4x3(4, 8, 12, 5, 10, 15, 6, 12, 18, 7, 14, 21));
fennec_test_spacer(1); fennec_test_spacer(2);
@@ -78,7 +279,7 @@ inline void fennec_test_math_matrix()
fennec_test_spacer(1); fennec_test_spacer(1);
fennec_test_run(fennec::transpose(mat2(1, 2, 3, 4)), mat2(1, 3, 2, 4)); fennec_test_run(fennec::transpose(mat2(1, 2, 3, 4)), mat2(1, 3, 2, 4));
fennec_test_run(fennec::transpose(mat3(1, 2, 3, 4, 5, 6, 7, 8, 9)), mat3(1, 4, 7, 2, 5, 8, 3, 6, 9)); fennec_test_run(fennec::transpose(mat3(1, 2, 3, 4, 5, 6, 7, 8, 9)), mat3(1, 4, 7, 2, 5, 8, 3, 6, 9));
fennec_test_run(fennec::transpose(mat4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)), mat4(1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16)); fennec_test_run(fennec::transpose(mat4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)), mat4(1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16));
fennec_test_spacer(1); fennec_test_spacer(1);
@@ -93,10 +294,10 @@ inline void fennec_test_math_matrix()
fennec_test_spacer(1); fennec_test_spacer(1);
fennec_test_run(fennec::transpose(mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), mat3x4(1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12)); fennec_test_run(fennec::transpose(mat4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), mat3x4(1, 4, 7, 10, 2, 5, 8, 11, 3, 6, 9, 12));
fennec_test_run(fennec::transpose(mat3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), mat4x3(1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12)); fennec_test_run(fennec::transpose(mat3x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), mat4x3(1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12));
fennec_test_spacer(1); fennec_test_spacer(2);
@@ -108,11 +309,13 @@ inline void fennec_test_math_matrix()
fennec_test_run(fennec::determinant(mat3(1, 4, 8, 6, 2, 5, 9, 7, 3)), 271.0f); fennec_test_run(fennec::determinant(mat3(1, 4, 8, 6, 2, 5, 9, 7, 3)), 271.0f);
fennec_test_run(fennec::determinant(mat4(2, 1, -3, 4, -1, 0, 2, 5, 3, 2, 1, 0, 4, -2, 3, 1)), 414.0f); fennec_test_run(fennec::determinant(mat4(2, 1, -3, 4, -1, 0, 2, 5, 3, 2, 1, 0, 4, -2, 3, 1)), 414.0f);
fennec_test_spacer(1); fennec_test_spacer(2);
fennec_test_section("inverse"); fennec_test_section("inverse");
fennec_test_spacer(1); fennec_test_spacer(2);
fennec_test_run(fennec::inverse(mat2(1, 2, 3, 4)), mat2(-2, 1, 1.5, -0.5)); fennec_test_run(fennec::inverse(mat2(1, 2, 3, 4)), mat2(-2, 1, 1.5, -0.5));
fennec_test_run(fennec::inverse(mat3(1, 2, 3, 0, 1, 4, 5, 6, 0)), mat3(-24, 18, 5, 20, -15, -4, -5, 4, 1)); fennec_test_run(fennec::inverse(mat3(1, 2, 3, 0, 1, 4, 5, 6, 0)), mat3(-24, 18, 5, 20, -15, -4, -5, 4, 1));

View File

@@ -403,6 +403,12 @@ inline void fennec_test_math_vector()
fennec_test_spacer(1); fennec_test_spacer(1);
fennec_test_run(not bvec2(false, false), bvec2(true, true));
fennec_test_run(not bvec3(false, false, true), bvec3(true, true, false));
fennec_test_run(not bvec4(false, false, true, true), bvec4(true, true, false, false));
fennec_test_spacer(1);
fennec_test_run(bvec2(false, false) && true, bvec2(false, false)); fennec_test_run(bvec2(false, false) && true, bvec2(false, false));
fennec_test_run(bvec3(false, false, true) && true, bvec3(false, false, true)); fennec_test_run(bvec3(false, false, true) && true, bvec3(false, false, true));
fennec_test_run(bvec4(false, false, true, true) && true, bvec4(false, false, true, true)); fennec_test_run(bvec4(false, false, true, true) && true, bvec4(false, false, true, true));