diff --git a/headers/vmath.hpp/vmath_ext.hpp b/headers/vmath.hpp/vmath_ext.hpp index c462e90..2cd9b71 100644 --- a/headers/vmath.hpp/vmath_ext.hpp +++ b/headers/vmath.hpp/vmath_ext.hpp @@ -795,7 +795,7 @@ namespace vmath_hpp /// REFERENCE: /// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivefovlh - const T sy = rcp(tan(fovy * T{0.5})); + const T sy = rcp(tan(fovy * T{0.5f})); const T sx = sy * rcp(aspect); const T sz = zfar * rcp(zfar - znear); const T tz = (znear * zfar) * rcp(znear - zfar); @@ -812,7 +812,7 @@ namespace vmath_hpp /// REFERENCE: /// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivefovrh - const T sy = rcp(tan(fovy * T{0.5})); + const T sy = rcp(tan(fovy * T{0.5f})); const T sx = sy * rcp(aspect); const T sz = zfar * rcp(znear - zfar); const T tz = (znear * zfar) * rcp(znear - zfar); @@ -901,7 +901,7 @@ namespace vmath_hpp /// REFERENCE: /// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ - auto xyzw = T{0.5} * sqrt(max(T{0}, vec{ + auto xyzw = T{0.5f} * sqrt(max(T{0}, vec{ T{1} + m[0][0] - m[1][1] - m[2][2], T{1} - m[0][0] + m[1][1] - m[2][2], T{1} - m[0][0] - m[1][1] + m[2][2], @@ -927,7 +927,7 @@ namespace vmath_hpp const T n = sqrt(length2(from) * length2(to)); const T s = dot(from, to) + n; - if ( s < T{0.000001} * n ) { + if ( s < T{0.000001f} * n ) { return abs(from.z) < abs(from.x) ? normalize(qua{vec{-from.y, from.x, T{0}}, T{0}}) : normalize(qua{vec{T{0}, -from.z, from.y}, T{0}}); @@ -946,7 +946,7 @@ namespace vmath_hpp /// REFERENCE: /// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ - const auto [s, c] = sincos(angle * T{0.5}); + const auto [s, c] = sincos(angle * T{0.5f}); const auto [x, y, z] = normalize(axis); return {vec{x, y, z} * s, c}; @@ -962,7 +962,7 @@ namespace vmath_hpp /// REFERENCE: /// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ - const auto [s, c] = sincos(angle * T{0.5}); + const auto [s, c] = sincos(angle * T{0.5f}); return {vec{s, T{0}, T{0}}, c}; } @@ -977,7 +977,7 @@ namespace vmath_hpp /// REFERENCE: /// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ - const auto [s, c] = sincos(angle * T{0.5}); + const auto [s, c] = sincos(angle * T{0.5f}); return {vec{T{0}, s, T{0}}, c}; } @@ -992,7 +992,7 @@ namespace vmath_hpp /// REFERENCE: /// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ - const auto [s, c] = sincos(angle * T{0.5}); + const auto [s, c] = sincos(angle * T{0.5f}); return {vec{T{0}, T{0}, s}, c}; } diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index aa6b37f..65e87f0 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -151,13 +151,13 @@ namespace vmath_hpp template < typename T > [[nodiscard]] std::enable_if_t, T> constexpr radians(T degrees) noexcept { - return degrees * T{0.01745329251994329576923690768489}; + return degrees * T(0.01745329251994329576923690768489); } template < typename T > [[nodiscard]] std::enable_if_t, T> constexpr degrees(T radians) noexcept { - return radians * T{57.295779513082320876798154814105}; + return radians * T(57.295779513082320876798154814105); } template < typename T > diff --git a/headers/vmath.hpp/vmath_qua_fun.hpp b/headers/vmath.hpp/vmath_qua_fun.hpp index ea7b755..b6c32d5 100644 --- a/headers/vmath.hpp/vmath_qua_fun.hpp +++ b/headers/vmath.hpp/vmath_qua_fun.hpp @@ -183,7 +183,7 @@ namespace vmath_hpp const T raw_cos_theta_sign = sign(raw_cos_theta); // half degree linear threshold: cos((pi / 180) * 0.25) - if ( const T cos_theta = raw_cos_theta * raw_cos_theta_sign; cos_theta < T{0.99999} ) { + if ( const T cos_theta = raw_cos_theta * raw_cos_theta_sign; cos_theta < T{0.99999f} ) { const T theta = acos(cos_theta); const T rsin_theta = rsqrt(T{1} - sqr(cos_theta)); const T xs_scale = sin((T{1} - a) * theta) * rsin_theta; diff --git a/untests/vmath_fix_tests.cpp b/untests/vmath_fix_tests.cpp index d20ace1..5baa823 100644 --- a/untests/vmath_fix_tests.cpp +++ b/untests/vmath_fix_tests.cpp @@ -8,9 +8,6 @@ namespace { - using namespace vmath_hpp; - using namespace vmath_tests; - template < typename T > class fix { public: @@ -25,76 +22,76 @@ namespace constexpr explicit fix(T underlying): underlying_(underlying) {} constexpr T underlying() const noexcept { return underlying_; } - constexpr friend fix abs(const fix& l) { return { fix{abs(l.underlying())} }; } - constexpr friend fix sqr(const fix& l) { return { fix{sqr(l.underlying())} }; } - constexpr friend fix sign(const fix& l) { return { fix{sign(l.underlying())} }; } + constexpr friend fix abs(const fix& l) { using vmath_hpp::abs; return { fix{abs(l.underlying())} }; } + constexpr friend fix sqr(const fix& l) { using vmath_hpp::sqr; return { fix{sqr(l.underlying())} }; } + constexpr friend fix sign(const fix& l) { using vmath_hpp::sign; return { fix{sign(l.underlying())} }; } - constexpr friend fix rcp(const fix& l) { return { fix{rcp(l.underlying())} }; } - constexpr friend fix floor(const fix& l) { return { fix{floor(l.underlying())} }; } - constexpr friend fix trunc(const fix& l) { return { fix{trunc(l.underlying())} }; } - constexpr friend fix round(const fix& l) { return { fix{round(l.underlying())} }; } - constexpr friend fix ceil(const fix& l) { return { fix{ceil(l.underlying())} }; } - constexpr friend fix fract(const fix& l) { return { fix{fract(l.underlying())} }; } + constexpr friend fix rcp(const fix& l) { using vmath_hpp::rcp; return { fix{rcp(l.underlying())} }; } + constexpr friend fix floor(const fix& l) { using vmath_hpp::floor; return { fix{floor(l.underlying())} }; } + constexpr friend fix trunc(const fix& l) { using vmath_hpp::trunc; return { fix{trunc(l.underlying())} }; } + constexpr friend fix round(const fix& l) { using vmath_hpp::round; return { fix{round(l.underlying())} }; } + constexpr friend fix ceil(const fix& l) { using vmath_hpp::ceil; return { fix{ceil(l.underlying())} }; } + constexpr friend fix fract(const fix& l) { using vmath_hpp::fract; return { fix{fract(l.underlying())} }; } - constexpr friend fix fmod(const fix& l, const fix& r) { return { fix{fmod(l.underlying(), r.underlying())} }; } - constexpr friend fix copysign(const fix& l, const fix& r) { return { fix{copysign(l.underlying(), r.underlying())} }; } + constexpr friend fix fmod(const fix& l, const fix& r) { using vmath_hpp::fmod; return { fix{fmod(l.underlying(), r.underlying())} }; } + constexpr friend fix copysign(const fix& l, const fix& r) { using vmath_hpp::copysign; return { fix{copysign(l.underlying(), r.underlying())} }; } - constexpr friend fix min(const fix& l, const fix& r) { return fix{min(l.underlying(), r.underlying())}; } - constexpr friend fix max(const fix& l, const fix& r) { return fix{max(l.underlying(), r.underlying())}; } - constexpr friend fix clamp(const fix& l, const fix& min_l, const fix& max_l) { return fix{clamp(l.underlying(), min_l.underlying(), max_l.underlying())}; } - constexpr friend fix saturate(const fix& l) { return fix{saturate(l.underlying())}; } - constexpr friend fix lerp(const fix& l, const fix& r, const fix& a) { return fix{lerp(l.underlying(), r.underlying(), a.underlying())}; } - constexpr friend fix lerp(const fix& l, const fix& r, const fix& a, const fix& b) { return fix{lerp(l.underlying(), r.underlying(), a.underlying(), b.underlying())}; } + constexpr friend fix min(const fix& l, const fix& r) { using vmath_hpp::min; return fix{min(l.underlying(), r.underlying())}; } + constexpr friend fix max(const fix& l, const fix& r) { using vmath_hpp::max; return fix{max(l.underlying(), r.underlying())}; } + constexpr friend fix clamp(const fix& l, const fix& min_l, const fix& max_l) { using vmath_hpp::clamp; return fix{clamp(l.underlying(), min_l.underlying(), max_l.underlying())}; } + constexpr friend fix saturate(const fix& l) { using vmath_hpp::saturate; return fix{saturate(l.underlying())}; } + constexpr friend fix lerp(const fix& l, const fix& r, const fix& a) { using vmath_hpp::lerp; return fix{lerp(l.underlying(), r.underlying(), a.underlying())}; } + constexpr friend fix lerp(const fix& l, const fix& r, const fix& a, const fix& b) { using vmath_hpp::lerp; return fix{lerp(l.underlying(), r.underlying(), a.underlying(), b.underlying())}; } - constexpr friend fix step(const fix& e, const fix& l) { return fix{step(e.underlying(), l.underlying())}; } - constexpr friend fix smoothstep(const fix& e0, const fix& e1, const fix& l) { return fix{smoothstep(e0.underlying(), e1.underlying(), l.underlying())}; } + constexpr friend fix step(const fix& e, const fix& l) { using vmath_hpp::step; return fix{step(e.underlying(), l.underlying())}; } + constexpr friend fix smoothstep(const fix& e0, const fix& e1, const fix& l) { using vmath_hpp::smoothstep; return fix{smoothstep(e0.underlying(), e1.underlying(), l.underlying())}; } - constexpr friend fix fma(const fix& x, const fix& y, const fix& z) { return fix{fma(x.underlying(), y.underlying(), z.underlying())}; } + constexpr friend fix fma(const fix& x, const fix& y, const fix& z) { using vmath_hpp::fma; return fix{fma(x.underlying(), y.underlying(), z.underlying())}; } // - constexpr friend fix any(const fix& l) { return fix{any(l.underlying())}; } - constexpr friend fix all(const fix& l) { return fix{all(l.underlying())}; } + constexpr friend fix any(const fix& l) { using vmath_hpp::any; return fix{any(l.underlying())}; } + constexpr friend fix all(const fix& l) { using vmath_hpp::all; return fix{all(l.underlying())}; } - constexpr friend fix approx(const fix& l, const fix& r) { return fix{approx(l.underlying(), r.underlying())}; } - constexpr friend fix approx(const fix& l, const fix& r, const fix& e) { return fix{approx(l.underlying(), r.underlying(), e.underlying())}; } + constexpr friend fix approx(const fix& l, const fix& r) { using vmath_hpp::approx; return fix{approx(l.underlying(), r.underlying())}; } + constexpr friend fix approx(const fix& l, const fix& r, const fix& e) { using vmath_hpp::approx; return fix{approx(l.underlying(), r.underlying(), e.underlying())}; } - constexpr friend fix less(const fix& l, const fix& r) { return fix{less(l.underlying(), r.underlying())}; } - constexpr friend fix less_equal(const fix& l, const fix& r) { return fix{less_equal(l.underlying(), r.underlying())}; } - constexpr friend fix greater(const fix& l, const fix& r) { return fix{greater(l.underlying(), r.underlying())}; } - constexpr friend fix greater_equal(const fix& l, const fix& r) { return fix{greater_equal(l.underlying(), r.underlying())}; } - constexpr friend fix equal_to(const fix& l, const fix& r) { return fix{equal_to(l.underlying(), r.underlying())}; } - constexpr friend fix not_equal_to(const fix& l, const fix& r) { return fix{not_equal_to(l.underlying(), r.underlying())}; } + constexpr friend fix less(const fix& l, const fix& r) { using vmath_hpp::less; return fix{less(l.underlying(), r.underlying())}; } + constexpr friend fix less_equal(const fix& l, const fix& r) { using vmath_hpp::less_equal; return fix{less_equal(l.underlying(), r.underlying())}; } + constexpr friend fix greater(const fix& l, const fix& r) { using vmath_hpp::greater; return fix{greater(l.underlying(), r.underlying())}; } + constexpr friend fix greater_equal(const fix& l, const fix& r) { using vmath_hpp::greater_equal; return fix{greater_equal(l.underlying(), r.underlying())}; } + constexpr friend fix equal_to(const fix& l, const fix& r) { using vmath_hpp::equal_to; return fix{equal_to(l.underlying(), r.underlying())}; } + constexpr friend fix not_equal_to(const fix& l, const fix& r) { using vmath_hpp::not_equal_to; return fix{not_equal_to(l.underlying(), r.underlying())}; } // - constexpr friend fix radians(const fix& l) { return fix{radians(l.underlying())}; } - constexpr friend fix degrees(const fix& l) { return fix{degrees(l.underlying())}; } - friend fix sin(const fix& l) { return fix{sin(l.underlying())}; } - friend fix cos(const fix& l) { return fix{cos(l.underlying())}; } - friend fix tan(const fix& l) { return fix{tan(l.underlying())}; } - friend fix asin(const fix& l) { return fix{asin(l.underlying())}; } - friend fix acos(const fix& l) { return fix{acos(l.underlying())}; } - friend fix atan(const fix& l) { return fix{atan(l.underlying())}; } - friend fix atan2(const fix& l, const fix& r) { return fix{atan2(l.underlying(), r.underlying())}; } - friend fix sinh(const fix& l) { return fix{sinh(l.underlying())}; } - friend fix cosh(const fix& l) { return fix{cosh(l.underlying())}; } - friend fix tanh(const fix& l) { return fix{tanh(l.underlying())}; } - friend fix asinh(const fix& l) { return fix{asinh(l.underlying())}; } - friend fix acosh(const fix& l) { return fix{acosh(l.underlying())}; } - friend fix atanh(const fix& l) { return fix{atanh(l.underlying())}; } + constexpr friend fix radians(const fix& l) { using vmath_hpp::radians; return fix{radians(l.underlying())}; } + constexpr friend fix degrees(const fix& l) { using vmath_hpp::degrees; return fix{degrees(l.underlying())}; } + friend fix sin(const fix& l) { using vmath_hpp::sin; return fix{sin(l.underlying())}; } + friend fix cos(const fix& l) { using vmath_hpp::cos; return fix{cos(l.underlying())}; } + friend fix tan(const fix& l) { using vmath_hpp::tan; return fix{tan(l.underlying())}; } + friend fix asin(const fix& l) { using vmath_hpp::asin; return fix{asin(l.underlying())}; } + friend fix acos(const fix& l) { using vmath_hpp::acos; return fix{acos(l.underlying())}; } + friend fix atan(const fix& l) { using vmath_hpp::atan; return fix{atan(l.underlying())}; } + friend fix atan2(const fix& l, const fix& r) { using vmath_hpp::atan2; return fix{atan2(l.underlying(), r.underlying())}; } + friend fix sinh(const fix& l) { using vmath_hpp::sinh; return fix{sinh(l.underlying())}; } + friend fix cosh(const fix& l) { using vmath_hpp::cosh; return fix{cosh(l.underlying())}; } + friend fix tanh(const fix& l) { using vmath_hpp::tanh; return fix{tanh(l.underlying())}; } + friend fix asinh(const fix& l) { using vmath_hpp::asinh; return fix{asinh(l.underlying())}; } + friend fix acosh(const fix& l) { using vmath_hpp::acosh; return fix{acosh(l.underlying())}; } + friend fix atanh(const fix& l) { using vmath_hpp::atanh; return fix{atanh(l.underlying())}; } friend std::pair sincos(const fix& l) { return { sin(l), cos(l) }; } friend void sincos(const fix& l, fix* s, fix* c) { *s = sin(l); *c = cos(l); } // - friend fix pow(const fix& l, const fix& r) { return fix{pow(l.underlying(), r.underlying())}; } - friend fix exp(const fix& l) { return fix{exp(l.underlying())}; } - friend fix log(const fix& l) { return fix{log(l.underlying())}; } - friend fix exp2(const fix& l) { return fix{exp2(l.underlying())}; } - friend fix log2(const fix& l) { return fix{log2(l.underlying())}; } - friend fix sqrt(const fix& l) { return fix{sqrt(l.underlying())}; } - friend fix rsqrt(const fix& l) { return fix{rsqrt(l.underlying())}; } + friend fix pow(const fix& l, const fix& r) { using vmath_hpp::pow; return fix{pow(l.underlying(), r.underlying())}; } + friend fix exp(const fix& l) { using vmath_hpp::exp; return fix{exp(l.underlying())}; } + friend fix log(const fix& l) { using vmath_hpp::log; return fix{log(l.underlying())}; } + friend fix exp2(const fix& l) { using vmath_hpp::exp2; return fix{exp2(l.underlying())}; } + friend fix log2(const fix& l) { using vmath_hpp::log2; return fix{log2(l.underlying())}; } + friend fix sqrt(const fix& l) { using vmath_hpp::sqrt; return fix{sqrt(l.underlying())}; } + friend fix rsqrt(const fix& l) { using vmath_hpp::rsqrt; return fix{rsqrt(l.underlying())}; } // @@ -122,6 +119,9 @@ namespace T underlying_{}; }; + using namespace vmath_hpp; + using namespace vmath_tests; + using qfix = qua>; using fix2b = vec, 2>; @@ -629,27 +629,27 @@ TEST_CASE("vmath/fix_vec") { vb = {fix{3} || fix2i{fix(1),fix(2)}}; vb = {fix2i{fix(1),fix(2)} || fix2i{fix(1),fix(2)}}; - b = {fix2i{fix(1),fix(2)} == fix2i{fix(3),fix(4)}}; - b = {fix2i{fix(1),fix(2)} != fix2i{fix(3),fix(4)}}; - b = {fix2i{fix(1),fix(2)} < fix2i{fix(3),fix(4)}}; + b = {fix2i{fix(1),fix(2)} == fix2i{fix(1),fix(2)}}; + b = {fix2i{fix(1),fix(2)} != fix2i{fix(1),fix(2)}}; + b = {fix2i{fix(1),fix(2)} < fix2i{fix(1),fix(2)}}; + + CHECK_FALSE(b); { - fix2i v{}; - fix2i vi{}; - vi = {v += fix{3}}; - vi = {v += fix2i{fix(4),fix(5)}}; - vi = {v -= fix{3}}; - vi = {v -= fix2i{fix(4),fix(5)}}; - vi = {v *= fix{3}}; - vi = {v *= fix2i{fix(4),fix(5)}}; - vi = {v /= fix{3}}; - vi = {v /= fix2i{fix(4),fix(5)}}; - vi = {v &= fix{3}}; - vi = {v &= fix2i{fix(4),fix(5)}}; - vi = {v |= fix{3}}; - vi = {v |= fix2i{fix(4),fix(5)}}; - vi = {v ^= fix{3}}; - vi = {v ^= fix2i{fix(4),fix(5)}}; + vi = {vi += fix{3}}; + vi = {vi += fix2i{fix(4),fix(5)}}; + vi = {vi -= fix{3}}; + vi = {vi -= fix2i{fix(4),fix(5)}}; + vi = {vi *= fix{3}}; + vi = {vi *= fix2i{fix(4),fix(5)}}; + vi = {vi /= fix{3}}; + vi = {vi /= fix2i{fix(4),fix(5)}}; + vi = {vi &= fix{3}}; + vi = {vi &= fix2i{fix(4),fix(5)}}; + vi = {vi |= fix{3}}; + vi = {vi |= fix2i{fix(4),fix(5)}}; + vi = {vi ^= fix{3}}; + vi = {vi ^= fix2i{fix(4),fix(5)}}; } } } @@ -789,9 +789,11 @@ TEST_CASE("vmath/fix_mat") { mb = {fix{3} || fix2x2i{fix(1),fix(2),fix(3),fix(4)}}; mb = {fix2x2i{fix(1),fix(2),fix(3),fix(4)} || fix2x2i{fix(1),fix(2),fix(3),fix(4)}}; - b = {fix2x2i{fix(1),fix(2),fix(3),fix(4)} == fix2x2i{fix(3),fix(4),fix(5),fix(6)}}; - b = {fix2x2i{fix(1),fix(2),fix(3),fix(4)} != fix2x2i{fix(3),fix(4),fix(5),fix(6)}}; - b = {fix2x2i{fix(1),fix(2),fix(3),fix(4)} < fix2x2i{fix(3),fix(4),fix(5),fix(6)}}; + b = {fix2x2i{fix(1),fix(2),fix(3),fix(4)} == fix2x2i{fix(1),fix(2),fix(3),fix(4)}}; + b = {fix2x2i{fix(1),fix(2),fix(3),fix(4)} != fix2x2i{fix(1),fix(2),fix(3),fix(4)}}; + b = {fix2x2i{fix(1),fix(2),fix(3),fix(4)} < fix2x2i{fix(1),fix(2),fix(3),fix(4)}}; + + CHECK_FALSE(b); { mi = {mi += fix{3}}; @@ -865,6 +867,8 @@ TEST_CASE("vmath/fix_qua") { b = {qfix{fix(1.f),fix(2.f),fix(3.f),fix(4.f)} == qfix{fix(1.f),fix(2.f),fix(3.f),fix(4.f)}}; b = {qfix{fix(1.f),fix(2.f),fix(3.f),fix(4.f)} != qfix{fix(1.f),fix(2.f),fix(3.f),fix(4.f)}}; b = {qfix{fix(1.f),fix(2.f),fix(3.f),fix(4.f)} < qfix{fix(1.f),fix(2.f),fix(3.f),fix(4.f)}}; + + CHECK_FALSE(b); } }