From aaaa946e6d4774b1ae3a758428e1254adf38e142 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 19 Mar 2018 16:51:29 -0700 Subject: [PATCH] Fabric: Equality operators for geometry types Summary: We will need this soon. Reviewed By: fkgozali Differential Revision: D7330338 fbshipit-source-id: 30aeadc182893e86c6a039c74d245f9b56624151 --- ReactCommon/fabric/graphics/Geometry.h | 44 ++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index dcaf88f43..8471b1d1a 100644 --- a/ReactCommon/fabric/graphics/Geometry.h +++ b/ReactCommon/fabric/graphics/Geometry.h @@ -34,6 +34,16 @@ struct Point { 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); + } + + bool operator !=(const Point& rhs) const { + return !(*this == rhs); + } }; /* @@ -42,6 +52,16 @@ struct Point { struct Size { Float width {0}; Float height {0}; + + 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 { + return !(*this == rhs); + } }; /* @@ -50,16 +70,36 @@ struct Size { struct Rect { Point origin {0, 0}; Size size {0, 0}; + + 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 { + return !(*this == rhs); + } }; /* * EdgeInsets */ struct EdgeInsets { - Float top {0}; Float left {0}; - Float bottom {0}; + Float top {0}; Float right {0}; + Float bottom {0}; + + 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 { + return !(*this == rhs); + } }; } // namespace react