remove math physics stuff

This commit is contained in:
2020-02-05 11:44:15 +07:00
parent 724fdf47b1
commit 02dcc6ee2c
13 changed files with 0 additions and 1211 deletions

View File

@@ -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"

View File

@@ -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<i16>;
using m4hu = mat4<u16>;
using r2d = ray2<f64>;
using r2f = ray2<f32>;
using r2i = ray2<i32>;
using r2u = ray2<u32>;
using r2hi = ray2<i16>;
using r2hu = ray2<u16>;
using r3d = ray3<f64>;
using r3f = ray3<f32>;
using r3i = ray3<i32>;
using r3u = ray3<u32>;
using r3hi = ray3<i16>;
using r3hu = ray3<u16>;
using b2d = rect<f64>;
using b2f = rect<f32>;
using b2i = rect<i32>;

View File

@@ -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<T>,
"type of 'ray2' must be arithmetic");
public:
using self_type = ray2;
using value_type = T;
public:
vec2<T> origin;
vec2<T> 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<T>& direction) noexcept;
constexpr ray2(const vec2<T>& origin, const vec2<T>& direction) noexcept;
template < typename To >
ray2<To> 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<T>& v) noexcept;
ray2& operator-=(const vec2<T>& v) noexcept;
ray2& operator*=(const vec2<T>& v) noexcept;
ray2& operator/=(const vec2<T>& v) noexcept;
};
}
namespace e2d
{
template < typename T >
constexpr ray2<T> ray2<T>::zero() noexcept {
return {vec2<T>::zero(), vec2<T>::zero()};
}
template < typename T >
constexpr ray2<T> ray2<T>::unit_x() noexcept {
return {vec2<T>::zero(), vec2<T>::unit_x()};
}
template < typename T >
constexpr ray2<T> ray2<T>::unit_y() noexcept {
return {vec2<T>::zero(), vec2<T>::unit_y()};
}
template < typename T >
constexpr ray2<T>::ray2(T dx, T dy) noexcept
: direction(dx, dy) {}
template < typename T >
constexpr ray2<T>::ray2(T ox, T oy, T dx, T dy) noexcept
: origin(ox, oy)
, direction(dx, dy) {}
template < typename T >
constexpr ray2<T>::ray2(const vec2<T>& direction) noexcept
: direction(direction) {}
template < typename T >
constexpr ray2<T>::ray2(const vec2<T>& origin, const vec2<T>& direction) noexcept
: origin(origin)
, direction(direction) {}
template < typename T >
template < typename To >
ray2<To> ray2<T>::cast_to() const noexcept {
return {
origin.template cast_to<To>(),
direction.template cast_to<To>()};
}
template < typename T >
T* ray2<T>::data() noexcept {
return origin.data();
}
template < typename T >
const T* ray2<T>::data() const noexcept {
return origin.data();
}
template < typename T >
T& ray2<T>::operator[](std::size_t index) noexcept {
E2D_ASSERT(index < 4);
return data()[index];
}
template < typename T >
T ray2<T>::operator[](std::size_t index) const noexcept {
E2D_ASSERT(index < 4);
return data()[index];
}
template < typename T >
ray2<T>& ray2<T>::operator+=(T v) noexcept {
origin += v;
return *this;
}
template < typename T >
ray2<T>& ray2<T>::operator-=(T v) noexcept {
origin -= v;
return *this;
}
template < typename T >
ray2<T>& ray2<T>::operator*=(T v) noexcept {
direction *= v;
return *this;
}
template < typename T >
ray2<T>& ray2<T>::operator/=(T v) noexcept {
direction /= v;
return *this;
}
template < typename T >
ray2<T>& ray2<T>::operator+=(const vec2<T>& v) noexcept {
origin += v;
return *this;
}
template < typename T >
ray2<T>& ray2<T>::operator-=(const vec2<T>& v) noexcept {
origin -= v;
return *this;
}
template < typename T >
ray2<T>& ray2<T>::operator*=(const vec2<T>& v) noexcept {
direction *= v;
return *this;
}
template < typename T >
ray2<T>& ray2<T>::operator/=(const vec2<T>& v) noexcept {
direction /= v;
return *this;
}
}
namespace e2d
{
//
// make_ray2
//
template < typename T >
constexpr ray2<T> make_ray2(T dx, T dy) noexcept {
return {dx, dy};
}
template < typename T >
constexpr ray2<T> make_ray2(T ox, T oy, T dx, T dy) noexcept {
return {ox, oy, dx, dy};
}
template < typename T >
constexpr ray2<T> make_ray2(const vec2<T>& direction) noexcept {
return {direction};
}
template < typename T >
constexpr ray2<T> make_ray2(const vec2<T>& origin, const vec2<T>& direction) noexcept {
return {origin, direction};
}
//
// ray2 (==,!=) ray2
//
template < typename T >
bool operator==(const ray2<T>& l, const ray2<T>& r) noexcept {
return l.origin == r.origin
&& l.direction == r.direction;
}
template < typename T >
bool operator!=(const ray2<T>& l, const ray2<T>& r) noexcept {
return !(l == r);
}
//
// ray2 (+,-,*,/) value
//
template < typename T >
ray2<T> operator+(const ray2<T>& l, T v) noexcept {
return {
l.origin + v,
l.direction};
}
template < typename T >
ray2<T> operator-(const ray2<T>& l, T v) noexcept {
return {
l.origin - v,
l.direction};
}
template < typename T >
ray2<T> operator*(const ray2<T>& l, T v) noexcept {
return {
l.origin,
l.direction * v};
}
template < typename T >
ray2<T> operator/(const ray2<T>& l, T v) noexcept {
return {
l.origin,
l.direction / v};
}
//
// ray2 (+,-,*,/) vec2
//
template < typename T >
ray2<T> operator+(const ray2<T>& l, const vec2<T>& v) noexcept {
return {
l.origin + v,
l.direction};
}
template < typename T >
ray2<T> operator-(const ray2<T>& l, const vec2<T>& v) noexcept {
return {
l.origin - v,
l.direction};
}
template < typename T >
ray2<T> operator*(const ray2<T>& l, const vec2<T>& v) noexcept {
return {
l.origin,
l.direction * v};
}
template < typename T >
ray2<T> operator/(const ray2<T>& l, const vec2<T>& v) noexcept {
return {
l.origin,
l.direction / v};
}
}
namespace e2d::math
{
//
// approximately
//
template < typename T >
bool approximately(
const ray2<T>& l,
const ray2<T>& r,
T precision = math::default_precision<T>()) noexcept
{
return math::approximately(l.origin, r.origin, precision)
&& math::approximately(l.direction, r.direction, precision);
}
}

