quaternion ctor conversions

This commit is contained in:
BlackMATov
2021-02-26 10:35:35 +07:00
parent e25be44585
commit 7e1596acd1
3 changed files with 20 additions and 12 deletions

View File

@@ -425,9 +425,10 @@ public:
qua_base(T vx, T vy, T vz, T s);
qua_base(const vec<T, 3>& v, T s);
explicit qua_base(const vec<T, 4>& vs);
explicit operator vec<T, 4>() const;
template < typename A > qua_base(const qua_base<A, 4>& other);
template < typename A > explicit operator vec<A, 4>() const;
};
template < typename T >

View File

@@ -26,18 +26,15 @@ namespace vmath_hpp::detail
constexpr qua_base(zero_init_t) : qua_base{zero_init, T{0}} {}
constexpr qua_base(identity_init_t) : qua_base{zero_init, T{1}} {}
constexpr qua_base(T vx, T vy, T vz, T s)
: v{vx, vy, vz}, s{s} {}
constexpr qua_base(T vx, T vy, T vz, T s): v{vx, vy, vz}, s{s} {}
constexpr qua_base(const vec<T, 3>& v, T s): v{v}, s{s} {}
constexpr explicit qua_base(const vec<T, 4>& vs): v{vs[0], vs[1], vs[2]}, s{vs[3]} {}
constexpr qua_base(const vec<T, 3>& v, T s)
: v{v}, s{s} {}
template < typename A, std::enable_if_t<std::is_convertible_v<A, T>, int> = 0 >
constexpr qua_base(const qua_base<A>& other): qua_base(other.v, other.s) {}
constexpr explicit qua_base(const vec<T, 4>& vs)
: v{vs[0], vs[1], vs[2]}, s{vs[3]} {}
constexpr explicit operator vec<T, 4>() const {
return {v, s};
}
template < typename A, std::enable_if_t<std::is_convertible_v<T, A>, int> = 0 >
constexpr explicit operator vec<A, 4>() const { return vec<A, 4>(v, s); }
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
switch ( index ) {

View File

@@ -76,6 +76,16 @@ TEST_CASE("vmath/qua_fun") {
STATIC_CHECK(1.0 / qfloat{1,1,1,1} == qdouble{1,1,1,1});
}
SUBCASE("Conversions2") {
STATIC_CHECK(qfloat(1,2.f,3.0,4u) == qfloat(1,2,3,4));
STATIC_CHECK(qfloat(int3(1,2,3),4u) == qfloat(1,2,3,4));
STATIC_CHECK(qfloat(int4(1,2,3,4)) == qfloat(1,2,3,4));
STATIC_CHECK(qfloat(qdouble(1,2,3,4)) == qfloat(1,2,3,4));
STATIC_CHECK(float4(qfloat(1,2,3,4)) == float4(1,2,3,4));
STATIC_CHECK(float4(qdouble(1,2,3,4)) == float4(1,2,3,4));
}
SUBCASE("Common Functions") {
{
CHECK(all(approx(