From ac83f75b8c1f84a7e13ea8f3afb69d0063a401b6 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 23 Dec 2019 17:07:16 -0800 Subject: [PATCH] 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 --- ReactCommon/fabric/graphics/Geometry.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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); + } }; /*