mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
approximately and contains_nan for matrix
This commit is contained in:
@@ -28,18 +28,20 @@ namespace e2d
|
||||
{1, 0},
|
||||
{0, 1}};
|
||||
public:
|
||||
static const mat2& zero() noexcept;
|
||||
static const mat2& identity() noexcept;
|
||||
static constexpr mat2 zero() noexcept;
|
||||
static constexpr mat2 identity() noexcept;
|
||||
public:
|
||||
mat2() noexcept = default;
|
||||
mat2(const mat2& other) noexcept = default;
|
||||
mat2& operator=(const mat2& other) noexcept = default;
|
||||
constexpr mat2() noexcept = default;
|
||||
constexpr mat2(const mat2& other) noexcept = default;
|
||||
constexpr mat2& operator=(const mat2& other) noexcept = default;
|
||||
|
||||
mat2(const vec2<T>& row0,
|
||||
const vec2<T>& row1) noexcept;
|
||||
constexpr mat2(
|
||||
const vec2<T>& row0,
|
||||
const vec2<T>& row1) noexcept;
|
||||
|
||||
mat2(T m11, T m12,
|
||||
T m21, T m22) noexcept;
|
||||
constexpr mat2(
|
||||
T m11, T m12,
|
||||
T m21, T m22) noexcept;
|
||||
|
||||
template < typename To >
|
||||
mat2<To> cast_to() const noexcept;
|
||||
@@ -61,29 +63,27 @@ namespace e2d
|
||||
namespace e2d
|
||||
{
|
||||
template < typename T >
|
||||
const mat2<T>& mat2<T>::zero() noexcept {
|
||||
static const mat2<T> zero{
|
||||
constexpr mat2<T> mat2<T>::zero() noexcept {
|
||||
return {
|
||||
0, 0,
|
||||
0, 0};
|
||||
return zero;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
const mat2<T>& mat2<T>::identity() noexcept {
|
||||
static const mat2<T> identity{
|
||||
constexpr mat2<T> mat2<T>::identity() noexcept {
|
||||
return {
|
||||
1, 0,
|
||||
0, 1};
|
||||
return identity;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
mat2<T>::mat2(
|
||||
constexpr mat2<T>::mat2(
|
||||
const vec2<T>& row0,
|
||||
const vec2<T>& row1) noexcept
|
||||
: rows{row0, row1} {}
|
||||
|
||||
template < typename T >
|
||||
mat2<T>::mat2(
|
||||
constexpr mat2<T>::mat2(
|
||||
T m11, T m12,
|
||||
T m21, T m22) noexcept
|
||||
: rows{{m11, m12},
|
||||
@@ -147,7 +147,7 @@ namespace e2d
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
mat2<T> make_mat2(
|
||||
constexpr mat2<T> make_mat2(
|
||||
const vec2<T>& row0,
|
||||
const vec2<T>& row1) noexcept
|
||||
{
|
||||
@@ -155,7 +155,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
mat2<T> make_mat2(
|
||||
constexpr mat2<T> make_mat2(
|
||||
T m11, T m12,
|
||||
T m21, T m22) noexcept
|
||||
{
|
||||
@@ -311,6 +311,21 @@ namespace e2d::math
|
||||
-sn, cs};
|
||||
}
|
||||
|
||||
//
|
||||
// approximately
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
bool approximately(
|
||||
const mat2<T>& l,
|
||||
const mat2<T>& r,
|
||||
T precision = math::default_precision<T>()) noexcept
|
||||
{
|
||||
return
|
||||
math::approximately(l.rows[0], r.rows[0], precision) &&
|
||||
math::approximately(l.rows[1], r.rows[1], precision);
|
||||
}
|
||||
|
||||
//
|
||||
// inversed
|
||||
//
|
||||
@@ -349,4 +364,15 @@ namespace e2d::math
|
||||
mm[0], mm[2],
|
||||
mm[1], mm[3]};
|
||||
}
|
||||
|
||||
//
|
||||
// contains_nan
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
bool contains_nan(const mat2<T>& v) noexcept {
|
||||
return
|
||||
math::contains_nan(v.rows[0]) ||
|
||||
math::contains_nan(v.rows[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,20 +30,22 @@ namespace e2d
|
||||
{0, 1, 0},
|
||||
{0, 0, 1}};
|
||||
public:
|
||||
static const mat3& zero() noexcept;
|
||||
static const mat3& identity() noexcept;
|
||||
static constexpr mat3 zero() noexcept;
|
||||
static constexpr mat3 identity() noexcept;
|
||||
public:
|
||||
mat3() noexcept = default;
|
||||
mat3(const mat3& other) noexcept = default;
|
||||
mat3& operator=(const mat3& other) noexcept = default;
|
||||
constexpr mat3() noexcept = default;
|
||||
constexpr mat3(const mat3& other) noexcept = default;
|
||||
constexpr mat3& operator=(const mat3& other) noexcept = default;
|
||||
|
||||
mat3(const vec3<T>& row0,
|
||||
const vec3<T>& row1,
|
||||
const vec3<T>& row2) noexcept;
|
||||
constexpr mat3(
|
||||
const vec3<T>& row0,
|
||||
const vec3<T>& row1,
|
||||
const vec3<T>& row2) noexcept;
|
||||
|
||||
mat3(T m11, T m12, T m13,
|
||||
T m21, T m22, T m23,
|
||||
T m31, T m32, T m33) noexcept;
|
||||
constexpr mat3(
|
||||
T m11, T m12, T m13,
|
||||
T m21, T m22, T m23,
|
||||
T m31, T m32, T m33) noexcept;
|
||||
|
||||
template < typename To >
|
||||
mat3<To> cast_to() const noexcept;
|
||||
@@ -65,32 +67,30 @@ namespace e2d
|
||||
namespace e2d
|
||||
{
|
||||
template < typename T >
|
||||
const mat3<T>& mat3<T>::zero() noexcept {
|
||||
static const mat3<T> zero{
|
||||
constexpr mat3<T> mat3<T>::zero() noexcept {
|
||||
return {
|
||||
0, 0, 0,
|
||||
0, 0, 0,
|
||||
0, 0, 0};
|
||||
return zero;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
const mat3<T>& mat3<T>::identity() noexcept {
|
||||
static const mat3<T> identity{
|
||||
constexpr mat3<T> mat3<T>::identity() noexcept {
|
||||
return {
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1};
|
||||
return identity;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
mat3<T>::mat3(
|
||||
constexpr mat3<T>::mat3(
|
||||
const vec3<T>& row0,
|
||||
const vec3<T>& row1,
|
||||
const vec3<T>& row2) noexcept
|
||||
: rows{row0, row1, row2} {}
|
||||
|
||||
template < typename T >
|
||||
mat3<T>::mat3(
|
||||
constexpr mat3<T>::mat3(
|
||||
T m11, T m12, T m13,
|
||||
T m21, T m22, T m23,
|
||||
T m31, T m32, T m33) noexcept
|
||||
@@ -157,7 +157,7 @@ namespace e2d
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
mat3<T> make_mat3(
|
||||
constexpr mat3<T> make_mat3(
|
||||
const vec3<T>& row0,
|
||||
const vec3<T>& row1,
|
||||
const vec3<T>& row2) noexcept
|
||||
@@ -166,7 +166,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
mat3<T> make_mat3(
|
||||
constexpr mat3<T> make_mat3(
|
||||
T m11, T m12, T m13,
|
||||
T m21, T m22, T m23,
|
||||
T m31, T m32, T m33) noexcept
|
||||
@@ -423,6 +423,22 @@ namespace e2d::math
|
||||
T(2) * (xz + yw), T(2) * (yz - xw), T(1) - T(2) * (xx + yy)};
|
||||
}
|
||||
|
||||
//
|
||||
// approximately
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
bool approximately(
|
||||
const mat3<T>& l,
|
||||
const mat3<T>& r,
|
||||
T precision = math::default_precision<T>()) noexcept
|
||||
{
|
||||
return
|
||||
math::approximately(l.rows[0], r.rows[0], precision) &&
|
||||
math::approximately(l.rows[1], r.rows[1], precision) &&
|
||||
math::approximately(l.rows[2], r.rows[2], precision);
|
||||
}
|
||||
|
||||
//
|
||||
// inversed
|
||||
//
|
||||
@@ -477,4 +493,16 @@ namespace e2d::math
|
||||
mm[1], mm[4], mm[7],
|
||||
mm[2], mm[5], mm[8]};
|
||||
}
|
||||
|
||||
//
|
||||
// contains_nan
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
bool contains_nan(const mat3<T>& v) noexcept {
|
||||
return
|
||||
math::contains_nan(v.rows[0]) ||
|
||||
math::contains_nan(v.rows[1]) ||
|
||||
math::contains_nan(v.rows[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,22 +33,24 @@ namespace e2d
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1}};
|
||||
public:
|
||||
static const mat4& zero() noexcept;
|
||||
static const mat4& identity() noexcept;
|
||||
static constexpr mat4 zero() noexcept;
|
||||
static constexpr mat4 identity() noexcept;
|
||||
public:
|
||||
mat4() noexcept = default;
|
||||
mat4(const mat4& other) noexcept = default;
|
||||
mat4& operator=(const mat4& other) noexcept = default;
|
||||
constexpr mat4() noexcept = default;
|
||||
constexpr mat4(const mat4& other) noexcept = default;
|
||||
constexpr mat4& operator=(const mat4& other) noexcept = default;
|
||||
|
||||
mat4(const vec4<T>& row0,
|
||||
const vec4<T>& row1,
|
||||
const vec4<T>& row2,
|
||||
const vec4<T>& row3) noexcept;
|
||||
constexpr mat4(
|
||||
const vec4<T>& row0,
|
||||
const vec4<T>& row1,
|
||||
const vec4<T>& row2,
|
||||
const vec4<T>& row3) noexcept;
|
||||
|
||||
mat4(T m11, T m12, T m13, T m14,
|
||||
T m21, T m22, T m23, T m24,
|
||||
T m31, T m32, T m33, T m34,
|
||||
T m41, T m42, T m43, T m44) noexcept;
|
||||
constexpr mat4(
|
||||
T m11, T m12, T m13, T m14,
|
||||
T m21, T m22, T m23, T m24,
|
||||
T m31, T m32, T m33, T m34,
|
||||
T m41, T m42, T m43, T m44) noexcept;
|
||||
|
||||
template < typename To >
|
||||
mat4<To> cast_to() const noexcept;
|
||||
@@ -70,27 +72,25 @@ namespace e2d
|
||||
namespace e2d
|
||||
{
|
||||
template < typename T >
|
||||
const mat4<T>& mat4<T>::zero() noexcept {
|
||||
static const mat4<T> zero{
|
||||
constexpr mat4<T> mat4<T>::zero() noexcept {
|
||||
return {
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0};
|
||||
return zero;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
const mat4<T>& mat4<T>::identity() noexcept {
|
||||
static const mat4<T> identity{
|
||||
constexpr mat4<T> mat4<T>::identity() noexcept {
|
||||
return {
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1};
|
||||
return identity;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
mat4<T>::mat4(
|
||||
constexpr mat4<T>::mat4(
|
||||
const vec4<T>& row0,
|
||||
const vec4<T>& row1,
|
||||
const vec4<T>& row2,
|
||||
@@ -98,7 +98,7 @@ namespace e2d
|
||||
: rows{row0, row1, row2, row3} {}
|
||||
|
||||
template < typename T >
|
||||
mat4<T>::mat4(
|
||||
constexpr mat4<T>::mat4(
|
||||
T m11, T m12, T m13, T m14,
|
||||
T m21, T m22, T m23, T m24,
|
||||
T m31, T m32, T m33, T m34,
|
||||
@@ -168,7 +168,7 @@ namespace e2d
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
mat4<T> make_mat4(
|
||||
constexpr mat4<T> make_mat4(
|
||||
const vec4<T>& row0,
|
||||
const vec4<T>& row1,
|
||||
const vec4<T>& row2,
|
||||
@@ -178,7 +178,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
mat4<T> make_mat4(
|
||||
constexpr mat4<T> make_mat4(
|
||||
T m11, T m12, T m13, T m14,
|
||||
T m21, T m22, T m23, T m24,
|
||||
T m31, T m32, T m33, T m34,
|
||||
@@ -647,6 +647,23 @@ namespace e2d::math
|
||||
T(0), T(0), tz, T(0)};
|
||||
}
|
||||
|
||||
//
|
||||
// approximately
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
bool approximately(
|
||||
const mat4<T>& l,
|
||||
const mat4<T>& r,
|
||||
T precision = math::default_precision<T>()) noexcept
|
||||
{
|
||||
return
|
||||
math::approximately(l.rows[0], r.rows[0], precision) &&
|
||||
math::approximately(l.rows[1], r.rows[1], precision) &&
|
||||
math::approximately(l.rows[2], r.rows[2], precision) &&
|
||||
math::approximately(l.rows[3], r.rows[3], precision);
|
||||
}
|
||||
|
||||
//
|
||||
// inversed
|
||||
//
|
||||
@@ -733,4 +750,17 @@ namespace e2d::math
|
||||
mm[2], mm[6], mm[10], mm[14],
|
||||
mm[3], mm[7], mm[11], mm[15]};
|
||||
}
|
||||
|
||||
//
|
||||
// contains_nan
|
||||
//
|
||||
|
||||
template < typename T >
|
||||
bool contains_nan(const mat4<T>& v) noexcept {
|
||||
return
|
||||
math::contains_nan(v.rows[0]) ||
|
||||
math::contains_nan(v.rows[1]) ||
|
||||
math::contains_nan(v.rows[2]) ||
|
||||
math::contains_nan(v.rows[3]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user