From 02dcc6ee2c9e3cb07407a7751bb8256035497339 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 5 Feb 2020 11:44:15 +0700 Subject: [PATCH] remove math physics stuff --- headers/enduro2d/math/_all.hpp | 2 - headers/enduro2d/math/_math.hpp | 20 -- headers/enduro2d/math/ray2.hpp | 296 ----------------- headers/enduro2d/math/ray3.hpp | 302 ------------------ headers/enduro2d/utils/strfmts.hpp | 90 ------ .../bin/library/scripts/emmy/math/ray2.lua | 34 -- .../bin/library/scripts/emmy/math/ray3.lua | 37 --- .../high/bindings/math_binds/_math_binds.hpp | 6 - .../high/bindings/math_binds/ray2_binds.cpp | 62 ---- .../high/bindings/math_binds/ray3_binds.cpp | 63 ---- untests/sources/untests_math/ray2.cpp | 140 -------- untests/sources/untests_math/ray3.cpp | 149 --------- untests/sources/untests_utils/strfmts.cpp | 10 - 13 files changed, 1211 deletions(-) delete mode 100644 headers/enduro2d/math/ray2.hpp delete mode 100644 headers/enduro2d/math/ray3.hpp delete mode 100644 samples/bin/library/scripts/emmy/math/ray2.lua delete mode 100644 samples/bin/library/scripts/emmy/math/ray3.lua delete mode 100644 sources/enduro2d/high/bindings/math_binds/ray2_binds.cpp delete mode 100644 sources/enduro2d/high/bindings/math_binds/ray3_binds.cpp delete mode 100644 untests/sources/untests_math/ray2.cpp delete mode 100644 untests/sources/untests_math/ray3.cpp diff --git a/headers/enduro2d/math/_all.hpp b/headers/enduro2d/math/_all.hpp index f801bf19..d81027c9 100644 --- a/headers/enduro2d/math/_all.hpp +++ b/headers/enduro2d/math/_all.hpp @@ -12,8 +12,6 @@ #include "mat2.hpp" #include "mat3.hpp" #include "mat4.hpp" -#include "ray2.hpp" -#include "ray3.hpp" #include "rect.hpp" #include "trig.hpp" #include "trs2.hpp" diff --git a/headers/enduro2d/math/_math.hpp b/headers/enduro2d/math/_math.hpp index f862fde4..d28d9075 100644 --- a/headers/enduro2d/math/_math.hpp +++ b/headers/enduro2d/math/_math.hpp @@ -28,12 +28,6 @@ namespace e2d template < typename T > class mat4; - template < typename T > - class ray2; - - template < typename T > - class ray3; - template < typename T > class rect; @@ -97,20 +91,6 @@ namespace e2d using m4hi = mat4; using m4hu = mat4; - using r2d = ray2; - using r2f = ray2; - using r2i = ray2; - using r2u = ray2; - using r2hi = ray2; - using r2hu = ray2; - - using r3d = ray3; - using r3f = ray3; - using r3i = ray3; - using r3u = ray3; - using r3hi = ray3; - using r3hu = ray3; - using b2d = rect; using b2f = rect; using b2i = rect; diff --git a/headers/enduro2d/math/ray2.hpp b/headers/enduro2d/math/ray2.hpp deleted file mode 100644 index 8621887f..00000000 --- a/headers/enduro2d/math/ray2.hpp +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* - * This file is part of the "Enduro2D" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#pragma once - -#include "_math.hpp" -#include "vec2.hpp" - -namespace e2d -{ - template < typename T > - class ray2 final { - static_assert( - std::is_arithmetic_v, - "type of 'ray2' must be arithmetic"); - public: - using self_type = ray2; - using value_type = T; - public: - vec2 origin; - vec2 direction; - public: - static constexpr ray2 zero() noexcept; - static constexpr ray2 unit_x() noexcept; - static constexpr ray2 unit_y() noexcept; - public: - constexpr ray2() noexcept = default; - constexpr ray2(const ray2& other) noexcept = default; - constexpr ray2& operator=(const ray2& other) noexcept = default; - - constexpr ray2(T dx, T dy) noexcept; - constexpr ray2(T ox, T oy, T dx, T dy) noexcept; - - constexpr ray2(const vec2& direction) noexcept; - constexpr ray2(const vec2& origin, const vec2& direction) noexcept; - - template < typename To > - ray2 cast_to() const noexcept; - - T* data() noexcept; - const T* data() const noexcept; - - T& operator[](std::size_t index) noexcept; - T operator[](std::size_t index) const noexcept; - - ray2& operator+=(T v) noexcept; - ray2& operator-=(T v) noexcept; - ray2& operator*=(T v) noexcept; - ray2& operator/=(T v) noexcept; - - ray2& operator+=(const vec2& v) noexcept; - ray2& operator-=(const vec2& v) noexcept; - ray2& operator*=(const vec2& v) noexcept; - ray2& operator/=(const vec2& v) noexcept; - }; -} - -namespace e2d -{ - template < typename T > - constexpr ray2 ray2::zero() noexcept { - return {vec2::zero(), vec2::zero()}; - } - - template < typename T > - constexpr ray2 ray2::unit_x() noexcept { - return {vec2::zero(), vec2::unit_x()}; - } - - template < typename T > - constexpr ray2 ray2::unit_y() noexcept { - return {vec2::zero(), vec2::unit_y()}; - } - - template < typename T > - constexpr ray2::ray2(T dx, T dy) noexcept - : direction(dx, dy) {} - - template < typename T > - constexpr ray2::ray2(T ox, T oy, T dx, T dy) noexcept - : origin(ox, oy) - , direction(dx, dy) {} - - template < typename T > - constexpr ray2::ray2(const vec2& direction) noexcept - : direction(direction) {} - - template < typename T > - constexpr ray2::ray2(const vec2& origin, const vec2& direction) noexcept - : origin(origin) - , direction(direction) {} - - template < typename T > - template < typename To > - ray2 ray2::cast_to() const noexcept { - return { - origin.template cast_to(), - direction.template cast_to()}; - } - - template < typename T > - T* ray2::data() noexcept { - return origin.data(); - } - - template < typename T > - const T* ray2::data() const noexcept { - return origin.data(); - } - - template < typename T > - T& ray2::operator[](std::size_t index) noexcept { - E2D_ASSERT(index < 4); - return data()[index]; - } - - template < typename T > - T ray2::operator[](std::size_t index) const noexcept { - E2D_ASSERT(index < 4); - return data()[index]; - } - - template < typename T > - ray2& ray2::operator+=(T v) noexcept { - origin += v; - return *this; - } - - template < typename T > - ray2& ray2::operator-=(T v) noexcept { - origin -= v; - return *this; - } - - template < typename T > - ray2& ray2::operator*=(T v) noexcept { - direction *= v; - return *this; - } - - template < typename T > - ray2& ray2::operator/=(T v) noexcept { - direction /= v; - return *this; - } - - template < typename T > - ray2& ray2::operator+=(const vec2& v) noexcept { - origin += v; - return *this; - } - - template < typename T > - ray2& ray2::operator-=(const vec2& v) noexcept { - origin -= v; - return *this; - } - - template < typename T > - ray2& ray2::operator*=(const vec2& v) noexcept { - direction *= v; - return *this; - } - - template < typename T > - ray2& ray2::operator/=(const vec2& v) noexcept { - direction /= v; - return *this; - } -} - -namespace e2d -{ - // - // make_ray2 - // - - template < typename T > - constexpr ray2 make_ray2(T dx, T dy) noexcept { - return {dx, dy}; - } - - template < typename T > - constexpr ray2 make_ray2(T ox, T oy, T dx, T dy) noexcept { - return {ox, oy, dx, dy}; - } - - template < typename T > - constexpr ray2 make_ray2(const vec2& direction) noexcept { - return {direction}; - } - - template < typename T > - constexpr ray2 make_ray2(const vec2& origin, const vec2& direction) noexcept { - return {origin, direction}; - } - - // - // ray2 (==,!=) ray2 - // - - template < typename T > - bool operator==(const ray2& l, const ray2& r) noexcept { - return l.origin == r.origin - && l.direction == r.direction; - } - - template < typename T > - bool operator!=(const ray2& l, const ray2& r) noexcept { - return !(l == r); - } - - // - // ray2 (+,-,*,/) value - // - - template < typename T > - ray2 operator+(const ray2& l, T v) noexcept { - return { - l.origin + v, - l.direction}; - } - - template < typename T > - ray2 operator-(const ray2& l, T v) noexcept { - return { - l.origin - v, - l.direction}; - } - - template < typename T > - ray2 operator*(const ray2& l, T v) noexcept { - return { - l.origin, - l.direction * v}; - } - - template < typename T > - ray2 operator/(const ray2& l, T v) noexcept { - return { - l.origin, - l.direction / v}; - } - - // - // ray2 (+,-,*,/) vec2 - // - - template < typename T > - ray2 operator+(const ray2& l, const vec2& v) noexcept { - return { - l.origin + v, - l.direction}; - } - - template < typename T > - ray2 operator-(const ray2& l, const vec2& v) noexcept { - return { - l.origin - v, - l.direction}; - } - - template < typename T > - ray2 operator*(const ray2& l, const vec2& v) noexcept { - return { - l.origin, - l.direction * v}; - } - - template < typename T > - ray2 operator/(const ray2& l, const vec2& v) noexcept { - return { - l.origin, - l.direction / v}; - } -} - -namespace e2d::math -{ - // - // approximately - // - - template < typename T > - bool approximately( - const ray2& l, - const ray2& r, - T precision = math::default_precision()) noexcept - { - return math::approximately(l.origin, r.origin, precision) - && math::approximately(l.direction, r.direction, precision); - } -} diff --git a/headers/enduro2d/math/ray3.hpp b/headers/enduro2d/math/ray3.hpp deleted file mode 100644 index 85487a09..00000000 --- a/headers/enduro2d/math/ray3.hpp +++ /dev/null @@ -1,302 +0,0 @@ -/******************************************************************************* - * This file is part of the "Enduro2D" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#pragma once - -#include "_math.hpp" -#include "vec3.hpp" - -namespace e2d -{ - template < typename T > - class ray3 final { - static_assert( - std::is_arithmetic_v, - "type of 'ray3' must be arithmetic"); - public: - using self_type = ray3; - using value_type = T; - public: - vec3 origin; - vec3 direction; - public: - static constexpr ray3 zero() noexcept; - static constexpr ray3 unit_x() noexcept; - static constexpr ray3 unit_y() noexcept; - static constexpr ray3 unit_z() noexcept; - public: - constexpr ray3() noexcept = default; - constexpr ray3(const ray3& other) noexcept = default; - constexpr ray3& operator=(const ray3& other) noexcept = default; - - constexpr ray3(T dx, T dy, T dz) noexcept; - constexpr ray3(T ox, T oy, T oz, T dx, T dy, T dz) noexcept; - - constexpr ray3(const vec3& direction) noexcept; - constexpr ray3(const vec3& origin, const vec3& direction) noexcept; - - template < typename To > - ray3 cast_to() const noexcept; - - T* data() noexcept; - const T* data() const noexcept; - - T& operator[](std::size_t index) noexcept; - T operator[](std::size_t index) const noexcept; - - ray3& operator+=(T v) noexcept; - ray3& operator-=(T v) noexcept; - ray3& operator*=(T v) noexcept; - ray3& operator/=(T v) noexcept; - - ray3& operator+=(const vec3& v) noexcept; - ray3& operator-=(const vec3& v) noexcept; - ray3& operator*=(const vec3& v) noexcept; - ray3& operator/=(const vec3& v) noexcept; - }; -} - -namespace e2d -{ - template < typename T > - constexpr ray3 ray3::zero() noexcept { - return {vec3::zero(), vec3::zero()}; - } - - template < typename T > - constexpr ray3 ray3::unit_x() noexcept { - return {vec3::zero(), vec3::unit_x()}; - } - - template < typename T > - constexpr ray3 ray3::unit_y() noexcept { - return {vec3::zero(), vec3::unit_y()}; - } - - template < typename T > - constexpr ray3 ray3::unit_z() noexcept { - return {vec3::zero(), vec3::unit_z()}; - } - - template < typename T > - constexpr ray3::ray3(T dx, T dy, T dz) noexcept - : direction(dx, dy, dz) {} - - template < typename T > - constexpr ray3::ray3(T ox, T oy, T oz, T dx, T dy, T dz) noexcept - : origin(ox, oy, oz) - , direction(dx, dy, dz) {} - - template < typename T > - constexpr ray3::ray3(const vec3& direction) noexcept - : direction(direction) {} - - template < typename T > - constexpr ray3::ray3(const vec3& origin, const vec3& direction) noexcept - : origin(origin) - , direction(direction) {} - - template < typename T > - template < typename To > - ray3 ray3::cast_to() const noexcept { - return { - origin.template cast_to(), - direction.template cast_to()}; - } - - template < typename T > - T* ray3::data() noexcept { - return origin.data(); - } - - template < typename T > - const T* ray3::data() const noexcept { - return origin.data(); - } - - template < typename T > - T& ray3::operator[](std::size_t index) noexcept { - E2D_ASSERT(index < 6); - return data()[index]; - } - - template < typename T > - T ray3::operator[](std::size_t index) const noexcept { - E2D_ASSERT(index < 6); - return data()[index]; - } - - template < typename T > - ray3& ray3::operator+=(T v) noexcept { - origin += v; - return *this; - } - - template < typename T > - ray3& ray3::operator-=(T v) noexcept { - origin -= v; - return *this; - } - - template < typename T > - ray3& ray3::operator*=(T v) noexcept { - direction *= v; - return *this; - } - - template < typename T > - ray3& ray3::operator/=(T v) noexcept { - direction /= v; - return *this; - } - - template < typename T > - ray3& ray3::operator+=(const vec3& v) noexcept { - origin += v; - return *this; - } - - template < typename T > - ray3& ray3::operator-=(const vec3& v) noexcept { - origin -= v; - return *this; - } - - template < typename T > - ray3& ray3::operator*=(const vec3& v) noexcept { - direction *= v; - return *this; - } - - template < typename T > - ray3& ray3::operator/=(const vec3& v) noexcept { - direction /= v; - return *this; - } -} - -namespace e2d -{ - // - // make_ray3 - // - - template < typename T > - constexpr ray3 make_ray3(T dx, T dy, T dz) noexcept { - return {dx, dy, dz}; - } - - template < typename T > - constexpr ray3 make_ray3(T ox, T oy, T oz, T dx, T dy, T dz) noexcept { - return {ox, oy, oz, dx, dy, dz}; - } - - template < typename T > - constexpr ray3 make_ray3(const vec3& direction) noexcept { - return {direction}; - } - - template < typename T > - constexpr ray3 make_ray3(const vec3& origin, const vec3& direction) noexcept { - return {origin, direction}; - } - - // - // ray3 (==,!=) ray3 - // - - template < typename T > - bool operator==(const ray3& l, const ray3& r) noexcept { - return l.origin == r.origin - && l.direction == r.direction; - } - - template < typename T > - bool operator!=(const ray3& l, const ray3& r) noexcept { - return !(l == r); - } - - // - // ray3 (+,-,*,/) value - // - - template < typename T > - ray3 operator+(const ray3& l, T v) noexcept { - return { - l.origin + v, - l.direction}; - } - - template < typename T > - ray3 operator-(const ray3& l, T v) noexcept { - return { - l.origin - v, - l.direction}; - } - - template < typename T > - ray3 operator*(const ray3& l, T v) noexcept { - return { - l.origin, - l.direction * v}; - } - - template < typename T > - ray3 operator/(const ray3& l, T v) noexcept { - return { - l.origin, - l.direction / v}; - } - - // - // ray3 (+,-,*,/) vec3 - // - - template < typename T > - ray3 operator+(const ray3& l, const vec3& v) noexcept { - return { - l.origin + v, - l.direction}; - } - - template < typename T > - ray3 operator-(const ray3& l, const vec3& v) noexcept { - return { - l.origin - v, - l.direction}; - } - - template < typename T > - ray3 operator*(const ray3& l, const vec3& v) noexcept { - return { - l.origin, - l.direction * v}; - } - - template < typename T > - ray3 operator/(const ray3& l, const vec3& v) noexcept { - return { - l.origin, - l.direction / v}; - } -} - -namespace e2d::math -{ - // - // approximately - // - - template < typename T > - bool approximately( - const ray3& l, - const ray3& r, - T precision = math::default_precision()) noexcept - { - return math::approximately(l.origin, r.origin, precision) - && math::approximately(l.direction, r.direction, precision); - } -} diff --git a/headers/enduro2d/utils/strfmts.hpp b/headers/enduro2d/utils/strfmts.hpp index 4f313783..7bcc2861 100644 --- a/headers/enduro2d/utils/strfmts.hpp +++ b/headers/enduro2d/utils/strfmts.hpp @@ -138,96 +138,6 @@ namespace e2d::strings } }; - // - // ray2 - // - - template < typename T > - class format_arg, std::enable_if_t>> { - ray2 value_; - u8 width_; - public: - template < typename U > - explicit format_arg(U&& value, u8 width = 0) noexcept - : value_(std::forward(value)), width_(width) {} - - std::ptrdiff_t write(char* dst, size_t size) const { - return math::numeric_cast( - format(dst, size, "(%0,%1,%2,%3)", - make_format_arg(value_.origin.x, width_), - make_format_arg(value_.origin.y, width_), - make_format_arg(value_.direction.x, width_), - make_format_arg(value_.direction.y, width_))); - } - }; - - template < typename T > - class format_arg, std::enable_if_t>> { - ray2 value_; - u8 width_; - u8 precision_; - public: - template < typename U > - explicit format_arg(U&& value, u8 width = 0, u8 precision = 6) noexcept - : value_(std::forward(value)), width_(width), precision_(precision) {} - - std::ptrdiff_t write(char* dst, size_t size) const { - return math::numeric_cast( - format(dst, size, "(%0,%1,%2,%3)", - make_format_arg(value_.origin.x, width_, precision_), - make_format_arg(value_.origin.y, width_, precision_), - make_format_arg(value_.direction.x, width_, precision_), - make_format_arg(value_.direction.y, width_, precision_))); - } - }; - - // - // ray3 - // - - template < typename T > - class format_arg, std::enable_if_t>> { - ray3 value_; - u8 width_; - public: - template < typename U > - explicit format_arg(U&& value, u8 width = 0) noexcept - : value_(std::forward(value)), width_(width) {} - - std::ptrdiff_t write(char* dst, size_t size) const { - return math::numeric_cast( - format(dst, size, "(%0,%1,%2,%3,%4,%5)", - make_format_arg(value_.origin.x, width_), - make_format_arg(value_.origin.y, width_), - make_format_arg(value_.origin.z, width_), - make_format_arg(value_.direction.x, width_), - make_format_arg(value_.direction.y, width_), - make_format_arg(value_.direction.z, width_))); - } - }; - - template < typename T > - class format_arg, std::enable_if_t>> { - ray3 value_; - u8 width_; - u8 precision_; - public: - template < typename U > - explicit format_arg(U&& value, u8 width = 0, u8 precision = 6) noexcept - : value_(std::forward(value)), width_(width), precision_(precision) {} - - std::ptrdiff_t write(char* dst, size_t size) const { - return math::numeric_cast( - format(dst, size, "(%0,%1,%2,%3,%4,%5)", - make_format_arg(value_.origin.x, width_, precision_), - make_format_arg(value_.origin.y, width_, precision_), - make_format_arg(value_.origin.z, width_, precision_), - make_format_arg(value_.direction.x, width_, precision_), - make_format_arg(value_.direction.y, width_, precision_), - make_format_arg(value_.direction.z, width_, precision_))); - } - }; - // // rect // diff --git a/samples/bin/library/scripts/emmy/math/ray2.lua b/samples/bin/library/scripts/emmy/math/ray2.lua deleted file mode 100644 index 15f6b911..00000000 --- a/samples/bin/library/scripts/emmy/math/ray2.lua +++ /dev/null @@ -1,34 +0,0 @@ ----@class ray2 -local ray2 = { - ---@type v2f - origin = v2f.zero(), - - ---@type v2f - direction = v2f.zero() -} - ----@overload fun(): ray2 ----@overload fun(r: ray2): ray2 ----@overload fun(dx: number, dy: number): ray2 ----@overload fun(ox: number, oy: number, dx: number, dy: number): ray2 ----@overload fun(d: v2f): ray2 ----@overload fun(o: v2f, d: v2f): ray2 ----@return ray2 -function ray2.new(...) end - ----@return ray2 -function ray2.zero() end - ----@return ray2 -function ray2.unit_x() end - ----@return ray2 -function ray2.unit_y() end - ----@param l ray2 ----@param r ray2 ----@return boolean -function ray2.approximately(l, r) end - ----@type ray2 -_G.ray2 = _G.ray2 or ray2 diff --git a/samples/bin/library/scripts/emmy/math/ray3.lua b/samples/bin/library/scripts/emmy/math/ray3.lua deleted file mode 100644 index da2cb0bd..00000000 --- a/samples/bin/library/scripts/emmy/math/ray3.lua +++ /dev/null @@ -1,37 +0,0 @@ ----@class ray3 -local ray3 = { - ---@type v3f - origin = v3f.zero(), - - ---@type v3f - direction = v3f.zero() -} - ----@overload fun(): ray3 ----@overload fun(r: ray3): ray3 ----@overload fun(dx: number, dy: number, dz: number): ray2 ----@overload fun(ox: number, oy: number, oz: number, dx: number, dy: number, dz: number): ray2 ----@overload fun(d: v3f): ray3 ----@overload fun(o: v3f, d: v3f): ray3 ----@return ray3 -function ray3.new(...) end - ----@return ray3 -function ray3.zero() end - ----@return ray3 -function ray3.unit_x() end - ----@return ray3 -function ray3.unit_y() end - ----@return ray3 -function ray3.unit_z() end - ----@param l ray3 ----@param r ray3 ----@return boolean -function ray3.approximately(l, r) end - ----@type ray3 -_G.ray3 = _G.ray3 or ray3 diff --git a/sources/enduro2d/high/bindings/math_binds/_math_binds.hpp b/sources/enduro2d/high/bindings/math_binds/_math_binds.hpp index 7dd79583..faaa6ed2 100644 --- a/sources/enduro2d/high/bindings/math_binds/_math_binds.hpp +++ b/sources/enduro2d/high/bindings/math_binds/_math_binds.hpp @@ -18,9 +18,6 @@ namespace e2d::bindings::math void bind_mat3(sol::state& l); void bind_mat4(sol::state& l); - void bind_ray2(sol::state& l); - void bind_ray3(sol::state& l); - void bind_rect(sol::state& l); void bind_aabb(sol::state& l); @@ -39,9 +36,6 @@ namespace e2d::bindings math::bind_mat3(l); math::bind_mat4(l); - math::bind_ray2(l); - math::bind_ray3(l); - math::bind_rect(l); math::bind_aabb(l); diff --git a/sources/enduro2d/high/bindings/math_binds/ray2_binds.cpp b/sources/enduro2d/high/bindings/math_binds/ray2_binds.cpp deleted file mode 100644 index 955efe56..00000000 --- a/sources/enduro2d/high/bindings/math_binds/ray2_binds.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * This file is part of the "Enduro2D" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#include "_math_binds.hpp" - -namespace -{ - using namespace e2d; - - template < typename T > - void bind_ray2_t(const str& name, sol::state& l) { - l.new_usertype>(name, - sol::constructors< - ray2(), - ray2(ray2), - ray2(T,T), - ray2(T,T,T,T), - ray2(vec2), - ray2(vec2,vec2)>(), - - "zero", &ray2::zero, - "unit_x", &ray2::unit_x, - "unit_y", &ray2::unit_y, - - "origin", &ray2::origin, - "direction", &ray2::direction, - - sol::meta_function::to_string, [](const ray2& v){ - return strings::rformat("%0", v); - }, - - sol::meta_function::equal_to, sol::resolve&, const ray2&)>(::operator==), - - sol::meta_function::addition, sol::overload( - sol::resolve(const ray2&, T)>(::operator+), - sol::resolve(const ray2&, const vec2&)>(::operator+)), - - sol::meta_function::subtraction, sol::overload( - sol::resolve(const ray2&, T)>(::operator-), - sol::resolve(const ray2&, const vec2&)>(::operator-)), - - sol::meta_function::multiplication, sol::overload( - sol::resolve(const ray2&, T)>(::operator*), - sol::resolve(const ray2&, const vec2&)>(::operator*)), - - sol::meta_function::division, sol::overload( - sol::resolve(const ray2&, T)>(::operator/), - sol::resolve(const ray2&, const vec2&)>(::operator/)), - - "approximately", [](const ray2& l, const ray2& r){ return math::approximately(l,r); }); - } -} - -namespace e2d::bindings::math -{ - void bind_ray2(sol::state& l) { - bind_ray2_t("r2f", l); - } -} diff --git a/sources/enduro2d/high/bindings/math_binds/ray3_binds.cpp b/sources/enduro2d/high/bindings/math_binds/ray3_binds.cpp deleted file mode 100644 index daa818ec..00000000 --- a/sources/enduro2d/high/bindings/math_binds/ray3_binds.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * This file is part of the "Enduro2D" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#include "_math_binds.hpp" - -namespace -{ - using namespace e2d; - - template < typename T > - void bind_ray3_t(const str& name, sol::state& l) { - l.new_usertype>(name, - sol::constructors< - ray3(), - ray3(ray3), - ray3(T,T,T), - ray3(T,T,T,T,T,T), - ray3(vec3), - ray3(vec3,vec3)>(), - - "zero", &ray3::zero, - "unit", &ray3::unit_x, - "unit_y", &ray3::unit_y, - "unit_z", &ray3::unit_z, - - "origin", &ray3::origin, - "direction", &ray3::direction, - - sol::meta_function::to_string, [](const ray3& v){ - return strings::rformat("%0", v); - }, - - sol::meta_function::equal_to, sol::resolve&, const ray3&)>(::operator==), - - sol::meta_function::addition, sol::overload( - sol::resolve(const ray3&, T)>(::operator+), - sol::resolve(const ray3&, const vec3&)>(::operator+)), - - sol::meta_function::subtraction, sol::overload( - sol::resolve(const ray3&, T)>(::operator-), - sol::resolve(const ray3&, const vec3&)>(::operator-)), - - sol::meta_function::multiplication, sol::overload( - sol::resolve(const ray3&, T)>(::operator*), - sol::resolve(const ray3&, const vec3&)>(::operator*)), - - sol::meta_function::division, sol::overload( - sol::resolve(const ray3&, T)>(::operator/), - sol::resolve(const ray3&, const vec3&)>(::operator/)), - - "approximately", [](const ray3& l, const ray3& r){ return math::approximately(l,r); }); - } -} - -namespace e2d::bindings::math -{ - void bind_ray3(sol::state& l) { - bind_ray3_t("r3f", l); - } -} diff --git a/untests/sources/untests_math/ray2.cpp b/untests/sources/untests_math/ray2.cpp deleted file mode 100644 index 03548c2d..00000000 --- a/untests/sources/untests_math/ray2.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * This file is part of the "Enduro2D" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#include "_math.hpp" -using namespace e2d; - -TEST_CASE("ray2") { - { - REQUIRE(r2i::zero() == r2i(v2i::zero())); - REQUIRE(r2i::unit_x() == r2i(v2i::unit_x())); - REQUIRE(r2i::unit_y() == r2i(v2i::unit_y())); - } - { - static_assert(std::is_same< - ray2, r2i::self_type - >::value, "static unit test error"); - static_assert(std::is_same< - i32, r2i::value_type - >::value, "static unit test error"); - static_assert(std::is_same< - vec2, decltype(std::declval().origin) - >::value, "static unit test error"); - static_assert(std::is_same< - vec2, decltype(std::declval().direction) - >::value, "static unit test error"); - - static_assert(std::is_same< - ray2, r2f::self_type - >::value, "static unit test error"); - static_assert(std::is_same< - f32, r2f::value_type - >::value, "static unit test error"); - static_assert(std::is_same< - vec2, decltype(std::declval().origin) - >::value, "static unit test error"); - static_assert(std::is_same< - vec2, decltype(std::declval().direction) - >::value, "static unit test error"); - } - { - REQUIRE(r2i().origin == v2i(0,0)); - REQUIRE(r2i().direction == v2i(0,0)); - - REQUIRE(r2i(1,2).origin == v2i(0,0)); - REQUIRE(r2i(1,2).direction == v2i(1,2)); - - REQUIRE(r2i(v2i{1,2}).origin == v2i(0,0)); - REQUIRE(r2i(v2i{1,2}).direction == v2i(1,2)); - - REQUIRE(r2i(1,2,3,4).origin == v2i(1,2)); - REQUIRE(r2i(1,2,3,4).direction == v2i(3,4)); - - REQUIRE(r2i({1,2},{3,4}).origin == v2i(1,2)); - REQUIRE(r2i({1,2},{3,4}).direction == v2i(3,4)); - } - { - REQUIRE(r2f({1,2},{3,4}).cast_to() == r2i({1,2},{3,4})); - } - { - auto r0 = r2i({1,2},{3,4}); - REQUIRE(r0.data()[0] == 1); - REQUIRE(r0.data()[1] == 2); - REQUIRE(r0.data()[2] == 3); - REQUIRE(r0.data()[3] == 4); - r0.data()[0] = 2; - REQUIRE(r0 == r2i({2,2},{3,4})); - const auto& cr0 = r0; - REQUIRE(cr0.data()[0] == 2); - REQUIRE(cr0.data()[1] == 2); - REQUIRE(cr0.data()[2] == 3); - REQUIRE(cr0.data()[3] == 4); - } - { - auto r0 = r2i({1,2},{3,4}); - REQUIRE(r0[0] == 1); - REQUIRE(r0[1] == 2); - REQUIRE(r0[2] == 3); - REQUIRE(r0[3] == 4); - r0[0] = 2; - REQUIRE(r0 == r2i({2,2},{3,4})); - const auto& cr0 = r0; - REQUIRE(cr0[0] == 2); - REQUIRE(cr0[1] == 2); - REQUIRE(cr0[2] == 3); - REQUIRE(cr0[3] == 4); - } - { - auto r0 = r2i({1,2},{3,4}); - REQUIRE(&r0 == &(r0 += 1)); - REQUIRE(r0 == r2i({2,3},{3,4})); - REQUIRE(&r0 == &(r0 -= 4)); - REQUIRE(r0 == r2i({-2,-1},{3,4})); - REQUIRE(&r0 == &(r0 *= 2)); - REQUIRE(r0 == r2i({-2,-1},{6,8})); - REQUIRE(&r0 == &(r0 /= 3)); - REQUIRE(r0 == r2i({-2,-1},{2,2})); - - REQUIRE(r2i({1,2},{3,4}) + 2 == r2i({3,4},{3,4})); - REQUIRE(r2i({1,2},{3,4}) - 2 == r2i({-1,0},{3,4})); - REQUIRE(r2i({1,2},{3,4}) * 3 == r2i({1,2},{9,12})); - REQUIRE(r2i({1,2},{6,9}) / 3 == r2i({1,2},{2,3})); - - REQUIRE(r2i({1,2},{3,4}) + v2i(1,2) == r2i({2,4},{3,4})); - REQUIRE(r2i({1,2},{3,4}) - v2i(1,2) == r2i({0,0},{3,4})); - REQUIRE(r2i({1,2},{3,4}) * v2i(2,3) == r2i({1,2},{6,12})); - REQUIRE(r2i({1,2},{6,8}) / v2i(3,2) == r2i({1,2},{2,4})); - } - { - REQUIRE(make_ray2(2,1) == r2i(0,0,2,1)); - REQUIRE(make_ray2(4,3,2,1) == r2i({4,3},{2,1})); - - REQUIRE(make_ray2(v2i{2,1}) == r2i({0,0},{2,1})); - REQUIRE(make_ray2(v2i{4,3},v2i{2,1}) == r2i({4,3},{2,1})); - } - { - auto r0 = r2i({1,2},{3,4}); - auto r1 = r2i(r0); - REQUIRE(r1 == r2i({1,2},{3,4})); - r1 = r2i({4,3},{2,1}); - REQUIRE(r1 == r2i({4,3},{2,1})); - } - { - REQUIRE(r2i({1,2},{3,4}) == r2i({1,2},{3,4})); - REQUIRE_FALSE(r2i({1,2},{3,4}) == r2i({1,2},{4,3})); - REQUIRE_FALSE(r2i({1,2},{3,4}) == r2i({2,1},{3,4})); - REQUIRE_FALSE(r2i({1,2},{3,4}) == r2i({2,1},{4,3})); - - REQUIRE_FALSE(r2i({1,2},{3,4}) != r2i({1,2},{3,4})); - REQUIRE(r2i({1,2},{3,4}) != r2i({1,2},{4,3})); - REQUIRE(r2i({1,2},{3,4}) != r2i({2,1},{3,4})); - REQUIRE(r2i({1,2},{3,4}) != r2i({2,1},{4,3})); - } - { - REQUIRE(math::approximately(r2i({1,2},{3,4}), r2i({1,2},{4,5}), 1)); - REQUIRE_FALSE(math::approximately(r2i({1,2},{3,4}), r2i({1,2},{4,5}))); - } -} diff --git a/untests/sources/untests_math/ray3.cpp b/untests/sources/untests_math/ray3.cpp deleted file mode 100644 index 1feb53e9..00000000 --- a/untests/sources/untests_math/ray3.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * This file is part of the "Enduro2D" - * For conditions of distribution and use, see copyright notice in LICENSE.md - * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) - ******************************************************************************/ - -#include "_math.hpp" -using namespace e2d; - -TEST_CASE("ray3") { - { - REQUIRE(r3i::zero() == r3i(v3i::zero())); - REQUIRE(r3i::unit_x() == r3i(v3i::unit_x())); - REQUIRE(r3i::unit_y() == r3i(v3i::unit_y())); - REQUIRE(r3i::unit_z() == r3i(v3i::unit_z())); - } - { - static_assert(std::is_same< - ray3, r3i::self_type - >::value, "static unit test error"); - static_assert(std::is_same< - i32, r3i::value_type - >::value, "static unit test error"); - static_assert(std::is_same< - vec3, decltype(std::declval().origin) - >::value, "static unit test error"); - static_assert(std::is_same< - vec3, decltype(std::declval().direction) - >::value, "static unit test error"); - - static_assert(std::is_same< - ray3, r3f::self_type - >::value, "static unit test error"); - static_assert(std::is_same< - f32, r3f::value_type - >::value, "static unit test error"); - static_assert(std::is_same< - vec3, decltype(std::declval().origin) - >::value, "static unit test error"); - static_assert(std::is_same< - vec3, decltype(std::declval().direction) - >::value, "static unit test error"); - } - { - REQUIRE(r3i().origin == v3i(0,0,0)); - REQUIRE(r3i().direction == v3i(0,0,0)); - - REQUIRE(r3i(1,2,3).origin == v3i(0,0,0)); - REQUIRE(r3i(1,2,3).direction == v3i(1,2,3)); - - REQUIRE(r3i(v3i{1,2,3}).origin == v3i(0,0,0)); - REQUIRE(r3i(v3i{1,2,3}).direction == v3i(1,2,3)); - - REQUIRE(r3i(1,2,3,3,4,5).origin == v3i(1,2,3)); - REQUIRE(r3i(1,2,3,3,4,5).direction == v3i(3,4,5)); - - REQUIRE(r3i({1,2,3},{3,4,5}).origin == v3i(1,2,3)); - REQUIRE(r3i({1,2,3},{3,4,5}).direction == v3i(3,4,5)); - } - { - REQUIRE(r3f({1,2,3},{3,4,5}).cast_to() == r3i({1,2,3},{3,4,5})); - } - { - auto r0 = r3i({1,2,3},{4,5,6}); - REQUIRE(r0.data()[0] == 1); - REQUIRE(r0.data()[1] == 2); - REQUIRE(r0.data()[2] == 3); - REQUIRE(r0.data()[3] == 4); - REQUIRE(r0.data()[4] == 5); - REQUIRE(r0.data()[5] == 6); - r0.data()[0] = 2; - REQUIRE(r0 == r3i({2,2,3},{4,5,6})); - const auto& cr0 = r0; - REQUIRE(cr0.data()[0] == 2); - REQUIRE(cr0.data()[1] == 2); - REQUIRE(cr0.data()[2] == 3); - REQUIRE(cr0.data()[3] == 4); - REQUIRE(cr0.data()[4] == 5); - REQUIRE(cr0.data()[5] == 6); - } - { - auto r0 = r3i({1,2,3},{4,5,6}); - REQUIRE(r0[0] == 1); - REQUIRE(r0[1] == 2); - REQUIRE(r0[2] == 3); - REQUIRE(r0[3] == 4); - REQUIRE(r0[4] == 5); - REQUIRE(r0[5] == 6); - r0[0] = 2; - REQUIRE(r0 == r3i({2,2,3},{4,5,6})); - const auto& cr0 = r0; - REQUIRE(cr0[0] == 2); - REQUIRE(cr0[1] == 2); - REQUIRE(cr0[2] == 3); - REQUIRE(cr0[3] == 4); - REQUIRE(cr0[4] == 5); - REQUIRE(cr0[5] == 6); - } - { - auto r0 = r3i({1,2,3},{4,5,6}); - REQUIRE(&r0 == &(r0 += 1)); - REQUIRE(r0 == r3i({2,3,4},{4,5,6})); - REQUIRE(&r0 == &(r0 -= 4)); - REQUIRE(r0 == r3i({-2,-1,0},{4,5,6})); - REQUIRE(&r0 == &(r0 *= 2)); - REQUIRE(r0 == r3i({-2,-1,0},{8,10,12})); - REQUIRE(&r0 == &(r0 /= 3)); - REQUIRE(r0 == r3i({-2,-1,0},{2,3,4})); - - REQUIRE(r3i({1,2,3},{4,5,6}) + 2 == r3i({3,4,5},{4,5,6})); - REQUIRE(r3i({1,2,3},{4,5,6}) - 2 == r3i({-1,0,1},{4,5,6})); - REQUIRE(r3i({1,2,3},{4,5,6}) * 2 == r3i({1,2,3},{8,10,12})); - REQUIRE(r3i({1,2,3},{4,5,6}) / 2 == r3i({1,2,3},{2,2,3})); - - REQUIRE(r3i({1,2,3},{4,5,6}) + v3i(1,2,3) == r3i({2,4,6},{4,5,6})); - REQUIRE(r3i({1,2,3},{4,5,6}) - v3i(3,2,1) == r3i({-2,0,2},{4,5,6})); - REQUIRE(r3i({1,2,3},{4,5,6}) * v3i(2,3,4) == r3i({1,2,3},{8,15,24})); - REQUIRE(r3i({1,2,3},{4,12,20}) / v3i(2,3,4) == r3i({1,2,3},{2,4,5})); - } - { - REQUIRE(make_ray3(2,1,0) == r3i(0,0,0,2,1,0)); - REQUIRE(make_ray3(4,3,2,2,1,0) == r3i({4,3,2},{2,1,0})); - - REQUIRE(make_ray3(v3i{2,1,0}) == r3i({0,0,0},{2,1,0})); - REQUIRE(make_ray3(v3i{4,3,2},v3i{2,1,0}) == r3i({4,3,2},{2,1,0})); - } - { - auto r0 = r3i({1,2,3},{4,5,6}); - auto r1 = r3i(r0); - REQUIRE(r1 == r3i({1,2,3},{4,5,6})); - r1 = r3i({4,3,2},{1,0,-1}); - REQUIRE(r1 == r3i({4,3,2},{1,0,-1})); - } - { - REQUIRE(r3i({1,2,3},{4,5,6}) == r3i({1,2,3},{4,5,6})); - REQUIRE_FALSE(r3i({1,2,3},{4,5,6}) == r3i({1,2,4},{3,5,6})); - REQUIRE_FALSE(r3i({1,2,3},{4,5,6}) == r3i({2,1,3},{4,5,6})); - REQUIRE_FALSE(r3i({1,2,3},{4,5,6}) == r3i({2,1,4},{3,5,6})); - - REQUIRE_FALSE(r3i({1,2,3},{4,5,6}) != r3i({1,2,3},{4,5,6})); - REQUIRE(r3i({1,2,3},{4,5,6}) != r3i({1,2,4},{3,5,6})); - REQUIRE(r3i({1,2,3},{4,5,6}) != r3i({2,1,3},{4,5,6})); - REQUIRE(r3i({1,2,3},{4,5,6}) != r3i({2,1,4},{3,5,6})); - } - { - REQUIRE(math::approximately(r3i({1,2,3},{4,1,2}), r3i({1,2,4},{5,1,2}), 1)); - REQUIRE_FALSE(math::approximately(r3i({1,2,3},{4,1,2}), r3i({1,2,4},{5,1,2}))); - } -} diff --git a/untests/sources/untests_utils/strfmts.cpp b/untests/sources/untests_utils/strfmts.cpp index fe9ab7cd..62fa53de 100644 --- a/untests/sources/untests_utils/strfmts.cpp +++ b/untests/sources/untests_utils/strfmts.cpp @@ -156,19 +156,9 @@ TEST_CASE("strfmts") { " 4.00us"); } { - REQUIRE(strings::rformat("%0", make_ray2(v2i{1,2},v2i{3,4})) == "(1,2,3,4)"); - REQUIRE(strings::rformat("%0", make_ray3(v3i{1,2,3},v3i{4,5,6})) == "(1,2,3,4,5,6)"); - REQUIRE(strings::rformat("%0", make_rect(1,2,3,4)) == "(1,2,3,4)"); REQUIRE(strings::rformat("%0", make_aabb(1,2,3,4,5,6)) == "(1,2,3,4,5,6)"); - REQUIRE(strings::rformat( - "%0", - strings::make_format_arg(make_ray2(v2f{1.f,2.f},v2f{3.f,4.f}), u8(5), u8(2))) == "( 1.00, 2.00, 3.00, 4.00)"); - REQUIRE(strings::rformat( - "%0", - strings::make_format_arg(make_ray3(v3f{1.f,2.f,3.f},v3f{4.f,5.f,6.f}), u8(5), u8(2))) == "( 1.00, 2.00, 3.00, 4.00, 5.00, 6.00)"); - REQUIRE(strings::rformat( "%0", strings::make_format_arg(make_rect(1.f,2.f,3.f,4.f), u8(5), u8(2))) == "( 1.00, 2.00, 3.00, 4.00)");