Add Point and Rect comparison operators

This commit is contained in:
Dmitry Marakasov 2014-02-11 04:52:25 +04:00
parent 802322ef1b
commit 0365329dc0
4 changed files with 27 additions and 0 deletions

View File

@ -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();
}

View File

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

View File

@ -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();
}

View File

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