diff --git a/README.md b/README.md index 7c703dc..57bd6ca 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ public: template < typename U > vec_base(const vec_base& other); template < typename U > explicit vec_base(const vec_base& other); template < typename U > explicit vec_base(const vec_base& 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& other); template < typename U > explicit vec_base(const vec_base& 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& yzw); template < typename U > vec_base(const vec_base& 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& other); template < typename U > explicit mat_base(const mat_base& other); template < typename U > explicit mat_base(const mat_base& 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& other); template < typename U > explicit mat_base(const mat_base& other); template < typename U > explicit mat_base(const mat_base& 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& other); template < typename U > explicit mat_base(const mat_base& other); template < typename U > explicit mat_base(const mat_base& 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& other); template < typename U > explicit operator vec() const; + + template < typename U > explicit qua_base(const U* p); }; template < typename T > diff --git a/headers/vmath.hpp/vmath_mat.hpp b/headers/vmath.hpp/vmath_mat.hpp index 0d27489..c9c3d74 100644 --- a/headers/vmath.hpp/vmath_mat.hpp +++ b/headers/vmath.hpp/vmath_mat.hpp @@ -66,6 +66,11 @@ namespace vmath_hpp::detail constexpr explicit mat_base(const mat_base& other): mat_base( row_type{other.rows[0]}, row_type{other.rows[1]}) {} + + template < typename U, std::enable_if_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, 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, 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}) {} }; } diff --git a/headers/vmath.hpp/vmath_qua.hpp b/headers/vmath.hpp/vmath_qua.hpp index e77e58d..91c03e9 100644 --- a/headers/vmath.hpp/vmath_qua.hpp +++ b/headers/vmath.hpp/vmath_qua.hpp @@ -36,6 +36,9 @@ namespace vmath_hpp::detail template < typename U, std::enable_if_t, int> = 0 > constexpr explicit operator vec() const { return vec(v, s); } + template < typename U, std::enable_if_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: diff --git a/headers/vmath.hpp/vmath_vec.hpp b/headers/vmath.hpp/vmath_vec.hpp index 5059ce6..bb13947 100644 --- a/headers/vmath.hpp/vmath_vec.hpp +++ b/headers/vmath.hpp/vmath_vec.hpp @@ -37,6 +37,9 @@ namespace vmath_hpp::detail template < typename U, std::enable_if_t, int> = 0 > constexpr explicit vec_base(const vec_base& other): vec_base(other[0], other[1]) {} + template < typename U, std::enable_if_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, int> = 0 > constexpr explicit vec_base(const vec_base& other): vec_base(other[0], other[1], other[2]) {} + template < typename U, std::enable_if_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, int> = 0 > constexpr vec_base(const vec_base& other): vec_base(other[0], other[1], other[2], other[3]) {} + template < typename U, std::enable_if_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: diff --git a/untests/vmath_mat_tests.cpp b/untests/vmath_mat_tests.cpp index bf5c226..919a045 100644 --- a/untests/vmath_mat_tests.cpp +++ b/untests/vmath_mat_tests.cpp @@ -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=") { diff --git a/untests/vmath_qua_tests.cpp b/untests/vmath_qua_tests.cpp index e926148..e1aa2d4 100644 --- a/untests/vmath_qua_tests.cpp +++ b/untests/vmath_qua_tests.cpp @@ -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=") { diff --git a/untests/vmath_vec_tests.cpp b/untests/vmath_vec_tests.cpp index 2e80d19..80d973e 100644 --- a/untests/vmath_vec_tests.cpp +++ b/untests/vmath_vec_tests.cpp @@ -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=") {