From 1573033b52357fd0347885344c573c0afc058177 Mon Sep 17 00:00:00 2001 From: Medusa Slockbower Date: Sat, 28 Jun 2025 12:09:59 -0400 Subject: [PATCH] -Removed lambda expansions due to gcc generating call instructions --- include/fennec/containers/array.h | 9 +- include/fennec/lang/assert.h | 1 + include/fennec/math/common.h | 4 +- include/fennec/math/detail/__matrix.h | 1 + include/fennec/math/geometric.h | 1 + include/fennec/math/matrix.h | 92 +++++----- include/fennec/math/vector.h | 18 ++ source/lang/assert.cpp | 2 + test/tests/math/test_matrix.h | 231 ++++++++++++++++++++++++-- test/tests/math/test_vector.h | 6 + 10 files changed, 298 insertions(+), 67 deletions(-) diff --git a/include/fennec/containers/array.h b/include/fennec/containers/array.h index 45e3f11..eb5b0b8 100644 --- a/include/fennec/containers/array.h +++ b/include/fennec/containers/array.h @@ -120,15 +120,16 @@ struct array /// /// \brief friend constexpr bool_t operator==(const array& lhs, const array& rhs) - { return [lhs, rhs](index_sequence) -> bool_t // Lambda Declaration, Creates Indices at Compile Time - { return ((lhs[i] == rhs[i]) && ...); }(make_index_sequence{}); } // Lambda Implementation, + { return array::__compare(lhs, rhs, make_index_sequence{}); } friend constexpr bool_t operator!=(const array& lhs, const array& rhs) - { return [lhs, rhs](index_sequence) -> bool_t - { return ((lhs[i] != rhs[i]) || ...); }(make_index_sequence{}); } + { return not array::__compare(lhs, rhs, make_index_sequence{}); } /// @} +private: + template + static bool __compare(const array& lhs, const array& rhs, index_sequence) { return ((lhs[i] == rhs[i]) && ...); } }; } diff --git a/include/fennec/lang/assert.h b/include/fennec/lang/assert.h index f74300a..c785a15 100644 --- a/include/fennec/lang/assert.h +++ b/include/fennec/lang/assert.h @@ -22,6 +22,7 @@ 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); + #define assert(expression) if(not(expression)) { __assert_impl(#expression, __FILE__, __LINE__, __PRETTY_FUNCTION__); } #endif // FENNEC_LANG_ASSERT_H diff --git a/include/fennec/math/common.h b/include/fennec/math/common.h index 34e5ffa..b4d0760 100644 --- a/include/fennec/math/common.h +++ b/include/fennec/math/common.h @@ -561,7 +561,7 @@ constexpr vector modf(const vector& x, vector requires(is_bool_v) constexpr genBType isnan(genType x) - { return ::isnan(x); } + { return ::isnanf(x); } // Vector Specializations ---------------------------------------------------------------------------------------------- @@ -584,7 +584,7 @@ constexpr vector isnan(const vector& x) /// \param x input value template requires(is_bool_v) constexpr genBType isinf(genType x) - { return ::isinf(x); } + { return ::isinff(x); } // Vector Specializations ---------------------------------------------------------------------------------------------- diff --git a/include/fennec/math/detail/__matrix.h b/include/fennec/math/detail/__matrix.h index c41c80b..52b5be6 100644 --- a/include/fennec/math/detail/__matrix.h +++ b/include/fennec/math/detail/__matrix.h @@ -141,6 +141,7 @@ constexpr matrix inverse(const matrix +#include #include namespace fennec diff --git a/include/fennec/math/matrix.h b/include/fennec/math/matrix.h index f562db3..a6fb0f8 100644 --- a/include/fennec/math/matrix.h +++ b/include/fennec/math/matrix.h @@ -154,11 +154,7 @@ constexpr matrix outerProduct(const vector constexpr mat transpose(const matrix& m) noexcept -{ - return [m](index_sequence) -> mat { - return mat(fennec::row(m, i) ...); - }(make_index_sequence{}); -} +{ return mat::transpose(m); } /// /// \brief Returns the determinant of m. @@ -225,7 +221,7 @@ struct matrix /// /// \brief alias for the transpose matrix type - using transpose_t = mat; + using transpose_t = mat; /// @@ -244,8 +240,7 @@ struct matrix /// \brief default constructor, initializes elements with 0 /// /// \details - constexpr matrix() - : data{ scalar_t(0) }{} + constexpr matrix() = default; /// @@ -329,7 +324,7 @@ struct matrix /// /// \copydetails matrix::operator[](size_t) const 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$ @@ -367,9 +362,7 @@ struct matrix /// \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) { - matrix_t retval = lhs; - ((retval[ColIndicesV] += rhs), ...); - return retval; + return matrix_t(lhs[ColIndicesV] + rhs ...); } /// @@ -379,9 +372,7 @@ struct matrix /// \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) { - matrix_t retval = rhs; - ((retval[ColIndicesV] += lhs), ...); - return retval; + return matrix_t(lhs + rhs[ColIndicesV] ...); } /// @@ -391,9 +382,7 @@ struct matrix /// \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) { - matrix_t retval = lhs; - ((retval[ColIndicesV] -= rhs), ...); - return retval; + return matrix_t(lhs[ColIndicesV] - rhs ...); } /// @@ -403,9 +392,7 @@ struct matrix /// \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) { - matrix_t retval = rhs; - ((retval[ColIndicesV] -= lhs), ...); - return retval; + return matrix_t(lhs - rhs[ColIndicesV] ...); } /// @@ -415,9 +402,7 @@ struct matrix /// \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) { - matrix_t retval = lhs; - ((retval[ColIndicesV] *= rhs), ...); - return retval; + return matrix_t(lhs[ColIndicesV] * rhs ...); } /// @@ -427,9 +412,7 @@ struct matrix /// \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) { - matrix_t retval = rhs; - ((retval[ColIndicesV] *= lhs), ...); - return retval; + return matrix_t(lhs * rhs[ColIndicesV] ...); } /// @@ -439,9 +422,7 @@ struct matrix /// \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) { - matrix_t retval = lhs; - ((retval[ColIndicesV] /= rhs), ...); - return retval; + return matrix_t(lhs[ColIndicesV] / rhs ...); } /// @@ -451,9 +432,7 @@ struct matrix /// \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) { - matrix_t retval = rhs; - ((retval[ColIndicesV] /= lhs), ...); - return retval; + return matrix_t(lhs / rhs[ColIndicesV] ...); } @@ -607,8 +586,9 @@ struct matrix /// \param rhs the vector /// \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) - { return [lhs, rhs](index_sequence) -> column_t - { return column_t(fennec::dot(fennec::row(lhs, i), rhs) ...); }(make_index_sequence{}); } + { + return __mul(lhs, rhs); + } /// /// \brief performs a linear algebraic multiply @@ -616,7 +596,7 @@ struct matrix /// \param rhs the matrix /// \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) - { 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 /// \param lhs the rows to multiply with /// \param rhs the columns to multiply with - constexpr friend matrix_t operator*(const matrix_t& lhs, const transpose_t& rhs) + template requires(columns == ORowsV) + constexpr friend matrix operator*(const matrix_t& lhs, const matrix& rhs) { - return [lhs, rhs](index_sequence) -> matrix_t { - return matrix_t(rhs * fennec::row(lhs, i)...); - }(make_index_sequence{}); + return matrix( + matrix::__mul(lhs, rhs[OColIndicesV])... + ); } /// @} @@ -660,36 +641,53 @@ struct matrix // Helpers ============================================================================================================= +public: + + static constexpr matrix_t transpose(const transpose_t& mat) + { return matrix_t(fennec::row(mat, ColIndicesV)...); } + private: + // ReSharper disable once CppMemberFunctionMayBeStatic template - constexpr void __construct() { } + constexpr void __construct() { } // base case, does nothing, this will get optimized away - template - constexpr void __construct(HeadT&& head, ArgsT&&...args) + // helper for parsing parameter packs + template + constexpr void __construct(HeadT&& head, RestT&&...rest) { - matrix::__insert(head); - matrix::__construct>(std::forward(args)...); + matrix::__insert(head); // insert the head element + matrix::__construct>(std::forward(rest)...); // propagate to the rest of the arguments } + // helper for inserting a scalar value template constexpr void __insert(scalar_t s) { data[i0 / rows][i0 % rows] = s; } - + // helper for inserting a scalar value of differing type template requires(is_arithmetic_v) constexpr void __insert(OScalarT s) { data[i0 / rows][i0 % rows] = scalar_t(s); } - + // helper for inserting a vector template constexpr void __insert(const vector& v) { (matrix::__insert(v[i]), ...); } + // helper for inserting a vector of differing type template constexpr void __insert(const vector& v) { (matrix::__insert(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]) + ...); + } }; diff --git a/include/fennec/math/vector.h b/include/fennec/math/vector.h index b527a3b..0d936ec 100644 --- a/include/fennec/math/vector.h +++ b/include/fennec/math/vector.h @@ -631,6 +631,15 @@ struct vector : detail::vector_base_type /// \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 /// @@ -743,6 +752,15 @@ struct vector : detail::vector_base_type /// \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 /// diff --git a/source/lang/assert.cpp b/source/lang/assert.cpp index 01a576d..aa02e7e 100644 --- a/source/lang/assert.cpp +++ b/source/lang/assert.cpp @@ -26,5 +26,7 @@ void __assert_impl(const char* expression, const char* file, int line, const cha { __assert_callback(expression, file, line, function); +#ifndef NDEBUG abort(); +#endif } \ No newline at end of file diff --git a/test/tests/math/test_matrix.h b/test/tests/math/test_matrix.h index 828fe04..d0a7c04 100644 --- a/test/tests/math/test_matrix.h +++ b/test/tests/math/test_matrix.h @@ -34,6 +34,207 @@ namespace test inline void fennec_test_math_matrix() { + fennec_test_section("component_count"); + + fennec_test_spacer(1); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 16), true); + + fennec_test_spacer(1); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 16), true); + + fennec_test_spacer(1); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 16), true); + + fennec_test_spacer(1); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 16), true); + + fennec_test_spacer(2); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 16), true); + + fennec_test_spacer(1); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 16), true); + + fennec_test_spacer(1); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 16), true); + + fennec_test_spacer(1); + + fennec_test_run((component_count_v == 4), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 6), true); + fennec_test_run((component_count_v == 9), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 12), true); + fennec_test_run((component_count_v == 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_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(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_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(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(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_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(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_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_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(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_spacer(1); + fennec_test_spacer(2); @@ -78,7 +279,7 @@ inline void fennec_test_math_matrix() fennec_test_spacer(1); 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_spacer(1); @@ -93,10 +294,10 @@ inline void fennec_test_math_matrix() 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(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(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_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(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_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(mat3(1, 2, 3, 0, 1, 4, 5, 6, 0)), mat3(-24, 18, 5, 20, -15, -4, -5, 4, 1)); diff --git a/test/tests/math/test_vector.h b/test/tests/math/test_vector.h index 2d271bd..e876fdf 100644 --- a/test/tests/math/test_vector.h +++ b/test/tests/math/test_vector.h @@ -403,6 +403,12 @@ inline void fennec_test_math_vector() 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(bvec3(false, false, true) && true, bvec3(false, false, true)); fennec_test_run(bvec4(false, false, true, true) && true, bvec4(false, false, true, true));