Make vector comparison operators transitive

This commit is contained in:
savilli
2024-01-08 01:41:39 +01:00
committed by sfan5
parent dda9b23c3d
commit 345285786f
2 changed files with 31 additions and 34 deletions

View File

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