mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Changelog: [Internal] Include FlexLayout C++ source to ReactCommons Reviewed By: d16r, NickGerleman Differential Revision: D38716145 fbshipit-source-id: 0ca2ab040e72168f2f1b479609b6cda2787eba66
67 lines
1.4 KiB
C++
67 lines
1.4 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.
|
|
*/
|
|
|
|
#include "Utils.h"
|
|
#include <cmath>
|
|
#include "Type.h"
|
|
|
|
namespace facebook {
|
|
namespace flexlayout {
|
|
namespace utils {
|
|
|
|
using namespace std;
|
|
using namespace facebook::flexlayout;
|
|
|
|
auto isUndefined(float value) -> bool {
|
|
return std::isnan(value);
|
|
}
|
|
|
|
auto isUndefined(double value) -> bool {
|
|
return std::isnan(value);
|
|
}
|
|
|
|
auto isDefined(float value) -> bool {
|
|
return !isUndefined(value);
|
|
}
|
|
|
|
auto isDefined(double value) -> bool {
|
|
return !isUndefined(value);
|
|
}
|
|
|
|
auto FlexLayoutFloatsEqual(const Float a, const Float b) -> bool {
|
|
if (isDefined(a) && isDefined(b)) {
|
|
return fabs(a - b) < EPSILON;
|
|
}
|
|
return isUndefined(a) && isUndefined(b);
|
|
}
|
|
|
|
auto FlexLayoutDoubleEqual(const double a, const double b) -> bool {
|
|
if (isDefined(a) && isDefined(b)) {
|
|
return fabs(a - b) < EPSILON;
|
|
}
|
|
return isUndefined(a) && isUndefined(b);
|
|
}
|
|
|
|
auto FlexLayoutFloatMax(const Float a, const Float b) -> float {
|
|
if (isDefined(a) && isDefined(b)) {
|
|
return fmax(a, b);
|
|
}
|
|
return isUndefined(a) ? b : a;
|
|
}
|
|
|
|
auto FlexLayoutFloatMin(const Float a, const Float b) -> float {
|
|
if (isDefined(a) && isDefined(b)) {
|
|
return fmin(a, b);
|
|
}
|
|
|
|
return isUndefined(a) ? b : a;
|
|
}
|
|
|
|
} // namespace utils
|
|
} // namespace flexlayout
|
|
} // namespace facebook
|