Move Rect and Point comparison operators out of classes

This commit is contained in:
Dmitry Marakasov 2015-11-26 13:12:28 +03:00
parent 95142b065c
commit a63cdde38f
2 changed files with 74 additions and 72 deletions

View File

@ -103,30 +103,6 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Point& operator=(Point&&) noexcept = default; Point& operator=(Point&&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Equality operator
///
/// \param[in] other Point to compare to
///
/// \returns True if two points are identical
///
////////////////////////////////////////////////////////////
constexpr bool operator==(const Point& other) const {
return x == other.x && y == other.y;
}
////////////////////////////////////////////////////////////
/// \brief Inequality operator
///
/// \param[in] other Point to compare to
///
/// \returns True if two points are not identical
///
////////////////////////////////////////////////////////////
constexpr bool operator!=(const Point& other) const {
return x != other.x || y != other.y;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get X coordinate of the point /// \brief Get X coordinate of the point
/// ///
@ -447,6 +423,43 @@ public:
} }
////////////////////////////////////////////////////////////
/// \brief Equality operator for SDL2pp::Point
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if two points are identical
///
////////////////////////////////////////////////////////////
constexpr bool operator==(const SDL2pp::Point&a, const SDL2pp::Point& b) {
return a.x == b.x && a.y == b.y;
}
////////////////////////////////////////////////////////////
/// \brief Inequality operator for SDL2pp::Point
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if two points are not identical
///
////////////////////////////////////////////////////////////
constexpr bool operator!=(const SDL2pp::Point& a, const SDL2pp::Point& b) {
return !(a == b);
}
////////////////////////////////////////////////////////////
/// \brief Less-than operator for SDL2pp::Point
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if a < b
///
////////////////////////////////////////////////////////////
bool operator<(const SDL2pp::Point& a, const SDL2pp::Point& b);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Stream output operator overload for SDL2pp::Point /// \brief Stream output operator overload for SDL2pp::Point
/// ///
@ -458,15 +471,4 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream& stream, const SDL2pp::Point& point); std::ostream& operator<<(std::ostream& stream, const SDL2pp::Point& point);
////////////////////////////////////////////////////////////
/// \brief Less-than operator for SDL2pp::Point
///
/// \param[in] a First comparison argument
/// \param[in] b Second comparison argument
///
/// \returns true if a < b
///
////////////////////////////////////////////////////////////
bool operator<(const SDL2pp::Point& a, const SDL2pp::Point& b);
#endif #endif

View File

@ -162,32 +162,6 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Rect& operator=(Rect&&) noexcept = default; Rect& operator=(Rect&&) noexcept = default;
////////////////////////////////////////////////////////////
/// \brief Equality operator
///
/// \param[in] other Rect to compare to
///
/// \returns True if two rectangles are identical
///
////////////////////////////////////////////////////////////
constexpr bool operator==(const Rect& other) const {
return x == other.x && y == other.y &&
w == other.w && h == other.h;
}
////////////////////////////////////////////////////////////
/// \brief Inequality operator
///
/// \param[in] other Rect to compare to
///
/// \returns True if two rectangles are not identical
///
////////////////////////////////////////////////////////////
constexpr bool operator!=(const Rect& other) const {
return x != other.x || y != other.y ||
w != other.w || h != other.h;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get X coordinate of the rect corner /// \brief Get X coordinate of the rect corner
/// ///
@ -523,6 +497,43 @@ public:
} }
////////////////////////////////////////////////////////////
/// \brief Equality operator for SDL2pp::Rect
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if two rectangles are identical
///
////////////////////////////////////////////////////////////
constexpr bool operator==(const SDL2pp::Rect& a, const SDL2pp::Rect& b) {
return a.x == b.x && a.y == b.y && a.w == b.w && a.h == b.h;
}
////////////////////////////////////////////////////////////
/// \brief Inequality operator for SDL2pp::Rect
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if two rectangles are not identical
///
////////////////////////////////////////////////////////////
constexpr bool operator!=(const SDL2pp::Rect& a, const SDL2pp::Rect& b) {
return !(a == b);
}
////////////////////////////////////////////////////////////
/// \brief Less-than operator for SDL2pp::Rect
///
/// \param[in] a First argument for comparison
/// \param[in] b Second argument for comparison
///
/// \returns True if a < b
///
////////////////////////////////////////////////////////////
bool operator<(const SDL2pp::Rect& a, const SDL2pp::Rect& b);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Stream output operator overload for SDL2pp::Rect /// \brief Stream output operator overload for SDL2pp::Rect
/// ///
@ -534,15 +545,4 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream& stream, const SDL2pp::Rect& rect); std::ostream& operator<<(std::ostream& stream, const SDL2pp::Rect& rect);
////////////////////////////////////////////////////////////
/// \brief Less-than operator for SDL2pp::Rect
///
/// \param[in] a First comparison argument
/// \param[in] b Second comparison argument
///
/// \returns true if a < b
///
////////////////////////////////////////////////////////////
bool operator<(const SDL2pp::Rect& a, const SDL2pp::Rect& b);
#endif #endif