From 545f087b46b5e41b7fa12debc289e5eda9d4ef86 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 15 May 2018 23:32:36 -0700 Subject: [PATCH] Fabric: Several helper functions for `react::Rect` Summary: Trivial. We will need them soon at least for ScrollView. Reviewed By: fkgozali Differential Revision: D7958244 fbshipit-source-id: ce92c6e6181181ac17d817292af18ffa46a4d975 --- ReactCommon/fabric/graphics/Geometry.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index 00efbe62f2a..ec5de410019 100644 --- a/ReactCommon/fabric/graphics/Geometry.h +++ b/ReactCommon/fabric/graphics/Geometry.h @@ -2,6 +2,7 @@ #pragma once +#include #include #include @@ -85,6 +86,20 @@ struct Rect { bool operator !=(const Rect& rhs) const { return !(*this == rhs); } + + Float getMaxX() const { return size.width > 0 ? origin.x + size.width : origin.x; } + Float getMaxY() const { return size.height > 0 ? origin.y + size.height : origin.y; } + Float getMinX() const { return size.width >= 0 ? origin.x : origin.x + size.width; } + Float getMinY() const { return size.height >= 0 ? origin.y : origin.y + size.height; } + + void unionInPlace(const Rect &rect) { + Float x1 = std::min(getMinX(), rect.getMinX()); + Float y1 = std::min(getMinY(), rect.getMinY()); + Float x2 = std::max(getMaxX(), rect.getMaxX()); + Float y2 = std::max(getMaxY(), rect.getMaxY()); + origin = {x1, y1}; + size = {x2 - x1, y2 - y1}; + } }; /*