Skip to content

Commit

Permalink
Fabric: RectangleEdges & RectangleCorners generics
Browse files Browse the repository at this point in the history
Summary:
@public

EdgeInsets and CornerInsets are now just qualifications of those generics:

	using EdgeInsets = RectangleEdges<Float>;
	using CornerInsets = RectangleCorners<Float>;

We will need more concrete types like that in the future diffs.

Reviewed By: mdvacca

Differential Revision: D9614428

fbshipit-source-id: e4d48a11d9083958c3ada68e6368afb150c64f6b
  • Loading branch information
shergin authored and gengjiawen committed Sep 14, 2018
1 parent 6d54008 commit d1e3e06
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions ReactCommon/fabric/graphics/Geometry.h
Expand Up @@ -110,21 +110,23 @@ struct Rect {
};

/*
* EdgeInsets
* Generic data structure describes some values associated with *edges*
* of a rectangle.
*/
struct EdgeInsets {
Float left {0};
Float top {0};
Float right {0};
Float bottom {0};

bool operator==(const EdgeInsets &rhs) const {
template <typename T>
struct RectangleEdges {
T left {};
T top {};
T right {};
T bottom {};

bool operator==(const RectangleEdges<T> &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 {
bool operator!=(const RectangleEdges<T> &rhs) const {
return !(*this == rhs);
}

Expand All @@ -136,21 +138,23 @@ struct EdgeInsets {
};

/*
* CornerInsets
* Generic data structure describes some values associated with *corners*
* of a rectangle.
*/
struct CornerInsets {
Float topLeft {0};
Float topRight {0};
Float bottomLeft {0};
Float bottomRight {0};

bool operator==(const CornerInsets &rhs) const {
template <typename T>
struct RectangleCorners {
T topLeft {};
T topRight {};
T bottomLeft {};
T bottomRight {};

bool operator==(const RectangleCorners<T> &rhs) const {
return
std::tie(this->topLeft, this->topRight, this->bottomLeft, this->bottomRight) ==
std::tie(rhs.topLeft, rhs.topRight, rhs.bottomLeft, rhs.bottomRight);
std::tie(this->topLeft, this->topRight, this->bottomLeft, this->bottomRight) ==
std::tie(rhs.topLeft, rhs.topRight, rhs.bottomLeft, rhs.bottomRight);
}

bool operator!=(const CornerInsets &rhs) const {
bool operator!=(const RectangleCorners<T> &rhs) const {
return !(*this == rhs);
}

Expand All @@ -161,5 +165,15 @@ struct CornerInsets {
}
};

/*
* EdgeInsets
*/
using EdgeInsets = RectangleEdges<Float>;

/*
* CornerInsets
*/
using CornerInsets = RectangleCorners<Float>;

} // namespace react
} // namespace facebook

0 comments on commit d1e3e06

Please sign in to comment.