mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-13 04:06:52 +07:00
add ctors from mem
This commit is contained in:
14
README.md
14
README.md
@@ -99,6 +99,8 @@ public:
|
||||
template < typename U > vec_base(const vec_base<U, 2>& other);
|
||||
template < typename U > explicit vec_base(const vec_base<U, 3>& other);
|
||||
template < typename U > explicit vec_base(const vec_base<U, 4>& other);
|
||||
|
||||
template < typename U > explicit vec_base(const U* p);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -120,6 +122,8 @@ public:
|
||||
|
||||
template < typename U > vec_base(const vec_base<U, 3>& other);
|
||||
template < typename U > explicit vec_base(const vec_base<U, 4>& other);
|
||||
|
||||
template < typename U > explicit vec_base(const U* p);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -145,6 +149,8 @@ public:
|
||||
vec_base(T x, const vec_base<T, 3>& yzw);
|
||||
|
||||
template < typename U > vec_base(const vec_base<U, 4>& other);
|
||||
|
||||
template < typename U > explicit vec_base(const U* p);
|
||||
};
|
||||
|
||||
template < typename T, size_t Size >
|
||||
@@ -248,6 +254,8 @@ public:
|
||||
template < typename U > mat_base(const mat_base<U, 2>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 3>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 4>& other);
|
||||
|
||||
template < typename U > explicit mat_base(const U* p);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -283,6 +291,8 @@ public:
|
||||
template < typename U > mat_base(const mat_base<U, 3>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 2>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 4>& other);
|
||||
|
||||
template < typename U > explicit mat_base(const U* p);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -320,6 +330,8 @@ public:
|
||||
template < typename U > mat_base(const mat_base<U, 4>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 2>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 3>& other);
|
||||
|
||||
template < typename U > explicit mat_base(const U* p);
|
||||
};
|
||||
|
||||
template < typename T, size_t Size >
|
||||
@@ -413,6 +425,8 @@ public:
|
||||
|
||||
template < typename U > qua_base(const qua_base<U, 4>& other);
|
||||
template < typename U > explicit operator vec<U, 4>() const;
|
||||
|
||||
template < typename U > explicit qua_base(const U* p);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
|
||||
@@ -66,6 +66,11 @@ namespace vmath_hpp::detail
|
||||
constexpr explicit mat_base(const mat_base<U, 4>& other): mat_base(
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]}) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const U* p): mat_base(
|
||||
row_type{p + 0u * row_type::size},
|
||||
row_type{p + 1u * row_type::size}) {}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -134,6 +139,12 @@ namespace vmath_hpp::detail
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]},
|
||||
row_type{other.rows[2]}) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const U* p): mat_base(
|
||||
row_type{p + 0u * row_type::size},
|
||||
row_type{p + 1u * row_type::size},
|
||||
row_type{p + 2u * row_type::size}) {}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -211,6 +222,13 @@ namespace vmath_hpp::detail
|
||||
row_type{other.rows[1], T{0}},
|
||||
row_type{other.rows[2], T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, T{1}}) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const U* p): mat_base(
|
||||
row_type{p + 0u * row_type::size},
|
||||
row_type{p + 1u * row_type::size},
|
||||
row_type{p + 2u * row_type::size},
|
||||
row_type{p + 3u * row_type::size}) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ namespace vmath_hpp::detail
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<T, U>, int> = 0 >
|
||||
constexpr explicit operator vec<U, 4>() const { return vec<U, 4>(v, s); }
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit qua_base(const U* p): qua_base(p[0], p[1], p[2], p[3]) {}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
default:
|
||||
|
||||
@@ -37,6 +37,9 @@ namespace vmath_hpp::detail
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const vec_base<U, 4>& other): vec_base(other[0], other[1]) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const U* p): vec_base(p[0], p[1]) {}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
default:
|
||||
@@ -78,6 +81,9 @@ namespace vmath_hpp::detail
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const vec_base<U, 4>& other): vec_base(other[0], other[1], other[2]) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const U* p): vec_base(p[0], p[1], p[2]) {}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
default:
|
||||
@@ -123,6 +129,9 @@ namespace vmath_hpp::detail
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr vec_base(const vec_base<U, 4>& other): vec_base(other[0], other[1], other[2], other[3]) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const U* p): vec_base(p[0], p[1], p[2], p[3]) {}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
default:
|
||||
|
||||
@@ -126,6 +126,12 @@ TEST_CASE("vmath/mat") {
|
||||
STATIC_CHECK(imat4(imat2({1,2},{3,4})) == imat4(1,2,0,0,3,4,0,0,0,0,1,0,0,0,0,1));
|
||||
STATIC_CHECK(imat4(imat3({1,2,3},{4,5,6},{7,8,9})) == imat4(1,2,3,0,4,5,6,0,7,8,9,0,0,0,0,1));
|
||||
}
|
||||
{
|
||||
constexpr float is[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
|
||||
STATIC_CHECK(dmat2(is) == dmat2(1,2,3,4));
|
||||
STATIC_CHECK(dmat3(is) == dmat3(1,2,3,4,5,6,7,8,9));
|
||||
STATIC_CHECK(dmat4(is) == dmat4({1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("operator=") {
|
||||
|
||||
@@ -68,6 +68,10 @@ TEST_CASE("vmath/qua") {
|
||||
STATIC_CHECK(fqua(fvec3(1,2,3),4) == fqua(1,2,3,4));
|
||||
STATIC_CHECK(fqua(fvec4(1,2,3,4)) == fqua(1,2,3,4));
|
||||
}
|
||||
{
|
||||
constexpr float is[] = {1,2,3,4};
|
||||
STATIC_CHECK(dqua(is) == dqua(1,2,3,4));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("operator=") {
|
||||
|
||||
@@ -115,6 +115,12 @@ TEST_CASE("vmath/vec") {
|
||||
STATIC_CHECK(ivec4(ivec3(1,2,3),4) == ivec4(1,2,3,4));
|
||||
STATIC_CHECK(ivec4(1,ivec3(2,3,4)) == ivec4(1,2,3,4));
|
||||
}
|
||||
{
|
||||
constexpr float is[] = {1,2,3,4};
|
||||
STATIC_CHECK(dvec2(is) == dvec2(1,2));
|
||||
STATIC_CHECK(dvec3(is) == dvec3(1,2,3));
|
||||
STATIC_CHECK(dvec4(is) == dvec4(1,2,3,4));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("operator=") {
|
||||
|
||||
Reference in New Issue
Block a user