diff --git a/README.md b/README.md index b1c9f86..4f3ce9a 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Most functions and types are based on the HLSL ([High-Level Shading Language for - [Matrix Types](#Matrix-Types) - [Vector Operators](#Vector-Operators) - [Matrix Operators](#Matrix-Operators) -- [Angle and Trigonometry Functions](#Angle-and-Trigonometry-Functions) +- [Angle and Trigonometric Functions](#Angle-and-Trigonometric-Functions) - [Exponential Functions](#Exponential-Functions) - [Common Functions](#Common-Functions) - [Geometric Functions](#Geometric-Functions) @@ -743,7 +743,7 @@ template < typename T, size_t Size > constexpr bool operator<(const mat& xs, const mat& ys); ``` -### Angle and Trigonometry Functions +### Angle and Trigonometric Functions #### Scalar diff --git a/headers/vmath.hpp/vmath_fun.hpp b/headers/vmath.hpp/vmath_fun.hpp index b25da71..bcf54d3 100644 --- a/headers/vmath.hpp/vmath_fun.hpp +++ b/headers/vmath.hpp/vmath_fun.hpp @@ -209,7 +209,7 @@ namespace vmath_hpp } // -// Angle and Trigonometry Functions +// Angle and Trigonometric Functions // namespace vmath_hpp @@ -228,94 +228,63 @@ namespace vmath_hpp template < typename T > [[nodiscard]] std::enable_if_t, T> - sin(T x) noexcept { - return std::sin(x); - } + sin(T x) noexcept { return std::sin(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - cos(T x) noexcept { - return std::cos(x); - } + cos(T x) noexcept { return std::cos(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - tan(T x) noexcept { - return std::tan(x); - } + tan(T x) noexcept { return std::tan(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - asin(T x) noexcept { - return std::asin(x); - } + asin(T x) noexcept { return std::asin(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - acos(T x) noexcept { - return std::acos(x); - } + acos(T x) noexcept { return std::acos(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - atan(T x) noexcept { - return std::atan(x); - } + atan(T x) noexcept { return std::atan(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - atan2(T y, T x) noexcept { - return std::atan2(y, x); - } + atan2(T y, T x) noexcept { return std::atan2(y, x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - sinh(T x) noexcept { - return std::sinh(x); - } + sinh(T x) noexcept { return std::sinh(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - cosh(T x) noexcept { - return std::cosh(x); - } + cosh(T x) noexcept { return std::cosh(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - tanh(T x) noexcept { - return std::tanh(x); - } + tanh(T x) noexcept { return std::tanh(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - asinh(T x) noexcept { - return std::asinh(x); - } + asinh(T x) noexcept { return std::asinh(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - acosh(T x) noexcept { - return std::acosh(x); - } + acosh(T x) noexcept { return std::acosh(x); } template < typename T > [[nodiscard]] std::enable_if_t, T> - atanh(T x) noexcept { - return std::atanh(x); - } + atanh(T x) noexcept { return std::atanh(x); } template < typename T > [[nodiscard]] std::enable_if_t, std::pair> - sincos(T x) noexcept { - return {sin(x), cos(x)}; - } + sincos(T x) noexcept { return {sin(x), cos(x)}; } template < typename T > [[nodiscard]] std::enable_if_t, void> - sincos(T x, T* s, T* c) noexcept { - *s = sin(x); - *c = cos(x); - } + sincos(T x, T* s, T* c) noexcept { *s = sin(x); *c = cos(x); } } // diff --git a/headers/vmath.hpp/vmath_vec_fun.hpp b/headers/vmath.hpp/vmath_vec_fun.hpp index 00a1858..ad28a25 100644 --- a/headers/vmath.hpp/vmath_vec_fun.hpp +++ b/headers/vmath.hpp/vmath_vec_fun.hpp @@ -465,7 +465,7 @@ namespace vmath_hpp } // -// Angle and Trigonometry Functions +// Angle and Trigonometric Functions // namespace vmath_hpp diff --git a/untests/vmath_fun_tests.cpp b/untests/vmath_fun_tests.cpp index e15b6f1..95d9297 100644 --- a/untests/vmath_fun_tests.cpp +++ b/untests/vmath_fun_tests.cpp @@ -14,32 +14,28 @@ namespace } TEST_CASE("vmath/fun") { - SECTION("Angle and Trigonometry Functions") { + SECTION("Angle and Trigonometric Functions") { STATIC_REQUIRE(radians(degrees(12.13f)) == uapprox(12.13f)); STATIC_REQUIRE(degrees(radians(12.13f)) == uapprox(12.13f)); - (void)sin(0.f); - (void)cos(0.f); - (void)tan(0.f); + { + REQUIRE(asin(sin(1.23f)) == uapprox(1.23f)); + REQUIRE(acos(cos(1.23f)) == uapprox(1.23f)); + REQUIRE(atan(tan(1.23f)) == uapprox(1.23f)); - (void)asin(0.f); - (void)acos(0.f); - (void)atan(0.f); - (void)atan2(0.f, 0.f); - - (void)sinh(0.f); - (void)cosh(0.f); - (void)tanh(0.f); - - (void)asinh(0.f); - (void)acosh(0.f); - (void)atanh(0.f); + REQUIRE(asinh(sinh(1.23f)) == uapprox(1.23f)); + REQUIRE(acosh(cosh(1.23f)) == uapprox(1.23f)); + REQUIRE(atanh(tanh(1.23f)) == uapprox(1.23f)); + } { float out_s{}, out_c{}; sincos(15.f, &out_s, &out_c); REQUIRE(out_s == uapprox(sin(15.f))); REQUIRE(out_c == uapprox(cos(15.f))); + const auto [out_s2, out_c2] = sincos(15.f); + REQUIRE(out_s2 == uapprox(sin(15.f))); + REQUIRE(out_c2 == uapprox(cos(15.f))); } } @@ -121,7 +117,10 @@ TEST_CASE("vmath/fun") { STATIC_REQUIRE(saturate(0.5f) == uapprox(0.5f)); STATIC_REQUIRE(saturate(1.5f) == uapprox(1.f)); - STATIC_REQUIRE(lerp(0.f, 10.f, 0.5f) == uapprox(5.f)); + STATIC_REQUIRE(lerp(2.f, 10.f, 0.f) == uapprox(2.f)); + STATIC_REQUIRE(lerp(2.f, 10.f, 0.5f) == uapprox(6.f)); + STATIC_REQUIRE(lerp(2.f, 10.f, 1.f) == uapprox(10.f)); + STATIC_REQUIRE(step(0.5f, 0.4f) == uapprox(0.f)); STATIC_REQUIRE(step(0.5f, 0.6f) == uapprox(1.f)); STATIC_REQUIRE(smoothstep(0.f, 1.f, 0.1f) == uapprox(0.028f)); diff --git a/untests/vmath_vec_fun_tests.cpp b/untests/vmath_vec_fun_tests.cpp index 51a31dd..1f9c0d7 100644 --- a/untests/vmath_vec_fun_tests.cpp +++ b/untests/vmath_vec_fun_tests.cpp @@ -130,7 +130,7 @@ TEST_CASE("vmath/vec_fun") { } } - SECTION("Angle and Trigonometry Functions") { + SECTION("Angle and Trigonometric Functions") { STATIC_REQUIRE(radians(degrees(float2(12.13f))) == uapprox2(12.13f)); STATIC_REQUIRE(degrees(radians(float2(12.13f))) == uapprox2(12.13f)); @@ -202,8 +202,13 @@ TEST_CASE("vmath/vec_fun") { STATIC_REQUIRE(saturate(float3(-1.f,0.5,1.5f)) == uapprox3(0.f,0.5f,1.f)); - STATIC_REQUIRE(lerp(float2(0.f), float2(10.f), 0.5f) == uapprox2(5.f)); - STATIC_REQUIRE(lerp(float2(0.f), float2(10.f), float2(0.5f)) == uapprox2(5.f)); + STATIC_REQUIRE(lerp(float2(2.f), float2(10.f), 0.f) == uapprox2(2.f)); + STATIC_REQUIRE(lerp(float2(2.f), float2(10.f), 0.5f) == uapprox2(6.f)); + STATIC_REQUIRE(lerp(float2(2.f), float2(10.f), 1.f) == uapprox2(10.f)); + + STATIC_REQUIRE(lerp(float2(2.f), float2(10.f), float2(0.f)) == uapprox2(2.f)); + STATIC_REQUIRE(lerp(float2(2.f), float2(10.f), float2(0.5f)) == uapprox2(6.f)); + STATIC_REQUIRE(lerp(float2(2.f), float2(10.f), float2(1.f)) == uapprox2(10.f)); STATIC_REQUIRE(step(0.5f, float2(0.4f)) == uapprox2(0.f)); STATIC_REQUIRE(step(0.5f, float2(0.6f)) == uapprox2(1.f));