View File

@@ -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<T>,
"type of 'ray3' must be arithmetic");
public:
using self_type = ray3;
using value_type = T;
public:
vec3<T> origin;
vec3<T> 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<T>& direction) noexcept;
constexpr ray3(const vec3<T>& origin, const vec3<T>& direction) noexcept;
template < typename To >
ray3<To> 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<T>& v) noexcept;
ray3& operator-=(const vec3<T>& v) noexcept;
ray3& operator*=(const vec3<T>& v) noexcept;
ray3& operator/=(const vec3<T>& v) noexcept;
};
}
namespace e2d
{
template < typename T >
constexpr ray3<T> ray3<T>::zero() noexcept {
return {vec3<T>::zero(), vec3<T>::zero()};
}
template < typename T >
constexpr ray3<T> ray3<T>::unit_x() noexcept {
return {vec3<T>::zero(), vec3<T>::unit_x()};
}
template < typename T >
constexpr ray3<T> ray3<T>::unit_y() noexcept {
return {vec3<T>::zero(), vec3<T>::unit_y()};
}
template < typename T >
constexpr ray3<T> ray3<T>::unit_z() noexcept {
return {vec3<T>::zero(), vec3<T>::unit_z()};
}
template < typename T >
constexpr ray3<T>::ray3(T dx, T dy, T dz) noexcept
: direction(dx, dy, dz) {}
template < typename T >
constexpr ray3<T>::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<T>::ray3(const vec3<T>& direction) noexcept
: direction(direction) {}
template < typename T >
constexpr ray3<T>::ray3(const vec3<T>& origin, const vec3<T>& direction) noexcept
: origin(origin)
, direction(direction) {}
template < typename T >
template < typename To >
ray3<To> ray3<T>::cast_to() const noexcept {
return {
origin.template cast_to<To>(),
direction.template cast_to<To>()};
}
template < typename T >
T* ray3<T>::data() noexcept {
return origin.data();
}
template < typename T >
const T* ray3<T>::data() const noexcept {
return origin.data();
}
template < typename T >
T& ray3<T>::operator[](std::size_t index) noexcept {
E2D_ASSERT(index < 6);
return data()[index];
}
template < typename T >
T ray3<T>::operator[](std::size_t index) const noexcept {
E2D_ASSERT(index < 6);
return data()[index];
}
template < typename T >
ray3<T>& ray3<T>::operator+=(T v) noexcept {
origin += v;
return *this;
}
template < typename T >
ray3<T>& ray3<T>::operator-=(T v) noexcept {
origin -= v;
return *this;
}
template < typename T >
ray3<T>& ray3<T>::operator*=(T v) noexcept {
direction *= v;
return *this;
}
template < typename T >
ray3<T>& ray3<T>::operator/=(T v) noexcept {
direction /= v;
return *this;
}
template < typename T >
ray3<T>& ray3<T>::operator+=(const vec3<T>& v) noexcept {
origin += v;
return *this;
}
template < typename T >
ray3<T>& ray3<T>::operator-=(const vec3<T>& v) noexcept {
origin -= v;
return *this;
}
template < typename T >
ray3<T>& ray3<T>::operator*=(const vec3<T>& v) noexcept {
direction *= v;
return *this;
}
template < typename T >
ray3<T>& ray3<T>::operator/=(const vec3<T>& v) noexcept {
direction /= v;
return *this;
}
}
namespace e2d
{
//
// make_ray3
//
template < typename T >
constexpr ray3<T> make_ray3(T dx, T dy, T dz) noexcept {
return {dx, dy, dz};
}
template < typename T >
constexpr ray3<T> 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<T> make_ray3(const vec3<T>& direction) noexcept {
return {direction};
}
template < typename T >
constexpr ray3<T> make_ray3(const vec3<T>& origin, const vec3<T>& direction) noexcept {
return {origin, direction};
}
//
// ray3 (==,!=) ray3
//
template < typename T >
bool operator==(const ray3<T>& l, const ray3<T>& r) noexcept {
return l.origin == r.origin
&& l.direction == r.direction;
}
template < typename T >
bool operator!=(const ray3<T>& l, const ray3<T>& r) noexcept {
return !(l == r);
}
//
// ray3 (+,-,*,/) value
//
template < typename T >
ray3<T> operator+(const ray3<T>& l, T v) noexcept {
return {
l.origin + v,
l.direction};
}
template < typename T >
ray3<T> operator-(const ray3<T>& l, T v) noexcept {
return {
l.origin - v,
l.direction};
}
template < typename T >
ray3<T> operator*(const ray3<T>& l, T v) noexcept {
return {
l.origin,
l.direction * v};
}
template < typename T >
ray3<T> operator/(const ray3<T>& l, T v) noexcept {
return {
l.origin,
l.direction / v};
}
//
// ray3 (+,-,*,/) vec3
//
template < typename T >
ray3<T> operator+(const ray3<T>& l, const vec3<T>& v) noexcept {
return {
l.origin + v,
l.direction};
}
template < typename T >
ray3<T> operator-(const ray3<T>& l, const vec3<T>& v) noexcept {
return {
l.origin - v,
l.direction};
}
template < typename T >
ray3<T> operator*(const ray3<T>& l, const vec3<T>& v) noexcept {
return {
l.origin,
l.direction * v};
}
template < typename T >
ray3<T> operator/(const ray3<T>& l, const vec3<T>& v) noexcept {
return {
l.origin,
l.direction / v};
}
}
namespace e2d::math
{
//
// approximately
//
template < typename T >
bool approximately(
const ray3<T>& l,
const ray3<T>& r,
T precision = math::default_precision<T>()) noexcept
{
return math::approximately(l.origin, r.origin, precision)
&& math::approximately(l.direction, r.direction, precision);
}
}

