From 495f8737361b7ff409f98b6645d5a1d8bffbfc44 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Fri, 3 Jul 2015 22:22:48 +0300 Subject: [PATCH] Add div/mul/remainder operators with another Point as an argument --- SDL2pp/Point.cc | 33 ++++++++++++++++++ SDL2pp/Point.hh | 89 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 114 insertions(+), 8 deletions(-) diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 1a24745..d64136c 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -82,14 +82,26 @@ Point Point::operator/(int value) const { return Point(x / value, y / value); } +Point Point::operator/(const Point& other) const { + return Point(x / other.x, y / other.y); +} + Point Point::operator%(int value) const { return Point(x % value, y % value); } +Point Point::operator%(const Point& other) const { + return Point(x % other.x, y % other.y); +} + Point Point::operator*(int value) const { return Point(x * value, y * value); } +Point Point::operator*(const Point& other) const { + return Point(x * other.x, y * other.y); +} + Point& Point::operator+=(const Point& other) { x += other.x; y += other.y; @@ -111,6 +123,13 @@ Point& Point::operator/=(int value) { return *this; } +Point& Point::operator/=(const Point& other) { + x /= other.x; + y /= other.y; + + return *this; +} + Point& Point::operator%=(int value) { x %= value; y %= value; @@ -118,6 +137,13 @@ Point& Point::operator%=(int value) { return *this; } +Point& Point::operator%=(const Point& other) { + x %= other.x; + y %= other.y; + + return *this; +} + Point& Point::operator*=(int value) { x *= value; y *= value; @@ -125,6 +151,13 @@ Point& Point::operator*=(int value) { return *this; } +Point& Point::operator*=(const Point& other) { + x *= other.x; + y *= other.y; + + return *this; +} + Point Point::GetClamped(const Rect& rect) const { Point p = *this; p.Clamp(rect); diff --git a/SDL2pp/Point.hh b/SDL2pp/Point.hh index bce691f..d1398a9 100644 --- a/SDL2pp/Point.hh +++ b/SDL2pp/Point.hh @@ -189,31 +189,71 @@ public: /// /// \param[in] value Divisor /// - /// \returns New Point representing memberwise division of point by an integer + /// \returns New Point representing memberwise division of + /// point by an integer /// //////////////////////////////////////////////////////////// Point operator/(int value) const; //////////////////////////////////////////////////////////// - /// \brief Get point's memberwise remainder from integer division + /// \brief Get point's memberwise division by another point /// /// \param[in] value Divisor /// - /// \returns New Point representing memberwise remainder from point divided by an integer + /// \returns New Point representing memberwise division of + /// point by another point + /// + //////////////////////////////////////////////////////////// + Point operator/(const Point& other) const; + + //////////////////////////////////////////////////////////// + /// \brief Get point's memberwise remainder from division + /// by an integer + /// + /// \param[in] value Divisor + /// + /// \returns New Point representing memberwise remainder + /// from division by an integer /// //////////////////////////////////////////////////////////// Point operator%(int value) const; //////////////////////////////////////////////////////////// - /// \brief Get point's memberwise multiplication by an integer + /// \brief Get point's memberwise remainder from division + /// by another point + /// + /// \param[in] value Divisor + /// + /// \returns New Point representing memberwise remainder + /// from division by another point + /// + //////////////////////////////////////////////////////////// + Point operator%(const Point& other) const; + + //////////////////////////////////////////////////////////// + /// \brief Get point's memberwise multiplication by an + /// integer /// /// \param[in] value Multiplier /// - /// \returns New Point representing memberwise multiplication of point by an integer + /// \returns New Point representing memberwise multiplication + /// of point by an integer /// //////////////////////////////////////////////////////////// Point operator*(int value) const; + //////////////////////////////////////////////////////////// + /// \brief Get point's memberwise multiplication by anoter + /// point + /// + /// \param[in] value Multiplier + /// + /// \returns New Point representing memberwise multiplication + /// of point by another point + /// + //////////////////////////////////////////////////////////// + Point operator*(const Point& other) const; + //////////////////////////////////////////////////////////// /// \brief Memberwise add another point /// @@ -245,7 +285,17 @@ public: Point& operator/=(int value); //////////////////////////////////////////////////////////// - /// \brief Memberwise remainder from integer division + /// \brief Memberwise divide by another point + /// + /// \param[in] value Divisor + /// + /// \returns Reference to self + /// + //////////////////////////////////////////////////////////// + Point& operator/=(const Point& other); + + //////////////////////////////////////////////////////////// + /// \brief Memberwise remainder from division by an integer /// /// \param[in] value Divisor /// @@ -254,6 +304,17 @@ public: //////////////////////////////////////////////////////////// Point& operator%=(int value); + //////////////////////////////////////////////////////////// + /// \brief Memberwise remainder from division by another + /// point + /// + /// \param[in] value Divisor + /// + /// \returns Reference to self + /// + //////////////////////////////////////////////////////////// + Point& operator%=(const Point& other); + //////////////////////////////////////////////////////////// /// \brief Memberwise multiply by an integer /// @@ -265,7 +326,18 @@ public: Point& operator*=(int value); //////////////////////////////////////////////////////////// - /// \brief Get a point with coordinates modified so it fits into a given rect + /// \brief Memberwise multiply by another point + /// + /// \param[in] value Multiplier + /// + /// \returns Reference to self + /// + //////////////////////////////////////////////////////////// + Point& operator*=(const Point& other); + + //////////////////////////////////////////////////////////// + /// \brief Get a point with coordinates modified so it fits + /// into a given rect /// /// \param[in] rect Rectangle to clamp with /// @@ -275,7 +347,8 @@ public: Point GetClamped(const Rect& rect) const; //////////////////////////////////////////////////////////// - /// \brief Clamp point coordinates to make it fit into a given rect + /// \brief Clamp point coordinates to make it fit into a + /// given rect /// /// \param[in] rect Rectangle to clamp with ///