diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 76eeece688..995cb0834a 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -157,6 +157,13 @@ bool Vector2::operator!=(const Vector2& p_vec2) const { return x!=p_vec2.x || y!=p_vec2.y; } +bool Vector2::nan_equals(const Vector2& p_vec2) const { + + return (x==p_vec2.x && y==p_vec2.y) || + (x==p_vec2.x && isnan(y) && isnan(p_vec2.y)) || + (isnan(x) && isnan(p_vec2.x) && y == p_vec2.y); +} + Vector2 Vector2::floor() const { return Vector2( Math::floor(x), Math::floor(y) ); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index a24c4266ee..6dd8799ba2 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -133,6 +133,7 @@ struct Vector2 { bool operator<(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y(p_a._data._mem) m_op *reinterpret_cast(p_b._data._mem));\ + case m_name: _RETURN( (*reinterpret_cast(p_a._data._mem))m_op(*reinterpret_cast(p_b._data._mem)));\ default: {}\ }\ r_valid=false;\ return;} - #define DEFAULT_OP_LOCALMEM_NEG(m_name,m_type)\ case m_name: {\ _RETURN( -*reinterpret_cast(p_a._data._mem));\ @@ -177,13 +188,28 @@ r_valid=false;\ return;} #define DEFAULT_OP_ARRAY_EQ(m_name,m_type)\ -DEFAULT_OP_ARRAY_OP(m_name,m_type,!=,!=,true,false,false) +DEFAULT_OP_ARRAY_OP(m_name,m_type,!=,!=,true,false,false,true) + +#define DEFAULT_OP_ARRAY_EQ_NAN(m_name,m_type)\ + DEFAULT_ARRAY_OP_HEAD(m_name,m_type,!=,false,false)\ + if ((ra[i] != rb[i]) && (isnan(ra[i]) != isnan(rb[i])))\ + _RETURN(false);\ + DEFAULT_ARRAY_OP_FOOT(true) + +#define DEFAULT_OP_ARRAY_EQ_NAN_V(m_name,m_type)\ +DEFAULT_OP_ARRAY_OP(m_name,m_type,!=,.nan_equals,true,false,false,false) #define DEFAULT_OP_ARRAY_LT(m_name,m_type)\ -DEFAULT_OP_ARRAY_OP(m_name,m_type,<,!=,false,a_len::Read ra = array_a.read();\ PoolVector::Read rb = array_b.read();\ \ for(int i=0;i