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:
parent
57d69772b7
commit
545f087b46
|
@ -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};
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue