[yoga] Replace float with double #1095

Closed
cntrump wants to merge 1 commits from pr_replace_float_with_double into main
36 changed files with 694 additions and 686 deletions

View File

@@ -13,14 +13,14 @@
using facebook::yoga::detail::CompactValue;
const auto tooSmall = nextafterf(CompactValue::LOWER_BOUND, -INFINITY);
const auto tooSmall = nextafter(CompactValue::LOWER_BOUND, -INFINITY);
const auto tooLargePoints =
nextafterf(CompactValue::UPPER_BOUND_POINT, INFINITY);
nextafter(CompactValue::UPPER_BOUND_POINT, INFINITY);
const auto tooLargePercent =
nextafterf(CompactValue::UPPER_BOUND_PERCENT, INFINITY);
nextafter(CompactValue::UPPER_BOUND_PERCENT, INFINITY);
TEST(YogaTest, compact_value_can_represent_undefined) {
auto c = CompactValue{YGValue{12.5f, YGUnitUndefined}};
auto c = CompactValue{YGValue{12.5, YGUnitUndefined}};
YGValue v = c;
ASSERT_EQ(v, YGValueUndefined);
ASSERT_NE(v, YGValueAuto);
@@ -32,7 +32,7 @@ TEST(YogaTest, compact_value_can_represent_undefined) {
TEST(YogaTest, compact_value_manages_infinity_as_undefined) {
auto c = CompactValue{
YGValue{std::numeric_limits<float>::infinity(), YGUnitUndefined}};
YGValue{std::numeric_limits<double>::infinity(), YGUnitUndefined}};
YGValue v = c;
ASSERT_EQ(v, YGValueUndefined);
ASSERT_NE(v, YGValueAuto);
@@ -299,23 +299,23 @@ TEST(YogaTest, dedicated_unit_factories) {
ASSERT_EQ(CompactValue::ofUndefined(), CompactValue(YGValueUndefined));
ASSERT_EQ(CompactValue::ofAuto(), CompactValue(YGValueAuto));
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(-9876.5f),
CompactValue(YGValue{-9876.5f, YGUnitPoint}));
CompactValue::of<YGUnitPoint>(-9876.5),
CompactValue(YGValue{-9876.5, YGUnitPoint}));
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(123.456f),
CompactValue(YGValue{123.456f, YGUnitPercent}));
CompactValue::of<YGUnitPercent>(123.456),
CompactValue(YGValue{123.456, YGUnitPercent}));
}
TEST(YogaTest, dedicated_unit_maybe_factories) {
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPoint>(-9876.5f),
CompactValue(YGValue{-9876.5f, YGUnitPoint}));
CompactValue::ofMaybe<YGUnitPoint>(-9876.5),
CompactValue(YGValue{-9876.5, YGUnitPoint}));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPoint>(YGUndefined),
CompactValue(YGValueUndefined));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPercent>(123.456f),
CompactValue(YGValue{123.456f, YGUnitPercent}));
CompactValue::ofMaybe<YGUnitPercent>(123.456),
CompactValue(YGValue{123.456, YGUnitPercent}));
ASSERT_EQ(
CompactValue::ofMaybe<YGUnitPercent>(YGUndefined),
CompactValue(YGValueUndefined));
@@ -324,7 +324,7 @@ TEST(YogaTest, dedicated_unit_maybe_factories) {
TEST(YogaTest, can_be_assigned_from_YGValue) {
CompactValue c{};
YGValue v{2.0f, YGUnitPercent};
YGValue v{2.0, YGUnitPercent};
c = v;
ASSERT_EQ((YGValue) c, v);
@@ -335,28 +335,28 @@ TEST(YogaTest, can_be_assigned_from_YGValue) {
TEST(YogaTest, compact_value_bound_representations) {
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(CompactValue::LOWER_BOUND).repr(),
uint32_t{0});
uint64_t{0});
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(CompactValue::UPPER_BOUND_POINT).repr(),
uint32_t{0x3fffffff});
uint64_t{0x3fffffffffffffff});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(CompactValue::LOWER_BOUND).repr(),
uint32_t{0x40000000});
uint64_t{0x4000000000000000});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(CompactValue::UPPER_BOUND_PERCENT).repr(),
uint32_t{0x7f7fffff});
uint64_t{0x7f7fffffffffffff});
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(-CompactValue::LOWER_BOUND).repr(),
uint32_t{0x80000000});
uint64_t{0x8000000000000000});
ASSERT_EQ(
CompactValue::of<YGUnitPoint>(-CompactValue::UPPER_BOUND_POINT).repr(),
uint32_t{0xbfffffff});
uint64_t{0xbfffffffffffffff});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(-CompactValue::LOWER_BOUND).repr(),
uint32_t{0xc0000000});
uint64_t{0xc000000000000000});
ASSERT_EQ(
CompactValue::of<YGUnitPercent>(-CompactValue::UPPER_BOUND_PERCENT)
.repr(),
uint32_t{0xff7fffff});
uint64_t{0xff7fffffffffffff});
}

View File