View File

@@ -138,96 +138,6 @@ namespace e2d::strings
}
};
//
// ray2
//
template < typename T >
class format_arg<ray2<T>, std::enable_if_t<std::is_integral_v<T>>> {
ray2<T> value_;
u8 width_;
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0) noexcept
: value_(std::forward<U>(value)), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const {
return math::numeric_cast<std::ptrdiff_t>(
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<ray2<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
ray2<T> value_;
u8 width_;
u8 precision_;
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0, u8 precision = 6) noexcept
: value_(std::forward<U>(value)), width_(width), precision_(precision) {}
std::ptrdiff_t write(char* dst, size_t size) const {
return math::numeric_cast<std::ptrdiff_t>(
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<ray3<T>, std::enable_if_t<std::is_integral_v<T>>> {
ray3<T> value_;
u8 width_;
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0) noexcept
: value_(std::forward<U>(value)), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const {
return math::numeric_cast<std::ptrdiff_t>(
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<ray3<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
ray3<T> value_;
u8 width_;
u8 precision_;
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0, u8 precision = 6) noexcept
: value_(std::forward<U>(value)), width_(width), precision_(precision) {}
std::ptrdiff_t write(char* dst, size_t size) const {
return math::numeric_cast<std::ptrdiff_t>(
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
//

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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<ray2<T>>(name,
sol::constructors<
ray2<T>(),
ray2<T>(ray2<T>),
ray2<T>(T,T),
ray2<T>(T,T,T,T),
ray2<T>(vec2<T>),
ray2<T>(vec2<T>,vec2<T>)>(),
"zero", &ray2<T>::zero,
"unit_x", &ray2<T>::unit_x,
"unit_y", &ray2<T>::unit_y,
"origin", &ray2<T>::origin,
"direction", &ray2<T>::direction,
sol::meta_function::to_string, [](const ray2<T>& v){
return strings::rformat("%0", v);
},
sol::meta_function::equal_to, sol::resolve<bool(const ray2<T>&, const ray2<T>&)>(::operator==),
sol::meta_function::addition, sol::overload(
sol::resolve<ray2<T>(const ray2<T>&, T)>(::operator+),
sol::resolve<ray2<T>(const ray2<T>&, const vec2<T>&)>(::operator+)),
sol::meta_function::subtraction, sol::overload(
sol::resolve<ray2<T>(const ray2<T>&, T)>(::operator-),
sol::resolve<ray2<T>(const ray2<T>&, const vec2<T>&)>(::operator-)),
sol::meta_function::multiplication, sol::overload(
sol::resolve<ray2<T>(const ray2<T>&, T)>(::operator*),
sol::resolve<ray2<T>(const ray2<T>&, const vec2<T>&)>(::operator*)),
sol::meta_function::division, sol::overload(
sol::resolve<ray2<T>(const ray2<T>&, T)>(::operator/),
sol::resolve<ray2<T>(const ray2<T>&, const vec2<T>&)>(::operator/)),
"approximately", [](const ray2<T>& l, const ray2<T>& r){ return math::approximately(l,r); });
}
}
namespace e2d::bindings::math
{
void bind_ray2(sol::state& l) {
bind_ray2_t<f32>("r2f", l);
}
}

View File

@@ -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<ray3<T>>(name,
sol::constructors<
ray3<T>(),
ray3<T>(ray3<T>),
ray3<T>(T,T,T),
ray3<T>(T,T,T,T,T,T),
ray3<T>(vec3<T>),
ray3<T>(vec3<T>,vec3<T>)>(),
"zero", &ray3<T>::zero,
"unit", &ray3<T>::unit_x,
"unit_y", &ray3<T>::unit_y,
"unit_z", &ray3<T>::unit_z,
"origin", &ray3<T>::origin,
"direction", &ray3<T>::direction,
sol::meta_function::to_string, [](const ray3<T>& v){
return strings::rformat("%0", v);
},
sol::meta_function::equal_to, sol::resolve<bool(const ray3<T>&, const ray3<T>&)>(::operator==),
sol::meta_function::addition, sol::overload(
sol::resolve<ray3<T>(const ray3<T>&, T)>(::operator+),
sol::resolve<ray3<T>(const ray3<T>&, const vec3<T>&)>(::operator+)),
sol::meta_function::subtraction, sol::overload(
sol::resolve<ray3<T>(const ray3<T>&, T)>(::operator-),
sol::resolve<ray3<T>(const ray3<T>&, const vec3<T>&)>(::operator-)),
sol::meta_function::multiplication, sol::overload(
sol::resolve<ray3<T>(const ray3<T>&, T)>(::operator*),
sol::resolve<ray3<T>(const ray3<T>&, const vec3<T>&)>(::operator*)),
sol::meta_function::division, sol::overload(
sol::resolve<ray3<T>(const ray3<T>&, T)>(::operator/),
sol::resolve<ray3<T>(const ray3<T>&, const vec3<T>&)>(::operator/)),
"approximately", [](const ray3<T>& l, const ray3<T>& r){ return math::approximately(l,r); });
}
}
namespace e2d::bindings::math
{
void bind_ray3(sol::state& l) {
bind_ray3_t<f32>("r3f", l);
}
}

View File

@@ -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<i32>, 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<i32>, decltype(std::declval<r2i>().origin)
>::value, "static unit test error");
static_assert(std::is_same<
vec2<i32>, decltype(std::declval<r2i>().direction)
>::value, "static unit test error");
static_assert(std::is_same<
ray2<f32>, 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<f32>, decltype(std::declval<r2f>().origin)
>::value, "static unit test error");
static_assert(std::is_same<
vec2<f32>, decltype(std::declval<r2f>().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<i32>() == 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})));
}
}

View File

@@ -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<i32>, 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<i32>, decltype(std::declval<r3i>().origin)
>::value, "static unit test error");
static_assert(std::is_same<
vec3<i32>, decltype(std::declval<r3i>().direction)
>::value, "static unit test error");
static_assert(std::is_same<
ray3<f32>, 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<f32>, decltype(std::declval<r3f>().origin)
>::value, "static unit test error");
static_assert(std::is_same<
vec3<f32>, decltype(std::declval<r3f>().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<i32>() == 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})));
}
}

View File

@@ -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)");