Files
react-native/ReactCommon/react/renderer/graphics/RectangleEdges.h
T
TatianaKapos 879d303fc7 Fix windows build of RectangleEdges (#35516)
Summary:
[PR: Avoid emitting mountitems for default values](https://github.com/facebook/react-native/commit/56e9aa369f5c13af38cf80ba47e9eb29d835ec89) used a constexpr in a template, which windows is unable to compile since type at this point is incomplete. Once removed, windows is able to build again. Let me know if there's a better way to fix this!

See [10072](https://github.com/microsoft/react-native-windows/issues/10072) for windows error messages

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[General] [Fixed] - Remove constexpr from RectangleEdges.h

Pull Request resolved: https://github.com/facebook/react-native/pull/35516

Test Plan: Windows has forked this file and had the change for ~5 month, all tests pass on Windows side

Reviewed By: javache

Differential Revision: D41639514

Pulled By: rshest

fbshipit-source-id: fbe595f71a7ab0accb7a76edf58ffb6aeef1ae96
2022-12-01 07:43:59 -08:00

101 lines
2.3 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <tuple>
#include <folly/Hash.h>
#include <react/renderer/graphics/Float.h>
#include <react/renderer/graphics/Rect.h>
namespace facebook {
namespace react {
/*
* Generic data structure describes some values associated with *edges*
* of a rectangle.
*/
template <typename T>
struct RectangleEdges {
T left{};
T top{};
T right{};
T bottom{};
bool operator==(RectangleEdges<T> const &rhs) const noexcept {
return std::tie(this->left, this->top, this->right, this->bottom) ==
std::tie(rhs.left, rhs.top, rhs.right, rhs.bottom);
}
bool operator!=(RectangleEdges<T> const &rhs) const noexcept {
return !(*this == rhs);
}
bool isUniform() const noexcept {
return left == top && left == right && left == bottom;
}
static RectangleEdges<T> const ZERO;
};
template <typename T>
RectangleEdges<T> const RectangleEdges<T>::ZERO = {};
template <typename T>
RectangleEdges<T> operator+(
RectangleEdges<T> const &lhs,
RectangleEdges<T> const &rhs) noexcept {
return RectangleEdges<T>{
lhs.left + rhs.left,
lhs.top + rhs.top,
lhs.right + rhs.right,
lhs.bottom + rhs.bottom};
}
template <typename T>
RectangleEdges<T> operator-(
RectangleEdges<T> const &lhs,
RectangleEdges<T> const &rhs) noexcept {
return RectangleEdges<T>{
lhs.left - rhs.left,
lhs.top - rhs.top,
lhs.right - rhs.right,
lhs.bottom - rhs.bottom};
}
/*
* EdgeInsets
*/
using EdgeInsets = RectangleEdges<Float>;
/*
* Adjusts a rectangle by the given edge insets.
*/
inline Rect insetBy(Rect const &rect, EdgeInsets const &insets) noexcept {
return Rect{
{rect.origin.x + insets.left, rect.origin.y + insets.top},
{rect.size.width - insets.left - insets.right,
rect.size.height - insets.top - insets.bottom}};
}
} // namespace react
} // namespace facebook
namespace std {
template <typename T>
struct hash<facebook::react::RectangleEdges<T>> {
size_t operator()(
facebook::react::RectangleEdges<T> const &edges) const noexcept {
return folly::hash::hash_combine(
0, edges.left, edges.right, edges.top, edges.bottom);
}
};
} // namespace std