diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index b1c05ab7a95..bde7a8878ad 100644 --- a/ReactCommon/fabric/graphics/Geometry.h +++ b/ReactCommon/fabric/graphics/Geometry.h @@ -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); + } }; /*