Fabric: Defined `+` and `*` operators for Point and Size geometric types

Summary:
@public
Trivial. Those operations are very useful in layout algorithms.

Reviewed By: mdvacca

Differential Revision: D9403566

fbshipit-source-id: e76967aaaac3a36bf6d3e7a468b5ae7769a4dcac
This commit is contained in:
Valentin Shergin 2018-09-03 22:53:13 -07:00 committed by Facebook Github Bot
parent 1cc29c53fb
commit 2a942b7ae8
1 changed files with 32 additions and 14 deletions

View File

@ -20,23 +20,29 @@ struct Point {
Float x {0};
Float y {0};
Point& operator += (const Point& rhs) {
x += rhs.x;
y += rhs.y;
Point &operator+=(const Point &point) {
x += point.x;
y += point.y;
return *this;
}
friend Point operator + (Point lhs, const Point& rhs) {
Point &operator*=(const Point &point) {
x *= point.x;
y *= point.y;
return *this;
}
friend Point operator+(Point lhs, const Point &rhs) {
return lhs += rhs;
}
bool operator ==(const Point& rhs) const {
bool operator==(const Point &rhs) const {
return
std::tie(this->x, this->y) ==
std::tie(rhs.x, rhs.y);
}
bool operator !=(const Point& rhs) const {
bool operator!=(const Point &rhs) const {
return !(*this == rhs);
}
};
@ -48,13 +54,25 @@ struct Size {
Float width {0};
Float height {0};
bool operator ==(const Size& rhs) const {
Size &operator+=(const Point &point) {
width += point.x;
height += point.y;
return *this;
}
Size &operator*=(const Point &point) {
width *= point.x;
height *= point.y;
return *this;
}
bool operator==(const Size &rhs) const {
return
std::tie(this->width, this->height) ==
std::tie(rhs.width, rhs.height);
}
bool operator !=(const Size& rhs) const {
bool operator!=(const Size &rhs) const {
return !(*this == rhs);
}
};
@ -66,13 +84,13 @@ struct Rect {
Point origin {0, 0};
Size size {0, 0};
bool operator ==(const Rect& rhs) const {
bool operator==(const Rect &rhs) const {
return
std::tie(this->origin, this->size) ==
std::tie(rhs.origin, rhs.size);
}
bool operator !=(const Rect& rhs) const {
bool operator!=(const Rect &rhs) const {
return !(*this == rhs);
}
@ -100,13 +118,13 @@ struct EdgeInsets {
Float right {0};
Float bottom {0};
bool operator ==(const EdgeInsets& rhs) const {
bool operator==(const EdgeInsets &rhs) const {
return
std::tie(this->left, this->top, this->right, this->bottom) ==
std::tie(rhs.left, rhs.top, rhs.right, rhs.bottom);
}
bool operator !=(const EdgeInsets& rhs) const {
bool operator!=(const EdgeInsets &rhs) const {
return !(*this == rhs);
}
@ -126,13 +144,13 @@ struct CornerInsets {
Float bottomLeft {0};
Float bottomRight {0};
bool operator ==(const CornerInsets& rhs) const {
bool operator==(const CornerInsets &rhs) const {
return
std::tie(this->topLeft, this->topRight, this->bottomLeft, this->bottomRight) ==
std::tie(rhs.topLeft, rhs.topRight, rhs.bottomLeft, rhs.bottomRight);
}
bool operator !=(const CornerInsets& rhs) const {
bool operator!=(const CornerInsets &rhs) const {
return !(*this == rhs);
}