From 860bb8b66005ef3a1d791bca403838d74fa88a10 Mon Sep 17 00:00:00 2001 From: "Lvv.me" Date: Mon, 5 Jul 2021 10:57:32 +0800 Subject: [PATCH] [yoga] Replace float with double --- tests/CompactValueTest.cpp | 44 +-- tests/EventsTest.cpp | 6 +- tests/YGAlignBaselineTest.cpp | 14 +- tests/YGAspectRatioTest.cpp | 4 +- tests/YGBaselineFuncTest.cpp | 6 +- tests/YGComputedMarginTest.cpp | 6 +- tests/YGComputedPaddingTest.cpp | 6 +- tests/YGDefaultValuesTest.cpp | 4 +- tests/YGFlexTest.cpp | 6 +- tests/YGFloatOptionalTest.cpp | 40 +- tests/YGMeasureCacheTest.cpp | 22 +- tests/YGMeasureModeTest.cpp | 8 +- tests/YGMeasureTest.cpp | 20 +- tests/YGMinMaxDimensionTest.cpp | 4 +- tests/YGNodeCallbackTest.cpp | 38 +- tests/YGPercentageTest.cpp | 4 +- tests/YGRoundingFunctionTest.cpp | 4 +- tests/YGRoundingMeasureFuncTest.cpp | 38 +- tests/YGRoundingTest.cpp | 56 +-- tests/YGStyleAccessorsTest.cpp | 48 +-- tests/YGValueTest.cpp | 12 +- yoga/CompactValue.h | 60 +-- yoga/Utils.cpp | 16 +- yoga/Utils.h | 38 +- yoga/YGConfig.h | 2 +- yoga/YGEnums.h | 4 + yoga/YGFloatOptional.h | 14 +- yoga/YGLayout.h | 12 +- yoga/YGMacros.h | 4 + yoga/YGNode.cpp | 66 ++-- yoga/YGNode.h | 60 +-- yoga/YGValue.h | 14 +- yoga/Yoga-internal.h | 24 +- yoga/Yoga.cpp | 548 ++++++++++++++-------------- yoga/Yoga.h | 120 +++--- yoga/event/event.h | 8 +- 36 files changed, 694 insertions(+), 686 deletions(-) diff --git a/tests/CompactValueTest.cpp b/tests/CompactValueTest.cpp index 47e9aaa6..a77d0e92 100644 --- a/tests/CompactValueTest.cpp +++ b/tests/CompactValueTest.cpp @@ -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::infinity(), YGUnitUndefined}}; + YGValue{std::numeric_limits::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(-9876.5f), - CompactValue(YGValue{-9876.5f, YGUnitPoint})); + CompactValue::of(-9876.5), + CompactValue(YGValue{-9876.5, YGUnitPoint})); ASSERT_EQ( - CompactValue::of(123.456f), - CompactValue(YGValue{123.456f, YGUnitPercent})); + CompactValue::of(123.456), + CompactValue(YGValue{123.456, YGUnitPercent})); } TEST(YogaTest, dedicated_unit_maybe_factories) { ASSERT_EQ( - CompactValue::ofMaybe(-9876.5f), - CompactValue(YGValue{-9876.5f, YGUnitPoint})); + CompactValue::ofMaybe(-9876.5), + CompactValue(YGValue{-9876.5, YGUnitPoint})); ASSERT_EQ( CompactValue::ofMaybe(YGUndefined), CompactValue(YGValueUndefined)); ASSERT_EQ( - CompactValue::ofMaybe(123.456f), - CompactValue(YGValue{123.456f, YGUnitPercent})); + CompactValue::ofMaybe(123.456), + CompactValue(YGValue{123.456, YGUnitPercent})); ASSERT_EQ( CompactValue::ofMaybe(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(CompactValue::LOWER_BOUND).repr(), - uint32_t{0}); + uint64_t{0}); ASSERT_EQ( CompactValue::of(CompactValue::UPPER_BOUND_POINT).repr(), - uint32_t{0x3fffffff}); + uint64_t{0x3fffffffffffffff}); ASSERT_EQ( CompactValue::of(CompactValue::LOWER_BOUND).repr(), - uint32_t{0x40000000}); + uint64_t{0x4000000000000000}); ASSERT_EQ( CompactValue::of(CompactValue::UPPER_BOUND_PERCENT).repr(), - uint32_t{0x7f7fffff}); + uint64_t{0x7f7fffffffffffff}); ASSERT_EQ( CompactValue::of(-CompactValue::LOWER_BOUND).repr(), - uint32_t{0x80000000}); + uint64_t{0x8000000000000000}); ASSERT_EQ( CompactValue::of(-CompactValue::UPPER_BOUND_POINT).repr(), - uint32_t{0xbfffffff}); + uint64_t{0xbfffffffffffffff}); ASSERT_EQ( CompactValue::of(-CompactValue::LOWER_BOUND).repr(), - uint32_t{0xc0000000}); + uint64_t{0xc000000000000000}); ASSERT_EQ( CompactValue::of(-CompactValue::UPPER_BOUND_PERCENT) .repr(), - uint32_t{0xff7fffff}); + uint64_t{0xff7fffffffffffff}); } diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index e8300846..f67eb742 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -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); diff --git a/tests/YGAlignBaselineTest.cpp b/tests/YGAlignBaselineTest.cpp index 35abfe76..ffa65246 100644 --- a/tests/YGAlignBaselineTest.cpp +++ b/tests/YGAlignBaselineTest.cpp @@ -9,18 +9,18 @@ #include #include -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, diff --git a/tests/YGAspectRatioTest.cpp b/tests/YGAspectRatioTest.cpp index a1c31ecd..7a81720e 100644 --- a/tests/YGAspectRatioTest.cpp +++ b/tests/YGAspectRatioTest.cpp @@ -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, diff --git a/tests/YGBaselineFuncTest.cpp b/tests/YGBaselineFuncTest.cpp index eb15185e..adfc07da 100644 --- a/tests/YGBaselineFuncTest.cpp +++ b/tests/YGBaselineFuncTest.cpp @@ -9,8 +9,8 @@ #include #include -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); diff --git a/tests/YGComputedMarginTest.cpp b/tests/YGComputedMarginTest.cpp index fedfd561..1ab9a9b9 100644 --- a/tests/YGComputedMarginTest.cpp +++ b/tests/YGComputedMarginTest.cpp @@ -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 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); diff --git a/tests/YGComputedPaddingTest.cpp b/tests/YGComputedPaddingTest.cpp index c3aabab7..ac72a98b 100644 --- a/tests/YGComputedPaddingTest.cpp +++ b/tests/YGComputedPaddingTest.cpp @@ -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 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); diff --git a/tests/YGDefaultValuesTest.cpp b/tests/YGDefaultValuesTest.cpp index a622c1b3..12a70dd8 100644 --- a/tests/YGDefaultValuesTest.cpp +++ b/tests/YGDefaultValuesTest.cpp @@ -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); diff --git a/tests/YGFlexTest.cpp b/tests/YGFlexTest.cpp index ab6dec76..3066ac28 100644 --- a/tests/YGFlexTest.cpp +++ b/tests/YGFlexTest.cpp @@ -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); diff --git a/tests/YGFloatOptionalTest.cpp b/tests/YGFloatOptionalTest.cpp index 6d245f83..4bc34bfe 100644 --- a/tests/YGFloatOptionalTest.cpp +++ b/tests/YGFloatOptionalTest.cpp @@ -12,17 +12,17 @@ #include 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); } diff --git a/tests/YGMeasureCacheTest.cpp b/tests/YGMeasureCacheTest.cpp index 60ad6f47..233bfdb5 100644 --- a/tests/YGMeasureCacheTest.cpp +++ b/tests/YGMeasureCacheTest.cpp @@ -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); diff --git a/tests/YGMeasureModeTest.cpp b/tests/YGMeasureModeTest.cpp index 6ed7b2c0..2f73c754 100644 --- a/tests/YGMeasureModeTest.cpp +++ b/tests/YGMeasureModeTest.cpp @@ -10,9 +10,9 @@ #include 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(); diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index e47607d4..5a9dc561 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -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{ diff --git a/tests/YGMinMaxDimensionTest.cpp b/tests/YGMinMaxDimensionTest.cpp index 621aff4d..ef3fcb6e 100644 --- a/tests/YGMinMaxDimensionTest.cpp +++ b/tests/YGMinMaxDimensionTest.cpp @@ -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) { diff --git a/tests/YGNodeCallbackTest.cpp b/tests/YGNodeCallbackTest.cpp index 5e765a0d..0f67bed9 100644 --- a/tests/YGNodeCallbackTest.cpp +++ b/tests/YGNodeCallbackTest.cpp @@ -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) { diff --git a/tests/YGPercentageTest.cpp b/tests/YGPercentageTest.cpp index 805df24b..ed794e26 100644 --- a/tests/YGPercentageTest.cpp +++ b/tests/YGPercentageTest.cpp @@ -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) { diff --git a/tests/YGRoundingFunctionTest.cpp b/tests/YGRoundingFunctionTest.cpp index 21daeac6..5543ca7b 100644 --- a/tests/YGRoundingFunctionTest.cpp +++ b/tests/YGRoundingFunctionTest.cpp @@ -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}; } diff --git a/tests/YGRoundingMeasureFuncTest.cpp b/tests/YGRoundingMeasureFuncTest.cpp index 822e3701..397cf316 100644 --- a/tests/YGRoundingMeasureFuncTest.cpp +++ b/tests/YGRoundingMeasureFuncTest.cpp @@ -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); diff --git a/tests/YGRoundingTest.cpp b/tests/YGRoundingTest.cpp index 1b3af640..6e82c116 100644 --- a/tests/YGRoundingTest.cpp +++ b/tests/YGRoundingTest.cpp @@ -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); diff --git a/tests/YGStyleAccessorsTest.cpp b/tests/YGStyleAccessorsTest.cpp index d0bda431..19fb0296 100644 --- a/tests/YGStyleAccessorsTest.cpp +++ b/tests/YGStyleAccessorsTest.cpp @@ -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(7777.77f), - CompactValue::of(-100.0f)) + CompactValue::of(7777.77), + CompactValue::of(-100.0)) INDEX_ACCESSOR_TEST( position, @@ -188,8 +188,8 @@ INDEX_ACCESSOR_TEST( YGEdgeBottom, CompactValue::ofAuto(), CompactValue::ofUndefined(), - CompactValue::of(7777.77f), - CompactValue::of(-100.0f)) + CompactValue::of(7777.77), + CompactValue::of(-100.0)) INDEX_ACCESSOR_TEST( margin, @@ -197,22 +197,22 @@ INDEX_ACCESSOR_TEST( YGEdgeTop, CompactValue::ofAuto(), CompactValue::ofUndefined(), - CompactValue::of(7777.77f), - CompactValue::of(-100.0f)) + CompactValue::of(7777.77), + CompactValue::of(-100.0)) INDEX_ACCESSOR_TEST( padding, CompactValue::ofUndefined(), YGEdgeAll, - CompactValue::of(7777.77f), + CompactValue::of(7777.77), CompactValue::ofUndefined(), - CompactValue::of(-100.0f)) + CompactValue::of(-100.0)) INDEX_ACCESSOR_TEST( border, CompactValue::ofUndefined(), YGEdgeHorizontal, - CompactValue::of(-7777.77f), + CompactValue::of(-7777.77), CompactValue::ofUndefined()) INDEX_ACCESSOR_TEST( @@ -221,8 +221,8 @@ INDEX_ACCESSOR_TEST( YGDimensionWidth, CompactValue::ofUndefined(), CompactValue::ofAuto(), - CompactValue::of(7777.77f), - CompactValue::of(-100.0f)) + CompactValue::of(7777.77), + CompactValue::of(-100.0)) INDEX_ACCESSOR_TEST( minDimensions, @@ -230,8 +230,8 @@ INDEX_ACCESSOR_TEST( YGDimensionHeight, CompactValue::ofAuto(), CompactValue::ofUndefined(), - CompactValue::of(7777.77f), - CompactValue::of(-100.0f)) + CompactValue::of(7777.77), + CompactValue::of(-100.0)) INDEX_ACCESSOR_TEST( maxDimensions, @@ -239,15 +239,15 @@ INDEX_ACCESSOR_TEST( YGDimensionHeight, CompactValue::ofAuto(), CompactValue::ofUndefined(), - CompactValue::of(7777.77f), - CompactValue::of(-100.0f)) + CompactValue::of(7777.77), + CompactValue::of(-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 diff --git a/tests/YGValueTest.cpp b/tests/YGValueTest.cpp index 4ab4aa8c..379c33f2 100644 --- a/tests/YGValueTest.cpp +++ b/tests/YGValueTest.cpp @@ -10,14 +10,14 @@ #include 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})); } diff --git a/yoga/CompactValue.h b/yoga/CompactValue.h index f398668e..def5533a 100644 --- a/yoga/CompactValue.h +++ b/yoga/CompactValue.h @@ -14,7 +14,7 @@ #include static_assert( - std::numeric_limits::is_iec559, + std::numeric_limits::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 - 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 - static CompactValue ofMaybe(float value) noexcept { + static CompactValue ofMaybe(double value) noexcept { return std::isnan(value) || std::isinf(value) ? ofUndefined() : of(value); } @@ -88,9 +88,9 @@ public: } constexpr CompactValue() noexcept - : payload_(std::numeric_limits::quiet_NaN()) {} + : payload_(std::numeric_limits::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(float) noexcept = delete; +CompactValue CompactValue::of(double) noexcept = delete; template <> -CompactValue CompactValue::of(float) noexcept = delete; +CompactValue CompactValue::of(double) noexcept = delete; template <> -CompactValue CompactValue::ofMaybe(float) noexcept = delete; +CompactValue CompactValue::ofMaybe(double) noexcept = delete; template <> -CompactValue CompactValue::ofMaybe(float) noexcept = delete; +CompactValue CompactValue::ofMaybe(double) noexcept = delete; constexpr bool operator==(CompactValue a, CompactValue b) noexcept { return a.payload_.repr == b.payload_.repr; diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index eaa74b06..fb74d90f 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -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; } diff --git a/yoga/Utils.h b/yoga/Utils.h index 57e1d45d..0f275ae0 100644 --- a/yoga/Utils.h +++ b/yoga/Utils.h @@ -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 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 bool YGFloatArrayEqual( - const std::array& val1, - const std::array& val2) { + const std::array& val1, + const std::array& 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); } diff --git a/yoga/YGConfig.h b/yoga/YGConfig.h index e87d6758..7e1e3f06 100644 --- a/yoga/YGConfig.h +++ b/yoga/YGConfig.h @@ -40,7 +40,7 @@ public: bool useLegacyStretchBehaviour = false; bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false; bool printTree = false; - float pointScaleFactor = 1.0f; + double pointScaleFactor = 1.0; std::array()> experimentalFeatures = {}; void* context = nullptr; diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 3dc458dc..d308634b 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -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 diff --git a/yoga/YGFloatOptional.h b/yoga/YGFloatOptional.h index e4cf0284..dbb3b165 100644 --- a/yoga/YGFloatOptional.h +++ b/yoga/YGFloatOptional.h @@ -13,14 +13,14 @@ struct YGFloatOptional { private: - float value_ = std::numeric_limits::quiet_NaN(); + double value_ = std::numeric_limits::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); } diff --git a/yoga/YGLayout.h b/yoga/YGLayout.h index b7604d8e..0153ba64 100644 --- a/yoga/YGLayout.h +++ b/yoga/YGLayout.h @@ -13,11 +13,11 @@ using namespace facebook::yoga; struct YGLayout { - std::array position = {}; - std::array dimensions = {{YGUndefined, YGUndefined}}; - std::array margin = {}; - std::array border = {}; - std::array padding = {}; + std::array position = {}; + std::array dimensions = {{YGUndefined, YGUndefined}}; + std::array margin = {}; + std::array border = {}; + std::array padding = {}; private: static constexpr size_t directionOffset = 0; @@ -41,7 +41,7 @@ public: uint32_t nextCachedMeasurementsIndex = 0; std::array cachedMeasurements = {}; - std::array measuredDimensions = {{YGUndefined, YGUndefined}}; + std::array measuredDimensions = {{YGUndefined, YGUndefined}}; YGCachedMeasurement cachedLayout = YGCachedMeasurement(); diff --git a/yoga/YGMacros.h b/yoga/YGMacros.h index c6917f1b..86cb619f 100644 --- a/yoga/YGMacros.h +++ b/yoga/YGMacros.h @@ -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 diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index f4c14bf3..0a596327 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -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)); } diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 4b6e6277..5b419542 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -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; diff --git a/yoga/YGValue.h b/yoga/YGValue.h index a2000978..032c2fc7 100644 --- a/yoga/YGValue.h +++ b/yoga/YGValue.h @@ -16,21 +16,21 @@ #endif #if defined(COMPILING_WITH_CLANG_ON_WINDOWS) #include -constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); +constexpr double YGUndefined = std::numeric_limits::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(value), YGUnitPoint}; + return YGValue{static_cast(value), YGUnitPoint}; } inline YGValue operator"" _pt(unsigned long long value) { return operator"" _pt(static_cast(value)); } inline YGValue operator"" _percent(long double value) { - return YGValue{static_cast(value), YGUnitPercent}; + return YGValue{static_cast(value), YGUnitPercent}; } inline YGValue operator"" _percent(unsigned long long value) { return operator"" _percent(static_cast(value)); @@ -92,4 +93,5 @@ inline YGValue operator"" _percent(unsigned long long value) { } // namespace yoga } // namespace facebook +YG_EXTERN_CXX_END #endif diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h index acd173be..e2d66c93 100644 --- a/yoga/Yoga-internal.h +++ b/yoga/Yoga-internal.h @@ -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); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 2c68674a..6e4a1ee4 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -20,9 +20,9 @@ #ifdef _MSC_VER #include -/* define fmaxf if < VC12 */ +/* define fmax if < VC12 */ #if _MSC_VER < 1800 -__forceinline const float fmaxf(const float a, const float b) { +__forceinline const double fmax(const double a, const double b) { return (a > b) ? a : b; } #endif @@ -110,15 +110,15 @@ static inline bool YGDoubleIsUndefined(const double value) { return facebook::yoga::isUndefined(value); } -YOGA_EXPORT bool YGFloatIsUndefined(const float value) { +YOGA_EXPORT bool YGFloatIsUndefined(const double value) { return facebook::yoga::isUndefined(value); } -YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) { +YOGA_EXPORT const void* YGNodeGetContext(YGNodeRef node) { return node->getContext(); } -YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, void* context) { +YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, const void* context) { return node->setContext(context); } @@ -499,13 +499,13 @@ YOGA_EXPORT void YGNodeCopyStyle( } } -YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef node) { +YOGA_EXPORT double YGNodeStyleGetFlexGrow(const YGNodeConstRef node) { return node->getStyle().flexGrow().isUndefined() ? kDefaultFlexGrow : node->getStyle().flexGrow().unwrap(); } -YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef node) { +YOGA_EXPORT double YGNodeStyleGetFlexShrink(const YGNodeConstRef node) { return node->getStyle().flexShrink().isUndefined() ? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink) @@ -655,12 +655,12 @@ YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { } // TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { +YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const double flex) { updateStyle(node, &YGStyle::flex, YGFloatOptional{flex}); } // TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef node) { +YOGA_EXPORT double YGNodeStyleGetFlex(const YGNodeConstRef node) { return node->getStyle().flex().isUndefined() ? YGUndefined : node->getStyle().flex().unwrap(); @@ -669,7 +669,7 @@ YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef node) { // TODO(T26792433): Change the API to accept YGFloatOptional. YOGA_EXPORT void YGNodeStyleSetFlexGrow( const YGNodeRef node, - const float flexGrow) { + const double flexGrow) { updateStyle( node, &YGStyle::flexGrow, YGFloatOptional{flexGrow}); } @@ -677,7 +677,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexGrow( // TODO(T26792433): Change the API to accept YGFloatOptional. YOGA_EXPORT void YGNodeStyleSetFlexShrink( const YGNodeRef node, - const float flexShrink) { + const double flexShrink) { updateStyle( node, &YGStyle::flexShrink, YGFloatOptional{flexShrink}); } @@ -693,14 +693,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { YOGA_EXPORT void YGNodeStyleSetFlexBasis( const YGNodeRef node, - const float flexBasis) { + const double flexBasis) { auto value = detail::CompactValue::ofMaybe(flexBasis); updateStyle(node, &YGStyle::flexBasis, value); } YOGA_EXPORT void YGNodeStyleSetFlexBasisPercent( const YGNodeRef node, - const float flexBasisPercent) { + const double flexBasisPercent) { auto value = detail::CompactValue::ofMaybe(flexBasisPercent); updateStyle(node, &YGStyle::flexBasis, value); } @@ -713,7 +713,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { YOGA_EXPORT void YGNodeStyleSetPosition( YGNodeRef node, YGEdge edge, - float points) { + double points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::position, edge, value); @@ -721,7 +721,7 @@ YOGA_EXPORT void YGNodeStyleSetPosition( YOGA_EXPORT void YGNodeStyleSetPositionPercent( YGNodeRef node, YGEdge edge, - float percent) { + double percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::position, edge, value); @@ -733,7 +733,7 @@ YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { YOGA_EXPORT void YGNodeStyleSetMargin( YGNodeRef node, YGEdge edge, - float points) { + double points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::margin, edge, value); @@ -741,7 +741,7 @@ YOGA_EXPORT void YGNodeStyleSetMargin( YOGA_EXPORT void YGNodeStyleSetMarginPercent( YGNodeRef node, YGEdge edge, - float percent) { + double percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::margin, edge, value); @@ -757,7 +757,7 @@ YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { YOGA_EXPORT void YGNodeStyleSetPadding( YGNodeRef node, YGEdge edge, - float points) { + double points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::padding, edge, value); @@ -765,7 +765,7 @@ YOGA_EXPORT void YGNodeStyleSetPadding( YOGA_EXPORT void YGNodeStyleSetPaddingPercent( YGNodeRef node, YGEdge edge, - float percent) { + double percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::padding, edge, value); @@ -778,13 +778,13 @@ YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { YOGA_EXPORT void YGNodeStyleSetBorder( const YGNodeRef node, const YGEdge edge, - const float border) { + const double border) { auto value = detail::CompactValue::ofMaybe(border); updateIndexedStyleProp( node, &YGStyle::border, edge, value); } -YOGA_EXPORT float YGNodeStyleGetBorder( +YOGA_EXPORT double YGNodeStyleGetBorder( const YGNodeConstRef node, const YGEdge edge) { auto border = node->getStyle().border()[edge]; @@ -800,7 +800,7 @@ YOGA_EXPORT float YGNodeStyleGetBorder( // Yoga specific properties, not compatible with flexbox specification // TODO(T26792433): Change the API to accept YGFloatOptional. -YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { +YOGA_EXPORT double YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { const YGFloatOptional op = node->getStyle().aspectRatio(); return op.isUndefined() ? YGUndefined : op.unwrap(); } @@ -808,17 +808,17 @@ YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { // TODO(T26792433): Change the API to accept YGFloatOptional. YOGA_EXPORT void YGNodeStyleSetAspectRatio( const YGNodeRef node, - const float aspectRatio) { + const double aspectRatio) { updateStyle( node, &YGStyle::aspectRatio, YGFloatOptional{aspectRatio}); } -YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) { +YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, double points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionWidth, value); } -YOGA_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { +YOGA_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, double percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionWidth, value); @@ -834,12 +834,12 @@ YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { return node->getStyle().dimensions()[YGDimensionWidth]; } -YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) { +YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, double points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionHeight, value); } -YOGA_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { +YOGA_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, double percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionHeight, value); @@ -857,14 +857,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { YOGA_EXPORT void YGNodeStyleSetMinWidth( const YGNodeRef node, - const float minWidth) { + const double minWidth) { auto value = detail::CompactValue::ofMaybe(minWidth); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionWidth, value); } YOGA_EXPORT void YGNodeStyleSetMinWidthPercent( const YGNodeRef node, - const float minWidth) { + const double minWidth) { auto value = detail::CompactValue::ofMaybe(minWidth); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionWidth, value); @@ -875,14 +875,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { YOGA_EXPORT void YGNodeStyleSetMinHeight( const YGNodeRef node, - const float minHeight) { + const double minHeight) { auto value = detail::CompactValue::ofMaybe(minHeight); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionHeight, value); } YOGA_EXPORT void YGNodeStyleSetMinHeightPercent( const YGNodeRef node, - const float minHeight) { + const double minHeight) { auto value = detail::CompactValue::ofMaybe(minHeight); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionHeight, value); @@ -893,14 +893,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { YOGA_EXPORT void YGNodeStyleSetMaxWidth( const YGNodeRef node, - const float maxWidth) { + const double maxWidth) { auto value = detail::CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionWidth, value); } YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent( const YGNodeRef node, - const float maxWidth) { + const double maxWidth) { auto value = detail::CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionWidth, value); @@ -911,14 +911,14 @@ YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { YOGA_EXPORT void YGNodeStyleSetMaxHeight( const YGNodeRef node, - const float maxHeight) { + const double maxHeight) { auto value = detail::CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionHeight, value); } YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent( const YGNodeRef node, - const float maxHeight) { + const double maxHeight) { auto value = detail::CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionHeight, value); @@ -959,18 +959,18 @@ YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { return node->getLayout().instanceName[edge]; \ } -YG_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[YGEdgeLeft]); -YG_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[YGEdgeTop]); -YG_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[YGEdgeRight]); -YG_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[YGEdgeBottom]); -YG_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth]); -YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]); +YG_NODE_LAYOUT_PROPERTY_IMPL(double, Left, position[YGEdgeLeft]); +YG_NODE_LAYOUT_PROPERTY_IMPL(double, Top, position[YGEdgeTop]); +YG_NODE_LAYOUT_PROPERTY_IMPL(double, Right, position[YGEdgeRight]); +YG_NODE_LAYOUT_PROPERTY_IMPL(double, Bottom, position[YGEdgeBottom]); +YG_NODE_LAYOUT_PROPERTY_IMPL(double, Width, dimensions[YGDimensionWidth]); +YG_NODE_LAYOUT_PROPERTY_IMPL(double, Height, dimensions[YGDimensionHeight]); YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction()); YG_NODE_LAYOUT_PROPERTY_IMPL(bool, HadOverflow, hadOverflow()); -YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin); -YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border); -YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding); +YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(double, Margin, margin); +YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(double, Border, border); +YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(double, Padding, padding); YOGA_EXPORT bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout( const YGNodeRef node) { @@ -981,13 +981,13 @@ std::atomic gCurrentGenerationCount(0); bool YGLayoutNodeInternal( const YGNodeRef node, - const float availableWidth, - const float availableHeight, + const double availableWidth, + const double availableHeight, const YGDirection ownerDirection, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, + const double ownerWidth, + const double ownerHeight, const bool performLayout, const LayoutPassReason reason, const YGConfigRef config, @@ -1027,10 +1027,10 @@ static const std::array pos = {{ static const std::array dim = { {YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}}; -static inline float YGNodePaddingAndBorderForAxis( +static inline double YGNodePaddingAndBorderForAxis( const YGNodeConstRef node, const YGFlexDirection axis, - const float widthSize) { + const double widthSize) { return (node->getLeadingPaddingAndBorder(axis, widthSize) + node->getTrailingPaddingAndBorder(axis, widthSize)) .unwrap(); @@ -1047,12 +1047,12 @@ static inline YGAlign YGNodeAlignItem(const YGNode* node, const YGNode* child) { return align; } -static float YGBaseline(const YGNodeRef node, void* layoutContext) { +static double YGBaseline(const YGNodeRef node, void* layoutContext) { if (node->hasBaselineFunc()) { Event::publish(node); - const float baseline = node->baseline( + const double baseline = node->baseline( node->getLayout().measuredDimensions[YGDimensionWidth], node->getLayout().measuredDimensions[YGDimensionHeight], layoutContext); @@ -1091,7 +1091,7 @@ static float YGBaseline(const YGNodeRef node, void* layoutContext) { return node->getLayout().measuredDimensions[YGDimensionHeight]; } - const float baseline = YGBaseline(baselineChild, layoutContext); + const double baseline = YGBaseline(baselineChild, layoutContext); return baseline + baselineChild->getLayout().position[YGEdgeTop]; } @@ -1114,10 +1114,10 @@ static bool YGIsBaselineLayout(const YGNodeRef node) { return false; } -static inline float YGNodeDimWithMargin( +static inline double YGNodeDimWithMargin( const YGNodeRef node, const YGFlexDirection axis, - const float widthSize) { + const double widthSize) { return node->getLayout().measuredDimensions[dim[axis]] + (node->getLeadingMargin(axis, widthSize) + node->getTrailingMargin(axis, widthSize)) @@ -1127,32 +1127,32 @@ static inline float YGNodeDimWithMargin( static inline bool YGNodeIsStyleDimDefined( const YGNodeRef node, const YGFlexDirection axis, - const float ownerSize) { + const double ownerSize) { bool isUndefined = YGFloatIsUndefined(node->getResolvedDimension(dim[axis]).value); return !( node->getResolvedDimension(dim[axis]).unit == YGUnitAuto || node->getResolvedDimension(dim[axis]).unit == YGUnitUndefined || (node->getResolvedDimension(dim[axis]).unit == YGUnitPoint && - !isUndefined && node->getResolvedDimension(dim[axis]).value < 0.0f) || + !isUndefined && node->getResolvedDimension(dim[axis]).value < 0.0) || (node->getResolvedDimension(dim[axis]).unit == YGUnitPercent && !isUndefined && - (node->getResolvedDimension(dim[axis]).value < 0.0f || + (node->getResolvedDimension(dim[axis]).value < 0.0 || YGFloatIsUndefined(ownerSize)))); } static inline bool YGNodeIsLayoutDimDefined( const YGNodeRef node, const YGFlexDirection axis) { - const float value = node->getLayout().measuredDimensions[dim[axis]]; - return !YGFloatIsUndefined(value) && value >= 0.0f; + const double value = node->getLayout().measuredDimensions[dim[axis]]; + return !YGFloatIsUndefined(value) && value >= 0.0; } static YGFloatOptional YGNodeBoundAxisWithinMinAndMax( const YGNodeConstRef node, const YGFlexDirection axis, const YGFloatOptional value, - const float axisSize) { + const double axisSize) { YGFloatOptional min; YGFloatOptional max; @@ -1181,12 +1181,12 @@ static YGFloatOptional YGNodeBoundAxisWithinMinAndMax( // Like YGNodeBoundAxisWithinMinAndMax but also ensures that the value doesn't // go below the padding and border amount. -static inline float YGNodeBoundAxis( +static inline double YGNodeBoundAxis( const YGNodeRef node, const YGFlexDirection axis, - const float value, - const float axisSize, - const float widthSize) { + const double value, + const double axisSize, + const double widthSize) { return YGFloatMax( YGNodeBoundAxisWithinMinAndMax( node, axis, YGFloatOptional{value}, axisSize) @@ -1198,7 +1198,7 @@ static void YGNodeSetChildTrailingPosition( const YGNodeRef node, const YGNodeRef child, const YGFlexDirection axis) { - const float size = child->getLayout().measuredDimensions[dim[axis]]; + const double size = child->getLayout().measuredDimensions[dim[axis]]; child->setLayoutPosition( node->getLayout().measuredDimensions[dim[axis]] - size - child->getLayout().position[pos[axis]], @@ -1208,10 +1208,10 @@ static void YGNodeSetChildTrailingPosition( static void YGConstrainMaxSizeForMode( const YGNodeConstRef node, const enum YGFlexDirection axis, - const float ownerAxisSize, - const float ownerWidth, + const double ownerAxisSize, + const double ownerWidth, YGMeasureMode* mode, - float* size) { + double* size) { const YGFloatOptional maxSize = YGResolveValue( node->getStyle().maxDimensions()[dim[axis]], ownerAxisSize) + @@ -1235,11 +1235,11 @@ static void YGConstrainMaxSizeForMode( static void YGNodeComputeFlexBasisForChild( const YGNodeRef node, const YGNodeRef child, - const float width, + const double width, const YGMeasureMode widthMode, - const float height, - const float ownerWidth, - const float ownerHeight, + const double height, + const double ownerWidth, + const double ownerHeight, const YGMeasureMode heightMode, const YGDirection direction, const YGConfigRef config, @@ -1250,11 +1250,11 @@ static void YGNodeComputeFlexBasisForChild( const YGFlexDirection mainAxis = YGResolveFlexDirection(node->getStyle().flexDirection(), direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - const float mainAxisSize = isMainAxisRow ? width : height; - const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; + const double mainAxisSize = isMainAxisRow ? width : height; + const double mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; - float childWidth; - float childHeight; + double childWidth; + double childHeight; YGMeasureMode childWidthMeasureMode; YGMeasureMode childHeightMeasureMode; @@ -1434,9 +1434,9 @@ static void YGNodeComputeFlexBasisForChild( static void YGNodeAbsoluteLayoutChild( const YGNodeRef node, const YGNodeRef child, - const float width, + const double width, const YGMeasureMode widthMode, - const float height, + const double height, const YGDirection direction, const YGConfigRef config, LayoutData& layoutMarkerData, @@ -1448,8 +1448,8 @@ static void YGNodeAbsoluteLayoutChild( const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction); const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); - float childWidth = YGUndefined; - float childHeight = YGUndefined; + double childWidth = YGUndefined; + double childHeight = YGUndefined; YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined; YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined; @@ -1590,7 +1590,7 @@ static void YGNodeAbsoluteLayoutChild( child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[mainAxis]] - child->getLayout().measuredDimensions[dim[mainAxis]]) / - 2.0f, + 2.0, leading[mainAxis]); } else if ( !child->isLeadingPositionDefined(mainAxis) && @@ -1619,7 +1619,7 @@ static void YGNodeAbsoluteLayoutChild( child->setLayoutPosition( (node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().measuredDimensions[dim[crossAxis]]) / - 2.0f, + 2.0, leading[crossAxis]); } else if ( !child->isLeadingPositionDefined(crossAxis) && @@ -1634,12 +1634,12 @@ static void YGNodeAbsoluteLayoutChild( static void YGNodeWithMeasureFuncSetMeasuredDimensions( const YGNodeRef node, - float availableWidth, - float availableHeight, + double availableWidth, + double availableHeight, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, + const double ownerWidth, + const double ownerHeight, LayoutData& layoutMarkerData, void* const layoutContext, const LayoutPassReason reason) { @@ -1657,16 +1657,16 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( const auto& padding = node->getLayout().padding; const auto& border = node->getLayout().border; - const float paddingAndBorderAxisRow = padding[YGEdgeLeft] + + const double paddingAndBorderAxisRow = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight]; - const float paddingAndBorderAxisColumn = padding[YGEdgeTop] + + const double paddingAndBorderAxisColumn = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom]; // We want to make sure we don't call measure with negative size - const float innerWidth = YGFloatIsUndefined(availableWidth) + const double innerWidth = YGFloatIsUndefined(availableWidth) ? availableWidth : YGFloatMax(0, availableWidth - paddingAndBorderAxisRow); - const float innerHeight = YGFloatIsUndefined(availableHeight) + const double innerHeight = YGFloatIsUndefined(availableHeight) ? availableHeight : YGFloatMax(0, availableHeight - paddingAndBorderAxisColumn); @@ -1741,16 +1741,16 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( // or the minimum size as indicated by the padding and border sizes. static void YGNodeEmptyContainerSetMeasuredDimensions( const YGNodeRef node, - const float availableWidth, - const float availableHeight, + const double availableWidth, + const double availableHeight, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight) { + const double ownerWidth, + const double ownerHeight) { const auto& padding = node->getLayout().padding; const auto& border = node->getLayout().border; - float width = availableWidth; + double width = availableWidth; if (widthMeasureMode == YGMeasureModeUndefined || widthMeasureMode == YGMeasureModeAtMost) { width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + @@ -1760,7 +1760,7 @@ static void YGNodeEmptyContainerSetMeasuredDimensions( YGNodeBoundAxis(node, YGFlexDirectionRow, width, ownerWidth, ownerWidth), YGDimensionWidth); - float height = availableHeight; + double height = availableHeight; if (heightMeasureMode == YGMeasureModeUndefined || heightMeasureMode == YGMeasureModeAtMost) { height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + @@ -1774,16 +1774,16 @@ static void YGNodeEmptyContainerSetMeasuredDimensions( static bool YGNodeFixedSizeSetMeasuredDimensions( const YGNodeRef node, - const float availableWidth, - const float availableHeight, + const double availableWidth, + const double availableHeight, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight) { + const double ownerWidth, + const double ownerHeight) { if ((!YGFloatIsUndefined(availableWidth) && - widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0.0f) || + widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0.0) || (!YGFloatIsUndefined(availableHeight) && - heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || + heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0) || (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { node->setLayoutMeasuredDimension( @@ -1792,8 +1792,8 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( YGFlexDirectionRow, YGFloatIsUndefined(availableWidth) || (widthMeasureMode == YGMeasureModeAtMost && - availableWidth < 0.0f) - ? 0.0f + availableWidth < 0.0) + ? 0.0 : availableWidth, ownerWidth, ownerWidth), @@ -1805,8 +1805,8 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( YGFlexDirectionColumn, YGFloatIsUndefined(availableHeight) || (heightMeasureMode == YGMeasureModeAtMost && - availableHeight < 0.0f) - ? 0.0f + availableHeight < 0.0) + ? 0.0 : availableHeight, ownerHeight, ownerWidth), @@ -1829,13 +1829,13 @@ static void YGZeroOutLayoutRecursivly( YGZeroOutLayoutRecursivly, layoutContext); } -static float YGNodeCalculateAvailableInnerDim( +static double YGNodeCalculateAvailableInnerDim( const YGNodeConstRef node, const YGDimension dimension, - const float availableDim, - const float paddingAndBorder, - const float ownerDim) { - float availableInnerDim = availableDim - paddingAndBorder; + const double availableDim, + const double paddingAndBorder, + const double ownerDim) { + double availableInnerDim = availableDim - paddingAndBorder; // Max dimension overrides predefined dimension value; Min dimension in turn // overrides both of the above if (!YGFloatIsUndefined(availableInnerDim)) { @@ -1843,14 +1843,14 @@ static float YGNodeCalculateAvailableInnerDim( // constraints const YGFloatOptional minDimensionOptional = YGResolveValue(node->getStyle().minDimensions()[dimension], ownerDim); - const float minInnerDim = minDimensionOptional.isUndefined() - ? 0.0f + const double minInnerDim = minDimensionOptional.isUndefined() + ? 0.0 : minDimensionOptional.unwrap() - paddingAndBorder; const YGFloatOptional maxDimensionOptional = YGResolveValue(node->getStyle().maxDimensions()[dimension], ownerDim); - const float maxInnerDim = maxDimensionOptional.isUndefined() + const double maxInnerDim = maxDimensionOptional.isUndefined() ? FLT_MAX : maxDimensionOptional.unwrap() - paddingAndBorder; availableInnerDim = @@ -1860,10 +1860,10 @@ static float YGNodeCalculateAvailableInnerDim( return availableInnerDim; } -static float YGNodeComputeFlexBasisForChildren( +static double YGNodeComputeFlexBasisForChildren( const YGNodeRef node, - const float availableInnerWidth, - const float availableInnerHeight, + const double availableInnerWidth, + const double availableInnerHeight, YGMeasureMode widthMeasureMode, YGMeasureMode heightMeasureMode, YGDirection direction, @@ -1874,7 +1874,7 @@ static float YGNodeComputeFlexBasisForChildren( void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { - float totalOuterFlexBasis = 0.0f; + double totalOuterFlexBasis = 0.0; YGNodeRef singleFlexChild = nullptr; const YGVector& children = node->getChildren(); YGMeasureMode measureModeMainDim = @@ -1886,8 +1886,8 @@ static float YGNodeComputeFlexBasisForChildren( for (auto child : children) { if (child->isNodeFlexible()) { if (singleFlexChild != nullptr || - YGFloatsEqual(child->resolveFlexGrow(), 0.0f) || - YGFloatsEqual(child->resolveFlexShrink(), 0.0f)) { + YGFloatsEqual(child->resolveFlexGrow(), 0.0) || + YGFloatsEqual(child->resolveFlexShrink(), 0.0)) { // There is already a flexible child, or this flexible child doesn't // have flexGrow and flexShrink, abort singleFlexChild = nullptr; @@ -1910,10 +1910,10 @@ static float YGNodeComputeFlexBasisForChildren( if (performLayout) { // Set the initial position (relative to the owner). const YGDirection childDirection = child->resolveDirection(direction); - const float mainDim = YGFlexDirectionIsRow(mainAxis) + const double mainDim = YGFlexDirectionIsRow(mainAxis) ? availableInnerWidth : availableInnerHeight; - const float crossDim = YGFlexDirectionIsRow(mainAxis) + const double crossDim = YGFlexDirectionIsRow(mainAxis) ? availableInnerHeight : availableInnerWidth; child->setPosition( @@ -1960,15 +1960,15 @@ static float YGNodeComputeFlexBasisForChildren( static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( const YGNodeRef& node, const YGDirection ownerDirection, - const float mainAxisownerSize, - const float availableInnerWidth, - const float availableInnerMainDim, + const double mainAxisownerSize, + const double availableInnerWidth, + const double availableInnerMainDim, const uint32_t startOfLineIndex, const uint32_t lineCount) { YGCollectFlexItemsRowValues flexAlgoRowMeasurement = {}; flexAlgoRowMeasurement.relativeChildren.reserve(node->getChildren().size()); - float sizeConsumedOnCurrentLineIncludingMinConstraint = 0; + double sizeConsumedOnCurrentLineIncludingMinConstraint = 0; const YGFlexDirection mainAxis = YGResolveFlexDirection( node->getStyle().flexDirection(), node->resolveDirection(ownerDirection)); const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; @@ -1982,9 +1982,9 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( continue; } child->setLineIndex(lineCount); - const float childMarginMainAxis = + const double childMarginMainAxis = child->getMarginForAxis(mainAxis, availableInnerWidth).unwrap(); - const float flexBasisWithMinAndMaxConstraints = + const double flexBasisWithMinAndMaxConstraints = YGNodeBoundAxisWithinMinAndMax( child, mainAxis, @@ -2040,16 +2040,16 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues( // of the flex items abide the min and max constraints. At the end of this // function the child nodes would have proper size. Prior using this function // please ensure that YGDistributeFreeSpaceFirstPass is called. -static float YGDistributeFreeSpaceSecondPass( +static double YGDistributeFreeSpaceSecondPass( YGCollectFlexItemsRowValues& collectedFlexItemsValues, const YGNodeRef node, const YGFlexDirection mainAxis, const YGFlexDirection crossAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, + const double mainAxisownerSize, + const double availableInnerMainDim, + const double availableInnerCrossDim, + const double availableInnerWidth, + const double availableInnerHeight, const bool flexBasisOverflows, const YGMeasureMode measureModeCrossDim, const bool performLayout, @@ -2058,10 +2058,10 @@ static float YGDistributeFreeSpaceSecondPass( void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { - float childFlexBasis = 0; - float flexShrinkScaledFactor = 0; - float flexGrowFactor = 0; - float deltaFreeSpace = 0; + double childFlexBasis = 0; + double flexShrinkScaledFactor = 0; + double flexGrowFactor = 0; + double deltaFreeSpace = 0; const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; @@ -2072,7 +2072,7 @@ static float YGDistributeFreeSpaceSecondPass( currentRelativeChild->getLayout().computedFlexBasis, mainAxisownerSize) .unwrap(); - float updatedMainSize = childFlexBasis; + double updatedMainSize = childFlexBasis; if (!YGFloatIsUndefined(collectedFlexItemsValues.remainingFreeSpace) && collectedFlexItemsValues.remainingFreeSpace < 0) { @@ -2080,7 +2080,7 @@ static float YGDistributeFreeSpaceSecondPass( -currentRelativeChild->resolveFlexShrink() * childFlexBasis; // Is this child able to shrink? if (flexShrinkScaledFactor != 0) { - float childSize; + double childSize; if (!YGFloatIsUndefined( collectedFlexItemsValues.totalFlexShrinkScaledFactors) && @@ -2121,15 +2121,15 @@ static float YGDistributeFreeSpaceSecondPass( deltaFreeSpace += updatedMainSize - childFlexBasis; - const float marginMain = + const double marginMain = currentRelativeChild->getMarginForAxis(mainAxis, availableInnerWidth) .unwrap(); - const float marginCross = + const double marginCross = currentRelativeChild->getMarginForAxis(crossAxis, availableInnerWidth) .unwrap(); - float childCrossSize; - float childMainSize = updatedMainSize + marginMain; + double childCrossSize; + double childMainSize = updatedMainSize + marginMain; YGMeasureMode childCrossMeasureMode; YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; @@ -2200,8 +2200,8 @@ static float YGDistributeFreeSpaceSecondPass( YGUnitAuto && currentRelativeChild->marginTrailingValue(crossAxis).unit != YGUnitAuto; - const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; - const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; + const double childWidth = isMainAxisRow ? childMainSize : childCrossSize; + const double childHeight = !isMainAxisRow ? childMainSize : childCrossSize; const YGMeasureMode childWidthMeasureMode = isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode; @@ -2241,17 +2241,17 @@ static float YGDistributeFreeSpaceSecondPass( static void YGDistributeFreeSpaceFirstPass( YGCollectFlexItemsRowValues& collectedFlexItemsValues, const YGFlexDirection mainAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerWidth) { - float flexShrinkScaledFactor = 0; - float flexGrowFactor = 0; - float baseMainSize = 0; - float boundMainSize = 0; - float deltaFreeSpace = 0; + const double mainAxisownerSize, + const double availableInnerMainDim, + const double availableInnerWidth) { + double flexShrinkScaledFactor = 0; + double flexGrowFactor = 0; + double baseMainSize = 0; + double boundMainSize = 0; + double deltaFreeSpace = 0; for (auto currentRelativeChild : collectedFlexItemsValues.relativeChildren) { - float childFlexBasis = + double childFlexBasis = YGNodeBoundAxisWithinMinAndMax( currentRelativeChild, mainAxis, @@ -2349,11 +2349,11 @@ static void YGResolveFlexibleLength( YGCollectFlexItemsRowValues& collectedFlexItemsValues, const YGFlexDirection mainAxis, const YGFlexDirection crossAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, + const double mainAxisownerSize, + const double availableInnerMainDim, + const double availableInnerCrossDim, + const double availableInnerWidth, + const double availableInnerHeight, const bool flexBasisOverflows, const YGMeasureMode measureModeCrossDim, const bool performLayout, @@ -2362,7 +2362,7 @@ static void YGResolveFlexibleLength( void* const layoutContext, const uint32_t depth, const uint32_t generationCount) { - const float originalFreeSpace = collectedFlexItemsValues.remainingFreeSpace; + const double originalFreeSpace = collectedFlexItemsValues.remainingFreeSpace; // First pass: detect the flex items whose min/max constraints trigger YGDistributeFreeSpaceFirstPass( collectedFlexItemsValues, @@ -2372,7 +2372,7 @@ static void YGResolveFlexibleLength( availableInnerWidth); // Second pass: resolve the sizes of the flexible items - const float distributedFreeSpace = YGDistributeFreeSpaceSecondPass( + const double distributedFreeSpace = YGDistributeFreeSpaceSecondPass( collectedFlexItemsValues, node, mainAxis, @@ -2403,17 +2403,17 @@ static void YGJustifyMainAxis( const YGFlexDirection crossAxis, const YGMeasureMode measureModeMainDim, const YGMeasureMode measureModeCrossDim, - const float mainAxisownerSize, - const float ownerWidth, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, + const double mainAxisownerSize, + const double ownerWidth, + const double availableInnerMainDim, + const double availableInnerCrossDim, + const double availableInnerWidth, const bool performLayout, void* const layoutContext) { const auto& style = node->getStyle(); - const float leadingPaddingAndBorderMain = + const double leadingPaddingAndBorderMain = node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); - const float trailingPaddingAndBorderMain = + const double trailingPaddingAndBorderMain = node->getTrailingPaddingAndBorder(mainAxis, ownerWidth).unwrap(); // If we are using "at most" rules in the main axis, make sure that // remainingFreeSpace is 0 when min main dimension is not given @@ -2429,12 +2429,12 @@ static void YGJustifyMainAxis( // `minAvailableMainDim` denotes minimum available space in which child // can be laid out, it will exclude space consumed by padding and border. - const float minAvailableMainDim = + const double minAvailableMainDim = YGResolveValue( style.minDimensions()[dim[mainAxis]], mainAxisownerSize) .unwrap() - leadingPaddingAndBorderMain - trailingPaddingAndBorderMain; - const float occupiedSpaceByChildNodes = + const double occupiedSpaceByChildNodes = availableInnerMainDim - collectedFlexItemsValues.remainingFreeSpace; collectedFlexItemsValues.remainingFreeSpace = YGFloatMax(0, minAvailableMainDim - occupiedSpaceByChildNodes); @@ -2461,8 +2461,8 @@ static void YGJustifyMainAxis( // In order to position the elements in the main axis, we have two controls. // The space between the beginning and the first element and the space between // each two elements. - float leadingMainDim = 0; - float betweenMainDim = 0; + double leadingMainDim = 0; + double betweenMainDim = 0; const YGJustify justifyContent = node->getStyle().justifyContent(); if (numberOfAutoMarginsOnCurrentLine == 0) { @@ -2503,8 +2503,8 @@ static void YGJustifyMainAxis( leadingPaddingAndBorderMain + leadingMainDim; collectedFlexItemsValues.crossDim = 0; - float maxAscentForCurrentLine = 0; - float maxDescentForCurrentLine = 0; + double maxAscentForCurrentLine = 0; + double maxDescentForCurrentLine = 0; bool isNodeBaselineLayout = YGIsBaselineLayout(node); for (uint32_t i = startOfLineIndex; i < collectedFlexItemsValues.endOfLineIndex; @@ -2570,12 +2570,12 @@ static void YGJustifyMainAxis( if (isNodeBaselineLayout) { // If the child is baseline aligned then the cross dimension is // calculated by adding maxAscent and maxDescent from the baseline. - const float ascent = YGBaseline(child, layoutContext) + + const double ascent = YGBaseline(child, layoutContext) + child ->getLeadingMargin( YGFlexDirectionColumn, availableInnerWidth) .unwrap(); - const float descent = + const double descent = child->getLayout().measuredDimensions[YGDimensionHeight] + child ->getMarginForAxis( @@ -2679,13 +2679,13 @@ static void YGJustifyMainAxis( // static void YGNodelayoutImpl( const YGNodeRef node, - const float availableWidth, - const float availableHeight, + const double availableWidth, + const double availableHeight, const YGDirection ownerDirection, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, + const double ownerWidth, + const double ownerHeight, const bool performLayout, const YGConfigRef config, LayoutData& layoutMarkerData, @@ -2723,21 +2723,21 @@ static void YGNodelayoutImpl( direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight; const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft; - const float marginRowLeading = + const double marginRowLeading = node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(); node->setLayoutMargin(marginRowLeading, startEdge); - const float marginRowTrailing = + const double marginRowTrailing = node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(); node->setLayoutMargin(marginRowTrailing, endEdge); - const float marginColumnLeading = + const double marginColumnLeading = node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(); node->setLayoutMargin(marginColumnLeading, YGEdgeTop); - const float marginColumnTrailing = + const double marginColumnTrailing = node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(); node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom); - const float marginAxisRow = marginRowLeading + marginRowTrailing; - const float marginAxisColumn = marginColumnLeading + marginColumnTrailing; + const double marginAxisRow = marginRowLeading + marginRowTrailing; + const double marginAxisColumn = marginColumnLeading + marginColumnTrailing; node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge); node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge); @@ -2812,16 +2812,16 @@ static void YGNodelayoutImpl( const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis); const bool isNodeFlexWrap = node->getStyle().flexWrap() != YGWrapNoWrap; - const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; - const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; + const double mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; + const double crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; - const float paddingAndBorderAxisMain = + const double paddingAndBorderAxisMain = YGNodePaddingAndBorderForAxis(node, mainAxis, ownerWidth); - const float leadingPaddingAndBorderCross = + const double leadingPaddingAndBorderCross = node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); - const float trailingPaddingAndBorderCross = + const double trailingPaddingAndBorderCross = node->getTrailingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); - const float paddingAndBorderAxisCross = + const double paddingAndBorderAxisCross = leadingPaddingAndBorderCross + trailingPaddingAndBorderCross; YGMeasureMode measureModeMainDim = @@ -2829,34 +2829,34 @@ static void YGNodelayoutImpl( YGMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; - const float paddingAndBorderAxisRow = + const double paddingAndBorderAxisRow = isMainAxisRow ? paddingAndBorderAxisMain : paddingAndBorderAxisCross; - const float paddingAndBorderAxisColumn = + const double paddingAndBorderAxisColumn = isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS - float availableInnerWidth = YGNodeCalculateAvailableInnerDim( + double availableInnerWidth = YGNodeCalculateAvailableInnerDim( node, YGDimensionWidth, availableWidth - marginAxisRow, paddingAndBorderAxisRow, ownerWidth); - float availableInnerHeight = YGNodeCalculateAvailableInnerDim( + double availableInnerHeight = YGNodeCalculateAvailableInnerDim( node, YGDimensionHeight, availableHeight - marginAxisColumn, paddingAndBorderAxisColumn, ownerHeight); - float availableInnerMainDim = + double availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight; - const float availableInnerCrossDim = + const double availableInnerCrossDim = isMainAxisRow ? availableInnerHeight : availableInnerWidth; // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM - float totalOuterFlexBasis = YGNodeComputeFlexBasisForChildren( + double totalOuterFlexBasis = YGNodeComputeFlexBasisForChildren( node, availableInnerWidth, availableInnerHeight, @@ -2888,10 +2888,10 @@ static void YGNodelayoutImpl( uint32_t lineCount = 0; // Accumulated cross dimensions of all lines so far. - float totalLineCrossDim = 0; + double totalLineCrossDim = 0; // Max main dimension of all the lines. - float maxLineMainDim = 0; + double maxLineMainDim = 0; YGCollectFlexItemsRowValues collectedFlexItemsValues; for (; endOfLineIndex < childCount; lineCount++, startOfLineIndex = endOfLineIndex) { @@ -2921,24 +2921,24 @@ static void YGNodelayoutImpl( if (measureModeMainDim != YGMeasureModeExactly) { const auto& minDimensions = node->getStyle().minDimensions(); const auto& maxDimensions = node->getStyle().maxDimensions(); - const float minInnerWidth = + const double minInnerWidth = YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - paddingAndBorderAxisRow; - const float maxInnerWidth = + const double maxInnerWidth = YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - paddingAndBorderAxisRow; - const float minInnerHeight = + const double minInnerHeight = YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight) .unwrap() - paddingAndBorderAxisColumn; - const float maxInnerHeight = + const double maxInnerHeight = YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight) .unwrap() - paddingAndBorderAxisColumn; - const float minInnerMainDim = + const double minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; - const float maxInnerMainDim = + const double maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight; if (!YGFloatIsUndefined(minInnerMainDim) && @@ -3031,7 +3031,7 @@ static void YGNodelayoutImpl( performLayout, layoutContext); - float containerCrossAxis = availableInnerCrossDim; + double containerCrossAxis = availableInnerCrossDim; if (measureModeCrossDim == YGMeasureModeUndefined || measureModeCrossDim == YGMeasureModeAtMost) { // Compute the cross axis from the max cross dimension of the children. @@ -3094,7 +3094,7 @@ static void YGNodelayoutImpl( pos[crossAxis]); } } else { - float leadingCrossDim = leadingPaddingAndBorderCross; + double leadingCrossDim = leadingPaddingAndBorderCross; // For a relative children, we're either using alignItems (owner) or // alignSelf (child) in order to determine the position in the cross @@ -3111,10 +3111,10 @@ static void YGNodelayoutImpl( // no need to stretch. if (!YGNodeIsStyleDimDefined( child, crossAxis, availableInnerCrossDim)) { - float childMainSize = + double childMainSize = child->getLayout().measuredDimensions[dim[mainAxis]]; const auto& childStyle = child->getStyle(); - float childCrossSize = !childStyle.aspectRatio().isUndefined() + double childCrossSize = !childStyle.aspectRatio().isUndefined() ? child->getMarginForAxis(crossAxis, availableInnerWidth) .unwrap() + (isMainAxisRow @@ -3143,9 +3143,9 @@ static void YGNodelayoutImpl( &childCrossMeasureMode, &childCrossSize); - const float childWidth = + const double childWidth = isMainAxisRow ? childMainSize : childCrossSize; - const float childHeight = + const double childHeight = !isMainAxisRow ? childMainSize : childCrossSize; auto alignContent = node->getStyle().alignContent(); @@ -3180,18 +3180,18 @@ static void YGNodelayoutImpl( generationCount); } } else { - const float remainingCrossDim = containerCrossAxis - + const double remainingCrossDim = containerCrossAxis - YGNodeDimWithMargin(child, crossAxis, availableInnerWidth); if (child->marginLeadingValue(crossAxis).unit == YGUnitAuto && child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { - leadingCrossDim += YGFloatMax(0.0f, remainingCrossDim / 2); + leadingCrossDim += YGFloatMax(0.0, remainingCrossDim / 2); } else if ( child->marginTrailingValue(crossAxis).unit == YGUnitAuto) { // No-Op } else if ( child->marginLeadingValue(crossAxis).unit == YGUnitAuto) { - leadingCrossDim += YGFloatMax(0.0f, remainingCrossDim); + leadingCrossDim += YGFloatMax(0.0, remainingCrossDim); } else if (alignItem == YGAlignFlexStart) { // No-Op } else if (alignItem == YGAlignCenter) { @@ -3217,10 +3217,10 @@ static void YGNodelayoutImpl( // STEP 8: MULTI-LINE CONTENT ALIGNMENT // currentLead stores the size of the cross dim if (performLayout && (isNodeFlexWrap || YGIsBaselineLayout(node))) { - float crossDimLead = 0; - float currentLead = leadingPaddingAndBorderCross; + double crossDimLead = 0; + double currentLead = leadingPaddingAndBorderCross; if (!YGFloatIsUndefined(availableInnerCrossDim)) { - const float remainingAlignContentDim = + const double remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; switch (node->getStyle().alignContent()) { case YGAlignFlexEnd: @@ -3261,9 +3261,9 @@ static void YGNodelayoutImpl( uint32_t ii; // compute the line's height and find the endIndex - float lineHeight = 0; - float maxAscentForCurrentLine = 0; - float maxDescentForCurrentLine = 0; + double lineHeight = 0; + double maxAscentForCurrentLine = 0; + double maxDescentForCurrentLine = 0; for (ii = startIndex; ii < childCount; ii++) { const YGNodeRef child = node->getChild(ii); if (child->getStyle().display() == YGDisplayNone) { @@ -3281,12 +3281,12 @@ static void YGNodelayoutImpl( .unwrap()); } if (YGNodeAlignItem(node, child) == YGAlignBaseline) { - const float ascent = YGBaseline(child, layoutContext) + + const double ascent = YGBaseline(child, layoutContext) + child ->getLeadingMargin( YGFlexDirectionColumn, availableInnerWidth) .unwrap(); - const float descent = + const double descent = child->getLayout().measuredDimensions[YGDimensionHeight] + child ->getMarginForAxis( @@ -3331,7 +3331,7 @@ static void YGNodelayoutImpl( break; } case YGAlignCenter: { - float childHeight = + double childHeight = child->getLayout().measuredDimensions[dim[crossAxis]]; child->setLayoutPosition( @@ -3350,14 +3350,14 @@ static void YGNodelayoutImpl( // measured with the owners height yet. if (!YGNodeIsStyleDimDefined( child, crossAxis, availableInnerCrossDim)) { - const float childWidth = isMainAxisRow + const double childWidth = isMainAxisRow ? (child->getLayout() .measuredDimensions[YGDimensionWidth] + child->getMarginForAxis(mainAxis, availableInnerWidth) .unwrap()) : lineHeight; - const float childHeight = !isMainAxisRow + const double childHeight = !isMainAxisRow ? (child->getLayout() .measuredDimensions[YGDimensionHeight] + child->getMarginForAxis(crossAxis, availableInnerWidth) @@ -3590,17 +3590,17 @@ static const char* YGMeasureModeName( static inline bool YGMeasureModeSizeIsExactAndMatchesOldMeasuredSize( YGMeasureMode sizeMode, - float size, - float lastComputedSize) { + double size, + double lastComputedSize) { return sizeMode == YGMeasureModeExactly && YGFloatsEqual(size, lastComputedSize); } static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits( YGMeasureMode sizeMode, - float size, + double size, YGMeasureMode lastSizeMode, - float lastComputedSize) { + double lastComputedSize) { return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined && (size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize)); @@ -3608,10 +3608,10 @@ static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits( static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid( YGMeasureMode sizeMode, - float size, + double size, YGMeasureMode lastSizeMode, - float lastSize, - float lastComputedSize) { + double lastSize, + double lastComputedSize) { return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost && !YGFloatIsUndefined(lastSize) && !YGFloatIsUndefined(size) && !YGFloatIsUndefined(lastComputedSize) && @@ -3619,7 +3619,7 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid( (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize)); } -YOGA_EXPORT float YGRoundValueToPixelGrid( +YOGA_EXPORT double YGRoundValueToPixelGrid( const double value, const double pointScaleFactor, const bool forceCeil, @@ -3636,12 +3636,12 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( // - x = 2.2: floor( 2.2) = 2, ceil( 2.2) = 3 // - x = -2.2: floor(-2.2) = -3, ceil(-2.2) = -2 // - // Regarding `fmodf`. For fractional negative numbers, `fmodf` returns a - // negative number. For example, `fmodf(-2.2) = -0.2`. However, we want + // Regarding `fmod`. For fractional negative numbers, `fmod` returns a + // negative number. For example, `fmod(-2.2) = -0.2`. However, we want // `fractial` to be the number such that subtracting it from `value` will // give us `floor(value)`. In the case of negative numbers, adding 1 to - // `fmodf(value)` gives us this. Let's continue the example from above: - // - fractial = fmodf(-2.2) = -0.2 + // `fmod(value)` gives us this. Let's continue the example from above: + // - fractial = fmod(-2.2) = -0.2 // - Add 1 to the fraction: fractial2 = fractial + 1 = -0.2 + 1 = 0.8 // - Finding the `floor`: -2.2 - fractial2 = -2.2 - 0.8 = -3 ++fractial; @@ -3667,22 +3667,22 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( return (YGDoubleIsUndefined(scaledValue) || YGDoubleIsUndefined(pointScaleFactor)) ? YGUndefined - : (float) (scaledValue / pointScaleFactor); + : (scaledValue / pointScaleFactor); } YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( const YGMeasureMode widthMode, - const float width, + const double width, const YGMeasureMode heightMode, - const float height, + const double height, const YGMeasureMode lastWidthMode, - const float lastWidth, + const double lastWidth, const YGMeasureMode lastHeightMode, - const float lastHeight, - const float lastComputedWidth, - const float lastComputedHeight, - const float marginRow, - const float marginColumn, + const double lastHeight, + const double lastComputedWidth, + const double lastComputedHeight, + const double marginRow, + const double marginColumn, const YGConfigRef config) { if ((!YGFloatIsUndefined(lastComputedHeight) && lastComputedHeight < 0) || (!YGFloatIsUndefined(lastComputedWidth) && lastComputedWidth < 0)) { @@ -3690,17 +3690,17 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( } bool useRoundedComparison = config != nullptr && config->pointScaleFactor != 0; - const float effectiveWidth = useRoundedComparison + const double effectiveWidth = useRoundedComparison ? YGRoundValueToPixelGrid(width, config->pointScaleFactor, false, false) : width; - const float effectiveHeight = useRoundedComparison + const double effectiveHeight = useRoundedComparison ? YGRoundValueToPixelGrid(height, config->pointScaleFactor, false, false) : height; - const float effectiveLastWidth = useRoundedComparison + const double effectiveLastWidth = useRoundedComparison ? YGRoundValueToPixelGrid( lastWidth, config->pointScaleFactor, false, false) : lastWidth; - const float effectiveLastHeight = useRoundedComparison + const double effectiveLastHeight = useRoundedComparison ? YGRoundValueToPixelGrid( lastHeight, config->pointScaleFactor, false, false) : lastHeight; @@ -3752,13 +3752,13 @@ YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( // bool YGLayoutNodeInternal( const YGNodeRef node, - const float availableWidth, - const float availableHeight, + const double availableWidth, + const double availableHeight, const YGDirection ownerDirection, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, - const float ownerWidth, - const float ownerHeight, + const double ownerWidth, + const double ownerHeight, const bool performLayout, const LayoutPassReason reason, const YGConfigRef config, @@ -3796,9 +3796,9 @@ bool YGLayoutNodeInternal( // they are the most expensive to measure, so it's worth avoiding redundant // measurements if at all possible. if (node->hasMeasureFunc()) { - const float marginAxisRow = + const double marginAxisRow = node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = + const double marginAxisColumn = node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); // First, try to use the layout cache. @@ -4020,16 +4020,16 @@ bool YGLayoutNodeInternal( YOGA_EXPORT void YGConfigSetPointScaleFactor( const YGConfigRef config, - const float pixelsInPoint) { + const double pixelsInPoint) { YGAssertWithConfig( config, - pixelsInPoint >= 0.0f, + pixelsInPoint >= 0.0, "Scale factor should not be less than zero"); // We store points for Pixel as we will use it for rounding - if (pixelsInPoint == 0.0f) { + if (pixelsInPoint == 0.0) { // Zero is used to skip rounding - config->pointScaleFactor = 0.0f; + config->pointScaleFactor = 0.0; } else { config->pointScaleFactor = pixelsInPoint; } @@ -4040,7 +4040,7 @@ static void YGRoundToPixelGrid( const double pointScaleFactor, const double absoluteLeft, const double absoluteTop) { - if (pointScaleFactor == 0.0f) { + if (pointScaleFactor == 0.0) { return; } @@ -4117,8 +4117,8 @@ static void unsetUseLegacyFlagRecursively(YGNodeRef node) { YOGA_EXPORT void YGNodeCalculateLayoutWithContext( const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, + const double ownerWidth, + const double ownerHeight, const YGDirection ownerDirection, void* layoutContext) { @@ -4130,7 +4130,7 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( // the input parameters don't change. gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed); node->resolveDimension(); - float width = YGUndefined; + double width = YGUndefined; YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; const auto& maxDimensions = node->getStyle().maxDimensions(); if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, ownerWidth)) { @@ -4151,7 +4151,7 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( : YGMeasureModeExactly; } - float height = YGUndefined; + double height = YGUndefined; YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, ownerHeight)) { height = (YGResolveValue( @@ -4188,7 +4188,7 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( gCurrentGenerationCount.load(std::memory_order_relaxed))) { node->setPosition( node->getLayout().direction(), ownerWidth, ownerHeight, ownerWidth); - YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f); + YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0, 0.0); #ifdef DEBUG if (node->getConfig()->printTree) { @@ -4242,8 +4242,8 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( YGRoundToPixelGrid( nodeWithoutLegacyFlag, nodeWithoutLegacyFlag->getConfig()->pointScaleFactor, - 0.0f, - 0.0f); + 0.0, + 0.0); // Set whether the two layouts are different or not. auto neededLegacyStretchBehaviour = @@ -4265,8 +4265,8 @@ YOGA_EXPORT void YGNodeCalculateLayoutWithContext( YOGA_EXPORT void YGNodeCalculateLayout( const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, + const double ownerWidth, + const double ownerHeight, const YGDirection ownerDirection) { YGNodeCalculateLayoutWithContext( node, ownerWidth, ownerHeight, ownerDirection, nullptr); diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 86cd65e2..aa9439ca 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -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 #include @@ -371,4 +372,5 @@ void YGTraversePreOrder( void YGNodeSetChildren(YGNodeRef owner, const std::vector& children); +YG_EXTERN_CXX_END #endif diff --git a/yoga/event/event.h b/yoga/event/event.h index 404ec376..d375846f 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -127,12 +127,12 @@ struct Event::TypedData { template <> struct Event::TypedData { 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; }; -- 2.50.1.windows.1