mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2026-02-05 01:23:02 +07:00
Merge branch 'feature/conversions' into dev
This commit is contained in:
34
README.md
34
README.md
@@ -95,6 +95,10 @@ public:
|
||||
|
||||
explicit vec_base(T v);
|
||||
vec_base(T x, T y);
|
||||
|
||||
template < typename U > vec_base(const vec_base<U, 2>& other);
|
||||
template < typename U > explicit vec_base(const vec_base<U, 3>& other);
|
||||
template < typename U > explicit vec_base(const vec_base<U, 4>& other);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -114,7 +118,8 @@ public:
|
||||
vec_base(const vec_base<T, 2>& xy, T z);
|
||||
vec_base(T x, const vec_base<T, 2>& yz);
|
||||
|
||||
explicit operator vec<T, 2>() const;
|
||||
template < typename U > vec_base(const vec_base<U, 3>& other);
|
||||
template < typename U > explicit vec_base(const vec_base<U, 4>& other);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -133,15 +138,13 @@ public:
|
||||
|
||||
vec_base(const vec_base<T, 2>& xy, T z, T w);
|
||||
vec_base(T x, const vec_base<T, 2>& yz, T w);
|
||||
|
||||
vec_base(T x, T y, const vec_base<T, 2>& zw);
|
||||
vec_base(const vec_base<T, 2>& xy, const vec_base<T, 2>& zw);
|
||||
|
||||
vec_base(const vec_base<T, 3>& xyz, T w);
|
||||
vec_base(T x, const vec_base<T, 3>& yzw);
|
||||
|
||||
explicit operator vec<T, 2>() const;
|
||||
explicit operator vec<T, 3>() const;
|
||||
template < typename U > vec_base(const vec_base<U, 4>& other);
|
||||
};
|
||||
|
||||
template < typename T, size_t Size >
|
||||
@@ -249,6 +252,10 @@ public:
|
||||
mat_base(
|
||||
const row_type& row0,
|
||||
const row_type& row1);
|
||||
|
||||
template < typename U > mat_base(const mat_base<U, 2>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 3>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 4>& other);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -281,9 +288,9 @@ public:
|
||||
const mat_base<T, 2>& m,
|
||||
const vec_base<T, 2>& v);
|
||||
|
||||
explicit mat_base(const mat_base<T, 2>& other);
|
||||
|
||||
explicit operator mat<T, 2>() const;
|
||||
template < typename U > mat_base(const mat_base<U, 3>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 2>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 4>& other);
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -318,11 +325,9 @@ public:
|
||||
const mat_base<T, 3>& m,
|
||||
const vec_base<T, 3>& v);
|
||||
|
||||
explicit mat_base(const mat_base<T, 2>& other);
|
||||
explicit mat_base(const mat_base<T, 3>& other);
|
||||
|
||||
explicit operator mat<T, 2>() const;
|
||||
explicit operator mat<T, 3>() const;
|
||||
template < typename U > mat_base(const mat_base<U, 4>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 2>& other);
|
||||
template < typename U > explicit mat_base(const mat_base<U, 3>& other);
|
||||
};
|
||||
|
||||
template < typename T, size_t Size >
|
||||
@@ -420,9 +425,10 @@ public:
|
||||
|
||||
qua_base(T vx, T vy, T vz, T s);
|
||||
qua_base(const vec<T, 3>& v, T s);
|
||||
|
||||
explicit qua_base(const vec<T, 4>& vs);
|
||||
explicit operator vec<T, 4>() const;
|
||||
|
||||
template < typename U > qua_base(const qua_base<U, 4>& other);
|
||||
template < typename U > explicit operator vec<U, 4>() const;
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
|
||||
@@ -26,9 +26,9 @@ namespace vmath_hpp::detail
|
||||
: mat_base(identity_init) {}
|
||||
|
||||
constexpr mat_base(uninit_t) {}
|
||||
constexpr mat_base(zero_init_t) : mat_base{zero_init, zero_init} {}
|
||||
constexpr mat_base(unit_init_t) : mat_base{unit_init, unit_init} {}
|
||||
constexpr mat_base(identity_init_t) : mat_base{T{1}} {}
|
||||
constexpr mat_base(zero_init_t): mat_base{zero_init, zero_init} {}
|
||||
constexpr mat_base(unit_init_t): mat_base{unit_init, unit_init} {}
|
||||
constexpr mat_base(identity_init_t): mat_base{T{1}} {}
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
@@ -51,6 +51,21 @@ namespace vmath_hpp::detail
|
||||
const row_type& row0,
|
||||
const row_type& row1)
|
||||
: rows{row0, row1} {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr mat_base(const mat_base<U, 2>& other): mat_base(
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]}) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const mat_base<U, 3>& other): mat_base(
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]}) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const mat_base<U, 4>& other): mat_base(
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]}) {}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -63,9 +78,9 @@ namespace vmath_hpp::detail
|
||||
: mat_base(identity_init) {}
|
||||
|
||||
constexpr mat_base(uninit_t) {}
|
||||
constexpr mat_base(zero_init_t) : mat_base{zero_init, zero_init, zero_init} {}
|
||||
constexpr mat_base(unit_init_t) : mat_base{unit_init, unit_init, unit_init} {}
|
||||
constexpr mat_base(identity_init_t) : mat_base{T{1}} {}
|
||||
constexpr mat_base(zero_init_t): mat_base{zero_init, zero_init, zero_init} {}
|
||||
constexpr mat_base(unit_init_t): mat_base{unit_init, unit_init, unit_init} {}
|
||||
constexpr mat_base(identity_init_t): mat_base{T{1}} {}
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
@@ -102,18 +117,23 @@ namespace vmath_hpp::detail
|
||||
{m.rows[1], T{0}},
|
||||
{v, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 2>& other)
|
||||
: rows{
|
||||
{other.rows[0], T{0}},
|
||||
{other.rows[1], T{0}},
|
||||
{T{0}, T{0}, T{1}}} {}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr mat_base(const mat_base<U, 3>& other): mat_base(
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]},
|
||||
row_type{other.rows[2]}) {}
|
||||
|
||||
constexpr explicit operator mat<T, 2>() const {
|
||||
return {
|
||||
vec<T, 2>{rows[0]},
|
||||
vec<T, 2>{rows[1]}};
|
||||
}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const mat_base<U, 2>& other): mat_base(
|
||||
row_type{other.rows[0], T{0}},
|
||||
row_type{other.rows[1], T{0}},
|
||||
row_type{T{0}, T{0}, T{1}}) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const mat_base<U, 4>& other): mat_base(
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]},
|
||||
row_type{other.rows[2]}) {}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
@@ -126,9 +146,9 @@ namespace vmath_hpp::detail
|
||||
: mat_base(identity_init) {}
|
||||
|
||||
constexpr mat_base(uninit_t) {}
|
||||
constexpr mat_base(zero_init_t) : mat_base{zero_init, zero_init, zero_init, zero_init} {}
|
||||
constexpr mat_base(unit_init_t) : mat_base{unit_init, unit_init, unit_init, unit_init} {}
|
||||
constexpr mat_base(identity_init_t) : mat_base{T{1}} {}
|
||||
constexpr mat_base(zero_init_t): mat_base{zero_init, zero_init, zero_init, zero_init} {}
|
||||
constexpr mat_base(unit_init_t): mat_base{unit_init, unit_init, unit_init, unit_init} {}
|
||||
constexpr mat_base(identity_init_t): mat_base{T{1}} {}
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
@@ -171,34 +191,26 @@ namespace vmath_hpp::detail
|
||||
{m.rows[2], T{0}},
|
||||
{v, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 2>& other)
|
||||
: rows{
|
||||
{other.rows[0], T{0}, T{0}},
|
||||
{other.rows[1], T{0}, T{0}},
|
||||
{T{0}, T{0}, T{1}, T{0}},
|
||||
{T{0}, T{0}, T{0}, T{1}}} {}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr mat_base(const mat_base<U, 4>& other): mat_base(
|
||||
row_type{other.rows[0]},
|
||||
row_type{other.rows[1]},
|
||||
row_type{other.rows[2]},
|
||||
row_type{other.rows[3]}) {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 3>& other)
|
||||
: rows{
|
||||
{other.rows[0], T{0}},
|
||||
{other.rows[1], T{0}},
|
||||
{other.rows[2], T{0}},
|
||||
{T{0}, T{0}, T{0}, T{1}}} {}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const mat_base<U, 2>& other): mat_base(
|
||||
row_type{other.rows[0], T{0}, T{0}},
|
||||
row_type{other.rows[1], T{0}, T{0}},
|
||||
row_type{T{0}, T{0}, T{1}, T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, T{1}}) {}
|
||||
|
||||
constexpr explicit operator mat<T, 2>() const {
|
||||
return {
|
||||
vec<T, 2>{rows[0]},
|
||||
vec<T, 2>{rows[1]}};
|
||||
}
|
||||
|
||||
constexpr explicit operator mat<T, 3>() const {
|
||||
return {
|
||||
vec<T, 3>{rows[0]},
|
||||
vec<T, 3>{rows[1]},
|
||||
vec<T, 3>{rows[2]}};
|
||||
}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit mat_base(const mat_base<U, 3>& other): mat_base(
|
||||
row_type{other.rows[0], T{0}},
|
||||
row_type{other.rows[1], T{0}},
|
||||
row_type{other.rows[2], T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, T{1}}) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -26,18 +26,15 @@ namespace vmath_hpp::detail
|
||||
constexpr qua_base(zero_init_t) : qua_base{zero_init, T{0}} {}
|
||||
constexpr qua_base(identity_init_t) : qua_base{zero_init, T{1}} {}
|
||||
|
||||
constexpr qua_base(T vx, T vy, T vz, T s)
|
||||
: v{vx, vy, vz}, s{s} {}
|
||||
constexpr qua_base(T vx, T vy, T vz, T s): v{vx, vy, vz}, s{s} {}
|
||||
constexpr qua_base(const vec<T, 3>& v, T s): v{v}, s{s} {}
|
||||
constexpr explicit qua_base(const vec<T, 4>& vs): v{vs[0], vs[1], vs[2]}, s{vs[3]} {}
|
||||
|
||||
constexpr qua_base(const vec<T, 3>& v, T s)
|
||||
: v{v}, s{s} {}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr qua_base(const qua_base<U>& other): qua_base(other.v, other.s) {}
|
||||
|
||||
constexpr explicit qua_base(const vec<T, 4>& vs)
|
||||
: v{vs[0], vs[1], vs[2]}, s{vs[3]} {}
|
||||
|
||||
constexpr explicit operator vec<T, 4>() const {
|
||||
return {v, s};
|
||||
}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<T, U>, int> = 0 >
|
||||
constexpr explicit operator vec<U, 4>() const { return vec<U, 4>(v, s); }
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
|
||||
@@ -22,14 +22,20 @@ namespace vmath_hpp::detail
|
||||
: vec_base{zero_init} {}
|
||||
|
||||
constexpr vec_base(uninit_t) {}
|
||||
constexpr vec_base(zero_init_t) : vec_base{T{0}} {}
|
||||
constexpr vec_base(unit_init_t) : vec_base{T{1}} {}
|
||||
constexpr vec_base(zero_init_t): vec_base{T{0}} {}
|
||||
constexpr vec_base(unit_init_t): vec_base{T{1}} {}
|
||||
|
||||
constexpr explicit vec_base(T v)
|
||||
: x{v}, y{v} {}
|
||||
constexpr explicit vec_base(T v): x{v}, y{v} {}
|
||||
constexpr vec_base(T x, T y): x{x}, y{y} {}
|
||||
|
||||
constexpr vec_base(T x, T y)
|
||||
: x{x}, y{y} {}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr vec_base(const vec_base<U, 2>& other): vec_base(other[0], other[1]) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const vec_base<U, 3>& other): vec_base(other[0], other[1]) {}
|
||||
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const vec_base<U, 4>& other): vec_base(other[0], other[1]) {}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
@@ -57,24 +63,20 @@ namespace vmath_hpp::detail
|
||||
: vec_base{zero_init} {}
|
||||
|
||||
constexpr vec_base(uninit_t) {}
|
||||
constexpr vec_base(zero_init_t) : vec_base{T{0}} {}
|
||||
constexpr vec_base(unit_init_t) : vec_base{T{1}} {}
|
||||
constexpr vec_base(zero_init_t): vec_base{T{0}} {}
|
||||
constexpr vec_base(unit_init_t): vec_base{T{1}} {}
|
||||
|
||||
constexpr explicit vec_base(T v)
|
||||
: x{v}, y{v}, z{v} {}
|
||||
constexpr explicit vec_base(T v): x{v}, y{v}, z{v} {}
|
||||
constexpr vec_base(T x, T y, T z): x{x}, y{y}, z{z} {}
|
||||
|
||||
constexpr vec_base(T x, T y, T z)
|
||||
: x{x}, y{y}, z{z} {}
|
||||
constexpr vec_base(const vec_base<T, 2>& xy, T z): vec_base(xy[0], xy[1], z) {}
|
||||
constexpr vec_base(T x, const vec_base<T, 2>& yz): vec_base(x, yz[0], yz[1]) {}
|
||||
|
||||
constexpr vec_base(const vec_base<T, 2>& xy, T z)
|
||||
: x{xy[0]}, y{xy[1]}, z{z} {}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr vec_base(const vec_base<U, 3>& other): vec_base(other[0], other[1], other[2]) {}
|
||||
|
||||
constexpr vec_base(T x, const vec_base<T, 2>& yz)
|
||||
: x{x}, y{yz[0]}, z{yz[1]} {}
|
||||
|
||||
constexpr explicit operator vec<T, 2>() const {
|
||||
return {x, y};
|
||||
}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr explicit vec_base(const vec_base<U, 4>& other): vec_base(other[0], other[1], other[2]) {}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
@@ -107,37 +109,19 @@ namespace vmath_hpp::detail
|
||||
constexpr vec_base(zero_init_t) : vec_base{T{0}} {}
|
||||
constexpr vec_base(unit_init_t) : vec_base{T{1}} {}
|
||||
|
||||
constexpr explicit vec_base(T v)
|
||||
: x{v}, y{v}, z{v}, w{v} {}
|
||||
constexpr explicit vec_base(T v): x{v}, y{v}, z{v}, w{v} {}
|
||||
constexpr vec_base(T x, T y, T z, T w): x{x}, y{y}, z{z}, w{w} {}
|
||||
|
||||
constexpr vec_base(T x, T y, T z, T w)
|
||||
: x{x}, y{y}, z{z}, w{w} {}
|
||||
constexpr vec_base(const vec_base<T, 2>& xy, T z, T w): vec_base(xy[0], xy[1], z, w) {}
|
||||
constexpr vec_base(T x, const vec_base<T, 2>& yz, T w): vec_base(x, yz[0], yz[1], w) {}
|
||||
constexpr vec_base(T x, T y, const vec_base<T, 2>& zw): vec_base(x, y, zw[0], zw[1]) {}
|
||||
constexpr vec_base(const vec_base<T, 2>& xy, const vec_base<T, 2>& zw): vec_base(xy[0], xy[1], zw[0], zw[1]) {}
|
||||
|
||||
constexpr vec_base(const vec_base<T, 2>& xy, T z, T w)
|
||||
: x{xy[0]}, y{xy[1]}, z{z}, w{w} {}
|
||||
constexpr vec_base(const vec_base<T, 3>& xyz, T w): vec_base(xyz[0], xyz[1], xyz[2], w) {}
|
||||
constexpr vec_base(T x, const vec_base<T, 3>& yzw): vec_base(x, yzw[0], yzw[1], yzw[2]) {}
|
||||
|
||||
constexpr vec_base(T x, const vec_base<T, 2>& yz, T w)
|
||||
: x{x}, y{yz[0]}, z{yz[1]}, w{w} {}
|
||||
|
||||
constexpr vec_base(T x, T y, const vec_base<T, 2>& zw)
|
||||
: x{x}, y{y}, z{zw[0]}, w{zw[1]} {}
|
||||
|
||||
constexpr vec_base(const vec_base<T, 2>& xy, const vec_base<T, 2>& zw)
|
||||
: x{xy[0]}, y{xy[1]}, z{zw[0]}, w{zw[1]} {}
|
||||
|
||||
constexpr vec_base(const vec_base<T, 3>& xyz, T w)
|
||||
: x{xyz[0]}, y{xyz[1]}, z{xyz[2]}, w{w} {}
|
||||
|
||||
constexpr vec_base(T x, const vec_base<T, 3>& yzw)
|
||||
: x{x}, y{yzw[0]}, z{yzw[1]}, w{yzw[2]} {}
|
||||
|
||||
constexpr explicit operator vec<T, 2>() const {
|
||||
return {x, y};
|
||||
}
|
||||
|
||||
constexpr explicit operator vec<T, 3>() const {
|
||||
return {x, y, z};
|
||||
}
|
||||
template < typename U, std::enable_if_t<std::is_convertible_v<U, T>, int> = 0 >
|
||||
constexpr vec_base(const vec_base<U, 4>& other): vec_base(other[0], other[1], other[2], other[3]) {}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
||||
switch ( index ) {
|
||||
|
||||
@@ -25,7 +25,13 @@ target_compile_options(${PROJECT_NAME}
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
/W4>
|
||||
PRIVATE
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
|
||||
-Wall -Wextra -Wpedantic>)
|
||||
$<$<CXX_COMPILER_ID:GNU>:
|
||||
-Wall -Wextra -Wpedantic>
|
||||
PRIVATE
|
||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
|
||||
-Weverything -Wno-unknown-warning-option
|
||||
-Wconversion -Wimplicit-int-float-conversion
|
||||
-Wno-c++98-compat-pedantic -Wno-ctad-maybe-unsupported
|
||||
-Wno-float-equal -Wno-double-promotion -Wno-shadow-field-in-constructor>)
|
||||
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#define STATIC_CHECK(...)\
|
||||
static_assert(__VA_ARGS__, #__VA_ARGS__);\
|
||||
CHECK(__VA_ARGS__);
|
||||
CHECK(__VA_ARGS__)
|
||||
|
||||
#define STATIC_CHECK_FALSE(...)\
|
||||
static_assert(!(__VA_ARGS__), "!(" #__VA_ARGS__ ")");\
|
||||
CHECK(!(__VA_ARGS__));
|
||||
CHECK(!(__VA_ARGS__))
|
||||
|
||||
@@ -122,6 +122,7 @@ namespace
|
||||
using namespace vmath_tests;
|
||||
|
||||
using qfix = qua<fix<float>>;
|
||||
using qfixi = qua<fix<int>>;
|
||||
|
||||
using fix2b = vec<fix<bool>, 2>;
|
||||
using fix3b = vec<fix<bool>, 3>;
|
||||
@@ -285,8 +286,8 @@ namespace vmath_hpp
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template fix<bool> any(const fix2f&);
|
||||
template fix<bool> all(const fix2f&);
|
||||
template fix<bool> any(const fix2i&);
|
||||
template fix<bool> all(const fix2i&);
|
||||
template fix2b approx(const fix2f&, const fix2f&);
|
||||
template fix2b approx(const fix2f&, const fix2f&, fix<float>);
|
||||
template fix2b less(const fix2f&, const fix2f&);
|
||||
@@ -299,8 +300,8 @@ namespace vmath_hpp
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template fix<bool> any(const fix2x2f&);
|
||||
template fix<bool> all(const fix2x2f&);
|
||||
template fix<bool> any(const fix2x2i&);
|
||||
template fix<bool> all(const fix2x2i&);
|
||||
template fix2x2b approx(const fix2x2f&, const fix2x2f&);
|
||||
template fix2x2b approx(const fix2x2f&, const fix2x2f&, fix<float>);
|
||||
template fix2x2b less(const fix2x2f&, const fix2x2f&);
|
||||
@@ -313,8 +314,8 @@ namespace vmath_hpp
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template fix<bool> any(const qfix&);
|
||||
template fix<bool> all(const qfix&);
|
||||
template fix<bool> any(const qfixi&);
|
||||
template fix<bool> all(const qfixi&);
|
||||
template fix4b approx(const qfix&, const qfix&);
|
||||
template fix4b approx(const qfix&, const qfix&, fix<float>);
|
||||
template fix4b less(const qfix&, const qfix&);
|
||||
|
||||
@@ -17,11 +17,11 @@ namespace
|
||||
for ( int i = 1; i <= Size; ++i ) {
|
||||
for ( int j = 1; j <= Size; ++j ) {
|
||||
if ( j < i - Size ) {
|
||||
m[i - 1][j - 1] = 0;
|
||||
m[unsigned(i - 1)][unsigned(j - 1)] = 0;
|
||||
} else if ( j == (i - 1) ) {
|
||||
m[i - 1][j - 1] = Size + 1 - i;
|
||||
m[unsigned(i - 1)][unsigned(j - 1)] = Size + 1 - i;
|
||||
} else {
|
||||
m[i - 1][j - 1] = Size + 1 - j;
|
||||
m[unsigned(i - 1)][unsigned(j - 1)] = Size + 1 - j;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,24 +138,58 @@ TEST_CASE("vmath/mat_fun") {
|
||||
}
|
||||
|
||||
SUBCASE("Operators2") {
|
||||
STATIC_CHECK(int2x2{} + 0.f == float2x2{});
|
||||
STATIC_CHECK(0.f + int2x2{} == float2x2{});
|
||||
STATIC_CHECK(int2x2{} + float2x2{} == float2x2{2.f});
|
||||
STATIC_CHECK(float2x2{} + int2x2{} == float2x2{2.f});
|
||||
STATIC_CHECK(int2x2{} + 0.0 == double2x2{});
|
||||
STATIC_CHECK(0.0 + int2x2{} == double2x2{});
|
||||
STATIC_CHECK(int2x2{} + double2x2{} == double2x2{2.0});
|
||||
STATIC_CHECK(double2x2{} + int2x2{} == double2x2{2.0});
|
||||
|
||||
STATIC_CHECK(int2x2{} - 0.f == float2x2{});
|
||||
STATIC_CHECK(0.f - int2x2{} == float2x2{-1.f});
|
||||
STATIC_CHECK(int2x2{} - float2x2{} == float2x2{0.f});
|
||||
STATIC_CHECK(float2x2{} - int2x2{} == float2x2{0.f});
|
||||
STATIC_CHECK(int2x2{} - 0.0 == double2x2{});
|
||||
STATIC_CHECK(0.0 - int2x2{} == double2x2{-1.0});
|
||||
STATIC_CHECK(int2x2{} - double2x2{} == double2x2{0.0});
|
||||
STATIC_CHECK(double2x2{} - int2x2{} == double2x2{0.0});
|
||||
|
||||
STATIC_CHECK(int2x2{} * 1.f == float2x2{});
|
||||
STATIC_CHECK(0.f * int2x2{1} == float2x2{0.f});
|
||||
STATIC_CHECK(int2{} * float2x2{} == float2{});
|
||||
STATIC_CHECK(int2x2{} * float2x2{} == float2x2{});
|
||||
STATIC_CHECK(float2x2{} * int2x2{1} == float2x2{});
|
||||
STATIC_CHECK(int2x2{} * 1.0 == double2x2{});
|
||||
STATIC_CHECK(0.0 * int2x2{1} == double2x2{0.0});
|
||||
STATIC_CHECK(int2{} * double2x2{} == double2{});
|
||||
STATIC_CHECK(int2x2{} * double2x2{} == double2x2{});
|
||||
STATIC_CHECK(double2x2{} * int2x2{1} == double2x2{});
|
||||
|
||||
STATIC_CHECK(int2x2{} / 1.f == float2x2{});
|
||||
STATIC_CHECK(0.f / int2x2{1,1,1,1} == float2x2{0.f});
|
||||
STATIC_CHECK(int2x2{} / 1.0 == double2x2{});
|
||||
STATIC_CHECK(0.0 / int2x2{1,1,1,1} == double2x2{0.0});
|
||||
}
|
||||
|
||||
SUBCASE("Conversions2") {
|
||||
{
|
||||
STATIC_CHECK(double2x2(1.0) == double2x2(1));
|
||||
STATIC_CHECK(double2x2(int2(1,2)) == double2x2(double2(1,2)));
|
||||
STATIC_CHECK(double2x2(int2(1,2),float2(3,4)) == double2x2(1,2,3,4));
|
||||
|
||||
STATIC_CHECK(double2x2(int2x2(1)) == double2x2(1));
|
||||
STATIC_CHECK(double2x2(int3x3(1)) == double2x2(1));
|
||||
STATIC_CHECK(double2x2(int4x4(1)) == double2x2(1));
|
||||
}
|
||||
{
|
||||
STATIC_CHECK(double3x3(1.0) == double3x3(1));
|
||||
STATIC_CHECK(double3x3(int3(1,2,3)) == double3x3(double3(1,2,3)));
|
||||
STATIC_CHECK(double3x3(int3(1,2,3),float3(2,3,4),uint3(3,4,5)) == double3x3(1,2,3,2,3,4,3,4,5));
|
||||
|
||||
STATIC_CHECK(double3x3(int2x2(1),uint2(2)) == double3x3(double2x2(1),double2(2)));
|
||||
|
||||
STATIC_CHECK(double3x3(int2x2(1)) == double3x3(1));
|
||||
STATIC_CHECK(double3x3(int3x3(1)) == double3x3(1));
|
||||
STATIC_CHECK(double3x3(int4x4(1)) == double3x3(1));
|
||||
}
|
||||
{
|
||||
STATIC_CHECK(double4x4(1.0) == double4x4(1));
|
||||
STATIC_CHECK(double4x4(int4(1,2,3,4)) == double4x4(double4(1,2,3,4)));
|
||||
STATIC_CHECK(double4x4(int4(1,2,3,4),float4(2,3,4,5),uint4(3,4,5,6),int4(4,5,6,7)) == double4x4(1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7));
|
||||
|
||||
STATIC_CHECK(double4x4(int3x3(1),uint3(2)) == double4x4(double3x3(1),double3(2)));
|
||||
|
||||
STATIC_CHECK(double4x4(int2x2(1)) == double4x4(1));
|
||||
STATIC_CHECK(double4x4(int3x3(1)) == double4x4(1));
|
||||
STATIC_CHECK(double4x4(int4x4(1)) == double4x4(1));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("relational functions") {
|
||||
|
||||
@@ -76,6 +76,16 @@ TEST_CASE("vmath/qua_fun") {
|
||||
STATIC_CHECK(1.0 / qfloat{1,1,1,1} == qdouble{1,1,1,1});
|
||||
}
|
||||
|
||||
SUBCASE("Conversions2") {
|
||||
STATIC_CHECK(qdouble(1,2.f,3.0,4u) == qdouble(1,2,3,4));
|
||||
STATIC_CHECK(qdouble(int3(1,2,3),4u) == qdouble(1,2,3,4));
|
||||
STATIC_CHECK(qdouble(int4(1,2,3,4)) == qdouble(1,2,3,4));
|
||||
STATIC_CHECK(qdouble(qfloat(1,2,3,4)) == qdouble(1,2,3,4));
|
||||
|
||||
STATIC_CHECK(float4(qfloat(1,2,3,4)) == float4(1,2,3,4));
|
||||
STATIC_CHECK(double4(qfloat(1,2,3,4)) == double4(1,2,3,4));
|
||||
}
|
||||
|
||||
SUBCASE("Common Functions") {
|
||||
{
|
||||
CHECK(all(approx(
|
||||
|
||||
@@ -104,7 +104,7 @@ TEST_CASE("vmath/qua") {
|
||||
|
||||
SUBCASE("iter") {
|
||||
{
|
||||
qfloat v{1,2,3,4};
|
||||
qua v{1,2,3,4};
|
||||
|
||||
CHECK(*v.begin() == 1);
|
||||
CHECK(*(v.begin() + 1) == 2);
|
||||
@@ -135,12 +135,12 @@ TEST_CASE("vmath/qua") {
|
||||
CHECK(v.crend() - 4 == v.crbegin());
|
||||
|
||||
*v.begin() = 3;
|
||||
CHECK(v == qfloat{3,2,3,4});
|
||||
CHECK(v == qua{3,2,3,4});
|
||||
*v.rbegin() = 5;
|
||||
CHECK(v == qfloat{3,2,3,5});
|
||||
CHECK(v == qua{3,2,3,5});
|
||||
}
|
||||
{
|
||||
const qfloat v{1,2,3,4};
|
||||
const qua v{1,2,3,4};
|
||||
|
||||
CHECK(*v.begin() == 1);
|
||||
CHECK(*(v.begin() + 1) == 2);
|
||||
@@ -230,12 +230,12 @@ TEST_CASE("vmath/qua") {
|
||||
}
|
||||
|
||||
SUBCASE("at") {
|
||||
STATIC_CHECK(qfloat(1,2,3,4).at(0) == 1);
|
||||
STATIC_CHECK(qfloat(1,2,3,4).at(1) == 2);
|
||||
STATIC_CHECK(qfloat(1,2,3,4).at(2) == 3);
|
||||
STATIC_CHECK(qfloat(1,2,3,4).at(3) == 4);
|
||||
STATIC_CHECK(qua(1,2,3,4).at(0) == 1);
|
||||
STATIC_CHECK(qua(1,2,3,4).at(1) == 2);
|
||||
STATIC_CHECK(qua(1,2,3,4).at(2) == 3);
|
||||
STATIC_CHECK(qua(1,2,3,4).at(3) == 4);
|
||||
#ifndef VMATH_HPP_NO_EXCEPTIONS
|
||||
CHECK_THROWS_AS((void)qfloat(1,2,3,4).at(4), std::out_of_range);
|
||||
CHECK_THROWS_AS((void)qua(1,2,3,4).at(4), std::out_of_range);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -104,25 +104,57 @@ TEST_CASE("vmath/vec_fun") {
|
||||
}
|
||||
|
||||
SUBCASE("Operators2") {
|
||||
STATIC_CHECK(int2{} + 0.f == float2{});
|
||||
STATIC_CHECK(0.f + int2{} == float2{});
|
||||
STATIC_CHECK(int2{} + float2{} == float2{});
|
||||
STATIC_CHECK(float2{} + int2{} == float2{});
|
||||
STATIC_CHECK(int2{} + 0.0 == double2{});
|
||||
STATIC_CHECK(0.0 + int2{} == double2{});
|
||||
STATIC_CHECK(int2{} + double2{} == double2{});
|
||||
STATIC_CHECK(double2{} + int2{} == double2{});
|
||||
|
||||
STATIC_CHECK(int2{} - 0.f == float2{});
|
||||
STATIC_CHECK(0.f - int2{} == float2{});
|
||||
STATIC_CHECK(int2{} - float2{} == float2{});
|
||||
STATIC_CHECK(float2{} - int2{} == float2{});
|
||||
STATIC_CHECK(int2{} - 0.0 == double2{});
|
||||
STATIC_CHECK(0.0 - int2{} == double2{});
|
||||
STATIC_CHECK(int2{} - double2{} == double2{});
|
||||
STATIC_CHECK(double2{} - int2{} == double2{});
|
||||
|
||||
STATIC_CHECK(int2{} * 1.f == float2{});
|
||||
STATIC_CHECK(0.f * int2{1} == float2{});
|
||||
STATIC_CHECK(int2{} * float2{1.f} == float2{});
|
||||
STATIC_CHECK(float2{} * int2{1} == float2{});
|
||||
STATIC_CHECK(int2{} * 1.0 == double2{});
|
||||
STATIC_CHECK(0.0 * int2{1} == double2{});
|
||||
STATIC_CHECK(int2{} * double2{1.0} == double2{});
|
||||
STATIC_CHECK(double2{} * int2{1} == double2{});
|
||||
|
||||
STATIC_CHECK(int2{} / 1.f == float2{});
|
||||
STATIC_CHECK(0.f / int2{1} == float2{});
|
||||
STATIC_CHECK(int2{} / float2{1.f} == float2{});
|
||||
STATIC_CHECK(float2{} / int2{1} == float2{});
|
||||
STATIC_CHECK(int2{} / 1.0 == double2{});
|
||||
STATIC_CHECK(0.0 / int2{1} == double2{});
|
||||
STATIC_CHECK(int2{} / double2{1.0} == double2{});
|
||||
STATIC_CHECK(double2{} / int2{1} == double2{});
|
||||
}
|
||||
|
||||
SUBCASE("Conversions2") {
|
||||
{
|
||||
STATIC_CHECK(double2(1) == double2(1,1));
|
||||
STATIC_CHECK(double2(1,2.f) == double2(1,2));
|
||||
STATIC_CHECK(double2(int2(1,2)) == double2(1,2));
|
||||
STATIC_CHECK(double2(int3(1,2,3)) == double2(1,2));
|
||||
STATIC_CHECK(double2(int4(1,2,3,4)) == double2(1,2));
|
||||
}
|
||||
{
|
||||
STATIC_CHECK(double3(1) == double3(1,1,1));
|
||||
STATIC_CHECK(double3(1,2.f,3u) == double3(1,2,3));
|
||||
STATIC_CHECK(double3(int3(1,2,3)) == double3(1,2,3));
|
||||
STATIC_CHECK(double3(int4(1,2,3,4)) == double3(1,2,3));
|
||||
|
||||
STATIC_CHECK(double3(int2(1,2),3.f) == double3(1,2,3));
|
||||
STATIC_CHECK(double3(1.f,int2(2,3)) == double3(1,2,3));
|
||||
}
|
||||
{
|
||||
STATIC_CHECK(double4(1) == double4(1,1,1,1));
|
||||
STATIC_CHECK(double4(1,2.f,3u,4) == double4(1,2,3,4));
|
||||
STATIC_CHECK(double4(int4(1,2,3,4)) == double4(1,2,3,4));
|
||||
|
||||
STATIC_CHECK(double4(int2{1,2},3u,4.f) == double4(1,2,3,4));
|
||||
STATIC_CHECK(double4(1,int2{2,3},4.f) == double4(1,2,3,4));
|
||||
STATIC_CHECK(double4(1,2.f,int2{3,4}) == double4(1,2,3,4));
|
||||
STATIC_CHECK(double4(int2{1,2},double2{3,4}) == double4(1,2,3,4));
|
||||
|
||||
STATIC_CHECK(double4(int3{1,2,3},4.f) == double4(1,2,3,4));
|
||||
STATIC_CHECK(double4(1.f,int3{2,3,4}) == double4(1,2,3,4));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Angle and Trigonometric Functions") {
|
||||
@@ -263,16 +295,16 @@ TEST_CASE("vmath/vec_fun") {
|
||||
STATIC_CHECK(distance2(float2(-5.f,0.f), float2(-10.f,0.f)) == uapprox(25.f));
|
||||
|
||||
STATIC_CHECK(dot(int2(1,2),int2(3,4)) == 11);
|
||||
STATIC_CHECK(dot(int2(1,2),float2(3,4)) == uapprox(11.f));
|
||||
STATIC_CHECK(dot(float2(3,4),int2(1,2)) == uapprox(11.f));
|
||||
STATIC_CHECK(dot(int2(1,2),double2(3,4)) == uapprox(11.0));
|
||||
STATIC_CHECK(dot(double2(3,4),int2(1,2)) == uapprox(11.0));
|
||||
|
||||
STATIC_CHECK(cross(int2(1,0),int2(0,1)) == 1);
|
||||
STATIC_CHECK(cross(int2(1,0),float2(0,1)) == uapprox(1.f));
|
||||
STATIC_CHECK(cross(float2(0,1),int2(1,0)) == uapprox(-1.f));
|
||||
STATIC_CHECK(cross(int2(1,0),double2(0,1)) == uapprox(1.0));
|
||||
STATIC_CHECK(cross(double2(0,1),int2(1,0)) == uapprox(-1.0));
|
||||
|
||||
STATIC_CHECK(cross(int3(1,0,0),int3(0,1,0)) == int3(0,0,1));
|
||||
STATIC_CHECK(cross(int3(1,0,0),float3(0,1,0)) == uapprox3(0.f,0.f,1.f));
|
||||
STATIC_CHECK(cross(float3(0,1,0),int3(1,0,0)) == uapprox3(0.f,0.f,-1.f));
|
||||
STATIC_CHECK(cross(int3(1,0,0),double3(0,1,0)) == uapprox3(0.0,0.0,1.0));
|
||||
STATIC_CHECK(cross(double3(0,1,0),int3(1,0,0)) == uapprox3(0.0,0.0,-1.0));
|
||||
|
||||
CHECK(normalize(float2(0.5f,0.f)).x == uapprox(1.f));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user