From b934e673c7f7f8847ed61926930d627cf8370c31 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 19:25:01 +0700 Subject: [PATCH 1/5] make_minmax_rect --- headers/enduro2d/math/rect.hpp | 17 +++++++++++++++++ untests/sources/untests_math/rect.cpp | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/headers/enduro2d/math/rect.hpp b/headers/enduro2d/math/rect.hpp index 13cf3c68..9b08f15b 100644 --- a/headers/enduro2d/math/rect.hpp +++ b/headers/enduro2d/math/rect.hpp @@ -93,6 +93,23 @@ namespace e2d return {position, size}; } + template < typename T > + rect make_minmax_rect(T x1, T y1, T x2, T y2) noexcept { + const vec2 min = {math::min(x1, x2), math::min(y1, y2)}; + const vec2 max = {math::max(x1, x2), math::max(y1, y2)}; + return {min, max - min}; + } + + template < typename T > + rect make_minmax_rect(const vec2& p1, const vec2& p2) noexcept { + return make_minmax_rect(p1.x, p1.y, p2.x, p2.y); + } + + template < typename T > + rect make_minmax_rect(const rect& r) noexcept { + return make_minmax_rect(r.position, r.position + r.size); + } + // // rect (==,!=) rect // diff --git a/untests/sources/untests_math/rect.cpp b/untests/sources/untests_math/rect.cpp index efa656cc..fdc33e58 100644 --- a/untests/sources/untests_math/rect.cpp +++ b/untests/sources/untests_math/rect.cpp @@ -32,6 +32,15 @@ TEST_CASE("rect") { REQUIRE(make_rect(4,3,2,1) == r4i(4,3,2,1)); REQUIRE(make_rect(v2i{2,1}) == r4i(0,0,2,1)); REQUIRE(make_rect(v2i{4,3},v2i{2,1}) == r4i(4,3,2,1)); + + REQUIRE(make_minmax_rect(1,2,3,4) == r4i(1,2,2,2)); + REQUIRE(make_minmax_rect(3,4,1,2) == r4i(1,2,2,2)); + + REQUIRE(make_minmax_rect(v2i{1,2}, v2i{3,4}) == r4i(1,2,2,2)); + REQUIRE(make_minmax_rect(v2i{3,4}, v2i{1,2}) == r4i(1,2,2,2)); + + REQUIRE(make_minmax_rect(r4i(1,2,3,4)) == r4i(1,2,3,4)); + REQUIRE(make_minmax_rect(r4i(1,2,-3,4)) == r4i(-2,2,3,4)); } { auto r0 = r4i(1,2,3,4); From ca4f05a989d424581d46dfb6ada21ca7e5d51f8c Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 20:00:46 +0700 Subject: [PATCH 2/5] math::overlaps --- headers/enduro2d/math/rect.hpp | 16 ++++++++++++++++ untests/sources/untests_math/rect.cpp | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/headers/enduro2d/math/rect.hpp b/headers/enduro2d/math/rect.hpp index 9b08f15b..66343cbd 100644 --- a/headers/enduro2d/math/rect.hpp +++ b/headers/enduro2d/math/rect.hpp @@ -217,6 +217,22 @@ namespace e2d { namespace math && p.y >= min.y && p.y <= max.y; } + // + // overlaps + // + + template < typename T > + bool overlaps(const rect& l, const rect& r) noexcept { + const vec2 min_l = minimum(l); + const vec2 max_l = maximum(l); + const vec2 min_r = minimum(r); + const vec2 max_r = maximum(r); + return max_l.x > min_r.x + && min_l.x < max_r.x + && max_l.y > min_r.y + && min_l.y < max_r.y; + } + // // contains_nan // diff --git a/untests/sources/untests_math/rect.cpp b/untests/sources/untests_math/rect.cpp index fdc33e58..fd343c47 100644 --- a/untests/sources/untests_math/rect.cpp +++ b/untests/sources/untests_math/rect.cpp @@ -110,6 +110,16 @@ TEST_CASE("rect") { REQUIRE_FALSE(math::inside(r4i(1,2,-3,-4), v2i(-3,2))); REQUIRE_FALSE(math::inside(r4i(1,2,-3,-4), v2i(1,-3))); + REQUIRE_FALSE(math::overlaps(r4i(0,0,10,10), r4i(10,0,10,10))); + REQUIRE_FALSE(math::overlaps(r4i(0,0,10,10), r4i(0,10,10,10))); + REQUIRE_FALSE(math::overlaps(r4i(0,0,10,10), r4i(10,10,10,10))); + REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(9,0,10,10))); + REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(0,9,10,10))); + REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(9,9,10,10))); + REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(-9,0,10,10))); + REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(0,-9,10,10))); + REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(-9,-9,10,10))); + REQUIRE_FALSE(math::contains_nan(r4i(1,2,3,4))); REQUIRE_FALSE(math::contains_nan(r4f(1.f,2.f,3.f,4.f))); REQUIRE(math::contains_nan(r4f(1.f,std::numeric_limits::quiet_NaN()))); From 98782fcb6fc76053b7395d9a786a4123350281cd Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 20:47:33 +0700 Subject: [PATCH 3/5] normalized_to_point/point_to_normalized for rect --- headers/enduro2d/math/_math.hpp | 17 +++++++++++++ headers/enduro2d/math/rect.hpp | 26 ++++++++++++++++++++ untests/sources/untests_math/rect.cpp | 35 +++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/headers/enduro2d/math/_math.hpp b/headers/enduro2d/math/_math.hpp index 8ba7987c..8c6fe919 100644 --- a/headers/enduro2d/math/_math.hpp +++ b/headers/enduro2d/math/_math.hpp @@ -495,4 +495,21 @@ namespace e2d { namespace math constexpr std::underlying_type_t enum_to_number(E e) noexcept { return static_cast>(e); } + + // + // lerp/inverse_lerp + // + + template < typename T > + std::enable_if_t::value, T> + lerp(T l, T r, T v) noexcept { + return l + (r - l) * v; + } + + template < typename T > + std::enable_if_t::value, T> + inverse_lerp(T l, T r, T v) noexcept { + E2D_ASSERT(!is_near_zero(r - l, T(0))); + return (v - l) / (r - l); + } }} diff --git a/headers/enduro2d/math/rect.hpp b/headers/enduro2d/math/rect.hpp index 66343cbd..6378327d 100644 --- a/headers/enduro2d/math/rect.hpp +++ b/headers/enduro2d/math/rect.hpp @@ -233,6 +233,32 @@ namespace e2d { namespace math && min_l.y < max_r.y; } + // + // normalized_to_point/point_to_normalized + // + + template < typename T > + std::enable_if_t::value, vec2> + normalized_to_point(const rect& r, const vec2& p) noexcept { + const vec2 min = minimum(r); + const vec2 max = maximum(r); + return { + math::lerp(min.x, max.x, p.x), + math::lerp(min.y, max.y, p.y)}; + } + + template < typename T > + std::enable_if_t::value, vec2> + point_to_normalized(const rect& r, const vec2& p) noexcept { + E2D_ASSERT(!math::is_near_zero(r.size.x, T(0))); + E2D_ASSERT(!math::is_near_zero(r.size.y, T(0))); + const vec2 min = minimum(r); + const vec2 max = maximum(r); + return { + math::inverse_lerp(min.x, max.x, p.x), + math::inverse_lerp(min.y, max.y, p.y)}; + } + // // contains_nan // diff --git a/untests/sources/untests_math/rect.cpp b/untests/sources/untests_math/rect.cpp index fd343c47..9611846e 100644 --- a/untests/sources/untests_math/rect.cpp +++ b/untests/sources/untests_math/rect.cpp @@ -125,4 +125,39 @@ TEST_CASE("rect") { REQUIRE(math::contains_nan(r4f(1.f,std::numeric_limits::quiet_NaN()))); REQUIRE(math::contains_nan(r4f(std::numeric_limits::infinity(), 1.f))); } + { + REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(0.f, 0.f)) == v2f(0.f, 0.f)); + REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(0.5f, 0.5f)) == v2f(5.f, 10.f)); + REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(0.25f, 0.75f)) == v2f(2.5f, 15.f)); + REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(1.f, 1.f)) == v2f(10.f, 20.f)); + + REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(0.f, 0.f)) == v2f(1.f, 2.f)); + REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(0.5f, 0.5f)) == v2f(6.f, 12.f)); + REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(0.25f, 0.75f)) == v2f(3.5f, 17.f)); + REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(1.f, 1.f)) == v2f(11.f, 22.f)); + + REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, -11.f, -22.f), v2f(0.f, 0.f)) == v2f(-10.f, -20.f)); + REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, -11.f, -22.f), v2f(0.5f, 0.5f)) == v2f(-4.5f, -9.f)); + REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, -11.f, -22.f), v2f(1.f, 1.f)) == v2f(1.f, 2.f)); + + REQUIRE(math::normalized_to_point(r4f(0.f,0.f), v2f(0.f,0.f)) == v2f(0.f,0.f)); + REQUIRE(math::normalized_to_point(r4f(0.f,0.f), v2f(1.f,1.f)) == v2f(0.f,0.f)); + REQUIRE(math::normalized_to_point(r4f(1.f,2.f,0.f,0.f), v2f(0.f,0.f)) == v2f(1.f,2.f)); + REQUIRE(math::normalized_to_point(r4f(1.f,2.f,0.f,0.f), v2f(1.f,1.f)) == v2f(1.f,2.f)); + } + { + REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(0.f, 0.f)) == v2f(0.f, 0.f)); + REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(5.f, 10.f)) == v2f(0.5f,0.5f)); + REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(2.5f, 15.f)) == v2f(0.25f, 0.75f)); + REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(10.f, 20.f)) == v2f(1.f, 1.f)); + + REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(1.f, 2.f)) == v2f(0.f, 0.f)); + REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(6.f, 12.f)) == v2f(0.5f, 0.5f)); + REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(3.5f, 17.f)) == v2f(0.25f, 0.75f)); + REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(11.f, 22.f)) == v2f(1.f, 1.f)); + + REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, -11.f, -22.f), v2f(-10.f, -20.f)) == v2f(0.f, 0.f)); + REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, -11.f, -22.f), v2f(-4.5f, -9.f)) == v2f(0.5f, 0.5f)); + REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, -11.f, -22.f), v2f(1.f, 2.f)) == v2f(1.f, 1.f)); + } } From ed4e0d86f50969778c5325fc6461219df7c25ac4 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 22:26:45 +0700 Subject: [PATCH 4/5] lerp/inverse_lerp --- headers/enduro2d/math/_math.hpp | 8 +++--- headers/enduro2d/math/rect.hpp | 16 ++++-------- headers/enduro2d/math/vec2.hpp | 28 +++++++++++++++++++++ headers/enduro2d/math/vec3.hpp | 31 +++++++++++++++++++++++ headers/enduro2d/math/vec4.hpp | 34 ++++++++++++++++++++++++++ untests/sources/untests_math/_math.cpp | 31 +++++++++++++++++++++++ untests/sources/untests_math/vec2.cpp | 19 ++++++++++++++ untests/sources/untests_math/vec3.cpp | 19 ++++++++++++++ untests/sources/untests_math/vec4.cpp | 19 ++++++++++++++ 9 files changed, 189 insertions(+), 16 deletions(-) diff --git a/headers/enduro2d/math/_math.hpp b/headers/enduro2d/math/_math.hpp index 8c6fe919..7d8bc07a 100644 --- a/headers/enduro2d/math/_math.hpp +++ b/headers/enduro2d/math/_math.hpp @@ -501,15 +501,13 @@ namespace e2d { namespace math // template < typename T > - std::enable_if_t::value, T> - lerp(T l, T r, T v) noexcept { + T lerp(T l, T r, T v) noexcept { return l + (r - l) * v; } template < typename T > - std::enable_if_t::value, T> - inverse_lerp(T l, T r, T v) noexcept { - E2D_ASSERT(!is_near_zero(r - l, T(0))); + T inverse_lerp(T l, T r, T v) noexcept { + E2D_ASSERT(!approximately(l, r, T(0))); return (v - l) / (r - l); } }} diff --git a/headers/enduro2d/math/rect.hpp b/headers/enduro2d/math/rect.hpp index 6378327d..9a4fe508 100644 --- a/headers/enduro2d/math/rect.hpp +++ b/headers/enduro2d/math/rect.hpp @@ -200,9 +200,9 @@ namespace e2d { namespace math template < typename T > rect merged(const rect& l, const rect& r) noexcept { - const vec2 min = math::minimized(minimum(l), minimum(r)); - const vec2 max = math::maximized(maximum(l), maximum(r)); - return { min, max - min }; + return make_minmax_rect( + math::minimized(minimum(l), minimum(r)), + math::maximized(maximum(l), maximum(r))); } // @@ -242,21 +242,15 @@ namespace e2d { namespace math normalized_to_point(const rect& r, const vec2& p) noexcept { const vec2 min = minimum(r); const vec2 max = maximum(r); - return { - math::lerp(min.x, max.x, p.x), - math::lerp(min.y, max.y, p.y)}; + return math::lerp(min, max, p); } template < typename T > std::enable_if_t::value, vec2> point_to_normalized(const rect& r, const vec2& p) noexcept { - E2D_ASSERT(!math::is_near_zero(r.size.x, T(0))); - E2D_ASSERT(!math::is_near_zero(r.size.y, T(0))); const vec2 min = minimum(r); const vec2 max = maximum(r); - return { - math::inverse_lerp(min.x, max.x, p.x), - math::inverse_lerp(min.y, max.y, p.y)}; + return math::inverse_lerp(min, max, p); } // diff --git a/headers/enduro2d/math/vec2.hpp b/headers/enduro2d/math/vec2.hpp index f986e04b..ec390928 100644 --- a/headers/enduro2d/math/vec2.hpp +++ b/headers/enduro2d/math/vec2.hpp @@ -505,6 +505,34 @@ namespace e2d { namespace math return clamped(v, vec2::zero(), vec2::unit()); } + // + // lerp/inverse_lerp + // + + template < typename T > + std::enable_if_t::value, vec2> + lerp(const vec2& l, const vec2& r, T v) noexcept { + return { + math::lerp(l.x, r.x, v), + math::lerp(l.y, r.y, v)}; + } + + template < typename T > + std::enable_if_t::value, vec2> + lerp(const vec2& l, const vec2& r, const vec2& v) noexcept { + return { + math::lerp(l.x, r.x, v.x), + math::lerp(l.y, r.y, v.y)}; + } + + template < typename T > + std::enable_if_t::value, vec2> + inverse_lerp(const vec2& l, const vec2& r, const vec2& v) noexcept { + return { + math::inverse_lerp(l.x, r.x, v.x), + math::inverse_lerp(l.y, r.y, v.y)}; + } + // // contains_nan // diff --git a/headers/enduro2d/math/vec3.hpp b/headers/enduro2d/math/vec3.hpp index f2351d86..0ded3b75 100644 --- a/headers/enduro2d/math/vec3.hpp +++ b/headers/enduro2d/math/vec3.hpp @@ -563,6 +563,37 @@ namespace e2d { namespace math return clamped(v, vec3::zero(), vec3::unit()); } + // + // lerp/inverse_lerp + // + + template < typename T > + std::enable_if_t::value, vec3> + lerp(const vec3& l, const vec3& r, T v) noexcept { + return { + math::lerp(l.x, r.x, v), + math::lerp(l.y, r.y, v), + math::lerp(l.z, r.z, v)}; + } + + template < typename T > + std::enable_if_t::value, vec3> + lerp(const vec3& l, const vec3& r, const vec3& v) noexcept { + return { + math::lerp(l.x, r.x, v.x), + math::lerp(l.y, r.y, v.y), + math::lerp(l.z, r.z, v.z)}; + } + + template < typename T > + std::enable_if_t::value, vec3> + inverse_lerp(const vec3& l, const vec3& r, const vec3& v) noexcept { + return { + math::inverse_lerp(l.x, r.x, v.x), + math::inverse_lerp(l.y, r.y, v.y), + math::inverse_lerp(l.z, r.z, v.z)}; + } + // // contains_nan // diff --git a/headers/enduro2d/math/vec4.hpp b/headers/enduro2d/math/vec4.hpp index 6653adc9..ce1a055d 100644 --- a/headers/enduro2d/math/vec4.hpp +++ b/headers/enduro2d/math/vec4.hpp @@ -597,6 +597,40 @@ namespace e2d { namespace math return clamped(v, vec4::zero(), vec4::unit()); } + // + // lerp/inverse_lerp + // + + template < typename T > + std::enable_if_t::value, vec4> + lerp(const vec4& l, const vec4& r, T v) noexcept { + return { + math::lerp(l.x, r.x, v), + math::lerp(l.y, r.y, v), + math::lerp(l.z, r.z, v), + math::lerp(l.w, r.w, v)}; + } + + template < typename T > + std::enable_if_t::value, vec4> + lerp(const vec4& l, const vec4& r, const vec4& v) noexcept { + return { + math::lerp(l.x, r.x, v.x), + math::lerp(l.y, r.y, v.y), + math::lerp(l.z, r.z, v.z), + math::lerp(l.w, r.w, v.w)}; + } + + template < typename T > + std::enable_if_t::value, vec4> + inverse_lerp(const vec4& l, const vec4& r, const vec4& v) noexcept { + return { + math::inverse_lerp(l.x, r.x, v.x), + math::inverse_lerp(l.y, r.y, v.y), + math::inverse_lerp(l.z, r.z, v.z), + math::inverse_lerp(l.w, r.w, v.w)}; + } + // // contains_nan // diff --git a/untests/sources/untests_math/_math.cpp b/untests/sources/untests_math/_math.cpp index 5ad776e9..e2e9049b 100644 --- a/untests/sources/untests_math/_math.cpp +++ b/untests/sources/untests_math/_math.cpp @@ -255,6 +255,37 @@ TEST_CASE("math") { REQUIRE(math::is_near_zero(0.0001f, 0.001f)); REQUIRE(math::is_near_zero(-0.0001f, 0.001f)); } + { + enum class ee_u8 : u8 { + ee1 = 10, + ee2 = 42 + }; + enum class ee_i16 : i16 { + ee1 = 10, + ee2 = 42 + }; + auto e1 = math::enum_to_number(ee_u8::ee1); + auto e2 = math::enum_to_number(ee_i16::ee2); + REQUIRE(e1 == u8(10)); + REQUIRE(e2 == i16(42)); + static_assert( + std::is_same::value, + "static unit test error"); + static_assert( + std::is_same::value, + "static unit test error"); + } + { + REQUIRE(math::approximately(math::lerp(1.f, 11.f, 0.f), 1.f)); + REQUIRE(math::approximately(math::lerp(1.f, 11.f, 0.5f), 6.f)); + REQUIRE(math::approximately(math::lerp(1.f, 11.f, 1.f), 11.f)); + REQUIRE(math::approximately(math::lerp(1.f, 11.f, 2.f), 21.f)); + + REQUIRE(math::approximately(math::inverse_lerp(1.f, 11.f, 1.f), 0.f)); + REQUIRE(math::approximately(math::inverse_lerp(1.f, 11.f, 6.f), 0.5f)); + REQUIRE(math::approximately(math::inverse_lerp(1.f, 11.f, 11.f), 1.f)); + REQUIRE(math::approximately(math::inverse_lerp(1.f, 11.f, 21.f), 2.f)); + } { static_assert( std::is_same>::value, diff --git a/untests/sources/untests_math/vec2.cpp b/untests/sources/untests_math/vec2.cpp index e7ea3f94..445660e3 100644 --- a/untests/sources/untests_math/vec2.cpp +++ b/untests/sources/untests_math/vec2.cpp @@ -248,6 +248,25 @@ TEST_CASE("vec2") { REQUIRE(math::saturated(v2f(-1, 0.5f)) == v2f(0,0.5f)); REQUIRE(math::saturated(v2f(0.5f,2.f)) == v2f(0.5f,1.f)); } + { + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), 0.f) == v2f(1,2)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), 0.5f) == v2f(5.5f,11)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), 1.f) == v2f(10,20)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), 2.f) == v2f(19,38)); + + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(0.f)) == v2f(1,2)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(0.5f)) == v2f(5.5f,11)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(1.f)) == v2f(10,20)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(2.f)) == v2f(19,38)); + + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(0.f,1.f)) == v2f(1,20)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(0.5f,2.f)) == v2f(5.5f,38)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(1.f,0.5f)) == v2f(10,11)); + REQUIRE(math::lerp(v2f(1,2), v2f(10,20), v2f(2.f,0.f)) == v2f(19,2)); + + REQUIRE(math::inverse_lerp(v2f(1,2), v2f(10,20), v2f(5.5f,11)) == v2f(0.5f)); + REQUIRE(math::inverse_lerp(v2f(1,2), v2f(10,20), v2f(5.5f,38)) == v2f(0.5f,2.f)); + } { REQUIRE_FALSE(math::contains_nan(v2i(0,1))); REQUIRE_FALSE(math::contains_nan(v2f(0.f,1.f))); diff --git a/untests/sources/untests_math/vec3.cpp b/untests/sources/untests_math/vec3.cpp index df25132b..d29833a4 100644 --- a/untests/sources/untests_math/vec3.cpp +++ b/untests/sources/untests_math/vec3.cpp @@ -271,6 +271,25 @@ TEST_CASE("vec3") { REQUIRE(math::saturated(v3f(2,0.6f,2)) == v3f(1,0.6f,1)); REQUIRE(math::saturated(v3f(0.6f,-2,2)) == v3f(0.6f,0,1)); } + { + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), 0.f) == v3f(1,2,1)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), 0.5f) == v3f(5.5f,11,5.5f)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), 1.f) == v3f(10,20,10)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), 2.f) == v3f(19,38,19)); + + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(0.f)) == v3f(1,2,1)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(0.5f)) == v3f(5.5f,11,5.5f)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(1.f)) == v3f(10,20,10)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(2.f)) == v3f(19,38,19)); + + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(0.f,1.f,0.f)) == v3f(1,20,1)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(0.5f,2.f,0.5f)) == v3f(5.5f,38,5.5f)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(1.f,0.5f,1.f)) == v3f(10,11,10)); + REQUIRE(math::lerp(v3f(1,2,1), v3f(10,20,10), v3f(2.f,0.f,2.f)) == v3f(19,2,19)); + + REQUIRE(math::inverse_lerp(v3f(1,2,1), v3f(10,20,10), v3f(5.5f,11,5.5f)) == v3f(0.5f)); + REQUIRE(math::inverse_lerp(v3f(1,2,1), v3f(10,20,10), v3f(5.5f,38,5.5f)) == v3f(0.5f,2.f,0.5f)); + } { REQUIRE_FALSE(math::contains_nan(v3i(0,1,2))); REQUIRE_FALSE(math::contains_nan(v3f(0.f,1.f,2.f))); diff --git a/untests/sources/untests_math/vec4.cpp b/untests/sources/untests_math/vec4.cpp index e9d523dc..ad35a31a 100644 --- a/untests/sources/untests_math/vec4.cpp +++ b/untests/sources/untests_math/vec4.cpp @@ -288,6 +288,25 @@ TEST_CASE("vec4") { REQUIRE(math::saturated(v4f(2,0.6f,2,0.7f)) == v4f(1,0.6f,1,0.7f)); REQUIRE(math::saturated(v4f(0.6f,-2,2,2)) == v4f(0.6f,0,1,1)); } + { + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), 0.f) == v4f(1,2,1,2)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), 0.5f) == v4f(5.5f,11,5.5f,11)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), 1.f) == v4f(10,20,10,20)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), 2.f) == v4f(19,38,19,38)); + + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(0.f)) == v4f(1,2,1,2)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(0.5f)) == v4f(5.5f,11,5.5f,11)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(1.f)) == v4f(10,20,10,20)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(2.f)) == v4f(19,38,19,38)); + + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(0.f,1.f,0.f,1.f)) == v4f(1,20,1,20)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(0.5f,2.f,0.5f,2.f)) == v4f(5.5f,38,5.5f,38)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(1.f,0.5f,1.f,0.5f)) == v4f(10,11,10,11)); + REQUIRE(math::lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(2.f,0.f,2.f,0.f)) == v4f(19,2,19,2)); + + REQUIRE(math::inverse_lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(5.5f,11,5.5f,11)) == v4f(0.5f)); + REQUIRE(math::inverse_lerp(v4f(1,2,1,2), v4f(10,20,10,20), v4f(5.5f,38,5.5f,38)) == v4f(0.5f,2.f,0.5f,2.f)); + } { REQUIRE_FALSE(math::contains_nan(v4i(0,1,2,3))); REQUIRE_FALSE(math::contains_nan(v4f(0.f,1.f,2.f,3.f))); From 09f7bc8a92d59a7d63e81456a8fc1333b3b60d34 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 23:32:23 +0700 Subject: [PATCH 5/5] math aabb class --- headers/enduro2d/math/_all.hpp | 1 + headers/enduro2d/math/_math.hpp | 22 ++- headers/enduro2d/math/aabb.hpp | 263 ++++++++++++++++++++++++++ headers/enduro2d/math/rect.hpp | 12 +- headers/enduro2d/math/vec3.hpp | 9 +- headers/enduro2d/math/vec4.hpp | 9 +- untests/sources/untests_math/aabb.cpp | 116 ++++++++++++ untests/sources/untests_math/rect.cpp | 220 ++++++++++----------- 8 files changed, 516 insertions(+), 136 deletions(-) create mode 100644 headers/enduro2d/math/aabb.hpp create mode 100644 untests/sources/untests_math/aabb.cpp diff --git a/headers/enduro2d/math/_all.hpp b/headers/enduro2d/math/_all.hpp index 46b3da52..2d037d79 100644 --- a/headers/enduro2d/math/_all.hpp +++ b/headers/enduro2d/math/_all.hpp @@ -8,6 +8,7 @@ #include "_math.hpp" +#include "aabb.hpp" #include "mat2.hpp" #include "mat3.hpp" #include "mat4.hpp" diff --git a/headers/enduro2d/math/_math.hpp b/headers/enduro2d/math/_math.hpp index 7d8bc07a..23ed859d 100644 --- a/headers/enduro2d/math/_math.hpp +++ b/headers/enduro2d/math/_math.hpp @@ -31,6 +31,9 @@ namespace e2d template < typename T > class rect; + template < typename T > + class aabb; + template < typename T, typename Tag > class unit; @@ -82,12 +85,19 @@ namespace e2d using m4hi = mat4; using m4hu = mat4; - using r4d = rect; - using r4f = rect; - using r4i = rect; - using r4u = rect; - using r4hi = rect; - using r4hu = rect; + using b2d = rect; + using b2f = rect; + using b2i = rect; + using b2u = rect; + using b2hi = rect; + using b2hu = rect; + + using b3d = aabb; + using b3f = aabb; + using b3i = aabb; + using b3u = aabb; + using b3hi = aabb; + using b3hu = aabb; struct deg_tag {}; struct rad_tag {}; diff --git a/headers/enduro2d/math/aabb.hpp b/headers/enduro2d/math/aabb.hpp new file mode 100644 index 00000000..c64450ae --- /dev/null +++ b/headers/enduro2d/math/aabb.hpp @@ -0,0 +1,263 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018 Matvey Cherevko + ******************************************************************************/ + +#pragma once + +#include "_math.hpp" +#include "vec3.hpp" + +namespace e2d +{ + template < typename T > + class aabb final { + static_assert( + std::is_arithmetic::value, + "type of 'aabb' must be arithmetic"); + public: + using self_type = aabb; + using value_type = T; + public: + vec3 position; + vec3 size; + public: + aabb() noexcept = default; + aabb(const aabb& other) noexcept = default; + aabb& operator=(const aabb& other) noexcept = default; + + aabb(T w, T h, T l) noexcept; + aabb(T x, T y, T z, T w, T h, T l) noexcept; + + aabb(const vec3& nsize) noexcept; + aabb(const vec3& nposition, const vec3& nsize) noexcept; + + template < typename To > + aabb cast_to() const noexcept; + }; +} + +namespace e2d +{ + template < typename T > + aabb::aabb(T w, T h, T l) noexcept + : size(w, h, l) {} + + template < typename T > + aabb::aabb(T x, T y, T z, T w, T h, T l) noexcept + : position(x, y, z) + , size(w, h, l) {} + + template < typename T > + aabb::aabb(const vec3& nsize) noexcept + : size(nsize) {} + + template < typename T > + aabb::aabb(const vec3& nposition, const vec3& nsize) noexcept + : position(nposition) + , size(nsize) {} + + template < typename T > + template < typename To > + aabb aabb::cast_to() const noexcept { + return { + position.template cast_to(), + size.template cast_to()}; + } +} + +namespace e2d +{ + // + // make_aabb + // + + template < typename T > + aabb make_aabb(T w, T h, T l) noexcept { + return {w, h, l}; + } + + template < typename T > + aabb make_aabb(T x, T y, T z, T w, T h, T l) noexcept { + return {x, y, z, w, h, l}; + } + + template < typename T > + aabb make_aabb(const vec3& size) noexcept { + return {size}; + } + + template < typename T > + aabb make_aabb(const vec3& position, const vec3& size) noexcept { + return {position, size}; + } + + template < typename T > + aabb make_minmax_aabb(T x1, T y1, T z1, T x2, T y2, T z2) noexcept { + const vec3 min = {math::min(x1, x2), math::min(y1, y2), math::min(z1, z2)}; + const vec3 max = {math::max(x1, x2), math::max(y1, y2), math::max(z1, z2)}; + return {min, max - min}; + } + + template < typename T > + aabb make_minmax_aabb(const vec3& p1, const vec3& p2) noexcept { + return make_minmax_aabb(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); + } + + template < typename T > + aabb make_minmax_aabb(const aabb& b) noexcept { + return make_minmax_aabb(b.position, b.position + b.size); + } + + // + // aabb (==,!=) aabb + // + + template < typename T > + bool operator==(const aabb& l, const aabb& r) noexcept { + return l.position == r.position + && l.size == r.size; + } + + template < typename T > + bool operator!=(const aabb& l, const aabb& r) noexcept { + return !(l == r); + } + + // + // aabb (<,>,<=,>=) aabb + // + + template < typename T > + bool operator<(const aabb& l, const aabb& r) noexcept { + return l.size.x * l.size.y * l.size.z < r.size.x * r.size.y * r.size.z; + } + + template < typename T > + bool operator>(const aabb& l, const aabb& r) noexcept { + return r < l; + } + + template < typename T > + bool operator<=(const aabb& l, const aabb& r) noexcept { + return !(r < l); + } + + template < typename T > + bool operator>=(const aabb& l, const aabb& r) noexcept { + return !(l < r); + } +} + +namespace e2d { namespace math +{ + // + // approximately + // + + template < typename T > + bool approximately( + const aabb& l, + const aabb& r, + T precision = math::default_precision()) noexcept + { + return math::approximately(l.position, r.position, precision) + && math::approximately(l.size, r.size, precision); + } + + // + // minimum/maximum + // + + template < typename T > + vec3 minimum(const aabb& b) noexcept { + return math::minimized(b.position, b.position + b.size); + } + + template < typename T > + vec3 maximum(const aabb& b) noexcept { + return math::maximized(b.position, b.position + b.size); + } + + // + // volume + // + + template < typename T > + T volume(const aabb& b) noexcept { + return b.size.x * b.size.y * b.size.z; + } + + template < typename T > + T abs_volume(const aabb& b) noexcept { + return math::abs(b.size.x * b.size.y * b.size.z); + } + + // + // merged + // + + template < typename T > + aabb merged(const aabb& l, const aabb& r) noexcept { + return make_minmax_aabb( + math::minimized(minimum(l), minimum(r)), + math::maximized(maximum(l), maximum(r))); + } + + // + // inside + // + + template < typename T > + bool inside(const aabb& r, const vec3& p) noexcept { + const vec3 min = minimum(r); + const vec3 max = maximum(r); + return p.x >= min.x && p.x <= max.x + && p.y >= min.y && p.y <= max.y + && p.z >= min.z && p.z <= max.z; + } + + // + // overlaps + // + + template < typename T > + bool overlaps(const aabb& l, const aabb& r) noexcept { + const vec3 min_l = minimum(l); + const vec3 max_l = maximum(l); + const vec3 min_r = minimum(r); + const vec3 max_r = maximum(r); + return max_l.x > min_r.x && min_l.x < max_r.x + && max_l.y > min_r.y && min_l.y < max_r.y + && max_l.z > min_r.z && min_l.z < max_r.z; + } + + // + // normalized_to_point/point_to_normalized + // + + template < typename T > + vec3 normalized_to_point(const aabb& r, const vec3& p) noexcept { + const vec3 min = minimum(r); + const vec3 max = maximum(r); + return math::lerp(min, max, p); + } + + template < typename T > + vec3 point_to_normalized(const aabb& r, const vec3& p) noexcept { + const vec3 min = minimum(r); + const vec3 max = maximum(r); + return math::inverse_lerp(min, max, p); + } + + // + // contains_nan + // + + template < typename T > + bool contains_nan(const aabb& r) noexcept { + return math::contains_nan(r.position) + || math::contains_nan(r.size); + } +}} diff --git a/headers/enduro2d/math/rect.hpp b/headers/enduro2d/math/rect.hpp index 9a4fe508..3c1790d4 100644 --- a/headers/enduro2d/math/rect.hpp +++ b/headers/enduro2d/math/rect.hpp @@ -227,10 +227,8 @@ namespace e2d { namespace math const vec2 max_l = maximum(l); const vec2 min_r = minimum(r); const vec2 max_r = maximum(r); - return max_l.x > min_r.x - && min_l.x < max_r.x - && max_l.y > min_r.y - && min_l.y < max_r.y; + return max_l.x > min_r.x && min_l.x < max_r.x + && max_l.y > min_r.y && min_l.y < max_r.y; } // @@ -238,16 +236,14 @@ namespace e2d { namespace math // template < typename T > - std::enable_if_t::value, vec2> - normalized_to_point(const rect& r, const vec2& p) noexcept { + vec2 normalized_to_point(const rect& r, const vec2& p) noexcept { const vec2 min = minimum(r); const vec2 max = maximum(r); return math::lerp(min, max, p); } template < typename T > - std::enable_if_t::value, vec2> - point_to_normalized(const rect& r, const vec2& p) noexcept { + vec2 point_to_normalized(const rect& r, const vec2& p) noexcept { const vec2 min = minimum(r); const vec2 max = maximum(r); return math::inverse_lerp(min, max, p); diff --git a/headers/enduro2d/math/vec3.hpp b/headers/enduro2d/math/vec3.hpp index 0ded3b75..1cdc8a86 100644 --- a/headers/enduro2d/math/vec3.hpp +++ b/headers/enduro2d/math/vec3.hpp @@ -568,8 +568,7 @@ namespace e2d { namespace math // template < typename T > - std::enable_if_t::value, vec3> - lerp(const vec3& l, const vec3& r, T v) noexcept { + vec3 lerp(const vec3& l, const vec3& r, T v) noexcept { return { math::lerp(l.x, r.x, v), math::lerp(l.y, r.y, v), @@ -577,8 +576,7 @@ namespace e2d { namespace math } template < typename T > - std::enable_if_t::value, vec3> - lerp(const vec3& l, const vec3& r, const vec3& v) noexcept { + vec3 lerp(const vec3& l, const vec3& r, const vec3& v) noexcept { return { math::lerp(l.x, r.x, v.x), math::lerp(l.y, r.y, v.y), @@ -586,8 +584,7 @@ namespace e2d { namespace math } template < typename T > - std::enable_if_t::value, vec3> - inverse_lerp(const vec3& l, const vec3& r, const vec3& v) noexcept { + vec3 inverse_lerp(const vec3& l, const vec3& r, const vec3& v) noexcept { return { math::inverse_lerp(l.x, r.x, v.x), math::inverse_lerp(l.y, r.y, v.y), diff --git a/headers/enduro2d/math/vec4.hpp b/headers/enduro2d/math/vec4.hpp index ce1a055d..8a9ee38f 100644 --- a/headers/enduro2d/math/vec4.hpp +++ b/headers/enduro2d/math/vec4.hpp @@ -602,8 +602,7 @@ namespace e2d { namespace math // template < typename T > - std::enable_if_t::value, vec4> - lerp(const vec4& l, const vec4& r, T v) noexcept { + vec4 lerp(const vec4& l, const vec4& r, T v) noexcept { return { math::lerp(l.x, r.x, v), math::lerp(l.y, r.y, v), @@ -612,8 +611,7 @@ namespace e2d { namespace math } template < typename T > - std::enable_if_t::value, vec4> - lerp(const vec4& l, const vec4& r, const vec4& v) noexcept { + vec4 lerp(const vec4& l, const vec4& r, const vec4& v) noexcept { return { math::lerp(l.x, r.x, v.x), math::lerp(l.y, r.y, v.y), @@ -622,8 +620,7 @@ namespace e2d { namespace math } template < typename T > - std::enable_if_t::value, vec4> - inverse_lerp(const vec4& l, const vec4& r, const vec4& v) noexcept { + vec4 inverse_lerp(const vec4& l, const vec4& r, const vec4& v) noexcept { return { math::inverse_lerp(l.x, r.x, v.x), math::inverse_lerp(l.y, r.y, v.y), diff --git a/untests/sources/untests_math/aabb.cpp b/untests/sources/untests_math/aabb.cpp new file mode 100644 index 00000000..2f882ff0 --- /dev/null +++ b/untests/sources/untests_math/aabb.cpp @@ -0,0 +1,116 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018 Matvey Cherevko + ******************************************************************************/ + +#include "_math.hpp" +using namespace e2d; + +TEST_CASE("aabb") { + { + REQUIRE(b3i().position == v3i(0,0,0)); + REQUIRE(b3i().size == v3i(0,0,0)); + + REQUIRE(b3i(1,2,3).position == v3i(0,0,0)); + REQUIRE(b3i(1,2,3).size == v3i(1,2,3)); + + REQUIRE(b3i(1,2,3,4,5,6).position == v3i(1,2,3)); + REQUIRE(b3i(1,2,3,4,5,6).size == v3i(4,5,6)); + + REQUIRE(b3i(v3i{1,2,3}).position == v3i(0,0,0)); + REQUIRE(b3i(v3i{1,2,3}).size == v3i(1,2,3)); + + REQUIRE(b3i(v3i{1,2,3},v3i{3,4,5}).position == v3i(1,2,3)); + REQUIRE(b3i(v3i{1,2,3},v3i{3,4,5}).size == v3i(3,4,5)); + } + { + REQUIRE(b3f(1,2,3,4,5,6).cast_to() == b3i(1,2,3,4,5,6)); + } + { + REQUIRE(make_aabb(2,1,0) == b3i(0,0,0,2,1,0)); + REQUIRE(make_aabb(4,3,2,1,0,-1) == b3i(4,3,2,1,0,-1)); + REQUIRE(make_aabb(v3i{2,1,0}) == b3i(0,0,0,2,1,0)); + REQUIRE(make_aabb(v3i{4,3,2},v3i{2,1,0}) == b3i(4,3,2,2,1,0)); + + REQUIRE(make_minmax_aabb(1,2,3,4,5,6) == b3i(1,2,3,3,3,3)); + REQUIRE(make_minmax_aabb(3,4,1,2,3,4) == b3i(2,3,1,1,1,3)); + } + { + auto r0 = b3i(1,2,3,4,5,6); + auto r1 = b3i(r0); + REQUIRE(r1 == b3i(1,2,3,4,5,6)); + r1 = b3i(4,3,2,1,0,-1); + REQUIRE(r1 == b3i(4,3,2,1,0,-1)); + } + { + REQUIRE(b3i(1,2,3,4,5,6) == b3i(1,2,3,4,5,6)); + REQUIRE_FALSE(b3i(1,2,3,4,5,6) == b3i(1,2,4,3,5,6)); + REQUIRE_FALSE(b3i(1,2,3,4,5,6) == b3i(2,1,3,4,5,6)); + REQUIRE_FALSE(b3i(1,2,3,4,5,6) == b3i(2,1,4,3,5,6)); + + REQUIRE_FALSE(b3i(1,2,3,4,5,6) != b3i(1,2,3,4,5,6)); + REQUIRE(b3i(1,2,3,4,5,6) != b3i(1,2,4,3,5,6)); + REQUIRE(b3i(1,2,3,4,5,6) != b3i(2,1,3,4,5,6)); + REQUIRE(b3i(1,2,3,4,5,6) != b3i(2,1,4,3,5,6)); + } + { + REQUIRE(b3i(4,4,1) < b3i(4,5,1)); + REQUIRE_FALSE(b3i(4,4,1) < b3i(3,4,1)); + REQUIRE_FALSE(b3i(4,4,1) < b3i(4,3,1)); + } + { + REQUIRE(math::approximately(b3i(1,2,3,4,1,2), b3i(1,2,4,5,1,2), 1)); + REQUIRE_FALSE(math::approximately(b3i(1,2,3,4,1,2), b3i(1,2,4,5,1,2))); + } + { + REQUIRE(math::minimum(b3i(1,2,3,4,5,6)) == v3i(1,2,3)); + REQUIRE(math::maximum(b3i(1,2,3,4,5,6)) == v3i(5,7,9)); + + REQUIRE(math::volume(b3i(1,2,3,4,5,6)) == 120); + REQUIRE(math::volume(b3i(1,2,3,-4,5,6)) == -120); + REQUIRE(math::volume(b3i(1,2,3,4,-5,6)) == -120); + REQUIRE(math::volume(b3i(1,2,3,-4,5,-6)) == 120); + + REQUIRE(math::abs_volume(b3i(1,2,3,4,5,6)) == 120); + REQUIRE(math::abs_volume(b3i(1,2,3,-4,5,6)) == 120); + REQUIRE(math::abs_volume(b3i(1,2,3,4,-5,6)) == 120); + REQUIRE(math::abs_volume(b3i(1,2,3,-4,5,-6)) == 120); + + REQUIRE(math::merged(b3i(1,2,3,4,5,6), b3i(1,2,3,4,5,6)) == b3i(1,2,3,4,5,6)); + REQUIRE(math::merged(b3i(1,2,3,4,5,6), b3i(0,2,3,4,5,6)) == b3i(0,2,3,5,5,6)); + REQUIRE(math::merged(b3i(1,2,3,4,5,6), b3i(1,2,3,4,5,7)) == b3i(1,2,3,4,5,7)); + + REQUIRE(math::inside(b3i(1,2,3,4,5,6), v3i(1,2,3))); + REQUIRE(math::inside(b3i(1,2,3,4,5,6), v3i(4,5,6))); + REQUIRE_FALSE(math::inside(b3i(1,2,3,4,5,6), v3i(3,4,10))); + REQUIRE_FALSE(math::inside(b3i(1,2,3,4,5,6), v3i(0,3,5))); + + REQUIRE_FALSE(math::overlaps(b3i(0,0,0,10,10,10), b3i(10,0,0,10,10,10))); + REQUIRE_FALSE(math::overlaps(b3i(0,0,0,10,10,10), b3i(0,0,10,10,10,10))); + REQUIRE_FALSE(math::overlaps(b3i(0,0,0,10,10,10), b3i(10,10,0,10,10,10))); + REQUIRE(math::overlaps(b3i(0,0,0,10,10,10), b3i(9,0,0,10,10,10))); + REQUIRE(math::overlaps(b3i(0,0,0,10,10,10), b3i(0,9,0,10,10,10))); + REQUIRE(math::overlaps(b3i(0,0,0,10,10,10), b3i(9,9,0,10,10,10))); + REQUIRE(math::overlaps(b3i(0,0,0,10,10,10), b3i(-9,0,0,10,10,10))); + REQUIRE(math::overlaps(b3i(0,0,0,10,10,10), b3i(0,-9,0,10,10,10))); + REQUIRE(math::overlaps(b3i(0,0,0,10,10,10), b3i(-9,-9,0,10,10,10))); + + REQUIRE_FALSE(math::contains_nan(b3i(1,2,3,4,5,6))); + REQUIRE_FALSE(math::contains_nan(b3f(1.f,2.f,3.f,4.f,5.f,6.f))); + REQUIRE(math::contains_nan(b3f(1.f,2.f,std::numeric_limits::quiet_NaN()))); + REQUIRE(math::contains_nan(b3f(std::numeric_limits::infinity(), 1.f,2.f))); + } + { + REQUIRE(math::normalized_to_point(b3f(10.f, 20.f, 30.f), v3f(0.f, 0.f, 0.f)) == v3f(0.f, 0.f, 0.f)); + REQUIRE(math::normalized_to_point(b3f(10.f, 20.f, 30.f), v3f(0.5f, 0.5f, 0.5f)) == v3f(5.f, 10.f, 15.f)); + REQUIRE(math::normalized_to_point(b3f(10.f, 20.f, 30.f), v3f(0.25f, 0.75f, 0.75f)) == v3f(2.5f, 15.f, 22.5f)); + REQUIRE(math::normalized_to_point(b3f(10.f, 20.f, 30.f), v3f(1.f, 1.f, 1.f)) == v3f(10.f, 20.f, 30.f)); + } + { + REQUIRE(math::point_to_normalized(b3f(10.f, 20.f, 30.f), v3f(0.f, 0.f, 0.f)) == v3f(0.f, 0.f, 0.f)); + REQUIRE(math::point_to_normalized(b3f(10.f, 20.f, 30.f), v3f(5.f, 10.f, 15.f)) == v3f(0.5f, 0.5f, 0.5f)); + REQUIRE(math::point_to_normalized(b3f(10.f, 20.f, 30.f), v3f(2.5f, 15.f, 22.5f)) == v3f(0.25f, 0.75f, 0.75f)); + REQUIRE(math::point_to_normalized(b3f(10.f, 20.f, 30.f), v3f(10.f, 20.f, 30.f)) == v3f(1.f, 1.f, 1.f)); + } +} diff --git a/untests/sources/untests_math/rect.cpp b/untests/sources/untests_math/rect.cpp index 9611846e..6f3b9a43 100644 --- a/untests/sources/untests_math/rect.cpp +++ b/untests/sources/untests_math/rect.cpp @@ -9,155 +9,155 @@ using namespace e2d; TEST_CASE("rect") { { - REQUIRE(r4i().position == v2i(0,0)); - REQUIRE(r4i().size == v2i(0,0)); + REQUIRE(b2i().position == v2i(0,0)); + REQUIRE(b2i().size == v2i(0,0)); - REQUIRE(r4i(1,2).position == v2i(0,0)); - REQUIRE(r4i(1,2).size == v2i(1,2)); + REQUIRE(b2i(1,2).position == v2i(0,0)); + REQUIRE(b2i(1,2).size == v2i(1,2)); - REQUIRE(r4i(1,2,3,4).position == v2i(1,2)); - REQUIRE(r4i(1,2,3,4).size == v2i(3,4)); + REQUIRE(b2i(1,2,3,4).position == v2i(1,2)); + REQUIRE(b2i(1,2,3,4).size == v2i(3,4)); - REQUIRE(r4i(v2i{1,2}).position == v2i(0,0)); - REQUIRE(r4i(v2i{1,2}).size == v2i(1,2)); + REQUIRE(b2i(v2i{1,2}).position == v2i(0,0)); + REQUIRE(b2i(v2i{1,2}).size == v2i(1,2)); - REQUIRE(r4i(v2i{1,2},v2i{3,4}).position == v2i(1,2)); - REQUIRE(r4i(v2i{1,2},v2i{3,4}).size == v2i(3,4)); + REQUIRE(b2i(v2i{1,2},v2i{3,4}).position == v2i(1,2)); + REQUIRE(b2i(v2i{1,2},v2i{3,4}).size == v2i(3,4)); } { - REQUIRE(r4f(1,2,3,4).cast_to() == r4i(1,2,3,4)); + REQUIRE(b2f(1,2,3,4).cast_to() == b2i(1,2,3,4)); } { - REQUIRE(make_rect(2,1) == r4i(0,0,2,1)); - REQUIRE(make_rect(4,3,2,1) == r4i(4,3,2,1)); - REQUIRE(make_rect(v2i{2,1}) == r4i(0,0,2,1)); - REQUIRE(make_rect(v2i{4,3},v2i{2,1}) == r4i(4,3,2,1)); + REQUIRE(make_rect(2,1) == b2i(0,0,2,1)); + REQUIRE(make_rect(4,3,2,1) == b2i(4,3,2,1)); + REQUIRE(make_rect(v2i{2,1}) == b2i(0,0,2,1)); + REQUIRE(make_rect(v2i{4,3},v2i{2,1}) == b2i(4,3,2,1)); - REQUIRE(make_minmax_rect(1,2,3,4) == r4i(1,2,2,2)); - REQUIRE(make_minmax_rect(3,4,1,2) == r4i(1,2,2,2)); + REQUIRE(make_minmax_rect(1,2,3,4) == b2i(1,2,2,2)); + REQUIRE(make_minmax_rect(3,4,1,2) == b2i(1,2,2,2)); - REQUIRE(make_minmax_rect(v2i{1,2}, v2i{3,4}) == r4i(1,2,2,2)); - REQUIRE(make_minmax_rect(v2i{3,4}, v2i{1,2}) == r4i(1,2,2,2)); + REQUIRE(make_minmax_rect(v2i{1,2}, v2i{3,4}) == b2i(1,2,2,2)); + REQUIRE(make_minmax_rect(v2i{3,4}, v2i{1,2}) == b2i(1,2,2,2)); - REQUIRE(make_minmax_rect(r4i(1,2,3,4)) == r4i(1,2,3,4)); - REQUIRE(make_minmax_rect(r4i(1,2,-3,4)) == r4i(-2,2,3,4)); + REQUIRE(make_minmax_rect(b2i(1,2,3,4)) == b2i(1,2,3,4)); + REQUIRE(make_minmax_rect(b2i(1,2,-3,4)) == b2i(-2,2,3,4)); } { - auto r0 = r4i(1,2,3,4); - auto r1 = r4i(r0); - REQUIRE(r1 == r4i(1,2,3,4)); - r1 = r4i(4,3,2,1); - REQUIRE(r1 == r4i(4,3,2,1)); + auto r0 = b2i(1,2,3,4); + auto r1 = b2i(r0); + REQUIRE(r1 == b2i(1,2,3,4)); + r1 = b2i(4,3,2,1); + REQUIRE(r1 == b2i(4,3,2,1)); } { - REQUIRE(r4i(1,2,3,4) == r4i(1,2,3,4)); - REQUIRE_FALSE(r4i(1,2,3,4) == r4i(1,2,4,3)); - REQUIRE_FALSE(r4i(1,2,3,4) == r4i(2,1,3,4)); - REQUIRE_FALSE(r4i(1,2,3,4) == r4i(2,1,4,3)); + REQUIRE(b2i(1,2,3,4) == b2i(1,2,3,4)); + REQUIRE_FALSE(b2i(1,2,3,4) == b2i(1,2,4,3)); + REQUIRE_FALSE(b2i(1,2,3,4) == b2i(2,1,3,4)); + REQUIRE_FALSE(b2i(1,2,3,4) == b2i(2,1,4,3)); - REQUIRE_FALSE(r4i(1,2,3,4) != r4i(1,2,3,4)); - REQUIRE(r4i(1,2,3,4) != r4i(1,2,4,3)); - REQUIRE(r4i(1,2,3,4) != r4i(2,1,3,4)); - REQUIRE(r4i(1,2,3,4) != r4i(2,1,4,3)); + REQUIRE_FALSE(b2i(1,2,3,4) != b2i(1,2,3,4)); + REQUIRE(b2i(1,2,3,4) != b2i(1,2,4,3)); + REQUIRE(b2i(1,2,3,4) != b2i(2,1,3,4)); + REQUIRE(b2i(1,2,3,4) != b2i(2,1,4,3)); } { - REQUIRE(r4i(4,4) < r4i(4,5)); - REQUIRE_FALSE(r4i(4,4) < r4i(3,4)); - REQUIRE_FALSE(r4i(4,4) < r4i(4,3)); + REQUIRE(b2i(4,4) < b2i(4,5)); + REQUIRE_FALSE(b2i(4,4) < b2i(3,4)); + REQUIRE_FALSE(b2i(4,4) < b2i(4,3)); } { - REQUIRE(math::approximately(r4i(1,2,3,4), r4i(1,2,4,5), 1)); - REQUIRE_FALSE(math::approximately(r4i(1,2,3,4), r4i(1,2,4,5))); + REQUIRE(math::approximately(b2i(1,2,3,4), b2i(1,2,4,5), 1)); + REQUIRE_FALSE(math::approximately(b2i(1,2,3,4), b2i(1,2,4,5))); } { - REQUIRE(math::minimum(r4i(1,2,3,4)) == v2i(1,2)); - REQUIRE(math::minimum(r4i(1,2,-3,5)) == v2i(-2,2)); - REQUIRE(math::minimum(r4i(1,2,3,-5)) == v2i(1,-3)); - REQUIRE(math::minimum(r4i(1,2,-3,-5)) == v2i(-2,-3)); + REQUIRE(math::minimum(b2i(1,2,3,4)) == v2i(1,2)); + REQUIRE(math::minimum(b2i(1,2,-3,5)) == v2i(-2,2)); + REQUIRE(math::minimum(b2i(1,2,3,-5)) == v2i(1,-3)); + REQUIRE(math::minimum(b2i(1,2,-3,-5)) == v2i(-2,-3)); - REQUIRE(math::maximum(r4i(1,2,3,4)) == v2i(4,6)); - REQUIRE(math::maximum(r4i(1,2,-3,5)) == v2i(1,7)); - REQUIRE(math::maximum(r4i(1,2,3,-5)) == v2i(4,2)); - REQUIRE(math::maximum(r4i(1,2,-3,-5)) == v2i(1,2)); + REQUIRE(math::maximum(b2i(1,2,3,4)) == v2i(4,6)); + REQUIRE(math::maximum(b2i(1,2,-3,5)) == v2i(1,7)); + REQUIRE(math::maximum(b2i(1,2,3,-5)) == v2i(4,2)); + REQUIRE(math::maximum(b2i(1,2,-3,-5)) == v2i(1,2)); - REQUIRE(math::area(r4i(1,2,3,4)) == 12); - REQUIRE(math::area(r4i(1,2,3,-4)) == -12); - REQUIRE(math::area(r4i(1,2,-3,4)) == -12); - REQUIRE(math::area(r4i(1,2,-3,-4)) == 12); + REQUIRE(math::area(b2i(1,2,3,4)) == 12); + REQUIRE(math::area(b2i(1,2,3,-4)) == -12); + REQUIRE(math::area(b2i(1,2,-3,4)) == -12); + REQUIRE(math::area(b2i(1,2,-3,-4)) == 12); - REQUIRE(math::abs_area(r4i(1,2,3,4)) == 12); - REQUIRE(math::abs_area(r4i(1,2,3,-4)) == 12); - REQUIRE(math::abs_area(r4i(1,2,-3,4)) == 12); - REQUIRE(math::abs_area(r4i(1,2,-3,-4)) == 12); + REQUIRE(math::abs_area(b2i(1,2,3,4)) == 12); + REQUIRE(math::abs_area(b2i(1,2,3,-4)) == 12); + REQUIRE(math::abs_area(b2i(1,2,-3,4)) == 12); + REQUIRE(math::abs_area(b2i(1,2,-3,-4)) == 12); - REQUIRE(math::merged(r4i(1,2,3,4), r4i(1,2,3,4)) == r4i(1,2,3,4)); - REQUIRE(math::merged(r4i(1,2,3,4), r4i(0,1,3,4)) == r4i(0,1,4,5)); - REQUIRE(math::merged(r4i(1,2,3,4), r4i(1,2,4,5)) == r4i(1,2,4,5)); - REQUIRE(math::merged(r4i(1,2,3,4), r4i(0,1,4,5)) == r4i(0,1,4,5)); + REQUIRE(math::merged(b2i(1,2,3,4), b2i(1,2,3,4)) == b2i(1,2,3,4)); + REQUIRE(math::merged(b2i(1,2,3,4), b2i(0,1,3,4)) == b2i(0,1,4,5)); + REQUIRE(math::merged(b2i(1,2,3,4), b2i(1,2,4,5)) == b2i(1,2,4,5)); + REQUIRE(math::merged(b2i(1,2,3,4), b2i(0,1,4,5)) == b2i(0,1,4,5)); - REQUIRE(math::merged(r4i(1,2,3,4), r4i(1,2,-3,-5)) == r4i(-2,-3,6,9)); - REQUIRE(math::merged(r4i(-1,-2,3,4), r4i(1,2,-3,-5)) == r4i(-2,-3,4,5)); + REQUIRE(math::merged(b2i(1,2,3,4), b2i(1,2,-3,-5)) == b2i(-2,-3,6,9)); + REQUIRE(math::merged(b2i(-1,-2,3,4), b2i(1,2,-3,-5)) == b2i(-2,-3,4,5)); - REQUIRE(math::inside(r4i(1,2,3,4), v2i(1,2))); - REQUIRE(math::inside(r4i(1,2,3,4), v2i(4,5))); - REQUIRE_FALSE(math::inside(r4i(1,2,3,4), v2i(4,7))); - REQUIRE_FALSE(math::inside(r4i(1,2,3,4), v2i(0,5))); + REQUIRE(math::inside(b2i(1,2,3,4), v2i(1,2))); + REQUIRE(math::inside(b2i(1,2,3,4), v2i(4,5))); + REQUIRE_FALSE(math::inside(b2i(1,2,3,4), v2i(4,7))); + REQUIRE_FALSE(math::inside(b2i(1,2,3,4), v2i(0,5))); - REQUIRE(math::inside(r4i(1,2,-3,-4), v2i(1,2))); - REQUIRE(math::inside(r4i(1,2,-3,-4), v2i(-1,-2))); - REQUIRE_FALSE(math::inside(r4i(1,2,-3,-4), v2i(2,2))); - REQUIRE_FALSE(math::inside(r4i(1,2,-3,-4), v2i(1,3))); - REQUIRE_FALSE(math::inside(r4i(1,2,-3,-4), v2i(-3,2))); - REQUIRE_FALSE(math::inside(r4i(1,2,-3,-4), v2i(1,-3))); + REQUIRE(math::inside(b2i(1,2,-3,-4), v2i(1,2))); + REQUIRE(math::inside(b2i(1,2,-3,-4), v2i(-1,-2))); + REQUIRE_FALSE(math::inside(b2i(1,2,-3,-4), v2i(2,2))); + REQUIRE_FALSE(math::inside(b2i(1,2,-3,-4), v2i(1,3))); + REQUIRE_FALSE(math::inside(b2i(1,2,-3,-4), v2i(-3,2))); + REQUIRE_FALSE(math::inside(b2i(1,2,-3,-4), v2i(1,-3))); - REQUIRE_FALSE(math::overlaps(r4i(0,0,10,10), r4i(10,0,10,10))); - REQUIRE_FALSE(math::overlaps(r4i(0,0,10,10), r4i(0,10,10,10))); - REQUIRE_FALSE(math::overlaps(r4i(0,0,10,10), r4i(10,10,10,10))); - REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(9,0,10,10))); - REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(0,9,10,10))); - REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(9,9,10,10))); - REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(-9,0,10,10))); - REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(0,-9,10,10))); - REQUIRE(math::overlaps(r4i(0,0,10,10), r4i(-9,-9,10,10))); + REQUIRE_FALSE(math::overlaps(b2i(0,0,10,10), b2i(10,0,10,10))); + REQUIRE_FALSE(math::overlaps(b2i(0,0,10,10), b2i(0,10,10,10))); + REQUIRE_FALSE(math::overlaps(b2i(0,0,10,10), b2i(10,10,10,10))); + REQUIRE(math::overlaps(b2i(0,0,10,10), b2i(9,0,10,10))); + REQUIRE(math::overlaps(b2i(0,0,10,10), b2i(0,9,10,10))); + REQUIRE(math::overlaps(b2i(0,0,10,10), b2i(9,9,10,10))); + REQUIRE(math::overlaps(b2i(0,0,10,10), b2i(-9,0,10,10))); + REQUIRE(math::overlaps(b2i(0,0,10,10), b2i(0,-9,10,10))); + REQUIRE(math::overlaps(b2i(0,0,10,10), b2i(-9,-9,10,10))); - REQUIRE_FALSE(math::contains_nan(r4i(1,2,3,4))); - REQUIRE_FALSE(math::contains_nan(r4f(1.f,2.f,3.f,4.f))); - REQUIRE(math::contains_nan(r4f(1.f,std::numeric_limits::quiet_NaN()))); - REQUIRE(math::contains_nan(r4f(std::numeric_limits::infinity(), 1.f))); + REQUIRE_FALSE(math::contains_nan(b2i(1,2,3,4))); + REQUIRE_FALSE(math::contains_nan(b2f(1.f,2.f,3.f,4.f))); + REQUIRE(math::contains_nan(b2f(1.f,std::numeric_limits::quiet_NaN()))); + REQUIRE(math::contains_nan(b2f(std::numeric_limits::infinity(), 1.f))); } { - REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(0.f, 0.f)) == v2f(0.f, 0.f)); - REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(0.5f, 0.5f)) == v2f(5.f, 10.f)); - REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(0.25f, 0.75f)) == v2f(2.5f, 15.f)); - REQUIRE(math::normalized_to_point(r4f(10.f, 20.f), v2f(1.f, 1.f)) == v2f(10.f, 20.f)); + REQUIRE(math::normalized_to_point(b2f(10.f, 20.f), v2f(0.f, 0.f)) == v2f(0.f, 0.f)); + REQUIRE(math::normalized_to_point(b2f(10.f, 20.f), v2f(0.5f, 0.5f)) == v2f(5.f, 10.f)); + REQUIRE(math::normalized_to_point(b2f(10.f, 20.f), v2f(0.25f, 0.75f)) == v2f(2.5f, 15.f)); + REQUIRE(math::normalized_to_point(b2f(10.f, 20.f), v2f(1.f, 1.f)) == v2f(10.f, 20.f)); - REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(0.f, 0.f)) == v2f(1.f, 2.f)); - REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(0.5f, 0.5f)) == v2f(6.f, 12.f)); - REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(0.25f, 0.75f)) == v2f(3.5f, 17.f)); - REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, 10.f, 20.f), v2f(1.f, 1.f)) == v2f(11.f, 22.f)); + REQUIRE(math::normalized_to_point(b2f(1.f, 2.f, 10.f, 20.f), v2f(0.f, 0.f)) == v2f(1.f, 2.f)); + REQUIRE(math::normalized_to_point(b2f(1.f, 2.f, 10.f, 20.f), v2f(0.5f, 0.5f)) == v2f(6.f, 12.f)); + REQUIRE(math::normalized_to_point(b2f(1.f, 2.f, 10.f, 20.f), v2f(0.25f, 0.75f)) == v2f(3.5f, 17.f)); + REQUIRE(math::normalized_to_point(b2f(1.f, 2.f, 10.f, 20.f), v2f(1.f, 1.f)) == v2f(11.f, 22.f)); - REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, -11.f, -22.f), v2f(0.f, 0.f)) == v2f(-10.f, -20.f)); - REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, -11.f, -22.f), v2f(0.5f, 0.5f)) == v2f(-4.5f, -9.f)); - REQUIRE(math::normalized_to_point(r4f(1.f, 2.f, -11.f, -22.f), v2f(1.f, 1.f)) == v2f(1.f, 2.f)); + REQUIRE(math::normalized_to_point(b2f(1.f, 2.f, -11.f, -22.f), v2f(0.f, 0.f)) == v2f(-10.f, -20.f)); + REQUIRE(math::normalized_to_point(b2f(1.f, 2.f, -11.f, -22.f), v2f(0.5f, 0.5f)) == v2f(-4.5f, -9.f)); + REQUIRE(math::normalized_to_point(b2f(1.f, 2.f, -11.f, -22.f), v2f(1.f, 1.f)) == v2f(1.f, 2.f)); - REQUIRE(math::normalized_to_point(r4f(0.f,0.f), v2f(0.f,0.f)) == v2f(0.f,0.f)); - REQUIRE(math::normalized_to_point(r4f(0.f,0.f), v2f(1.f,1.f)) == v2f(0.f,0.f)); - REQUIRE(math::normalized_to_point(r4f(1.f,2.f,0.f,0.f), v2f(0.f,0.f)) == v2f(1.f,2.f)); - REQUIRE(math::normalized_to_point(r4f(1.f,2.f,0.f,0.f), v2f(1.f,1.f)) == v2f(1.f,2.f)); + REQUIRE(math::normalized_to_point(b2f(0.f,0.f), v2f(0.f,0.f)) == v2f(0.f,0.f)); + REQUIRE(math::normalized_to_point(b2f(0.f,0.f), v2f(1.f,1.f)) == v2f(0.f,0.f)); + REQUIRE(math::normalized_to_point(b2f(1.f,2.f,0.f,0.f), v2f(0.f,0.f)) == v2f(1.f,2.f)); + REQUIRE(math::normalized_to_point(b2f(1.f,2.f,0.f,0.f), v2f(1.f,1.f)) == v2f(1.f,2.f)); } { - REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(0.f, 0.f)) == v2f(0.f, 0.f)); - REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(5.f, 10.f)) == v2f(0.5f,0.5f)); - REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(2.5f, 15.f)) == v2f(0.25f, 0.75f)); - REQUIRE(math::point_to_normalized(r4f(10.f, 20.f), v2f(10.f, 20.f)) == v2f(1.f, 1.f)); + REQUIRE(math::point_to_normalized(b2f(10.f, 20.f), v2f(0.f, 0.f)) == v2f(0.f, 0.f)); + REQUIRE(math::point_to_normalized(b2f(10.f, 20.f), v2f(5.f, 10.f)) == v2f(0.5f,0.5f)); + REQUIRE(math::point_to_normalized(b2f(10.f, 20.f), v2f(2.5f, 15.f)) == v2f(0.25f, 0.75f)); + REQUIRE(math::point_to_normalized(b2f(10.f, 20.f), v2f(10.f, 20.f)) == v2f(1.f, 1.f)); - REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(1.f, 2.f)) == v2f(0.f, 0.f)); - REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(6.f, 12.f)) == v2f(0.5f, 0.5f)); - REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(3.5f, 17.f)) == v2f(0.25f, 0.75f)); - REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, 10.f, 20.f), v2f(11.f, 22.f)) == v2f(1.f, 1.f)); + REQUIRE(math::point_to_normalized(b2f(1.f, 2.f, 10.f, 20.f), v2f(1.f, 2.f)) == v2f(0.f, 0.f)); + REQUIRE(math::point_to_normalized(b2f(1.f, 2.f, 10.f, 20.f), v2f(6.f, 12.f)) == v2f(0.5f, 0.5f)); + REQUIRE(math::point_to_normalized(b2f(1.f, 2.f, 10.f, 20.f), v2f(3.5f, 17.f)) == v2f(0.25f, 0.75f)); + REQUIRE(math::point_to_normalized(b2f(1.f, 2.f, 10.f, 20.f), v2f(11.f, 22.f)) == v2f(1.f, 1.f)); - REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, -11.f, -22.f), v2f(-10.f, -20.f)) == v2f(0.f, 0.f)); - REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, -11.f, -22.f), v2f(-4.5f, -9.f)) == v2f(0.5f, 0.5f)); - REQUIRE(math::point_to_normalized(r4f(1.f, 2.f, -11.f, -22.f), v2f(1.f, 2.f)) == v2f(1.f, 1.f)); + REQUIRE(math::point_to_normalized(b2f(1.f, 2.f, -11.f, -22.f), v2f(-10.f, -20.f)) == v2f(0.f, 0.f)); + REQUIRE(math::point_to_normalized(b2f(1.f, 2.f, -11.f, -22.f), v2f(-4.5f, -9.f)) == v2f(0.5f, 0.5f)); + REQUIRE(math::point_to_normalized(b2f(1.f, 2.f, -11.f, -22.f), v2f(1.f, 2.f)) == v2f(1.f, 1.f)); } }