Some simplifications to Point/Size/Rect classes.

This commit is contained in:
Stephen Anthony 2020-11-15 15:16:06 -03:30
parent 1476b2a6bf
commit 6bbcd150d8
1 changed files with 12 additions and 7 deletions

View File

@ -44,8 +44,8 @@ struct Point
if(c != 'x')
x = y = 0;
}
bool operator==(const Point & p) const { return x == p.x && y == p.y; }
bool operator!=(const Point & p) const { return x != p.x || y != p.y; }
bool operator==(const Point& p) const { return x == p.x && y == p.y; }
bool operator!=(const Point& p) const { return !(*this == p); }
friend ostream& operator<<(ostream& os, const Point& p) {
os << p.x << "x" << p.y;
@ -75,11 +75,11 @@ struct Size
}
bool operator==(const Size& s) const { return w == s.w && h == s.h; }
bool operator!=(const Size& s) const { return w != s.w || h != s.h; }
bool operator<(const Size& s) const { return w < s.w && h < s.h; }
bool operator<=(const Size& s) const { return w <= s.w && h <= s.h; }
bool operator>(const Size& s) const { return w > s.w || h > s.h; }
bool operator>=(const Size& s) const { return w >= s.w || h >= s.h; }
bool operator< (const Size& s) const { return w < s.w && h < s.h; }
bool operator> (const Size& s) const { return w > s.w || h > s.h; }
bool operator!=(const Size& s) const { return !(*this == s); }
bool operator<=(const Size& s) const { return !(*this > s); }
bool operator>=(const Size& s) const { return !(*this < s); }
friend ostream& operator<<(ostream& os, const Size& s) {
os << s.w << "x" << s.h;
@ -175,6 +175,11 @@ struct Rect
return r.left != x || r.top != y;
}
bool operator==(const Rect& r) const {
return top == r.top && left == r.left && bottom == r.bottom && right == r.right;
}
bool operator!=(const Rect& r) const { return !(*this == r); }
friend ostream& operator<<(ostream& os, const Rect& r) {
os << r.point() << "," << r.size();
return os;