additional matrix ctos from matrix and vector

This commit is contained in:
BlackMATov
2020-12-04 23:31:22 +07:00
parent eac4ad5437
commit 9767efbb1a
3 changed files with 35 additions and 0 deletions

View File

@@ -248,6 +248,10 @@ public:
const row_type& row1,
const row_type& row2);
constexpr mat_base(
const mat_base<T, 2>& m,
const vec_base<T, 2>& v);
constexpr explicit mat_base(const mat_base<T, 2>& other);
constexpr explicit mat_base(const mat_base<T, 4>& other);
};
@@ -279,6 +283,10 @@ public:
const row_type& row2,
const row_type& row3);
constexpr mat_base(
const mat_base<T, 3>& m,
const vec_base<T, 3>& v);
constexpr explicit mat_base(const mat_base<T, 2>& other);
constexpr explicit mat_base(const mat_base<T, 3>& other);
};

View File

@@ -99,6 +99,14 @@ namespace vmath_hpp::detail
const row_type& row2)
: rows{row0, row1, row2} {}
constexpr mat_base(
const mat_base<T, 2>& m,
const vec_base<T, 2>& v)
: rows{
row_type{m.rows[0], 0},
row_type{m.rows[1], 0},
row_type{v, 1}} {}
constexpr explicit mat_base(
const mat_base<T, 2>& other)
: rows{
@@ -158,6 +166,15 @@ namespace vmath_hpp::detail
const row_type& row3)
: rows{row0, row1, row2, row3} {}
constexpr mat_base(
const mat_base<T, 3>& m,
const vec_base<T, 3>& v)
: rows{
row_type{m.rows[0], 0},
row_type{m.rows[1], 0},
row_type{m.rows[2], 0},
row_type{v, 1}} {}
constexpr explicit mat_base(
const mat_base<T, 2>& other)
: rows{
@@ -281,6 +298,9 @@ namespace vmath_hpp
template < typename T >
mat(const vec<T, 3>&, const vec<T, 3>&, const vec<T, 3>&) -> mat<T, 3>;
template < typename T >
mat(const mat<T, 2>&, const vec<T, 2>&) -> mat<T, 3>;
template < typename T >
mat(std::initializer_list<T>, std::initializer_list<T>, std::initializer_list<T>) -> mat<T, 3>;
@@ -292,6 +312,9 @@ namespace vmath_hpp
template < typename T >
mat(const vec<T, 4>&, const vec<T, 4>&, const vec<T, 4>&, const vec<T, 4>&) -> mat<T, 4>;
template < typename T >
mat(const mat<T, 3>&, const vec<T, 3>&) -> mat<T, 4>;
template < typename T >
mat(std::initializer_list<T>, std::initializer_list<T>, std::initializer_list<T>, std::initializer_list<T>) -> mat<T, 4>;

View File

@@ -32,10 +32,12 @@ TEST_CASE("vmath/mat") {
STATIC_REQUIRE(mat{1,2,3,4,5,6,7,8,9}.size == 3);
STATIC_REQUIRE(mat{{1,2,3},{4,5,6},{7,8,9}}.size == 3);
STATIC_REQUIRE(mat{vec{1,2,3},vec{4,5,6},vec{7,8,9}}.size == 3);
STATIC_REQUIRE(mat{mat{1,2,3,4},vec{5,6}}.size == 3);
STATIC_REQUIRE(mat{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}.size == 4);
STATIC_REQUIRE(mat{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}.size == 4);
STATIC_REQUIRE(mat{vec{1,2,3,4},vec{5,6,7,8},vec{9,10,11,12},vec{13,14,15,16}}.size == 4);
STATIC_REQUIRE(mat{mat{1,2,3,4,5,6,7,8,9},vec{5,6,7}}.size == 4);
}
SUBCASE("ctors") {
@@ -74,6 +76,7 @@ TEST_CASE("vmath/mat") {
STATIC_REQUIRE(int3x3(int3{2,3,4}) == int3x3(2,0,0,0,3,0,0,0,4));
STATIC_REQUIRE(int3x3(1,2,3,4,5,6,7,8,9) == int3x3(1,2,3,4,5,6,7,8,9));
STATIC_REQUIRE(int3x3({1,2,3},{4,5,6},{7,8,9}) == int3x3(1,2,3,4,5,6,7,8,9));
STATIC_REQUIRE(int3x3(int2x2({1,2},{3,4}),int2{5,6}) == int3x3(1,2,0,3,4,0,5,6,1));
STATIC_REQUIRE(int3x3(int3x3({1,2,3},{4,5,6},{7,8,9})) == int3x3(1,2,3,4,5,6,7,8,9));
STATIC_REQUIRE(int3x3(int2x2({1,2},{3,4})) == int3x3(1,2,0,3,4,0,0,0,1));
STATIC_REQUIRE(int3x3(int4x4({1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16})) == int3x3(1,2,3,5,6,7,9,10,11));
@@ -83,6 +86,7 @@ TEST_CASE("vmath/mat") {
STATIC_REQUIRE(int4x4(int4{2,3,4,5}) == int4x4(2,0,0,0,0,3,0,0,0,0,4,0,0,0,0,5));
STATIC_REQUIRE(int4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) == int4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16));
STATIC_REQUIRE(int4x4({1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}) == int4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16));
STATIC_REQUIRE(int4x4(int3x3({1,2,3},{4,5,6},{7,8,9}),int3{10,11,12}) == int4x4(1,2,3,0,4,5,6,0,7,8,9,0,10,11,12,1));
STATIC_REQUIRE(int4x4(int4x4({1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16})) == int4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16));
STATIC_REQUIRE(int4x4(int2x2({1,2},{3,4})) == int4x4(1,2,0,0,3,4,0,0,0,0,1,0,0,0,0,1));
STATIC_REQUIRE(int4x4(int3x3({1,2,3},{4,5,6},{7,8,9})) == int4x4(1,2,3,0,4,5,6,0,7,8,9,0,0,0,0,1));