diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index 00efbe62f..ec5de4100 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}; + } }; /*