mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-05 18:00:41 +01:00
Make vector comparison operators transitive
This commit is contained in:
parent
dda9b23c3d
commit
345285786f
|
@ -75,36 +75,37 @@ public:
|
|||
return *(&X+index);
|
||||
}
|
||||
|
||||
//! sort in order X, Y. Equality with rounding tolerance.
|
||||
//! sort in order X, Y.
|
||||
bool operator<=(const vector2d<T>&other) const
|
||||
{
|
||||
return (X<other.X || core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && (Y<other.Y || core::equals(Y, other.Y)));
|
||||
return !(*this > other);
|
||||
}
|
||||
|
||||
//! sort in order X, Y. Equality with rounding tolerance.
|
||||
//! sort in order X, Y.
|
||||
bool operator>=(const vector2d<T>&other) const
|
||||
{
|
||||
return (X>other.X || core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && (Y>other.Y || core::equals(Y, other.Y)));
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
//! sort in order X, Y. Difference must be above rounding tolerance.
|
||||
//! sort in order X, Y.
|
||||
bool operator<(const vector2d<T>&other) const
|
||||
{
|
||||
return (X<other.X && !core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && Y<other.Y && !core::equals(Y, other.Y));
|
||||
return X < other.X || (X == other.X && Y < other.Y);
|
||||
}
|
||||
|
||||
//! sort in order X, Y. Difference must be above rounding tolerance.
|
||||
//! sort in order X, Y.
|
||||
bool operator>(const vector2d<T>&other) const
|
||||
{
|
||||
return (X>other.X && !core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && Y>other.Y && !core::equals(Y, other.Y));
|
||||
return X > other.X || (X == other.X && Y > other.Y);
|
||||
}
|
||||
|
||||
bool operator==(const vector2d<T>& other) const { return equals(other); }
|
||||
bool operator!=(const vector2d<T>& other) const { return !equals(other); }
|
||||
bool operator==(const vector2d<T>& other) const {
|
||||
return X == other.X && Y == other.Y;
|
||||
}
|
||||
|
||||
bool operator!=(const vector2d<T>& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
// functions
|
||||
|
||||
|
|
|
@ -68,52 +68,48 @@ namespace core
|
|||
return *(&X+index);
|
||||
}
|
||||
|
||||
//! sort in order X, Y, Z. Equality with rounding tolerance.
|
||||
//! sort in order X, Y, Z.
|
||||
bool operator<=(const vector3d<T>&other) const
|
||||
{
|
||||
return (X<other.X || core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && (Y<other.Y || core::equals(Y, other.Y))) ||
|
||||
(core::equals(X, other.X) && core::equals(Y, other.Y) && (Z<other.Z || core::equals(Z, other.Z)));
|
||||
return !(*this > other);
|
||||
}
|
||||
|
||||
//! sort in order X, Y, Z. Equality with rounding tolerance.
|
||||
//! sort in order X, Y, Z.
|
||||
bool operator>=(const vector3d<T>&other) const
|
||||
{
|
||||
return (X>other.X || core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && (Y>other.Y || core::equals(Y, other.Y))) ||
|
||||
(core::equals(X, other.X) && core::equals(Y, other.Y) && (Z>other.Z || core::equals(Z, other.Z)));
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
//! sort in order X, Y, Z. Difference must be above rounding tolerance.
|
||||
//! sort in order X, Y, Z.
|
||||
bool operator<(const vector3d<T>&other) const
|
||||
{
|
||||
return (X<other.X && !core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && Y<other.Y && !core::equals(Y, other.Y)) ||
|
||||
(core::equals(X, other.X) && core::equals(Y, other.Y) && Z<other.Z && !core::equals(Z, other.Z));
|
||||
return X < other.X || (X == other.X && Y < other.Y) ||
|
||||
(X == other.X && Y == other.Y && Z < other.Z);
|
||||
}
|
||||
|
||||
//! sort in order X, Y, Z. Difference must be above rounding tolerance.
|
||||
//! sort in order X, Y, Z.
|
||||
bool operator>(const vector3d<T>&other) const
|
||||
{
|
||||
return (X>other.X && !core::equals(X, other.X)) ||
|
||||
(core::equals(X, other.X) && Y>other.Y && !core::equals(Y, other.Y)) ||
|
||||
(core::equals(X, other.X) && core::equals(Y, other.Y) && Z>other.Z && !core::equals(Z, other.Z));
|
||||
return X > other.X || (X == other.X && Y > other.Y) ||
|
||||
(X == other.X && Y == other.Y && Z > other.Z);
|
||||
}
|
||||
|
||||
//! use weak float compare
|
||||
bool operator==(const vector3d<T>& other) const
|
||||
{
|
||||
return this->equals(other);
|
||||
return X == other.X && Y == other.Y && Z == other.Z;
|
||||
}
|
||||
|
||||
bool operator!=(const vector3d<T>& other) const
|
||||
{
|
||||
return !this->equals(other);
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
// functions
|
||||
|
||||
//! returns if this vector equals the other one, taking floating point rounding errors into account
|
||||
//! Checks if this vector equals the other one.
|
||||
/** Takes floating point rounding errors into account.
|
||||
\param other Vector to compare with.
|
||||
\return True if the two vector are (almost) equal, else false. */
|
||||
bool equals(const vector3d<T>& other) const
|
||||
{
|
||||
return core::equals(X, other.X) && core::equals(Y, other.Y) && core::equals(Z, other.Z);
|
||||
|
|
Loading…
Reference in New Issue
Block a user