From 5101e1fbbb7a56a6b705a27d19d11f3843d80861 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 14:17:38 +0700 Subject: [PATCH 1/7] update modules --- modules/catch2 | 2 +- modules/glfw | 2 +- modules/utfcpp | 2 +- sources/3rdparty/glfw/glfw3native.h | 47 ---------- untests/catch/catch.hpp | 136 ++++++++++++++++++++++++---- 5 files changed, 120 insertions(+), 69 deletions(-) diff --git a/modules/catch2 b/modules/catch2 index a575536a..1faccd60 160000 --- a/modules/catch2 +++ b/modules/catch2 @@ -1 +1 @@ -Subproject commit a575536abe20b58c48863600f8a71e93b4052b81 +Subproject commit 1faccd601d904a951142d8fba82914a8325b764e diff --git a/modules/glfw b/modules/glfw index 15cad022..2de2589f 160000 --- a/modules/glfw +++ b/modules/glfw @@ -1 +1 @@ -Subproject commit 15cad0223543745d13d4ce2de040d3b7defb3870 +Subproject commit 2de2589f910b1a85905f425be4d32f33cec092df diff --git a/modules/utfcpp b/modules/utfcpp index e6bde781..0a238813 160000 --- a/modules/utfcpp +++ b/modules/utfcpp @@ -1 +1 @@ -Subproject commit e6bde7819c60c453b720b5de8c7c5ee9ffd9805a +Subproject commit 0a238813416e0ac8ea998b8814f00611a00f0735 diff --git a/sources/3rdparty/glfw/glfw3native.h b/sources/3rdparty/glfw/glfw3native.h index 4372cb76..83d3ca44 100644 --- a/sources/3rdparty/glfw/glfw3native.h +++ b/sources/3rdparty/glfw/glfw3native.h @@ -62,7 +62,6 @@ extern "C" { * * `GLFW_EXPOSE_NATIVE_COCOA` * * `GLFW_EXPOSE_NATIVE_X11` * * `GLFW_EXPOSE_NATIVE_WAYLAND` - * * `GLFW_EXPOSE_NATIVE_MIR` * * The available context API macros are: * * `GLFW_EXPOSE_NATIVE_WGL` @@ -103,8 +102,6 @@ extern "C" { #include #elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) #include -#elif defined(GLFW_EXPOSE_NATIVE_MIR) - #include #endif #if defined(GLFW_EXPOSE_NATIVE_WGL) @@ -418,50 +415,6 @@ GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor); GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window); #endif -#if defined(GLFW_EXPOSE_NATIVE_MIR) -/*! @brief Returns the `MirConnection*` used by GLFW. - * - * @return The `MirConnection*` used by GLFW, or `NULL` if an - * [error](@ref error_handling) occurred. - * - * @thread_safety This function may be called from any thread. Access is not - * synchronized. - * - * @since Added in version 3.2. - * - * @ingroup native - */ -GLFWAPI MirConnection* glfwGetMirDisplay(void); - -/*! @brief Returns the Mir output ID of the specified monitor. - * - * @return The Mir output ID of the specified monitor, or zero if an - * [error](@ref error_handling) occurred. - * - * @thread_safety This function may be called from any thread. Access is not - * synchronized. - * - * @since Added in version 3.2. - * - * @ingroup native - */ -GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor); - -/*! @brief Returns the `MirWindow*` of the specified window. - * - * @return The `MirWindow*` of the specified window, or `NULL` if an - * [error](@ref error_handling) occurred. - * - * @thread_safety This function may be called from any thread. Access is not - * synchronized. - * - * @since Added in version 3.2. - * - * @ingroup native - */ -GLFWAPI MirWindow* glfwGetMirWindow(GLFWwindow* window); -#endif - #if defined(GLFW_EXPOSE_NATIVE_EGL) /*! @brief Returns the `EGLDisplay` used by GLFW. * diff --git a/untests/catch/catch.hpp b/untests/catch/catch.hpp index b0fa6416..4191607a 100644 --- a/untests/catch/catch.hpp +++ b/untests/catch/catch.hpp @@ -1,6 +1,6 @@ /* - * Catch v2.4.0 - * Generated: 2018-09-04 11:55:01.682061 + * Catch v2.4.1 + * Generated: 2018-09-28 15:50:15.645795 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved. @@ -15,7 +15,7 @@ #define CATCH_VERSION_MAJOR 2 #define CATCH_VERSION_MINOR 4 -#define CATCH_VERSION_PATCH 0 +#define CATCH_VERSION_PATCH 1 #ifdef __clang__ # pragma clang system_header @@ -121,11 +121,11 @@ namespace Catch { #ifdef __cplusplus -# if __cplusplus >= 201402L +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) # define CATCH_CPP14_OR_GREATER # endif -# if __cplusplus >= 201703L +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) # define CATCH_CPP17_OR_GREATER # endif @@ -200,7 +200,14 @@ namespace Catch { // Required for some versions of Cygwin to declare gettimeofday // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin # define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING + +# endif #endif // __CYGWIN__ //////////////////////////////////////////////////////////////////////////////// @@ -244,6 +251,32 @@ namespace Catch { #define CATCH_INTERNAL_CONFIG_COUNTER #endif +//////////////////////////////////////////////////////////////////////////////// +// Check if string_view is available and usable +// The check is split apart to work around v140 (VS2015) preprocessor issue... +#if defined(__has_include) +#if __has_include() && defined(CATCH_CPP17_OR_GREATER) +# define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW +#endif +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Check if variant is available and usable +#if defined(__has_include) +# if __has_include() && defined(CATCH_CPP17_OR_GREATER) +# if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 +# include +# if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) +# define CATCH_CONFIG_NO_CPP17_VARIANT +# else +# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT +# endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) +# endif // defined(__clang__) && (__clang_major__ < 8) +# endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // __has_include + #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) # define CATCH_CONFIG_COUNTER #endif @@ -267,6 +300,14 @@ namespace Catch { # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS #endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif + #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE #endif @@ -754,6 +795,10 @@ namespace Catch { // end catch_stream.h +#ifdef CATCH_CONFIG_CPP17_STRING_VIEW +#include +#endif + #ifdef __OBJC__ // start catch_objc_arc.hpp @@ -929,10 +974,11 @@ namespace Catch { struct StringMaker { static std::string convert(const std::string& str); }; -#ifdef CATCH_CONFIG_WCHAR + +#ifdef CATCH_CONFIG_CPP17_STRING_VIEW template<> - struct StringMaker { - static std::string convert(const std::wstring& wstr); + struct StringMaker { + static std::string convert(std::string_view str); }; #endif @@ -946,6 +992,18 @@ namespace Catch { }; #ifdef CATCH_CONFIG_WCHAR + template<> + struct StringMaker { + static std::string convert(const std::wstring& wstr); + }; + +# ifdef CATCH_CONFIG_CPP17_STRING_VIEW + template<> + struct StringMaker { + static std::string convert(std::wstring_view str); + }; +# endif + template<> struct StringMaker { static std::string convert(wchar_t const * str); @@ -1114,6 +1172,7 @@ namespace Catch { #if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) # define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER # define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +# define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER # define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER #endif @@ -1177,6 +1236,34 @@ namespace Catch { } #endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT) +#include +namespace Catch { + template<> + struct StringMaker { + static std::string convert(const std::monostate&) { + return "{ }"; + } + }; + + template + struct StringMaker> { + static std::string convert(const std::variant& variant) { + if (variant.valueless_by_exception()) { + return "{valueless variant}"; + } else { + return std::visit( + [](const auto& value) { + return ::Catch::Detail::stringify(value); + }, + variant + ); + } + } + }; +} +#endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER + namespace Catch { struct not_this_one {}; // Tag type for detecting which begin/ end are being selected @@ -2761,7 +2848,7 @@ namespace Matchers { auto lfirst = m_target.begin(), llast = m_target.end(); auto rfirst = vec.begin(), rlast = vec.end(); // Cut common prefix to optimize checking of permuted parts - while (lfirst != llast && *lfirst != *rfirst) { + while (lfirst != llast && *lfirst == *rfirst) { ++lfirst; ++rfirst; } if (lfirst == llast) { @@ -9597,7 +9684,7 @@ namespace Catch { } bool RunContext::aborting() const { - return m_totals.assertions.failed == static_cast(m_config->abortAfter()); + return m_totals.assertions.failed >= static_cast(m_config->abortAfter()); } void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { @@ -11512,14 +11599,9 @@ std::string StringMaker::convert(const std::string& str) { return s; } -#ifdef CATCH_CONFIG_WCHAR -std::string StringMaker::convert(const std::wstring& wstr) { - std::string s; - s.reserve(wstr.size()); - for (auto c : wstr) { - s += (c <= 0xff) ? static_cast(c) : '?'; - } - return ::Catch::Detail::stringify(s); +#ifdef CATCH_CONFIG_CPP17_STRING_VIEW +std::string StringMaker::convert(std::string_view str) { + return ::Catch::Detail::stringify(std::string{ str }); } #endif @@ -11537,7 +11619,23 @@ std::string StringMaker::convert(char* str) { return{ "{null string}" }; } } + #ifdef CATCH_CONFIG_WCHAR +std::string StringMaker::convert(const std::wstring& wstr) { + std::string s; + s.reserve(wstr.size()); + for (auto c : wstr) { + s += (c <= 0xff) ? static_cast(c) : '?'; + } + return ::Catch::Detail::stringify(s); +} + +# ifdef CATCH_CONFIG_CPP17_STRING_VIEW +std::string StringMaker::convert(std::wstring_view str) { + return StringMaker::convert(std::wstring(str)); +} +# endif + std::string StringMaker::convert(wchar_t const * str) { if (str) { return ::Catch::Detail::stringify(std::wstring{ str }); @@ -11738,7 +11836,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 2, 4, 0, "", 0 ); + static Version version( 2, 4, 1, "", 0 ); return version; } From 3cac51b76800bf977c1194c4f7110b8ae785ec3a Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 5 Oct 2018 05:12:14 +0700 Subject: [PATCH 2/7] fix make_XXX_matrix noexcepts --- headers/enduro2d/math/mat2.hpp | 10 +++++----- headers/enduro2d/math/mat3.hpp | 16 ++++++++-------- headers/enduro2d/math/mat4.hpp | 24 ++++++++++++------------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/headers/enduro2d/math/mat2.hpp b/headers/enduro2d/math/mat2.hpp index 88e1afff..2b609b94 100644 --- a/headers/enduro2d/math/mat2.hpp +++ b/headers/enduro2d/math/mat2.hpp @@ -263,28 +263,28 @@ namespace e2d { namespace math // template < typename T > - mat2 make_scale_matrix2(T x, T y) { + mat2 make_scale_matrix2(T x, T y) noexcept { return { x, 0, 0, y}; } template < typename T > - mat2 make_scale_matrix2(const vec4& xy) { + mat2 make_scale_matrix2(const vec4& xy) noexcept { return make_scale_matrix2( xy.x, xy.y); } template < typename T > - mat2 make_scale_matrix2(const vec3& xy) { + mat2 make_scale_matrix2(const vec3& xy) noexcept { return make_scale_matrix2( xy.x, xy.y); } template < typename T > - mat2 make_scale_matrix2(const vec2& xy) { + mat2 make_scale_matrix2(const vec2& xy) noexcept { return make_scale_matrix2( xy.x, xy.y); @@ -296,7 +296,7 @@ namespace e2d { namespace math template < typename T, typename AngleTag > std::enable_if_t::value, mat2> - make_rotation_matrix2(const unit& angle) { + make_rotation_matrix2(const unit& angle) noexcept { const T cs = math::cos(angle); const T sn = math::sin(angle); return { diff --git a/headers/enduro2d/math/mat3.hpp b/headers/enduro2d/math/mat3.hpp index 40d722b2..62ed4f3a 100644 --- a/headers/enduro2d/math/mat3.hpp +++ b/headers/enduro2d/math/mat3.hpp @@ -289,7 +289,7 @@ namespace e2d { namespace math // template < typename T > - mat3 make_scale_matrix3(T x, T y, T z = T(1)) { + mat3 make_scale_matrix3(T x, T y, T z = T(1)) noexcept { return { x, 0, 0, 0, y, 0, @@ -297,7 +297,7 @@ namespace e2d { namespace math } template < typename T > - mat3 make_scale_matrix3(const vec4& xyz) { + mat3 make_scale_matrix3(const vec4& xyz) noexcept { return make_scale_matrix3( xyz.x, xyz.y, @@ -305,7 +305,7 @@ namespace e2d { namespace math } template < typename T > - mat3 make_scale_matrix3(const vec3& xyz) { + mat3 make_scale_matrix3(const vec3& xyz) noexcept { return make_scale_matrix3( xyz.x, xyz.y, @@ -313,7 +313,7 @@ namespace e2d { namespace math } template < typename T > - mat3 make_scale_matrix3(const vec2& xy, T z = T(1)) { + mat3 make_scale_matrix3(const vec2& xy, T z = T(1)) noexcept { return make_scale_matrix3( xy.x, xy.y, @@ -330,7 +330,7 @@ namespace e2d { namespace math const unit& angle, T axis_x, T axis_y, - T axis_z) + T axis_z) noexcept { const T x = axis_x; const T y = axis_y; @@ -356,7 +356,7 @@ namespace e2d { namespace math template < typename T, typename AngleTag > mat3 make_rotation_matrix3( const unit& angle, - const vec4& axis_xyz) + const vec4& axis_xyz) noexcept { return make_rotation_matrix3( angle, @@ -368,7 +368,7 @@ namespace e2d { namespace math template < typename T, typename AngleTag > mat3 make_rotation_matrix3( const unit& angle, - const vec3& axis_xyz) + const vec3& axis_xyz) noexcept { return make_rotation_matrix3( angle, @@ -381,7 +381,7 @@ namespace e2d { namespace math mat3 make_rotation_matrix3( const unit& angle, const vec2& axis_xy, - T axis_z) + T axis_z) noexcept { return make_rotation_matrix3( angle, diff --git a/headers/enduro2d/math/mat4.hpp b/headers/enduro2d/math/mat4.hpp index b5ce2bb3..50cd3907 100644 --- a/headers/enduro2d/math/mat4.hpp +++ b/headers/enduro2d/math/mat4.hpp @@ -317,7 +317,7 @@ namespace e2d { namespace math // template < typename T > - mat4 make_scale_matrix4(T x, T y, T z = T(1)) { + mat4 make_scale_matrix4(T x, T y, T z = T(1)) noexcept { return { x, 0, 0, 0, 0, y, 0, 0, @@ -326,7 +326,7 @@ namespace e2d { namespace math } template < typename T > - mat4 make_scale_matrix4(const vec4& xyz) { + mat4 make_scale_matrix4(const vec4& xyz) noexcept { return make_scale_matrix4( xyz.x, xyz.y, @@ -334,7 +334,7 @@ namespace e2d { namespace math } template < typename T > - mat4 make_scale_matrix4(const vec3& xyz) { + mat4 make_scale_matrix4(const vec3& xyz) noexcept { return make_scale_matrix4( xyz.x, xyz.y, @@ -342,7 +342,7 @@ namespace e2d { namespace math } template < typename T > - mat4 make_scale_matrix4(const vec2& xy, T z = T(1)) { + mat4 make_scale_matrix4(const vec2& xy, T z = T(1)) noexcept { return make_scale_matrix4( xy.x, xy.y, @@ -354,7 +354,7 @@ namespace e2d { namespace math // template < typename T > - mat4 make_translation_matrix4(T x, T y, T z = T(0)) { + mat4 make_translation_matrix4(T x, T y, T z = T(0)) noexcept { return { 1, 0, 0, 0, 0, 1, 0, 0, @@ -363,7 +363,7 @@ namespace e2d { namespace math } template < typename T > - mat4 make_translation_matrix4(const vec4& xyz) { + mat4 make_translation_matrix4(const vec4& xyz) noexcept { return make_translation_matrix4( xyz.x, xyz.y, @@ -371,7 +371,7 @@ namespace e2d { namespace math } template < typename T > - mat4 make_translation_matrix4(const vec3& xyz) { + mat4 make_translation_matrix4(const vec3& xyz) noexcept { return make_translation_matrix4( xyz.x, xyz.y, @@ -379,7 +379,7 @@ namespace e2d { namespace math } template < typename T > - mat4 make_translation_matrix4(const vec2& xy, T z = T(0)) { + mat4 make_translation_matrix4(const vec2& xy, T z = T(0)) noexcept { return make_translation_matrix4( xy.x, xy.y, @@ -396,7 +396,7 @@ namespace e2d { namespace math const unit& angle, T axis_x, T axis_y, - T axis_z) + T axis_z) noexcept { const T x = axis_x; const T y = axis_y; @@ -423,7 +423,7 @@ namespace e2d { namespace math template < typename T, typename AngleTag > mat4 make_rotation_matrix4( const unit& angle, - const vec4& axis_xyz) + const vec4& axis_xyz) noexcept { return make_rotation_matrix4( angle, @@ -435,7 +435,7 @@ namespace e2d { namespace math template < typename T, typename AngleTag > mat4 make_rotation_matrix4( const unit& angle, - const vec3& axis_xyz) + const vec3& axis_xyz) noexcept { return make_rotation_matrix4( angle, @@ -448,7 +448,7 @@ namespace e2d { namespace math mat4 make_rotation_matrix4( const unit& angle, const vec2& axis_xy, - T axis_z) + T axis_z) noexcept { return make_rotation_matrix4( angle, From 4afa3c1edd96c4ebbd2389f9e38832c6e81caa58 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 4 Oct 2018 05:57:52 +0700 Subject: [PATCH 3/7] add 16bit math usings --- headers/enduro2d/math/_math.hpp | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/headers/enduro2d/math/_math.hpp b/headers/enduro2d/math/_math.hpp index 07c6dd1b..92af697c 100644 --- a/headers/enduro2d/math/_math.hpp +++ b/headers/enduro2d/math/_math.hpp @@ -37,35 +37,47 @@ namespace e2d namespace e2d { + using v2d = vec2; + using v2f = vec2; using v2i = vec2; using v2u = vec2; - using v2f = vec2; - using v2d = vec2; + using v2hi = vec2; + using v2hu = vec2; + using v3d = vec3; + using v3f = vec3; using v3i = vec3; using v3u = vec3; - using v3f = vec3; - using v3d = vec3; + using v3hi = vec3; + using v3hu = vec3; + using v4d = vec4; + using v4f = vec4; using v4i = vec4; using v4u = vec4; - using v4f = vec4; - using v4d = vec4; + using v4hi = vec4; + using v4hu = vec4; + using m2d = mat2; + using m2f = mat2; using m2i = mat2; using m2u = mat2; - using m2f = mat2; - using m2d = mat2; + using m2hi = mat2; + using m2hu = mat2; + using m3d = mat3; + using m3f = mat3; using m3i = mat3; using m3u = mat3; - using m3f = mat3; - using m3d = mat3; + using m3hi = mat3; + using m3hu = mat3; + using m4d = mat4; + using m4f = mat4; using m4i = mat4; using m4u = mat4; - using m4f = mat4; - using m4d = mat4; + using m4hi = mat4; + using m4hu = mat4; struct deg_tag {}; struct rad_tag {}; From 44abbc0a3611e34da58b2e3ca69e820da6779d82 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 5 Oct 2018 05:13:34 +0700 Subject: [PATCH 4/7] E2D_ALLOCA macros --- headers/enduro2d/base/macros.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/headers/enduro2d/base/macros.hpp b/headers/enduro2d/base/macros.hpp index 1df1d918..2aef6b31 100644 --- a/headers/enduro2d/base/macros.hpp +++ b/headers/enduro2d/base/macros.hpp @@ -26,6 +26,16 @@ # define E2D_ASSERT_MSG(expr, msg) ((void)0) #endif +// +// E2D_ALLOCA +// + +#if defined(E2D_COMPILER) && E2D_COMPILER == E2D_COMPILER_MSVC +# define E2D_ALLOCA(size) _malloca((size)) +#else +# define E2D_ALLOCA(size) alloca((size)) +#endif + // // E2D_UNUSED // From 395870905796f3d7c13639e18874b5e655905519 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 14:25:39 +0700 Subject: [PATCH 5/7] math::enum_to_number function --- headers/enduro2d/math/_math.hpp | 9 +++++++++ sources/enduro2d/core/input.cpp | 21 +++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/headers/enduro2d/math/_math.hpp b/headers/enduro2d/math/_math.hpp index 92af697c..4759ecce 100644 --- a/headers/enduro2d/math/_math.hpp +++ b/headers/enduro2d/math/_math.hpp @@ -476,4 +476,13 @@ namespace e2d { namespace math is_near_zero(T v, T precision = default_precision()) noexcept { return approximately(v, T(0), precision); } + + // + // enum_to_number + // + + template < typename E > + constexpr std::underlying_type_t enum_to_number(E e) noexcept { + return static_cast>(e); + } }} diff --git a/sources/enduro2d/core/input.cpp b/sources/enduro2d/core/input.cpp index 5a9cd4ad..c0cb76f9 100644 --- a/sources/enduro2d/core/input.cpp +++ b/sources/enduro2d/core/input.cpp @@ -24,11 +24,6 @@ namespace state = button_state::released; } } - - template < typename E > - constexpr std::underlying_type_t enum_to_number(E e) noexcept { - return static_cast>(e); - } } namespace e2d @@ -42,8 +37,11 @@ namespace e2d mutable std::mutex mutex; v2f cursor_pos; v2f scroll_delta; - std::array button_states; - char _pad[2]; + std::array< + button_state, + math::enum_to_number(mouse_button::unknown) + 1 + > button_states{}; + u8 _pad[2] = {0}; public: state() noexcept { std::fill( @@ -53,7 +51,7 @@ namespace e2d } std::size_t button_index(mouse_button btn) const noexcept { - const auto index = enum_to_number(btn); + const auto index = math::enum_to_number(btn); E2D_ASSERT(index < button_states.size()); return math::numeric_cast(index); } @@ -109,7 +107,10 @@ namespace e2d public: mutable std::mutex mutex; str32 input_text; - std::array key_states; + std::array< + button_state, + math::enum_to_number(keyboard_key::unknown) + 1 + > key_states{}; public: state() noexcept { std::fill( @@ -119,7 +120,7 @@ namespace e2d } std::size_t key_index(keyboard_key key) const noexcept { - const auto index = enum_to_number(key); + const auto index = math::enum_to_number(key); E2D_ASSERT(index < key_states.size()); return math::numeric_cast(index); } From a491cb1bf3267303b96b85e63d3ff2365325ebde Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 18:37:59 +0700 Subject: [PATCH 6/7] remove math::contains --- headers/enduro2d/math/vec2.hpp | 13 +------------ headers/enduro2d/math/vec3.hpp | 14 +------------- headers/enduro2d/math/vec4.hpp | 15 +-------------- headers/enduro2d/utils/color.hpp | 4 ---- headers/enduro2d/utils/color32.hpp | 5 ----- sources/enduro2d/utils/color.cpp | 14 +++++--------- sources/enduro2d/utils/color32.cpp | 16 ++++------------ untests/sources/untests_math/vec2.cpp | 12 ------------ untests/sources/untests_math/vec3.cpp | 14 -------------- untests/sources/untests_math/vec4.cpp | 16 ---------------- untests/sources/untests_utils/color.cpp | 8 -------- untests/sources/untests_utils/color32.cpp | 9 --------- 12 files changed, 12 insertions(+), 128 deletions(-) diff --git a/headers/enduro2d/math/vec2.hpp b/headers/enduro2d/math/vec2.hpp index f36fccb1..f986e04b 100644 --- a/headers/enduro2d/math/vec2.hpp +++ b/headers/enduro2d/math/vec2.hpp @@ -506,20 +506,9 @@ namespace e2d { namespace math } // - // contains + // contains_nan // - template < typename T > - bool contains( - const vec2& v, - T value, - T precision = math::default_precision()) noexcept - { - return - math::approximately(v.x, value, precision) || - math::approximately(v.y, value, precision); - } - template < typename T > bool contains_nan(const vec2& v) noexcept { return diff --git a/headers/enduro2d/math/vec3.hpp b/headers/enduro2d/math/vec3.hpp index a488e066..f2351d86 100644 --- a/headers/enduro2d/math/vec3.hpp +++ b/headers/enduro2d/math/vec3.hpp @@ -564,21 +564,9 @@ namespace e2d { namespace math } // - // contains + // contains_nan // - template < typename T > - bool contains( - const vec3& v, - T value, - T precision = math::default_precision()) noexcept - { - return - math::approximately(v.x, value, precision) || - math::approximately(v.y, value, precision) || - math::approximately(v.z, value, precision); - } - template < typename T > bool contains_nan(const vec3& v) noexcept { return diff --git a/headers/enduro2d/math/vec4.hpp b/headers/enduro2d/math/vec4.hpp index 78d64c73..6653adc9 100644 --- a/headers/enduro2d/math/vec4.hpp +++ b/headers/enduro2d/math/vec4.hpp @@ -598,22 +598,9 @@ namespace e2d { namespace math } // - // contains + // contains_nan // - template < typename T > - bool contains( - const vec4& v, - T value, - T precision = math::default_precision()) noexcept - { - return - math::approximately(v.x, value, precision) || - math::approximately(v.y, value, precision) || - math::approximately(v.z, value, precision) || - math::approximately(v.w, value, precision); - } - template < typename T > bool contains_nan(const vec4& v) noexcept { return diff --git a/headers/enduro2d/utils/color.hpp b/headers/enduro2d/utils/color.hpp index 1c8c1b9c..e6a52b39 100644 --- a/headers/enduro2d/utils/color.hpp +++ b/headers/enduro2d/utils/color.hpp @@ -87,10 +87,6 @@ namespace e2d { namespace math color clamped(const color& c, const color& cmin, const color& cmax) noexcept; color saturated(const color& c) noexcept; - bool contains( - const color& c, - f32 value, - f32 precision = math::default_precision()) noexcept; bool contains_nan(const color& c) noexcept; }} diff --git a/headers/enduro2d/utils/color32.hpp b/headers/enduro2d/utils/color32.hpp index e99c1094..87e17c1e 100644 --- a/headers/enduro2d/utils/color32.hpp +++ b/headers/enduro2d/utils/color32.hpp @@ -85,11 +85,6 @@ namespace e2d { namespace math color32 minimized(const color32& c, const color32& cmin) noexcept; color32 maximized(const color32& c, const color32& cmax) noexcept; color32 clamped(const color32& c, const color32& cmin, const color32& cmax) noexcept; - - bool contains( - const color32& c, - u8 value, - u8 precision = math::default_precision()) noexcept; }} namespace e2d { namespace colors diff --git a/sources/enduro2d/utils/color.cpp b/sources/enduro2d/utils/color.cpp index e75280f1..cc725496 100644 --- a/sources/enduro2d/utils/color.cpp +++ b/sources/enduro2d/utils/color.cpp @@ -125,7 +125,10 @@ namespace e2d } color& color::operator/=(const color& other) noexcept { - E2D_ASSERT(!math::contains(other, 0.f, 0.f)); + E2D_ASSERT(!math::is_near_zero(other.r, 0.f)); + E2D_ASSERT(!math::is_near_zero(other.g, 0.f)); + E2D_ASSERT(!math::is_near_zero(other.b, 0.f)); + E2D_ASSERT(!math::is_near_zero(other.a, 0.f)); r /= other.r; g /= other.g; b /= other.b; @@ -300,16 +303,9 @@ namespace e2d { namespace math } // - // contains + // contains_nan // - bool contains(const color& c, f32 value, f32 precision) noexcept { - return math::approximately(c.r, value, precision) - || math::approximately(c.g, value, precision) - || math::approximately(c.b, value, precision) - || math::approximately(c.a, value, precision); - } - bool contains_nan(const color& c) noexcept { return !math::is_finite(c.r) || !math::is_finite(c.g) diff --git a/sources/enduro2d/utils/color32.cpp b/sources/enduro2d/utils/color32.cpp index b3c03e68..4ffbd712 100644 --- a/sources/enduro2d/utils/color32.cpp +++ b/sources/enduro2d/utils/color32.cpp @@ -125,7 +125,10 @@ namespace e2d } color32& color32::operator/=(const color32& other) noexcept { - E2D_ASSERT(!math::contains(other, u8(0), u8(0))); + E2D_ASSERT(!math::is_near_zero(other.r, u8(0))); + E2D_ASSERT(!math::is_near_zero(other.g, u8(0))); + E2D_ASSERT(!math::is_near_zero(other.b, u8(0))); + E2D_ASSERT(!math::is_near_zero(other.a, u8(0))); r /= other.r; g /= other.g; b /= other.b; @@ -294,17 +297,6 @@ namespace e2d { namespace math math::clamp(c.b, cmin.b, cmax.b), math::clamp(c.a, cmin.a, cmax.a)); } - - // - // contains - // - - bool contains(const color32& c, u8 value, u8 precision) noexcept { - return math::approximately(c.r, value, precision) - || math::approximately(c.g, value, precision) - || math::approximately(c.b, value, precision) - || math::approximately(c.a, value, precision); - } }} namespace e2d { namespace colors diff --git a/untests/sources/untests_math/vec2.cpp b/untests/sources/untests_math/vec2.cpp index a9ae26af..e7ea3f94 100644 --- a/untests/sources/untests_math/vec2.cpp +++ b/untests/sources/untests_math/vec2.cpp @@ -253,17 +253,5 @@ TEST_CASE("vec2") { REQUIRE_FALSE(math::contains_nan(v2f(0.f,1.f))); REQUIRE(math::contains_nan(v2f(0.f,std::numeric_limits::quiet_NaN()))); REQUIRE(math::contains_nan(v2f(std::numeric_limits::infinity(),1.f))); - - REQUIRE_FALSE(math::contains(v2i(1,1), 0)); - REQUIRE(math::contains(v2i(1,1), 0, 1)); - REQUIRE(math::contains(v2i(0,1), 0)); - REQUIRE(math::contains(v2i(1,0), 0)); - REQUIRE(math::contains(v2i(0,0), 0)); - - REQUIRE_FALSE(math::contains(v2f(0.1f,0.2f), 0.f)); - REQUIRE(math::contains(v2f(0.1f,0.2f), 0.f, 0.25f)); - REQUIRE(math::contains(v2f(0,1.f), 0.f)); - REQUIRE(math::contains(v2f(1.f,0), 0.f)); - REQUIRE(math::contains(v2f(0,0), 0.f)); } } diff --git a/untests/sources/untests_math/vec3.cpp b/untests/sources/untests_math/vec3.cpp index 82de9d36..df25132b 100644 --- a/untests/sources/untests_math/vec3.cpp +++ b/untests/sources/untests_math/vec3.cpp @@ -277,19 +277,5 @@ TEST_CASE("vec3") { REQUIRE(math::contains_nan(v3f(0.f,1.f,std::numeric_limits::quiet_NaN()))); REQUIRE(math::contains_nan(v3f(std::numeric_limits::infinity(),1.f,2.f))); REQUIRE(math::contains_nan(v3f(1.f,std::numeric_limits::infinity(),2.f))); - - REQUIRE_FALSE(math::contains(v3i(1,1,1), 0)); - REQUIRE(math::contains(v3i(1,1,1), 0, 1)); - REQUIRE(math::contains(v3i(0,1,1), 0)); - REQUIRE(math::contains(v3i(1,0,1), 0)); - REQUIRE(math::contains(v3i(1,1,0), 0)); - REQUIRE(math::contains(v3i(0,0,0), 0)); - - REQUIRE_FALSE(math::contains(v3f(0.1f,0.2f,0.3f), 0.f)); - REQUIRE(math::contains(v3f(0.1f,0.2f,0.3f), 0.f, 0.35f)); - REQUIRE(math::contains(v3f(0,1.f,2.f), 0.f)); - REQUIRE(math::contains(v3f(1.f,0,2.f), 0.f)); - REQUIRE(math::contains(v3f(1.f,2.f,0), 0.f)); - REQUIRE(math::contains(v3f(0,0,0), 0.f)); } } diff --git a/untests/sources/untests_math/vec4.cpp b/untests/sources/untests_math/vec4.cpp index d5302376..e9d523dc 100644 --- a/untests/sources/untests_math/vec4.cpp +++ b/untests/sources/untests_math/vec4.cpp @@ -295,21 +295,5 @@ TEST_CASE("vec4") { REQUIRE(math::contains_nan(v4f(0.f,1.f,std::numeric_limits::quiet_NaN(),2.f))); REQUIRE(math::contains_nan(v4f(std::numeric_limits::infinity(),1.f,2.f,3.f))); REQUIRE(math::contains_nan(v4f(1.f,std::numeric_limits::infinity(),2.f,3.f))); - - REQUIRE_FALSE(math::contains(v4i(1,1,1,1), 0)); - REQUIRE(math::contains(v4i(1,1,1,1), 0, 1)); - REQUIRE(math::contains(v4i(0,1,1,1), 0)); - REQUIRE(math::contains(v4i(1,0,1,1), 0)); - REQUIRE(math::contains(v4i(1,1,0,1), 0)); - REQUIRE(math::contains(v4i(1,1,1,0), 0)); - REQUIRE(math::contains(v4i(0,0,0,0), 0)); - - REQUIRE_FALSE(math::contains(v4f(0.1f,0.2f,0.3f,0.4f), 0.f)); - REQUIRE(math::contains(v4f(0.1f,0.2f,0.3f,0.4f), 0.f, 0.45f)); - REQUIRE(math::contains(v4f(0,1.f,2.f,3.f), 0.f)); - REQUIRE(math::contains(v4f(1.f,0,2.f,3.f), 0.f)); - REQUIRE(math::contains(v4f(1.f,2.f,0,3.f), 0.f)); - REQUIRE(math::contains(v4f(1.f,2.f,3.f,0), 0.f)); - REQUIRE(math::contains(v4f(0,0,0,0), 0.f)); } } diff --git a/untests/sources/untests_utils/color.cpp b/untests/sources/untests_utils/color.cpp index 6afeb5d9..f3598c4c 100644 --- a/untests/sources/untests_utils/color.cpp +++ b/untests/sources/untests_utils/color.cpp @@ -131,14 +131,6 @@ TEST_CASE("color") { REQUIRE(math::contains_nan(color(0.f,1.f,std::numeric_limits::quiet_NaN(),2.f))); REQUIRE(math::contains_nan(color(std::numeric_limits::infinity(),1.f,2.f,3.f))); REQUIRE(math::contains_nan(color(1.f,std::numeric_limits::infinity(),2.f,3.f))); - - REQUIRE_FALSE(math::contains(color(0.1f,0.2f,0.3f,0.4f), 0.f)); - REQUIRE(math::contains(color(0.1f,0.2f,0.3f,0.4f), 0.f, 0.45f)); - REQUIRE(math::contains(color(0,1.f,2.f,3.f), 0.f)); - REQUIRE(math::contains(color(1.f,0,2.f,3.f), 0.f)); - REQUIRE(math::contains(color(1.f,2.f,0,3.f), 0.f)); - REQUIRE(math::contains(color(1.f,2.f,3.f,0), 0.f)); - REQUIRE(math::contains(color(0,0,0,0), 0.f)); } } { diff --git a/untests/sources/untests_utils/color32.cpp b/untests/sources/untests_utils/color32.cpp index 499c6261..1572fe8e 100644 --- a/untests/sources/untests_utils/color32.cpp +++ b/untests/sources/untests_utils/color32.cpp @@ -118,15 +118,6 @@ TEST_CASE("color32") { REQUIRE(math::minimized(c0, color32(2,3,4,5)) == color32(1,2,3,4)); REQUIRE(c0 == color32(1,2,3,4)); } - { - REQUIRE_FALSE(math::contains(color32(1,1,1,1), 0)); - REQUIRE(math::contains(color32(1,1,1,1), 0, 1)); - REQUIRE(math::contains(color32(0,1,1,1), 0)); - REQUIRE(math::contains(color32(1,0,1,1), 0)); - REQUIRE(math::contains(color32(1,1,0,1), 0)); - REQUIRE(math::contains(color32(1,1,1,0), 0)); - REQUIRE(math::contains(color32(0,0,0,0), 0)); - } { REQUIRE(colors::pack_color32(color32(1,2,3,4)) == 0x04010203); REQUIRE(colors::pack_color32(color32(0x12,0x34,0x56,0x78)) == 0x78123456); From 552e16222cf22703d4ad8c31ca87630c92dfdb50 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 24 Oct 2018 18:38:36 +0700 Subject: [PATCH 7/7] math rect class --- headers/enduro2d/math/_all.hpp | 1 + headers/enduro2d/math/_math.hpp | 10 ++ headers/enduro2d/math/rect.hpp | 212 ++++++++++++++++++++++++++ untests/sources/untests_math/rect.cpp | 109 +++++++++++++ 4 files changed, 332 insertions(+) create mode 100644 headers/enduro2d/math/rect.hpp create mode 100644 untests/sources/untests_math/rect.cpp diff --git a/headers/enduro2d/math/_all.hpp b/headers/enduro2d/math/_all.hpp index 999349c0..46b3da52 100644 --- a/headers/enduro2d/math/_all.hpp +++ b/headers/enduro2d/math/_all.hpp @@ -11,6 +11,7 @@ #include "mat2.hpp" #include "mat3.hpp" #include "mat4.hpp" +#include "rect.hpp" #include "trig.hpp" #include "unit.hpp" #include "vec2.hpp" diff --git a/headers/enduro2d/math/_math.hpp b/headers/enduro2d/math/_math.hpp index 4759ecce..8ba7987c 100644 --- a/headers/enduro2d/math/_math.hpp +++ b/headers/enduro2d/math/_math.hpp @@ -28,6 +28,9 @@ namespace e2d template < typename T > class mat4; + template < typename T > + class rect; + template < typename T, typename Tag > class unit; @@ -79,6 +82,13 @@ 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; + struct deg_tag {}; struct rad_tag {}; diff --git a/headers/enduro2d/math/rect.hpp b/headers/enduro2d/math/rect.hpp new file mode 100644 index 00000000..13cf3c68 --- /dev/null +++ b/headers/enduro2d/math/rect.hpp @@ -0,0 +1,212 @@ +/******************************************************************************* + * 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 "vec2.hpp" + +namespace e2d +{ + template < typename T > + class rect final { + static_assert( + std::is_arithmetic::value, + "type of 'rect' must be arithmetic"); + public: + using self_type = rect; + using value_type = T; + public: + vec2 position; + vec2 size; + public: + rect() noexcept = default; + rect(const rect& other) noexcept = default; + rect& operator=(const rect& other) noexcept = default; + + rect(T w, T h) noexcept; + rect(T x, T y, T w, T h) noexcept; + + rect(const vec2& nsize) noexcept; + rect(const vec2& nposition, const vec2& nsize) noexcept; + + template < typename To > + rect cast_to() const noexcept; + }; +} + +namespace e2d +{ + template < typename T > + rect::rect(T w, T h) noexcept + : size(w, h) {} + + template < typename T > + rect::rect(T x, T y, T w, T h) noexcept + : position(x, y) + , size(w, h) {} + + template < typename T > + rect::rect(const vec2& nsize) noexcept + : size(nsize) {} + + template < typename T > + rect::rect(const vec2& nposition, const vec2& nsize) noexcept + : position(nposition) + , size(nsize) {} + + template < typename T > + template < typename To > + rect rect::cast_to() const noexcept { + return { + position.template cast_to(), + size.template cast_to()}; + } +} + +namespace e2d +{ + // + // make_rect + // + + template < typename T > + rect make_rect(T w, T h) noexcept { + return {w, h}; + } + + template < typename T > + rect make_rect(T x, T y, T w, T h) noexcept { + return {x, y, w, h}; + } + + template < typename T > + rect make_rect(const vec2& size) noexcept { + return {size}; + } + + template < typename T > + rect make_rect(const vec2& position, const vec2& size) noexcept { + return {position, size}; + } + + // + // rect (==,!=) rect + // + + template < typename T > + bool operator==(const rect& l, const rect& r) noexcept { + return l.position == r.position + && l.size == r.size; + } + + template < typename T > + bool operator!=(const rect& l, const rect& r) noexcept { + return !(l == r); + } + + // + // rect (<,>,<=,>=) rect + // + + template < typename T > + bool operator<(const rect& l, const rect& r) noexcept { + return l.size.x * l.size.y < r.size.x * r.size.y; + } + + template < typename T > + bool operator>(const rect& l, const rect& r) noexcept { + return r < l; + } + + template < typename T > + bool operator<=(const rect& l, const rect& r) noexcept { + return !(r < l); + } + + template < typename T > + bool operator>=(const rect& l, const rect& r) noexcept { + return !(l < r); + } +} + +namespace e2d { namespace math +{ + // + // approximately + // + + template < typename T > + bool approximately( + const rect& l, + const rect& 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 > + vec2 minimum(const rect& r) noexcept { + return math::minimized(r.position, r.position + r.size); + } + + template < typename T > + vec2 maximum(const rect& r) noexcept { + return math::maximized(r.position, r.position + r.size); + } + + // + // area + // + + template < typename T > + T area(const rect& r) noexcept { + return r.size.x * r.size.y; + } + + template < typename T > + T abs_area(const rect& r) noexcept { + return math::abs(r.size.x * r.size.y); + } + + // + // merged + // + + 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 }; + } + + // + // inside + // + + template < typename T > + bool inside(const rect& r, const vec2& p) noexcept { + const vec2 min = minimum(r); + const vec2 max = maximum(r); + return p.x >= min.x && p.x <= max.x + && p.y >= min.y && p.y <= max.y; + } + + // + // contains_nan + // + + template < typename T > + bool contains_nan(const rect& r) noexcept { + return math::contains_nan(r.position) + || math::contains_nan(r.size); + } +}} diff --git a/untests/sources/untests_math/rect.cpp b/untests/sources/untests_math/rect.cpp new file mode 100644 index 00000000..efa656cc --- /dev/null +++ b/untests/sources/untests_math/rect.cpp @@ -0,0 +1,109 @@ +/******************************************************************************* + * 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("rect") { + { + REQUIRE(r4i().position == v2i(0,0)); + REQUIRE(r4i().size == v2i(0,0)); + + REQUIRE(r4i(1,2).position == v2i(0,0)); + REQUIRE(r4i(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(r4i(v2i{1,2}).position == v2i(0,0)); + REQUIRE(r4i(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(r4f(1,2,3,4).cast_to() == r4i(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)); + } + { + 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)); + } + { + 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_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(r4i(4,4) < r4i(4,5)); + REQUIRE_FALSE(r4i(4,4) < r4i(3,4)); + REQUIRE_FALSE(r4i(4,4) < r4i(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::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::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::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::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::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(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::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(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_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))); + } +}