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
This commit is contained in:
Valentin Shergin 2018-05-15 23:32:36 -07:00 committed by Facebook Github Bot
parent 57d69772b7
commit 545f087b46
1 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#pragma once
#include <algorithm>
#include <tuple>
#include <CoreGraphics/CGBase.h>
@ -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};
}
};
/*