From 0365329dc0472319306a66ef068d4302cfe17f55 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 11 Feb 2014 04:52:25 +0400 Subject: [PATCH] Add Point and Rect comparison operators --- SDL2pp/Point.cc | 10 ++++++++++ SDL2pp/Point.hh | 3 +++ SDL2pp/Rect.cc | 11 +++++++++++ SDL2pp/Rect.hh | 3 +++ 4 files changed, 27 insertions(+) diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 9c2c1b0..05417e9 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -59,6 +59,16 @@ Point& Point::operator=(const Point& other) { return *this; } +bool Point::operator==(const Point& other) const { + if (!point_ || !other.point_) + return point_ == other.point_; // true only if both null + return point_->x == other.point_->x && point_->y == other.point_->y; +} + +bool Point::operator!=(const Point& other) const { + return !(*this == other); +} + SDL_Point* Point::Get() { return point_.get(); } diff --git a/SDL2pp/Point.hh b/SDL2pp/Point.hh index 73c153b..72888d6 100644 --- a/SDL2pp/Point.hh +++ b/SDL2pp/Point.hh @@ -56,6 +56,9 @@ public: Point& operator=(const Point& other); Point& operator=(Point&&) noexcept = default; + bool operator==(const Point& other) const; + bool operator!=(const Point& other) const; + SDL_Point* Get(); const SDL_Point* Get() const; diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index 88a2388..1487de6 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -65,6 +65,17 @@ Rect& Rect::operator=(const Rect& other) { return *this; } +bool Rect::operator==(const Rect& other) const { + if (!rect_ || !other.rect_) + return rect_ == other.rect_; // true only if both null + return rect_->x == other.rect_->x && rect_->y == other.rect_->y && + rect_->w == other.rect_->w && rect_->h == other.rect_->h; +} + +bool Rect::operator!=(const Rect& other) const { + return !(*this == other); +} + SDL_Rect* Rect::Get() { return rect_.get(); } diff --git a/SDL2pp/Rect.hh b/SDL2pp/Rect.hh index 32211c5..3df81ff 100644 --- a/SDL2pp/Rect.hh +++ b/SDL2pp/Rect.hh @@ -48,6 +48,9 @@ public: Rect& operator=(const Rect& other); Rect& operator=(Rect&&) noexcept = default; + bool operator==(const Rect& other) const; + bool operator!=(const Rect& other) const; + SDL_Rect* Get(); const SDL_Rect* Get() const;