Extend Geometry class

Summary:
This diff extends Geometry class with methods to substract points and to determine if a Rect contains a Point or not

Changelog: [internal]

Reviewed By: sammy-SC

Differential Revision: D19190283

fbshipit-source-id: 7c7dd73be2cd644081ed9af8eeef7e137c618ae4
This commit is contained in:
David Vacca authored and Facebook Github Bot committed 2019-12-23 17:09:43 -08:00
1 parent 7932e1a658
commit ac83f75b8c
1 file changed
+16
+16
View File
@@ -30,6 +30,12 @@ struct Point {
return *this;
}
Point &operator-=(const Point &point) {
x -= point.x;
y -= point.y;
return *this;
}
Point &operator*=(const Point &point) {
x *= point.x;
y *= point.y;
@@ -40,6 +46,10 @@ struct Point {
return lhs += rhs;
}
friend Point operator-(Point lhs, const Point &rhs) {
return lhs -= rhs;
}
bool operator==(const Point &rhs) const {
return std::tie(this->x, this->y) == std::tie(rhs.x, rhs.y);
}
@@ -114,6 +124,12 @@ struct Rect {
origin = {x1, y1};
size = {x2 - x1, y2 - y1};
}
bool containsPoint(Point point) {
return point.x >= origin.x && point.y >= origin.y &&
point.x <= (origin.x + size.width) &&
point.y <= (origin.y + size.height);
}
};
/*