@@ -231,7 +231,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
YGNodeInsertChild(root, a, 0);
auto b = YGNodeNew();
YGNodeInsertChild(root, b, 1);
YGNodeStyleSetFlexBasis(a, 10.0f);
YGNodeStyleSetFlexBasis(a, 10.0);
for (auto s : {20, 30, 40}) {
YGNodeCalculateLayout(root, s, s, YGDirectionLTR);
@@ -251,7 +251,7 @@ TEST_F(EventTest, layout_events_has_max_measure_cache) {
TEST_F(EventTest, measure_functions_get_wrapped) {
auto root = YGNodeNew();
YGNodeSetMeasureFunc(
root, [](YGNodeRef, float, YGMeasureMode, float, YGMeasureMode) {
root, [](YGNodeRef, double, YGMeasureMode, double, YGMeasureMode) {
return YGSize{};
});
@@ -269,7 +269,7 @@ TEST_F(EventTest, baseline_functions_get_wrapped) {
auto child = YGNodeNew();
YGNodeInsertChild(root, child, 0);
YGNodeSetBaselineFunc(child, [](YGNodeRef, float, float) { return 0.0f; });
YGNodeSetBaselineFunc(child, [](YGNodeRef, double, double) { return 0.0; });
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetAlignItems(root, YGAlignBaseline);

View File

@@ -9,18 +9,18 @@
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static float _baselineFunc(
static double _baselineFunc(
YGNodeRef node,
const float width,
const float height) {
const double width,
const double height) {
return height / 2;
}
static YGSize _measure1(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
.width = 42,
@@ -30,9 +30,9 @@ static YGSize _measure1(
static YGSize _measure2(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
.width = 279,

View File

@@ -11,9 +11,9 @@
static YGSize _measure(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
.width = widthMode == YGMeasureModeExactly ? width : 50,

View File

@@ -9,8 +9,8 @@
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
static float _baseline(YGNodeRef node, const float width, const float height) {
float* baseline = (float*) node->getContext();
static double _baseline(YGNodeRef node, const double width, const double height) {
double* baseline = (double*) node->getContext();
return *baseline;
}
@@ -31,7 +31,7 @@ TEST(YogaTest, align_baseline_customer_func) {
YGNodeStyleSetHeight(root_child1, 20);
YGNodeInsertChild(root, root_child1, 1);
float baselineValue = 10;
double baselineValue = 10;
const YGNodeRef root_child1_child0 = YGNodeNew();
root_child1_child0->setContext(&baselineValue);
YGNodeStyleSetWidth(root_child1_child0, 50);

View File

@@ -37,7 +37,7 @@ TEST(YogaTest, margin_side_overrides_horizontal_and_vertical) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
? YGEdgeVertical
@@ -67,7 +67,7 @@ TEST(YogaTest, margin_side_overrides_all) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
@@ -87,7 +87,7 @@ TEST(YogaTest, margin_side_overrides_all) {
TEST(YogaTest, margin_horizontal_and_vertical_overrides_all) {
const std::array<YGEdge, 2> directions = {{YGEdgeHorizontal, YGEdgeVertical}};
for (float directionValue = 0; directionValue < 2; ++directionValue) {
for (double directionValue = 0; directionValue < 2; ++directionValue) {
for (const auto& direction : directions) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);

View File

@@ -37,7 +37,7 @@ TEST(YogaTest, padding_side_overrides_horizontal_and_vertical) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
YGEdge horizontalOrVertical = edge == YGEdgeTop || edge == YGEdgeBottom
? YGEdgeVertical
@@ -67,7 +67,7 @@ TEST(YogaTest, padding_side_overrides_all) {
YGEdgeLeft,
YGEdgeRight}};
for (float edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (double edgeValue = 0; edgeValue < 2; ++edgeValue) {
for (const auto& edge : edges) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
@@ -87,7 +87,7 @@ TEST(YogaTest, padding_side_overrides_all) {
TEST(YogaTest, padding_horizontal_and_vertical_overrides_all) {
const std::array<YGEdge, 2> directions = {{YGEdgeHorizontal, YGEdgeVertical}};
for (float directionValue = 0; directionValue < 2; ++directionValue) {
for (double directionValue = 0; directionValue < 2; ++directionValue) {
for (const auto& direction : directions) {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);

View File

@@ -96,7 +96,7 @@ TEST(YogaTest, assert_webdefault_values) {
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root));
ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root));
ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root));
ASSERT_FLOAT_EQ(1.0, YGNodeStyleGetFlexShrink(root));
YGNodeFreeRecursive(root);
YGConfigFree(config);
@@ -110,7 +110,7 @@ TEST(YogaTest, assert_webdefault_values_reset) {
ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root));
ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root));
ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root));
ASSERT_FLOAT_EQ(1.0, YGNodeStyleGetFlexShrink(root));
YGNodeFreeRecursive(root);
YGConfigFree(config);

View File

@@ -546,16 +546,16 @@ TEST(YogaTest, flex_grow_less_than_factor_one) {
YGNodeStyleSetHeight(root, 500);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0.2f);
YGNodeStyleSetFlexGrow(root_child0, 0.2);
YGNodeStyleSetFlexBasis(root_child0, 40);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 0.2f);
YGNodeStyleSetFlexGrow(root_child1, 0.2);
YGNodeInsertChild(root, root_child1, 1);
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child2, 0.4f);
YGNodeStyleSetFlexGrow(root_child2, 0.4);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

View File

@@ -12,17 +12,17 @@
#include <yoga/YGValue.h>
constexpr auto empty = YGFloatOptional{};
constexpr auto zero = YGFloatOptional{0.0f};
constexpr auto one = YGFloatOptional{1.0f};
constexpr auto positive = YGFloatOptional{1234.5f};
constexpr auto negative = YGFloatOptional{-9876.5f};
constexpr auto zero = YGFloatOptional{0.0};
constexpr auto one = YGFloatOptional{1.0};
constexpr auto positive = YGFloatOptional{1234.5};
constexpr auto negative = YGFloatOptional{-9876.5};
TEST(YGFloatOptional, value) {
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
ASSERT_EQ(zero.unwrap(), 0.0f);
ASSERT_EQ(one.unwrap(), 1.0f);
ASSERT_EQ(positive.unwrap(), 1234.5f);
ASSERT_EQ(negative.unwrap(), -9876.5f);
ASSERT_EQ(zero.unwrap(), 0.0);
ASSERT_EQ(one.unwrap(), 1.0);
ASSERT_EQ(positive.unwrap(), 1234.5);
ASSERT_EQ(negative.unwrap(), -9876.5);
ASSERT_TRUE(empty.isUndefined());
ASSERT_FALSE(zero.isUndefined());
@@ -36,15 +36,15 @@ TEST(YGFloatOptional, equality) {
ASSERT_TRUE(empty == YGUndefined);
ASSERT_FALSE(empty == zero);
ASSERT_FALSE(empty == negative);
ASSERT_FALSE(empty == 12.3f);
ASSERT_FALSE(empty == 12.3);
ASSERT_TRUE(zero == zero);
ASSERT_TRUE(zero == 0.0f);
ASSERT_TRUE(zero == 0.0);
ASSERT_FALSE(zero == positive);
ASSERT_FALSE(zero == -5555.5f);
ASSERT_FALSE(zero == -5555.5);
ASSERT_TRUE(one == one);
ASSERT_TRUE(one == 1.0f);
ASSERT_TRUE(one == 1.0);
ASSERT_FALSE(one == positive);
ASSERT_TRUE(positive == positive);
@@ -61,15 +61,15 @@ TEST(YGFloatOptional, inequality) {
ASSERT_FALSE(empty != YGUndefined);
ASSERT_TRUE(empty != zero);
ASSERT_TRUE(empty != negative);
ASSERT_TRUE(empty != 12.3f);
ASSERT_TRUE(empty != 12.3);
ASSERT_FALSE(zero != zero);
ASSERT_FALSE(zero != 0.0f);
ASSERT_FALSE(zero != 0.0);
ASSERT_TRUE(zero != positive);
ASSERT_TRUE(zero != -5555.5f);
ASSERT_TRUE(zero != -5555.5);
ASSERT_FALSE(one != one);
ASSERT_FALSE(one != 1.0f);
ASSERT_FALSE(one != 1.0);
ASSERT_TRUE(one != positive);
ASSERT_FALSE(positive != positive);
@@ -198,12 +198,12 @@ TEST(YGFloatOptionalTest, YGFloatOptionalMax) {
ASSERT_EQ(YGFloatOptionalMax(negative, empty), negative);
ASSERT_EQ(YGFloatOptionalMax(negative, YGFloatOptional{-INFINITY}), negative);
ASSERT_EQ(
YGFloatOptionalMax(YGFloatOptional{1.0f}, YGFloatOptional{1.125f}),
YGFloatOptional{1.125f});
YGFloatOptionalMax(YGFloatOptional{1.0}, YGFloatOptional{1.125}),
YGFloatOptional{1.125});
}
TEST(YGFloatOptionalTest, unwrap) {
ASSERT_TRUE(YGFloatIsUndefined(empty.unwrap()));
ASSERT_EQ(zero.unwrap(), 0.0f);
ASSERT_EQ(YGFloatOptional{123456.78f}.unwrap(), 123456.78f);
ASSERT_EQ(zero.unwrap(), 0.0);
ASSERT_EQ(YGFloatOptional{123456.78}.unwrap(), 123456.78);
}

View File

@@ -11,9 +11,9 @@
static YGSize _measureMax(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
(*measureCount)++;
@@ -26,9 +26,9 @@ static YGSize _measureMax(
static YGSize _measureMin(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
*measureCount = *measureCount + 1;
@@ -46,9 +46,9 @@ static YGSize _measureMin(
static YGSize _measure_84_49(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
if (measureCount) {
@@ -56,8 +56,8 @@ static YGSize _measure_84_49(
}
return YGSize{
.width = 84.f,
.height = 49.f,
.width = 84,
.height = 49,
};
}
@@ -160,12 +160,12 @@ TEST(
int measureCount = 0;
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 288.f);
YGNodeStyleSetHeight(root, 288.f);
YGNodeStyleSetWidth(root, 288);
YGNodeStyleSetHeight(root, 288);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
const YGNodeRef root_child0 = YGNodeNew();
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88f);
YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeInsertChild(root, root_child0, 0);

View File

@@ -10,9 +10,9 @@
#include <yoga/Yoga.h>
struct _MeasureConstraint {
float width;
double width;
YGMeasureMode widthMode;
float height;
double height;
YGMeasureMode heightMode;
};
@@ -23,9 +23,9 @@ struct _MeasureConstraintList {
static YGSize _measure(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
struct _MeasureConstraintList* constraintList =
(struct _MeasureConstraintList*) node->getContext();

View File

@@ -11,9 +11,9 @@
static YGSize _measure(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
int* measureCount = (int*) node->getContext();
if (measureCount) {
@@ -28,9 +28,9 @@ static YGSize _measure(
static YGSize _simulate_wrapping_text(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
if (widthMode == YGMeasureModeUndefined || width >= 68) {
return YGSize{.width = 68, .height = 16};
@@ -44,9 +44,9 @@ static YGSize _simulate_wrapping_text(
static YGSize _measure_assert_negative(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
EXPECT_GE(width, 0);
EXPECT_GE(height, 0);
@@ -643,9 +643,9 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
static YGSize _measure_90_10(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
@@ -656,9 +656,9 @@ static YGSize _measure_90_10(
static YGSize _measure_100_100(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{

View File

@@ -1298,9 +1298,9 @@ TEST(YogaTest, min_max_percent_no_width_height) {
static YGSize _measureCk_test_label_shrink_based_on_height(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
if (heightMode == YGMeasureModeAtMost) {

View File

@@ -22,7 +22,7 @@ TEST(YGNode, hasMeasureFunc_initial) {
TEST(YGNode, hasMeasureFunc_with_measure_fn) {
auto n = YGNode{};
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
n.setMeasureFunc([](YGNode*, double, YGMeasureMode, double, YGMeasureMode) {
return YGSize{};
});
ASSERT_TRUE(n.hasMeasureFunc());
@@ -32,7 +32,7 @@ TEST(YGNode, measure_with_measure_fn) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
[](YGNode*, double w, YGMeasureMode wm, double h, YGMeasureMode hm) {
return YGSize{w * wm, h / hm};
});
@@ -44,7 +44,7 @@ TEST(YGNode, measure_with_measure_fn) {
TEST(YGNode, measure_with_context_measure_fn) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
[](YGNode*, double, YGMeasureMode, double, YGMeasureMode, void* ctx) {
return *(YGSize*) ctx;
});
@@ -57,11 +57,11 @@ TEST(YGNode, measure_with_context_measure_fn) {
TEST(YGNode, switching_measure_fn_types) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
[](YGNode*, double, YGMeasureMode, double, YGMeasureMode, void*) {
return YGSize{};
});
n.setMeasureFunc(
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
[](YGNode*, double w, YGMeasureMode wm, double h, YGMeasureMode hm) {
return YGSize{w * wm, h / hm};
});
@@ -72,7 +72,7 @@ TEST(YGNode, switching_measure_fn_types) {
TEST(YGNode, hasMeasureFunc_after_unset) {
auto n = YGNode{};
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
n.setMeasureFunc([](YGNode*, double, YGMeasureMode, double, YGMeasureMode) {
return YGSize{};
});
@@ -83,7 +83,7 @@ TEST(YGNode, hasMeasureFunc_after_unset) {
TEST(YGNode, hasMeasureFunc_after_unset_context) {
auto n = YGNode{};
n.setMeasureFunc(
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
[](YGNode*, double, YGMeasureMode, double, YGMeasureMode, void*) {
return YGSize{};
});
@@ -98,30 +98,30 @@ TEST(YGNode, hasBaselineFunc_initial) {
TEST(YGNode, hasBaselineFunc_with_baseline_fn) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
n.setBaselineFunc([](YGNode*, double, double) { return 0.0; });
ASSERT_TRUE(n.hasBaselineFunc());
}
TEST(YGNode, baseline_with_baseline_fn) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float w, float h) { return w + h; });
n.setBaselineFunc([](YGNode*, double w, double h) { return w + h; });
ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f);
ASSERT_EQ(n.baseline(1.25, 2.5, nullptr), 3.75);
}
TEST(YGNode, baseline_with_context_baseline_fn) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float w, float h, void* ctx) {
return w + h + *(float*) ctx;
n.setBaselineFunc([](YGNode*, double w, double h, void* ctx) {
return w + h + *(double*) ctx;
});
auto ctx = -10.0f;
ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f);
auto ctx = -10.0;
ASSERT_EQ(n.baseline(1.25, 2.5, &ctx), -6.25);
}
TEST(YGNode, hasBaselineFunc_after_unset) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
n.setBaselineFunc([](YGNode*, double, double) { return 0.0; });
n.setBaselineFunc(nullptr);
ASSERT_FALSE(n.hasBaselineFunc());
@@ -129,7 +129,7 @@ TEST(YGNode, hasBaselineFunc_after_unset) {
TEST(YGNode, hasBaselineFunc_after_unset_context) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
n.setBaselineFunc([](YGNode*, double, double, void*) { return 0.0; });
n.setMeasureFunc(nullptr);
ASSERT_FALSE(n.hasMeasureFunc());
@@ -137,9 +137,9 @@ TEST(YGNode, hasBaselineFunc_after_unset_context) {
TEST(YGNode, switching_baseline_fn_types) {
auto n = YGNode{};
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
n.setBaselineFunc([](YGNode*, float, float) { return 1.0f; });
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
n.setBaselineFunc([](YGNode*, double, double, void*) { return 0.0; });
n.setBaselineFunc([](YGNode*, double, double) { return 1.0; });
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0);
}
void PrintTo(const YGSize& size, std::ostream* os) {

View File

@@ -1196,9 +1196,9 @@ TEST(YogaTest, percent_absolute_position) {
static YGSize _measureCk_test_label_shrink_based_on_height(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
if (heightMode == YGMeasureModeAtMost) {

View File

@@ -44,9 +44,9 @@ TEST(YogaTest, rounding_value) {
static YGSize measureText(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return (YGSize){.width = 10, .height = 10};
}

View File

@@ -11,37 +11,37 @@
static YGSize _measureFloor(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
width = 10.2f,
height = 10.2f,
width = 10.2,
height = 10.2,
};
}
static YGSize _measureCeil(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
width = 10.5f,
height = 10.5f,
width = 10.5,
height = 10.5,
};
}
static YGSize _measureFractial(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode) {
return YGSize{
width = 0.5f,
height = 0.5f,
width = 0.5,
height = 0.5,
};
}
@@ -53,35 +53,35 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_floor) {
root_child0->setMeasureFunc(_measureFloor);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 0.0f);
YGConfigSetPointScaleFactor(config, 0.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.2, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 1.0f);
YGConfigSetPointScaleFactor(config, 1.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(11, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 2.0f);
YGConfigSetPointScaleFactor(config, 2.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.5, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 4.0f);
YGConfigSetPointScaleFactor(config, 4.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10.25, YGNodeLayoutGetHeight(root_child0));
YGConfigSetPointScaleFactor(config, 1.0f / 3.0f);
YGConfigSetPointScaleFactor(config, 1.0 / 3.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
@@ -101,7 +101,7 @@ TEST(YogaTest, rounding_feature_with_custom_measure_func_ceil) {
root_child0->setMeasureFunc(_measureCeil);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 1.0f);
YGConfigSetPointScaleFactor(config, 1.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -124,7 +124,7 @@ TEST(
root_child0->setMeasureFunc(_measureFractial);
YGNodeInsertChild(root, root_child0, 0);
YGConfigSetPointScaleFactor(config, 2.0f);
YGConfigSetPointScaleFactor(config, 2.0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

View File

@@ -317,23 +317,23 @@ TEST(YogaTest, rounding_total_fractial) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 87.4f);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetWidth(root, 87.4);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0.7f);
YGNodeStyleSetFlexBasis(root_child0, 50.3f);
YGNodeStyleSetHeight(root_child0, 20.3f);
YGNodeStyleSetFlexGrow(root_child0, 0.7);
YGNodeStyleSetFlexBasis(root_child0, 50.3);
YGNodeStyleSetHeight(root_child0, 20.3);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 1.6f);
YGNodeStyleSetFlexGrow(root_child1, 1.6);
YGNodeStyleSetHeight(root_child1, 10);
YGNodeInsertChild(root, root_child1, 1);
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child2, 1.1f);
YGNodeStyleSetHeight(root_child2, 10.7f);
YGNodeStyleSetFlexGrow(root_child2, 1.1);
YGNodeStyleSetHeight(root_child2, 10.7);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -388,37 +388,37 @@ TEST(YogaTest, rounding_total_fractial_nested) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 87.4f);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetWidth(root, 87.4);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0.7f);
YGNodeStyleSetFlexBasis(root_child0, 50.3f);
YGNodeStyleSetHeight(root_child0, 20.3f);
YGNodeStyleSetFlexGrow(root_child0, 0.7);
YGNodeStyleSetFlexBasis(root_child0, 50.3);
YGNodeStyleSetHeight(root_child0, 20.3);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0_child0, 1);
YGNodeStyleSetFlexBasis(root_child0_child0, 0.3f);
YGNodeStyleSetPosition(root_child0_child0, YGEdgeBottom, 13.3f);
YGNodeStyleSetHeight(root_child0_child0, 9.9f);
YGNodeStyleSetFlexBasis(root_child0_child0, 0.3);
YGNodeStyleSetPosition(root_child0_child0, YGEdgeBottom, 13.3);
YGNodeStyleSetHeight(root_child0_child0, 9.9);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
const YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0_child1, 4);
YGNodeStyleSetFlexBasis(root_child0_child1, 0.3f);
YGNodeStyleSetPosition(root_child0_child1, YGEdgeTop, 13.3f);
YGNodeStyleSetHeight(root_child0_child1, 1.1f);
YGNodeStyleSetFlexBasis(root_child0_child1, 0.3);
YGNodeStyleSetPosition(root_child0_child1, YGEdgeTop, 13.3);
YGNodeStyleSetHeight(root_child0_child1, 1.1);
YGNodeInsertChild(root_child0, root_child0_child1, 1);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 1.6f);
YGNodeStyleSetFlexGrow(root_child1, 1.6);
YGNodeStyleSetHeight(root_child1, 10);
YGNodeInsertChild(root, root_child1, 1);
const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child2, 1.1f);
YGNodeStyleSetHeight(root_child2, 10.7f);
YGNodeStyleSetFlexGrow(root_child2, 1.1);
YGNodeStyleSetHeight(root_child2, 10.7);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
@@ -494,7 +494,7 @@ TEST(YogaTest, rounding_fractial_input_1) {
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);
@@ -565,7 +565,7 @@ TEST(YogaTest, rounding_fractial_input_2) {
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.6f);
YGNodeStyleSetHeight(root, 113.6);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);
@@ -635,9 +635,9 @@ TEST(YogaTest, rounding_fractial_input_3) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.3f);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.3);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);
@@ -707,9 +707,9 @@ TEST(YogaTest, rounding_fractial_input_4) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.7f);
YGNodeStyleSetPosition(root, YGEdgeTop, 0.7);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 113.4f);
YGNodeStyleSetHeight(root, 113.4);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 1);

View File

@@ -156,22 +156,22 @@ ACCESSOR_TEST(display, YGDisplayFlex, YGDisplayNone, YGDisplayFlex)
ACCESSOR_TEST(
flex,
YGFloatOptional{},
YGFloatOptional{123.45f},
YGFloatOptional{-9.87f},
YGFloatOptional{123.45},
YGFloatOptional{-9.87},
YGFloatOptional{})
ACCESSOR_TEST(
flexGrow,
YGFloatOptional{},
YGFloatOptional{123.45f},
YGFloatOptional{-9.87f},
YGFloatOptional{123.45},
YGFloatOptional{-9.87},
YGFloatOptional{})
ACCESSOR_TEST(
flexShrink,
YGFloatOptional{},
YGFloatOptional{123.45f},
YGFloatOptional{-9.87f},
YGFloatOptional{123.45},
YGFloatOptional{-9.87},
YGFloatOptional{})
ACCESSOR_TEST(
@@ -179,8 +179,8 @@ ACCESSOR_TEST(
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::ofAuto(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
position,
@@ -188,8 +188,8 @@ INDEX_ACCESSOR_TEST(
YGEdgeBottom,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
margin,
@@ -197,22 +197,22 @@ INDEX_ACCESSOR_TEST(
YGEdgeTop,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
padding,
CompactValue::ofUndefined(),
YGEdgeAll,
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
border,
CompactValue::ofUndefined(),
YGEdgeHorizontal,
CompactValue::of<YGUnitPoint>(-7777.77f),
CompactValue::of<YGUnitPoint>(-7777.77),
CompactValue::ofUndefined())
INDEX_ACCESSOR_TEST(
@@ -221,8 +221,8 @@ INDEX_ACCESSOR_TEST(
YGDimensionWidth,
CompactValue::ofUndefined(),
CompactValue::ofAuto(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
minDimensions,
@@ -230,8 +230,8 @@ INDEX_ACCESSOR_TEST(
YGDimensionHeight,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
INDEX_ACCESSOR_TEST(
maxDimensions,
@@ -239,15 +239,15 @@ INDEX_ACCESSOR_TEST(
YGDimensionHeight,
CompactValue::ofAuto(),
CompactValue::ofUndefined(),
CompactValue::of<YGUnitPoint>(7777.77f),
CompactValue::of<YGUnitPercent>(-100.0f))
CompactValue::of<YGUnitPoint>(7777.77),
CompactValue::of<YGUnitPercent>(-100.0))
ACCESSOR_TEST(
aspectRatio,
YGFloatOptional{},
YGFloatOptional{-123.45f},
YGFloatOptional{9876.5f},
YGFloatOptional{0.0f},
YGFloatOptional{-123.45},
YGFloatOptional{9876.5},
YGFloatOptional{0.0},
YGFloatOptional{});
} // namespace yoga

View File

@@ -10,14 +10,14 @@
#include <yoga/YGValue.h>
TEST(YGValue, supports_equality) {
ASSERT_EQ((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitPercent}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{56.7f, YGUnitPercent}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitPoint}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitAuto}));
ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitUndefined}));
ASSERT_EQ((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitPercent}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{56.7, YGUnitPercent}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitPoint}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitAuto}));
ASSERT_NE((YGValue{12.5, YGUnitPercent}), (YGValue{12.5, YGUnitUndefined}));
ASSERT_EQ(
(YGValue{12.5f, YGUnitUndefined}),
(YGValue{12.5, YGUnitUndefined}),
(YGValue{YGUndefined, YGUnitUndefined}));
ASSERT_EQ((YGValue{0, YGUnitAuto}), (YGValue{-1, YGUnitAuto}));
}

View File

@@ -14,7 +14,7 @@
#include <limits>
static_assert(
std::numeric_limits<float>::is_iec559,
std::numeric_limits<double>::is_iec559,
"facebook::yoga::detail::CompactValue only works with IEEE754 floats");
#ifdef YOGA_COMPACT_VALUE_TEST
@@ -27,7 +27,7 @@ namespace facebook {
namespace yoga {
namespace detail {
// This class stores YGValue in 32 bits.
// This class stores YGValue in 64 bits.
// - The value does not matter for Undefined and Auto. NaNs are used for their
// representation.
// - To differentiate between Point and Percent, one exponent bit is used.
@@ -44,13 +44,13 @@ class YOGA_EXPORT CompactValue {
friend constexpr bool operator==(CompactValue, CompactValue) noexcept;
public:
static constexpr auto LOWER_BOUND = 1.08420217e-19f;
static constexpr auto UPPER_BOUND_POINT = 36893485948395847680.0f;
static constexpr auto UPPER_BOUND_PERCENT = 18446742974197923840.0f;
static constexpr auto LOWER_BOUND = 1.4916681462400413e-154;
static constexpr auto UPPER_BOUND_POINT = 2.6815615859885191e+154;
static constexpr auto UPPER_BOUND_PERCENT = 1.0474849945267653e+152;
template <YGUnit Unit>
static CompactValue of(float value) noexcept {
if (value == 0.0f || (value < LOWER_BOUND && value > -LOWER_BOUND)) {
static CompactValue of(double value) noexcept {
if (value == 0.0 || (value < LOWER_BOUND && value > -LOWER_BOUND)) {
constexpr auto zero =
Unit == YGUnitPercent ? ZERO_BITS_PERCENT : ZERO_BITS_POINT;
return {Payload{zero}};
@@ -59,10 +59,10 @@ public:
constexpr auto upperBound =
Unit == YGUnitPercent ? UPPER_BOUND_PERCENT : UPPER_BOUND_POINT;
if (value > upperBound || value < -upperBound) {
value = copysignf(upperBound, value);
value = copysign(upperBound, value);
}
uint32_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0;
uint64_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0;
auto data = Payload{value};
data.repr -= BIAS;
data.repr |= unitBit;
@@ -70,7 +70,7 @@ public:
}
template <YGUnit Unit>
static CompactValue ofMaybe(float value) noexcept {
static CompactValue ofMaybe(double value) noexcept {
return std::isnan(value) || std::isinf(value) ? ofUndefined()
: of<Unit>(value);
}
@@ -88,9 +88,9 @@ public:
}
constexpr CompactValue() noexcept
: payload_(std::numeric_limits<float>::quiet_NaN()) {}
: payload_(std::numeric_limits<double>::quiet_NaN()) {}
CompactValue(const YGValue& x) noexcept : payload_(uint32_t{0}) {
CompactValue(const YGValue& x) noexcept : payload_(uint64_t{0}) {
switch (x.unit) {
case YGUnitUndefined:
*this = ofUndefined();
@@ -112,9 +112,9 @@ public:
case AUTO_BITS:
return YGValueAuto;
case ZERO_BITS_POINT:
return YGValue{0.0f, YGUnitPoint};
return YGValue{0.0, YGUnitPoint};
case ZERO_BITS_PERCENT:
return YGValue{0.0f, YGUnitPercent};
return YGValue{0.0, YGUnitPercent};
}
if (std::isnan(payload_.value)) {
@@ -125,8 +125,8 @@ public:
data.repr &= ~PERCENT_BIT;
data.repr += BIAS;
return YGValue{
data.value, payload_.repr & 0x40000000 ? YGUnitPercent : YGUnitPoint};
return YGValue{data.value,
payload_.repr & 0x4000000000000000 ? YGUnitPercent : YGUnitPoint};
}
bool isUndefined() const noexcept {
@@ -139,37 +139,37 @@ public:
private:
union Payload {
float value;
uint32_t repr;
double value;
uint64_t repr;
Payload() = delete;
constexpr Payload(uint32_t r) : repr(r) {}
constexpr Payload(float v) : value(v) {}
constexpr Payload(uint64_t r) : repr(r) {}
constexpr Payload(double v) : value(v) {}
};
static constexpr uint32_t BIAS = 0x20000000;
static constexpr uint32_t PERCENT_BIT = 0x40000000;
static constexpr uint64_t BIAS = 0x2000000000000000;
static constexpr uint64_t PERCENT_BIT = 0x4000000000000000;
// these are signaling NaNs with specific bit pattern as payload they will be
// silenced whenever going through an FPU operation on ARM + x86
static constexpr uint32_t AUTO_BITS = 0x7faaaaaa;
static constexpr uint32_t ZERO_BITS_POINT = 0x7f8f0f0f;
static constexpr uint32_t ZERO_BITS_PERCENT = 0x7f80f0f0;
static constexpr uint64_t AUTO_BITS = 0x7faaaaaaaaaaaaaa;
static constexpr uint64_t ZERO_BITS_POINT = 0x7f8f0f0f0f0f0f0f;
static constexpr uint64_t ZERO_BITS_PERCENT = 0x7f80f0f0f0f0f0f0;
constexpr CompactValue(Payload data) noexcept : payload_(data) {}
Payload payload_;
VISIBLE_FOR_TESTING uint32_t repr() { return payload_.repr; }
VISIBLE_FOR_TESTING uint64_t repr() { return payload_.repr; }
};
template <>
CompactValue CompactValue::of<YGUnitUndefined>(float) noexcept = delete;
CompactValue CompactValue::of<YGUnitUndefined>(double) noexcept = delete;
template <>
CompactValue CompactValue::of<YGUnitAuto>(float) noexcept = delete;
CompactValue CompactValue::of<YGUnitAuto>(double) noexcept = delete;
template <>
CompactValue CompactValue::ofMaybe<YGUnitUndefined>(float) noexcept = delete;
CompactValue CompactValue::ofMaybe<YGUnitUndefined>(double) noexcept = delete;
template <>
CompactValue CompactValue::ofMaybe<YGUnitAuto>(float) noexcept = delete;
CompactValue CompactValue::ofMaybe<YGUnitAuto>(double) noexcept = delete;
constexpr bool operator==(CompactValue a, CompactValue b) noexcept {
return a.payload_.repr == b.payload_.repr;

View File

@@ -18,16 +18,16 @@ YGFlexDirection YGFlexDirectionCross(
: YGFlexDirectionColumn;
}
float YGFloatMax(const float a, const float b) {
double YGFloatMax(const double a, const double b) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
return fmaxf(a, b);
return fmax(a, b);
}
return yoga::isUndefined(a) ? b : a;
}
float YGFloatMin(const float a, const float b) {
double YGFloatMin(const double a, const double b) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
return fminf(a, b);
return fmin(a, b);
}
return yoga::isUndefined(a) ? b : a;
@@ -43,12 +43,12 @@ bool YGValueEqual(const YGValue& a, const YGValue& b) {
return true;
}
return fabs(a.value - b.value) < 0.0001f;
return fabs(a.value - b.value) < 0.0001;
}
bool YGFloatsEqual(const float a, const float b) {
bool YGFloatsEqual(const double a, const double b) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
return fabs(a - b) < 0.0001f;
return fabs(a - b) < 0.0001;
}
return yoga::isUndefined(a) && yoga::isUndefined(b);
}
@@ -60,7 +60,7 @@ bool YGDoubleEqual(const double a, const double b) {
return yoga::isUndefined(a) && yoga::isUndefined(b);
}
float YGFloatSanitize(const float val) {
double YGFloatSanitize(const double val) {
return yoga::isUndefined(val) ? 0 : val;
}

View File

@@ -38,19 +38,19 @@
struct YGCollectFlexItemsRowValues {
uint32_t itemsOnLine;
float sizeConsumedOnCurrentLine;
float totalFlexGrowFactors;
float totalFlexShrinkScaledFactors;
double sizeConsumedOnCurrentLine;
double totalFlexGrowFactors;
double totalFlexShrinkScaledFactors;
uint32_t endOfLineIndex;
std::vector<YGNodeRef> relativeChildren;
float remainingFreeSpace;
double remainingFreeSpace;
// The size of the mainDim for the row after considering size, padding, margin
// and border of flex items. This is used to calculate maxLineDim after going
// through all the rows to decide on the main axis size of owner.
float mainDim;
double mainDim;
// The size of the crossDim for the row after considering size, padding,
// margin and border of flex items. Used for calculating containers crossSize.
float crossDim;
double crossDim;
};
bool YGValueEqual(const YGValue& a, const YGValue& b);
@@ -60,27 +60,27 @@ inline bool YGValueEqual(
return YGValueEqual((YGValue) a, (YGValue) b);
}
// This custom float equality function returns true if either absolute
// This custom double equality function returns true if either absolute
// difference between two floats is less than 0.0001f or both are undefined.
bool YGFloatsEqual(const float a, const float b);
bool YGFloatsEqual(const double a, const double b);
bool YGDoubleEqual(const double a, const double b);
float YGFloatMax(const float a, const float b);
double YGFloatMax(const double a, const double b);
YGFloatOptional YGFloatOptionalMax(
const YGFloatOptional op1,
const YGFloatOptional op2);
float YGFloatMin(const float a, const float b);
double YGFloatMin(const double a, const double b);
// This custom float comparison function compares the array of float with
// YGFloatsEqual, as the default float comparison operator will not work(Look
// This custom double comparison function compares the array of double with
// YGFloatsEqual, as the default double comparison operator will not work(Look
// at the comments of YGFloatsEqual function).
template <std::size_t size>
bool YGFloatArrayEqual(
const std::array<float, size>& val1,
const std::array<float, size>& val2) {
const std::array<double, size>& val1,
const std::array<double, size>& val2) {
bool areEqual = true;
for (std::size_t i = 0; i < size && areEqual; ++i) {
areEqual = YGFloatsEqual(val1[i], val2[i]);
@@ -89,7 +89,7 @@ bool YGFloatArrayEqual(
}
// This function returns 0 if YGFloatIsUndefined(val) is true and val otherwise
float YGFloatSanitize(const float val);
double YGFloatSanitize(const double val);
YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
@@ -102,12 +102,12 @@ inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
inline YGFloatOptional YGResolveValue(
const YGValue value,
const float ownerSize) {
const double ownerSize) {
switch (value.unit) {
case YGUnitPoint:
return YGFloatOptional{value.value};
case YGUnitPercent:
return YGFloatOptional{value.value * ownerSize * 0.01f};
return YGFloatOptional{value.value * ownerSize * 0.01};
default:
return YGFloatOptional{};
}
@@ -115,7 +115,7 @@ inline YGFloatOptional YGResolveValue(
inline YGFloatOptional YGResolveValue(
yoga::detail::CompactValue value,
float ownerSize) {
double ownerSize) {
return YGResolveValue((YGValue) value, ownerSize);
}
@@ -140,7 +140,7 @@ inline YGFlexDirection YGResolveFlexDirection(
inline YGFloatOptional YGResolveValueMargin(
yoga::detail::CompactValue value,
const float ownerSize) {
const double ownerSize) {
return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize);
}

View File

@@ -40,7 +40,7 @@ public:
bool useLegacyStretchBehaviour = false;
bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;
bool printTree = false;
float pointScaleFactor = 1.0f;
double pointScaleFactor = 1.0;
std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
experimentalFeatures = {};
void* context = nullptr;

View File

@@ -10,6 +10,7 @@
#include "YGMacros.h"
#ifdef __cplusplus
YG_EXTERN_CXX_BEGIN
namespace facebook {
namespace yoga {
namespace enums {
@@ -27,6 +28,7 @@ constexpr int n() {
} // namespace enums
} // namespace yoga
} // namespace facebook
YG_EXTERN_CXX_END
#endif
#define YG_ENUM_DECL(NAME, ...) \
@@ -37,6 +39,7 @@ constexpr int n() {
#define YG_ENUM_SEQ_DECL(NAME, ...) \
YG_ENUM_DECL(NAME, __VA_ARGS__) \
YG_EXTERN_C_END \
YG_EXTERN_CXX_BEGIN \
namespace facebook { \
namespace yoga { \
namespace enums { \
@@ -47,6 +50,7 @@ constexpr int n() {
} \
} \
} \
YG_EXTERN_CXX_END \
YG_EXTERN_C_BEGIN
#else
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL

View File

@@ -13,14 +13,14 @@
struct YGFloatOptional {
private:
float value_ = std::numeric_limits<float>::quiet_NaN();
double value_ = std::numeric_limits<double>::quiet_NaN();
public:
explicit constexpr YGFloatOptional(float value) : value_(value) {}
explicit constexpr YGFloatOptional(double value) : value_(value) {}
constexpr YGFloatOptional() = default;
// returns the wrapped value, or a value x with YGIsUndefined(x) == true
constexpr float unwrap() const { return value_; }
constexpr double unwrap() const { return value_; }
bool isUndefined() const { return std::isnan(value_); }
};
@@ -35,17 +35,17 @@ inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) {
return !(lhs == rhs);
}
inline bool operator==(YGFloatOptional lhs, float rhs) {
inline bool operator==(YGFloatOptional lhs, double rhs) {
return lhs == YGFloatOptional{rhs};
}
inline bool operator!=(YGFloatOptional lhs, float rhs) {
inline bool operator!=(YGFloatOptional lhs, double rhs) {
return !(lhs == rhs);
}
inline bool operator==(float lhs, YGFloatOptional rhs) {
inline bool operator==(double lhs, YGFloatOptional rhs) {
return rhs == lhs;
}
inline bool operator!=(float lhs, YGFloatOptional rhs) {
inline bool operator!=(double lhs, YGFloatOptional rhs) {
return !(lhs == rhs);
}

View File

@@ -13,11 +13,11 @@
using namespace facebook::yoga;
struct YGLayout {
std::array<float, 4> position = {};
std::array<float, 2> dimensions = {{YGUndefined, YGUndefined}};
std::array<float, 4> margin = {};
std::array<float, 4> border = {};
std::array<float, 4> padding = {};
std::array<double, 4> position = {};
std::array<double, 2> dimensions = {{YGUndefined, YGUndefined}};
std::array<double, 4> margin = {};
std::array<double, 4> border = {};
std::array<double, 4> padding = {};
private:
static constexpr size_t directionOffset = 0;
@@ -41,7 +41,7 @@ public:
uint32_t nextCachedMeasurementsIndex = 0;
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
cachedMeasurements = {};
std::array<float, 2> measuredDimensions = {{YGUndefined, YGUndefined}};
std::array<double, 2> measuredDimensions = {{YGUndefined, YGUndefined}};
YGCachedMeasurement cachedLayout = YGCachedMeasurement();

View File

@@ -8,9 +8,13 @@
#pragma once
#ifdef __cplusplus
#define YG_EXTERN_CXX_BEGIN extern "C++" {
#define YG_EXTERN_CXX_END }
#define YG_EXTERN_C_BEGIN extern "C" {
#define YG_EXTERN_C_END }
#else
#define YG_EXTERN_CXX_BEGIN
#define YG_EXTERN_CXX_END
#define YG_EXTERN_C_BEGIN
#define YG_EXTERN_C_END
#endif

View File

@@ -85,7 +85,7 @@ CompactValue YGNode::computeEdgeValueForColumn(
YGFloatOptional YGNode::getLeadingPosition(
const YGFlexDirection axis,
const float axisSize) const {
const double axisSize) const {
auto leadingPosition = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.position(),
@@ -99,7 +99,7 @@ YGFloatOptional YGNode::getLeadingPosition(
YGFloatOptional YGNode::getTrailingPosition(
const YGFlexDirection axis,
const float axisSize) const {
const double axisSize) const {
auto trailingPosition = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.position(),
@@ -137,7 +137,7 @@ bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const {
YGFloatOptional YGNode::getLeadingMargin(
const YGFlexDirection axis,
const float widthSize) const {
const double widthSize) const {
auto leadingMargin = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero())
@@ -148,7 +148,7 @@ YGFloatOptional YGNode::getLeadingMargin(
YGFloatOptional YGNode::getTrailingMargin(
const YGFlexDirection axis,
const float widthSize) const {
const double widthSize) const {
auto trailingMargin = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.margin(), YGEdgeEnd, trailing[axis], CompactValue::ofZero())
@@ -159,14 +159,14 @@ YGFloatOptional YGNode::getTrailingMargin(
YGFloatOptional YGNode::getMarginForAxis(
const YGFlexDirection axis,
const float widthSize) const {
const double widthSize) const {
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
}
YGSize YGNode::measure(
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode,
void* layoutContext) {
return facebook::yoga::detail::getBooleanData(flags, measureUsesContext_)
@@ -175,7 +175,7 @@ YGSize YGNode::measure(
: measure_.noContext(this, width, widthMode, height, heightMode);
}
float YGNode::baseline(float width, float height, void* layoutContext) {
double YGNode::baseline(double width, double height, void* layoutContext) {
return facebook::yoga::detail::getBooleanData(flags, baselineUsesContext_)
? baseline_.withContext(this, width, height, layoutContext)
: baseline_.noContext(this, width, height);
@@ -256,15 +256,15 @@ void YGNode::setLayoutDirection(YGDirection direction) {
layout_.setDirection(direction);
}
void YGNode::setLayoutMargin(float margin, int index) {
void YGNode::setLayoutMargin(double margin, int index) {
layout_.margin[index] = margin;
}
void YGNode::setLayoutBorder(float border, int index) {
void YGNode::setLayoutBorder(double border, int index) {
layout_.border[index] = border;
}
void YGNode::setLayoutPadding(float padding, int index) {
void YGNode::setLayoutPadding(double padding, int index) {
layout_.padding[index] = padding;
}
@@ -277,7 +277,7 @@ void YGNode::setLayoutComputedFlexBasis(
layout_.computedFlexBasis = computedFlexBasis;
}
void YGNode::setLayoutPosition(float position, int index) {
void YGNode::setLayoutPosition(double position, int index) {
layout_.position[index] = position;
}
@@ -286,7 +286,7 @@ void YGNode::setLayoutComputedFlexBasisGeneration(
layout_.computedFlexBasisGeneration = computedFlexBasisGeneration;
}
void YGNode::setLayoutMeasuredDimension(float measuredDimension, int index) {
void YGNode::setLayoutMeasuredDimension(double measuredDimension, int index) {
layout_.measuredDimensions[index] = measuredDimension;
}
@@ -294,7 +294,7 @@ void YGNode::setLayoutHadOverflow(bool hadOverflow) {
layout_.setHadOverflow(hadOverflow);
}
void YGNode::setLayoutDimension(float dimension, int index) {
void YGNode::setLayoutDimension(double dimension, int index) {
layout_.dimensions[index] = dimension;
}
@@ -302,7 +302,7 @@ void YGNode::setLayoutDimension(float dimension, int index) {
// -right depending on which is defined.
YGFloatOptional YGNode::relativePosition(
const YGFlexDirection axis,
const float axisSize) const {
const double axisSize) const {
if (isLeadingPositionDefined(axis)) {
return getLeadingPosition(axis, axisSize);
}
@@ -316,9 +316,9 @@ YGFloatOptional YGNode::relativePosition(
void YGNode::setPosition(
const YGDirection direction,
const float mainSize,
const float crossSize,
const float ownerWidth) {
const double mainSize,
const double crossSize,
const double ownerWidth) {
/* Root nodes should be always layouted as LTR, so we don't return negative
* values. */
const YGDirection directionRespectingRoot =
@@ -374,7 +374,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
return flexBasis;
}
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0) {
return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_)
? YGValueAuto
: YGValueZero;
@@ -432,7 +432,7 @@ void YGNode::markDirtyAndPropogateDownwards() {
});
}
float YGNode::resolveFlexGrow() const {
double YGNode::resolveFlexGrow() const {
// Root nodes flexGrow should always be 0
if (owner_ == nullptr) {
return 0.0;
@@ -440,13 +440,13 @@ float YGNode::resolveFlexGrow() const {
if (!style_.flexGrow().isUndefined()) {
return style_.flexGrow().unwrap();
}
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0f) {
if (!style_.flex().isUndefined() && style_.flex().unwrap() > 0.0) {
return style_.flex().unwrap();
}
return kDefaultFlexGrow;
}
float YGNode::resolveFlexShrink() const {
double YGNode::resolveFlexShrink() const {
if (owner_ == nullptr) {
return 0.0;
}
@@ -454,7 +454,7 @@ float YGNode::resolveFlexShrink() const {
return style_.flexShrink().unwrap();
}
if (!facebook::yoga::detail::getBooleanData(flags, useWebDefaults_) &&
!style_.flex().isUndefined() && style_.flex().unwrap() < 0.0f) {
!style_.flex().isUndefined() && style_.flex().unwrap() < 0.0) {
return -style_.flex().unwrap();
}
return facebook::yoga::detail::getBooleanData(flags, useWebDefaults_)
@@ -468,27 +468,27 @@ bool YGNode::isNodeFlexible() {
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
}
float YGNode::getLeadingBorder(const YGFlexDirection axis) const {
double YGNode::getLeadingBorder(const YGFlexDirection axis) const {
YGValue leadingBorder = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.border(), YGEdgeStart, leading[axis], CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.border(), leading[axis], CompactValue::ofZero());
return fmaxf(leadingBorder.value, 0.0f);
return fmax(leadingBorder.value, 0.0);
}
float YGNode::getTrailingBorder(const YGFlexDirection axis) const {
double YGNode::getTrailingBorder(const YGFlexDirection axis) const {
YGValue trailingBorder = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.border(), YGEdgeEnd, trailing[axis], CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.border(), trailing[axis], CompactValue::ofZero());
return fmaxf(trailingBorder.value, 0.0f);
return fmax(trailingBorder.value, 0.0);
}
YGFloatOptional YGNode::getLeadingPadding(
const YGFlexDirection axis,
const float widthSize) const {
const double widthSize) const {
auto leadingPadding = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.padding(),
@@ -498,31 +498,31 @@ YGFloatOptional YGNode::getLeadingPadding(
: computeEdgeValueForColumn(
style_.padding(), leading[axis], CompactValue::ofZero());
return YGFloatOptionalMax(
YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f));
YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0));
}
YGFloatOptional YGNode::getTrailingPadding(
const YGFlexDirection axis,
const float widthSize) const {
const double widthSize) const {
auto trailingPadding = YGFlexDirectionIsRow(axis)
? computeEdgeValueForRow(
style_.padding(), YGEdgeEnd, trailing[axis], CompactValue::ofZero())
: computeEdgeValueForColumn(
style_.padding(), trailing[axis], CompactValue::ofZero());
return YGFloatOptionalMax(
YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f));
YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0));
}
YGFloatOptional YGNode::getLeadingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const {
const double widthSize) const {
return getLeadingPadding(axis, widthSize) +
YGFloatOptional(getLeadingBorder(axis));
}
YGFloatOptional YGNode::getTrailingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const {
const double widthSize) const {
return getTrailingPadding(axis, widthSize) +
YGFloatOptional(getTrailingBorder(axis));
}

View File

@@ -23,8 +23,8 @@ YGConfigRef YGConfigGetDefault();
struct YOGA_EXPORT YGNode {
using MeasureWithContextFn =
YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*);
using BaselineWithContextFn = float (*)(YGNode*, float, float, void*);
YGSize (*)(YGNode*, double, YGMeasureMode, double, YGMeasureMode, void*);
using BaselineWithContextFn = double (*)(YGNode*, double, double, void*);
using PrintWithContextFn = void (*)(YGNode*, void*);
private:
@@ -37,7 +37,7 @@ private:
static constexpr size_t printUsesContext_ = 6;
static constexpr size_t useWebDefaults_ = 7;
void* context_ = nullptr;
const void* context_ = nullptr;
uint8_t flags = 1;
uint8_t reserved_ = 0;
union {
@@ -64,7 +64,7 @@ private:
YGFloatOptional relativePosition(
const YGFlexDirection axis,
const float axisSize) const;
const double axisSize) const;
void setMeasureFunc(decltype(measure_));
void setBaselineFunc(decltype(baseline_));
@@ -107,7 +107,7 @@ public:
YGNode& operator=(const YGNode&) = delete;
// Getters
void* getContext() const { return context_; }
const void* getContext() const { return context_; }
uint8_t& reserved() { return reserved_; }
uint8_t reserved() const { return reserved_; }
@@ -124,13 +124,13 @@ public:
bool hasMeasureFunc() const noexcept { return measure_.noContext != nullptr; }
YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void*);
YGSize measure(double, YGMeasureMode, double, YGMeasureMode, void*);
bool hasBaselineFunc() const noexcept {
return baseline_.noContext != nullptr;
}
float baseline(float width, float height, void* layoutContext);
double baseline(double width, double height, void* layoutContext);
YGDirtiedFunc getDirtied() const { return dirtied_; }
@@ -207,38 +207,38 @@ public:
// Methods related to positions, margin, padding and border
YGFloatOptional getLeadingPosition(
const YGFlexDirection axis,
const float axisSize) const;
const double axisSize) const;
bool isLeadingPositionDefined(const YGFlexDirection axis) const;
bool isTrailingPosDefined(const YGFlexDirection axis) const;
YGFloatOptional getTrailingPosition(
const YGFlexDirection axis,
const float axisSize) const;
const double axisSize) const;
YGFloatOptional getLeadingMargin(
const YGFlexDirection axis,
const float widthSize) const;
const double widthSize) const;
YGFloatOptional getTrailingMargin(
const YGFlexDirection axis,
const float widthSize) const;
float getLeadingBorder(const YGFlexDirection flexDirection) const;
float getTrailingBorder(const YGFlexDirection flexDirection) const;
const double widthSize) const;
double getLeadingBorder(const YGFlexDirection flexDirection) const;
double getTrailingBorder(const YGFlexDirection flexDirection) const;
YGFloatOptional getLeadingPadding(
const YGFlexDirection axis,
const float widthSize) const;
const double widthSize) const;
YGFloatOptional getTrailingPadding(
const YGFlexDirection axis,
const float widthSize) const;
const double widthSize) const;
YGFloatOptional getLeadingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const;
const double widthSize) const;
YGFloatOptional getTrailingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) const;
const double widthSize) const;
YGFloatOptional getMarginForAxis(
const YGFlexDirection axis,
const float widthSize) const;
const double widthSize) const;
// Setters
void setContext(void* context) { context_ = context; }
void setContext(const void* context) { context_ = context; }
void setPrintFunc(YGPrintFunc printFunc) {
print_.noContext = printFunc;
@@ -303,19 +303,19 @@ public:
void setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis);
void setLayoutComputedFlexBasisGeneration(
uint32_t computedFlexBasisGeneration);
void setLayoutMeasuredDimension(float measuredDimension, int index);
void setLayoutMeasuredDimension(double measuredDimension, int index);
void setLayoutHadOverflow(bool hadOverflow);
void setLayoutDimension(float dimension, int index);
void setLayoutDimension(double dimension, int index);
void setLayoutDirection(YGDirection direction);
void setLayoutMargin(float margin, int index);
void setLayoutBorder(float border, int index);
void setLayoutPadding(float padding, int index);
void setLayoutPosition(float position, int index);
void setLayoutMargin(double margin, int index);
void setLayoutBorder(double border, int index);
void setLayoutPadding(double padding, int index);
void setLayoutPosition(double position, int index);
void setPosition(
const YGDirection direction,
const float mainSize,
const float crossSize,
const float ownerWidth);
const double mainSize,
const double crossSize,
const double ownerWidth);
void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
void markDirtyAndPropogateDownwards();
@@ -337,8 +337,8 @@ public:
void cloneChildrenIfNeeded(void*);
void markDirtyAndPropogate();
float resolveFlexGrow() const;
float resolveFlexShrink() const;
double resolveFlexGrow() const;
double resolveFlexShrink() const;
bool isNodeFlexible();
bool didUseLegacyFlag();
bool isLayoutTreeEqualToNode(const YGNode& node) const;

View File

@@ -16,21 +16,21 @@
#endif
#if defined(COMPILING_WITH_CLANG_ON_WINDOWS)
#include <limits>
constexpr float YGUndefined = std::numeric_limits<float>::quiet_NaN();
constexpr double YGUndefined = std::numeric_limits<double>::quiet_NaN();
#else
YG_EXTERN_C_BEGIN
// Not defined in MSVC++
#ifndef NAN
static const uint32_t __nan = 0x7fc00000;
#define NAN (*(const float*) __nan)
static const uint64_t __nan = 0x7ff8000000000000;
#define NAN (*(const double*) __nan)
#endif
#define YGUndefined NAN
#endif
typedef struct YGValue {
float value;
double value;
YGUnit unit;
} YGValue;
@@ -44,6 +44,7 @@ YG_EXTERN_C_END
#undef COMPILING_WITH_CLANG_ON_WINDOWS
#ifdef __cplusplus
YG_EXTERN_CXX_BEGIN
inline bool operator==(const YGValue& lhs, const YGValue& rhs) {
if (lhs.unit != rhs.unit) {
@@ -75,14 +76,14 @@ namespace yoga {
namespace literals {
inline YGValue operator"" _pt(long double value) {
return YGValue{static_cast<float>(value), YGUnitPoint};
return YGValue{static_cast<double>(value), YGUnitPoint};
}
inline YGValue operator"" _pt(unsigned long long value) {
return operator"" _pt(static_cast<long double>(value));
}
inline YGValue operator"" _percent(long double value) {
return YGValue{static_cast<float>(value), YGUnitPercent};
return YGValue{static_cast<double>(value), YGUnitPercent};
}
inline YGValue operator"" _percent(unsigned long long value) {
return operator"" _percent(static_cast<long double>(value));
@@ -92,4 +93,5 @@ inline YGValue operator"" _percent(unsigned long long value) {
} // namespace yoga
} // namespace facebook
YG_EXTERN_CXX_END
#endif

View File

@@ -19,8 +19,8 @@ YG_EXTERN_C_BEGIN
void YGNodeCalculateLayoutWithContext(
YGNodeRef node,
float availableWidth,
float availableHeight,
double availableWidth,
double availableHeight,
YGDirection ownerDirection,
void* layoutContext);
@@ -29,10 +29,6 @@ YG_EXTERN_C_END
namespace facebook {
namespace yoga {
inline bool isUndefined(float value) {
return std::isnan(value);
}
inline bool isUndefined(double value) {
return std::isnan(value);
}
@@ -49,13 +45,13 @@ extern const YGValue YGValueAuto;
extern const YGValue YGValueZero;
struct YGCachedMeasurement {
float availableWidth;
float availableHeight;
double availableWidth;
double availableHeight;
YGMeasureMode widthMeasureMode;
YGMeasureMode heightMeasureMode;
float computedWidth;
float computedHeight;
double computedWidth;
double computedHeight;
YGCachedMeasurement()
: availableWidth(-1),
@@ -143,8 +139,8 @@ public:
} // namespace yoga
} // namespace facebook
static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f;
static const float kWebDefaultFlexShrink = 1.0f;
static const double kDefaultFlexGrow = 0.0;
static const double kDefaultFlexShrink = 0.0;
static const double kWebDefaultFlexShrink = 1.0;
extern bool YGFloatsEqual(const float a, const float b);
extern bool YGFloatsEqual(const double a, const double b);

File diff suppressed because it is too large Load Diff

View File

@@ -25,8 +25,8 @@
YG_EXTERN_C_BEGIN
typedef struct YGSize {
float width;
float height;
double width;
double height;
} YGSize;
typedef struct YGConfig* YGConfigRef;
@@ -36,11 +36,11 @@ typedef const struct YGNode* YGNodeConstRef;
typedef YGSize (*YGMeasureFunc)(
YGNodeRef node,
float width,
double width,
YGMeasureMode widthMode,
float height,
double height,
YGMeasureMode heightMode);
typedef float (*YGBaselineFunc)(YGNodeRef node, float width, float height);
typedef double (*YGBaselineFunc)(YGNodeRef node, double width, double height);
typedef void (*YGDirtiedFunc)(YGNodeRef node);
typedef void (*YGPrintFunc)(YGNodeRef node);
typedef void (*YGNodeCleanupFunc)(YGNodeRef node);
@@ -93,8 +93,8 @@ WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node);
WIN_EXPORT void YGNodeCalculateLayout(
YGNodeRef node,
float availableWidth,
float availableHeight,
double availableWidth,
double availableHeight,
YGDirection ownerDirection);
// Mark a node as dirty. Only valid for nodes with a custom measure function
@@ -113,27 +113,27 @@ WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(YGNodeRef node);
WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options);
WIN_EXPORT bool YGFloatIsUndefined(float value);
WIN_EXPORT bool YGFloatIsUndefined(double value);
WIN_EXPORT bool YGNodeCanUseCachedMeasurement(
YGMeasureMode widthMode,
float width,
double width,
YGMeasureMode heightMode,
float height,
double height,
YGMeasureMode lastWidthMode,
float lastWidth,
double lastWidth,
YGMeasureMode lastHeightMode,
float lastHeight,
float lastComputedWidth,
float lastComputedHeight,
float marginRow,
float marginColumn,
double lastHeight,
double lastComputedWidth,
double lastComputedHeight,
double marginRow,
double marginColumn,
YGConfigRef config);
WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode);
WIN_EXPORT void* YGNodeGetContext(YGNodeRef node);
WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context);
WIN_EXPORT const void* YGNodeGetContext(YGNodeRef node);
WIN_EXPORT void YGNodeSetContext(YGNodeRef node, const void* context);
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
bool YGNodeHasMeasureFunc(YGNodeRef node);
WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
@@ -187,75 +187,75 @@ WIN_EXPORT YGOverflow YGNodeStyleGetOverflow(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetDisplay(YGNodeRef node, YGDisplay display);
WIN_EXPORT YGDisplay YGNodeStyleGetDisplay(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlex(YGNodeRef node, float flex);
WIN_EXPORT float YGNodeStyleGetFlex(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlex(YGNodeRef node, double flex);
WIN_EXPORT double YGNodeStyleGetFlex(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlexGrow(YGNodeRef node, float flexGrow);
WIN_EXPORT float YGNodeStyleGetFlexGrow(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlexGrow(YGNodeRef node, double flexGrow);
WIN_EXPORT double YGNodeStyleGetFlexGrow(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlexShrink(YGNodeRef node, float flexShrink);
WIN_EXPORT float YGNodeStyleGetFlexShrink(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlexShrink(YGNodeRef node, double flexShrink);
WIN_EXPORT double YGNodeStyleGetFlexShrink(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis);
WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis);
WIN_EXPORT void YGNodeStyleSetFlexBasis(YGNodeRef node, double flexBasis);
WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, double flexBasis);
WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node);
WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetPosition(
YGNodeRef node,
YGEdge edge,
float position);
double position);
WIN_EXPORT void YGNodeStyleSetPositionPercent(
YGNodeRef node,
YGEdge edge,
float position);
double position);
WIN_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin);
WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, double margin);
WIN_EXPORT void YGNodeStyleSetMarginPercent(
YGNodeRef node,
YGEdge edge,
float margin);
double margin);
WIN_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge);
WIN_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetPadding(
YGNodeRef node,
YGEdge edge,
float padding);
double padding);
WIN_EXPORT void YGNodeStyleSetPaddingPercent(
YGNodeRef node,
YGEdge edge,
float padding);
double padding);
WIN_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border);
WIN_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, double border);
WIN_EXPORT double YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge);
WIN_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float width);
WIN_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float width);
WIN_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, double width);
WIN_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, double width);
WIN_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node);
WIN_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float height);
WIN_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float height);
WIN_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, double height);
WIN_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, double height);
WIN_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node);
WIN_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth);
WIN_EXPORT void YGNodeStyleSetMinWidthPercent(YGNodeRef node, float minWidth);
WIN_EXPORT void YGNodeStyleSetMinWidth(YGNodeRef node, double minWidth);
WIN_EXPORT void YGNodeStyleSetMinWidthPercent(YGNodeRef node, double minWidth);
WIN_EXPORT YGValue YGNodeStyleGetMinWidth(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight);
WIN_EXPORT void YGNodeStyleSetMinHeightPercent(YGNodeRef node, float minHeight);
WIN_EXPORT void YGNodeStyleSetMinHeight(YGNodeRef node, double minHeight);
WIN_EXPORT void YGNodeStyleSetMinHeightPercent(YGNodeRef node, double minHeight);
WIN_EXPORT YGValue YGNodeStyleGetMinHeight(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth);
WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(YGNodeRef node, float maxWidth);
WIN_EXPORT void YGNodeStyleSetMaxWidth(YGNodeRef node, double maxWidth);
WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(YGNodeRef node, double maxWidth);
WIN_EXPORT YGValue YGNodeStyleGetMaxWidth(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight);
WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(YGNodeRef node, float maxHeight);
WIN_EXPORT void YGNodeStyleSetMaxHeight(YGNodeRef node, double maxHeight);
WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(YGNodeRef node, double maxHeight);
WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node);
// Yoga specific properties, not compatible with flexbox specification Aspect
@@ -273,15 +273,15 @@ WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node);
// - On a node with flex grow/shrink aspect ratio controls the size of the node
// in the cross axis if unset
// - Aspect ratio takes min/max dimensions into account
WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node);
WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, double aspectRatio);
WIN_EXPORT double YGNodeStyleGetAspectRatio(YGNodeConstRef node);
WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetTop(YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetRight(YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node);
WIN_EXPORT double YGNodeLayoutGetLeft(YGNodeRef node);
WIN_EXPORT double YGNodeLayoutGetTop(YGNodeRef node);
WIN_EXPORT double YGNodeLayoutGetRight(YGNodeRef node);
WIN_EXPORT double YGNodeLayoutGetBottom(YGNodeRef node);
WIN_EXPORT double YGNodeLayoutGetWidth(YGNodeRef node);
WIN_EXPORT double YGNodeLayoutGetHeight(YGNodeRef node);
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node);
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeRef node);
bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(YGNodeRef node);
@@ -290,9 +290,9 @@ bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(YGNodeRef node);
// set using point values then the returned value will be the same as
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
// returned value is the computed value used during layout.
WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeRef node, YGEdge edge);
WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge);
WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge);
WIN_EXPORT double YGNodeLayoutGetMargin(YGNodeRef node, YGEdge edge);
WIN_EXPORT double YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge);
WIN_EXPORT double YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge);
WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
WIN_EXPORT void YGAssert(bool condition, const char* message);
@@ -308,7 +308,7 @@ WIN_EXPORT void YGAssertWithConfig(
// want to avoid rounding - set PointScaleFactor to 0
WIN_EXPORT void YGConfigSetPointScaleFactor(
YGConfigRef config,
float pixelsInPoint);
double pixelsInPoint);
void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
YGConfigRef config,
bool shouldDiffLayout);
@@ -351,7 +351,7 @@ WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
WIN_EXPORT void* YGConfigGetContext(YGConfigRef config);
WIN_EXPORT float YGRoundValueToPixelGrid(
WIN_EXPORT double YGRoundValueToPixelGrid(
double value,
double pointScaleFactor,
bool forceCeil,
@@ -360,6 +360,7 @@ WIN_EXPORT float YGRoundValueToPixelGrid(
YG_EXTERN_C_END
#ifdef __cplusplus
YG_EXTERN_CXX_BEGIN
#include <functional>
#include <vector>
@@ -371,4 +372,5 @@ void YGTraversePreOrder(
void YGNodeSetChildren(YGNodeRef owner, const std::vector<YGNodeRef>& children);
YG_EXTERN_CXX_END
#endif

View File

@@ -127,12 +127,12 @@ struct Event::TypedData<Event::LayoutPassEnd> {
template <>
struct Event::TypedData<Event::MeasureCallbackEnd> {
void* layoutContext;
float width;
double width;
YGMeasureMode widthMeasureMode;
float height;
double height;
YGMeasureMode heightMeasureMode;
float measuredWidth;
float measuredHeight;
double measuredWidth;
double measuredHeight;
const LayoutPassReason reason;
};