diff --git a/csharp/tests/Facebook.Yoga/YGRoundingTest.cs b/csharp/tests/Facebook.Yoga/YGRoundingTest.cs
index f1a60944..8c82ce02 100644
--- a/csharp/tests/Facebook.Yoga/YGRoundingTest.cs
+++ b/csharp/tests/Facebook.Yoga/YGRoundingTest.cs
@@ -684,17 +684,17 @@ namespace Facebook.Yoga
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
- Assert.AreEqual(64f, root_child0.LayoutHeight);
+ Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
- Assert.AreEqual(25f, root_child1.LayoutHeight);
+ Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
- Assert.AreEqual(24f, root_child2.LayoutHeight);
+ Assert.AreEqual(25f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
@@ -707,17 +707,17 @@ namespace Facebook.Yoga
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
- Assert.AreEqual(64f, root_child0.LayoutHeight);
+ Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
- Assert.AreEqual(25f, root_child1.LayoutHeight);
+ Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
- Assert.AreEqual(24f, root_child2.LayoutHeight);
+ Assert.AreEqual(25f, root_child2.LayoutHeight);
}
[Test]
@@ -793,5 +793,308 @@ namespace Facebook.Yoga
Assert.AreEqual(24f, root_child2.LayoutHeight);
}
+ [Test]
+ public void Test_rounding_inner_node_controversy_horizontal()
+ {
+ YogaConfig config = new YogaConfig();
+ config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
+
+ YogaNode root = new YogaNode(config);
+ root.FlexDirection = YogaFlexDirection.Row;
+ root.Width = 320;
+
+ YogaNode root_child0 = new YogaNode(config);
+ root_child0.FlexGrow = 1;
+ root_child0.Height = 10;
+ root.Insert(0, root_child0);
+
+ YogaNode root_child1 = new YogaNode(config);
+ root_child1.FlexGrow = 1;
+ root_child1.Height = 10;
+ root.Insert(1, root_child1);
+
+ YogaNode root_child1_child0 = new YogaNode(config);
+ root_child1_child0.FlexGrow = 1;
+ root_child1_child0.Height = 10;
+ root_child1.Insert(0, root_child1_child0);
+
+ YogaNode root_child2 = new YogaNode(config);
+ root_child2.FlexGrow = 1;
+ root_child2.Height = 10;
+ root.Insert(2, root_child2);
+ root.StyleDirection = YogaDirection.LTR;
+ root.CalculateLayout();
+
+ Assert.AreEqual(0f, root.LayoutX);
+ Assert.AreEqual(0f, root.LayoutY);
+ Assert.AreEqual(320f, root.LayoutWidth);
+ Assert.AreEqual(10f, root.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child0.LayoutX);
+ Assert.AreEqual(0f, root_child0.LayoutY);
+ Assert.AreEqual(107f, root_child0.LayoutWidth);
+ Assert.AreEqual(10f, root_child0.LayoutHeight);
+
+ Assert.AreEqual(107f, root_child1.LayoutX);
+ Assert.AreEqual(0f, root_child1.LayoutY);
+ Assert.AreEqual(106f, root_child1.LayoutWidth);
+ Assert.AreEqual(10f, root_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child0.LayoutY);
+ Assert.AreEqual(106f, root_child1_child0.LayoutWidth);
+ Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(213f, root_child2.LayoutX);
+ Assert.AreEqual(0f, root_child2.LayoutY);
+ Assert.AreEqual(107f, root_child2.LayoutWidth);
+ Assert.AreEqual(10f, root_child2.LayoutHeight);
+
+ root.StyleDirection = YogaDirection.RTL;
+ root.CalculateLayout();
+
+ Assert.AreEqual(0f, root.LayoutX);
+ Assert.AreEqual(0f, root.LayoutY);
+ Assert.AreEqual(320f, root.LayoutWidth);
+ Assert.AreEqual(10f, root.LayoutHeight);
+
+ Assert.AreEqual(213f, root_child0.LayoutX);
+ Assert.AreEqual(0f, root_child0.LayoutY);
+ Assert.AreEqual(107f, root_child0.LayoutWidth);
+ Assert.AreEqual(10f, root_child0.LayoutHeight);
+
+ Assert.AreEqual(107f, root_child1.LayoutX);
+ Assert.AreEqual(0f, root_child1.LayoutY);
+ Assert.AreEqual(106f, root_child1.LayoutWidth);
+ Assert.AreEqual(10f, root_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child0.LayoutY);
+ Assert.AreEqual(106f, root_child1_child0.LayoutWidth);
+ Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child2.LayoutX);
+ Assert.AreEqual(0f, root_child2.LayoutY);
+ Assert.AreEqual(107f, root_child2.LayoutWidth);
+ Assert.AreEqual(10f, root_child2.LayoutHeight);
+ }
+
+ [Test]
+ public void Test_rounding_inner_node_controversy_vertical()
+ {
+ YogaConfig config = new YogaConfig();
+ config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
+
+ YogaNode root = new YogaNode(config);
+ root.Height = 320;
+
+ YogaNode root_child0 = new YogaNode(config);
+ root_child0.FlexGrow = 1;
+ root_child0.Width = 10;
+ root.Insert(0, root_child0);
+
+ YogaNode root_child1 = new YogaNode(config);
+ root_child1.FlexGrow = 1;
+ root_child1.Width = 10;
+ root.Insert(1, root_child1);
+
+ YogaNode root_child1_child0 = new YogaNode(config);
+ root_child1_child0.FlexGrow = 1;
+ root_child1_child0.Width = 10;
+ root_child1.Insert(0, root_child1_child0);
+
+ YogaNode root_child2 = new YogaNode(config);
+ root_child2.FlexGrow = 1;
+ root_child2.Width = 10;
+ root.Insert(2, root_child2);
+ root.StyleDirection = YogaDirection.LTR;
+ root.CalculateLayout();
+
+ Assert.AreEqual(0f, root.LayoutX);
+ Assert.AreEqual(0f, root.LayoutY);
+ Assert.AreEqual(10f, root.LayoutWidth);
+ Assert.AreEqual(320f, root.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child0.LayoutX);
+ Assert.AreEqual(0f, root_child0.LayoutY);
+ Assert.AreEqual(10f, root_child0.LayoutWidth);
+ Assert.AreEqual(107f, root_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1.LayoutX);
+ Assert.AreEqual(107f, root_child1.LayoutY);
+ Assert.AreEqual(10f, root_child1.LayoutWidth);
+ Assert.AreEqual(106f, root_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child0.LayoutY);
+ Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
+ Assert.AreEqual(106f, root_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child2.LayoutX);
+ Assert.AreEqual(213f, root_child2.LayoutY);
+ Assert.AreEqual(10f, root_child2.LayoutWidth);
+ Assert.AreEqual(107f, root_child2.LayoutHeight);
+
+ root.StyleDirection = YogaDirection.RTL;
+ root.CalculateLayout();
+
+ Assert.AreEqual(0f, root.LayoutX);
+ Assert.AreEqual(0f, root.LayoutY);
+ Assert.AreEqual(10f, root.LayoutWidth);
+ Assert.AreEqual(320f, root.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child0.LayoutX);
+ Assert.AreEqual(0f, root_child0.LayoutY);
+ Assert.AreEqual(10f, root_child0.LayoutWidth);
+ Assert.AreEqual(107f, root_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1.LayoutX);
+ Assert.AreEqual(107f, root_child1.LayoutY);
+ Assert.AreEqual(10f, root_child1.LayoutWidth);
+ Assert.AreEqual(106f, root_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child0.LayoutY);
+ Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
+ Assert.AreEqual(106f, root_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child2.LayoutX);
+ Assert.AreEqual(213f, root_child2.LayoutY);
+ Assert.AreEqual(10f, root_child2.LayoutWidth);
+ Assert.AreEqual(107f, root_child2.LayoutHeight);
+ }
+
+ [Test]
+ public void Test_rounding_inner_node_controversy_combined()
+ {
+ YogaConfig config = new YogaConfig();
+ config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
+
+ YogaNode root = new YogaNode(config);
+ root.FlexDirection = YogaFlexDirection.Row;
+ root.Width = 640;
+ root.Height = 320;
+
+ YogaNode root_child0 = new YogaNode(config);
+ root_child0.FlexGrow = 1;
+ root_child0.Height = 100.Percent();
+ root.Insert(0, root_child0);
+
+ YogaNode root_child1 = new YogaNode(config);
+ root_child1.FlexGrow = 1;
+ root_child1.Height = 100.Percent();
+ root.Insert(1, root_child1);
+
+ YogaNode root_child1_child0 = new YogaNode(config);
+ root_child1_child0.FlexGrow = 1;
+ root_child1_child0.Width = 100.Percent();
+ root_child1.Insert(0, root_child1_child0);
+
+ YogaNode root_child1_child1 = new YogaNode(config);
+ root_child1_child1.FlexGrow = 1;
+ root_child1_child1.Width = 100.Percent();
+ root_child1.Insert(1, root_child1_child1);
+
+ YogaNode root_child1_child1_child0 = new YogaNode(config);
+ root_child1_child1_child0.FlexGrow = 1;
+ root_child1_child1_child0.Width = 100.Percent();
+ root_child1_child1.Insert(0, root_child1_child1_child0);
+
+ YogaNode root_child1_child2 = new YogaNode(config);
+ root_child1_child2.FlexGrow = 1;
+ root_child1_child2.Width = 100.Percent();
+ root_child1.Insert(2, root_child1_child2);
+
+ YogaNode root_child2 = new YogaNode(config);
+ root_child2.FlexGrow = 1;
+ root_child2.Height = 100.Percent();
+ root.Insert(2, root_child2);
+ root.StyleDirection = YogaDirection.LTR;
+ root.CalculateLayout();
+
+ Assert.AreEqual(0f, root.LayoutX);
+ Assert.AreEqual(0f, root.LayoutY);
+ Assert.AreEqual(640f, root.LayoutWidth);
+ Assert.AreEqual(320f, root.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child0.LayoutX);
+ Assert.AreEqual(0f, root_child0.LayoutY);
+ Assert.AreEqual(213f, root_child0.LayoutWidth);
+ Assert.AreEqual(320f, root_child0.LayoutHeight);
+
+ Assert.AreEqual(213f, root_child1.LayoutX);
+ Assert.AreEqual(0f, root_child1.LayoutY);
+ Assert.AreEqual(214f, root_child1.LayoutWidth);
+ Assert.AreEqual(320f, root_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child0.LayoutY);
+ Assert.AreEqual(214f, root_child1_child0.LayoutWidth);
+ Assert.AreEqual(107f, root_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child1.LayoutX);
+ Assert.AreEqual(107f, root_child1_child1.LayoutY);
+ Assert.AreEqual(214f, root_child1_child1.LayoutWidth);
+ Assert.AreEqual(106f, root_child1_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child1_child0.LayoutY);
+ Assert.AreEqual(214f, root_child1_child1_child0.LayoutWidth);
+ Assert.AreEqual(106f, root_child1_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child2.LayoutX);
+ Assert.AreEqual(213f, root_child1_child2.LayoutY);
+ Assert.AreEqual(214f, root_child1_child2.LayoutWidth);
+ Assert.AreEqual(107f, root_child1_child2.LayoutHeight);
+
+ Assert.AreEqual(427f, root_child2.LayoutX);
+ Assert.AreEqual(0f, root_child2.LayoutY);
+ Assert.AreEqual(213f, root_child2.LayoutWidth);
+ Assert.AreEqual(320f, root_child2.LayoutHeight);
+
+ root.StyleDirection = YogaDirection.RTL;
+ root.CalculateLayout();
+
+ Assert.AreEqual(0f, root.LayoutX);
+ Assert.AreEqual(0f, root.LayoutY);
+ Assert.AreEqual(640f, root.LayoutWidth);
+ Assert.AreEqual(320f, root.LayoutHeight);
+
+ Assert.AreEqual(427f, root_child0.LayoutX);
+ Assert.AreEqual(0f, root_child0.LayoutY);
+ Assert.AreEqual(213f, root_child0.LayoutWidth);
+ Assert.AreEqual(320f, root_child0.LayoutHeight);
+
+ Assert.AreEqual(213f, root_child1.LayoutX);
+ Assert.AreEqual(0f, root_child1.LayoutY);
+ Assert.AreEqual(214f, root_child1.LayoutWidth);
+ Assert.AreEqual(320f, root_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child0.LayoutY);
+ Assert.AreEqual(214f, root_child1_child0.LayoutWidth);
+ Assert.AreEqual(107f, root_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child1.LayoutX);
+ Assert.AreEqual(107f, root_child1_child1.LayoutY);
+ Assert.AreEqual(214f, root_child1_child1.LayoutWidth);
+ Assert.AreEqual(106f, root_child1_child1.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child1_child0.LayoutX);
+ Assert.AreEqual(0f, root_child1_child1_child0.LayoutY);
+ Assert.AreEqual(214f, root_child1_child1_child0.LayoutWidth);
+ Assert.AreEqual(106f, root_child1_child1_child0.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child1_child2.LayoutX);
+ Assert.AreEqual(213f, root_child1_child2.LayoutY);
+ Assert.AreEqual(214f, root_child1_child2.LayoutWidth);
+ Assert.AreEqual(107f, root_child1_child2.LayoutHeight);
+
+ Assert.AreEqual(0f, root_child2.LayoutX);
+ Assert.AreEqual(0f, root_child2.LayoutY);
+ Assert.AreEqual(213f, root_child2.LayoutWidth);
+ Assert.AreEqual(320f, root_child2.LayoutHeight);
+ }
+
}
}
diff --git a/gentest/fixtures/YGRoundingTest.html b/gentest/fixtures/YGRoundingTest.html
index c66e6b16..75062efe 100644
--- a/gentest/fixtures/YGRoundingTest.html
+++ b/gentest/fixtures/YGRoundingTest.html
@@ -62,3 +62,34 @@
+
+
+
+
+
+
diff --git a/gentest/gentest.js b/gentest/gentest.js
index b5759630..c326541f 100755
--- a/gentest/gentest.js
+++ b/gentest/gentest.js
@@ -420,25 +420,46 @@ function getDefaultStyleValue(style) {
return getComputedStyle(node, null).getPropertyValue(style);
}
-function calculateTree(root) {
+function getRoundedSize(node) {
+ var boundingRect = node.getBoundingClientRect();
+ return {
+ width: Math.round(boundingRect.right) - Math.round(boundingRect.left),
+ height: Math.round(boundingRect.bottom) - Math.round(boundingRect.top)
+ };
+}
+
+function calculateTree(root, roundToPixelGrid) {
var rootLayout = [];
+ // Any occurrence of "Rounding" mark during node tree traverse turns this feature on for whole subtree.
+ if ((root.getAttribute('experiments') || '').split(' ').indexOf('Rounding') != -1) {
+ roundToPixelGrid = true;
+ }
+
for (var i = 0; i < root.children.length; i++) {
var child = root.children[i];
- rootLayout.push({
+ var layout = {
name: child.id !== '' ? child.id : 'INSERT_NAME_HERE',
left: child.offsetLeft + child.parentNode.clientLeft,
top: child.offsetTop + child.parentNode.clientTop,
width: child.offsetWidth,
height: child.offsetHeight,
- children: calculateTree(child),
+ children: calculateTree(child, roundToPixelGrid),
style: getYogaStyle(child),
declaredStyle: child.style,
rawStyle: child.getAttribute('style'),
experiments: child.getAttribute('experiments')
? child.getAttribute('experiments').split(' ')
: [],
- });
+ };
+
+ if (roundToPixelGrid) {
+ var size = getRoundedSize(child);
+ layout.width = size.width;
+ layout.height = size.height;
+ }
+
+ rootLayout.push(layout);
}
return rootLayout;
diff --git a/java/tests/com/facebook/yoga/YGRoundingTest.java b/java/tests/com/facebook/yoga/YGRoundingTest.java
index ae2202df..089a3957 100644
--- a/java/tests/com/facebook/yoga/YGRoundingTest.java
+++ b/java/tests/com/facebook/yoga/YGRoundingTest.java
@@ -674,17 +674,17 @@ public class YGRoundingTest {
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
- assertEquals(64f, root_child0.getLayoutHeight(), 0.0f);
+ assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(64f, root_child1.getLayoutY(), 0.0f);
assertEquals(100f, root_child1.getLayoutWidth(), 0.0f);
- assertEquals(25f, root_child1.getLayoutHeight(), 0.0f);
+ assertEquals(24f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
- assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
+ assertEquals(25f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
@@ -697,17 +697,17 @@ public class YGRoundingTest {
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
- assertEquals(64f, root_child0.getLayoutHeight(), 0.0f);
+ assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(64f, root_child1.getLayoutY(), 0.0f);
assertEquals(100f, root_child1.getLayoutWidth(), 0.0f);
- assertEquals(25f, root_child1.getLayoutHeight(), 0.0f);
+ assertEquals(24f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
- assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
+ assertEquals(25f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
@@ -782,4 +782,304 @@ public class YGRoundingTest {
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
}
+ @Test
+ public void test_rounding_inner_node_controversy_horizontal() {
+ YogaConfig config = new YogaConfig();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
+
+ final YogaNode root = new YogaNode(config);
+ root.setFlexDirection(YogaFlexDirection.ROW);
+ root.setWidth(320f);
+
+ final YogaNode root_child0 = new YogaNode(config);
+ root_child0.setFlexGrow(1f);
+ root_child0.setHeight(10f);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child1 = new YogaNode(config);
+ root_child1.setFlexGrow(1f);
+ root_child1.setHeight(10f);
+ root.addChildAt(root_child1, 1);
+
+ final YogaNode root_child1_child0 = new YogaNode(config);
+ root_child1_child0.setFlexGrow(1f);
+ root_child1_child0.setHeight(10f);
+ root_child1.addChildAt(root_child1_child0, 0);
+
+ final YogaNode root_child2 = new YogaNode(config);
+ root_child2.setFlexGrow(1f);
+ root_child2.setHeight(10f);
+ root.addChildAt(root_child2, 2);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(320f, root.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(107f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(107f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(106f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(106f, root_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(213f, root_child2.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child2.getLayoutY(), 0.0f);
+ assertEquals(107f, root_child2.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child2.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(320f, root.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(213f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(107f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(107f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(106f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(106f, root_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child2.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child2.getLayoutY(), 0.0f);
+ assertEquals(107f, root_child2.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child2.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_rounding_inner_node_controversy_vertical() {
+ YogaConfig config = new YogaConfig();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
+
+ final YogaNode root = new YogaNode(config);
+ root.setHeight(320f);
+
+ final YogaNode root_child0 = new YogaNode(config);
+ root_child0.setFlexGrow(1f);
+ root_child0.setWidth(10f);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child1 = new YogaNode(config);
+ root_child1.setFlexGrow(1f);
+ root_child1.setWidth(10f);
+ root.addChildAt(root_child1, 1);
+
+ final YogaNode root_child1_child0 = new YogaNode(config);
+ root_child1_child0.setFlexGrow(1f);
+ root_child1_child0.setWidth(10f);
+ root_child1.addChildAt(root_child1_child0, 0);
+
+ final YogaNode root_child2 = new YogaNode(config);
+ root_child2.setFlexGrow(1f);
+ root_child2.setWidth(10f);
+ root.addChildAt(root_child2, 2);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(10f, root.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(107f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child2.getLayoutX(), 0.0f);
+ assertEquals(213f, root_child2.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child2.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child2.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(10f, root.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(107f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child2.getLayoutX(), 0.0f);
+ assertEquals(213f, root_child2.getLayoutY(), 0.0f);
+ assertEquals(10f, root_child2.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child2.getLayoutHeight(), 0.0f);
+ }
+
+ @Test
+ public void test_rounding_inner_node_controversy_combined() {
+ YogaConfig config = new YogaConfig();
+ config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
+
+ final YogaNode root = new YogaNode(config);
+ root.setFlexDirection(YogaFlexDirection.ROW);
+ root.setWidth(640f);
+ root.setHeight(320f);
+
+ final YogaNode root_child0 = new YogaNode(config);
+ root_child0.setFlexGrow(1f);
+ root_child0.setHeightPercent(100f);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child1 = new YogaNode(config);
+ root_child1.setFlexGrow(1f);
+ root_child1.setHeightPercent(100f);
+ root.addChildAt(root_child1, 1);
+
+ final YogaNode root_child1_child0 = new YogaNode(config);
+ root_child1_child0.setFlexGrow(1f);
+ root_child1_child0.setWidthPercent(100f);
+ root_child1.addChildAt(root_child1_child0, 0);
+
+ final YogaNode root_child1_child1 = new YogaNode(config);
+ root_child1_child1.setFlexGrow(1f);
+ root_child1_child1.setWidthPercent(100f);
+ root_child1.addChildAt(root_child1_child1, 1);
+
+ final YogaNode root_child1_child1_child0 = new YogaNode(config);
+ root_child1_child1_child0.setFlexGrow(1f);
+ root_child1_child1_child0.setWidthPercent(100f);
+ root_child1_child1.addChildAt(root_child1_child1_child0, 0);
+
+ final YogaNode root_child1_child2 = new YogaNode(config);
+ root_child1_child2.setFlexGrow(1f);
+ root_child1_child2.setWidthPercent(100f);
+ root_child1.addChildAt(root_child1_child2, 2);
+
+ final YogaNode root_child2 = new YogaNode(config);
+ root_child2.setFlexGrow(1f);
+ root_child2.setHeightPercent(100f);
+ root.addChildAt(root_child2, 2);
+ root.setDirection(YogaDirection.LTR);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(640f, root.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(213f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(213f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child1.getLayoutX(), 0.0f);
+ assertEquals(107f, root_child1_child1.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child1.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child2.getLayoutX(), 0.0f);
+ assertEquals(213f, root_child1_child2.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child2.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child1_child2.getLayoutHeight(), 0.0f);
+
+ assertEquals(427f, root_child2.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child2.getLayoutY(), 0.0f);
+ assertEquals(213f, root_child2.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root_child2.getLayoutHeight(), 0.0f);
+
+ root.setDirection(YogaDirection.RTL);
+ root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
+
+ assertEquals(0f, root.getLayoutX(), 0.0f);
+ assertEquals(0f, root.getLayoutY(), 0.0f);
+ assertEquals(640f, root.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(427f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(213f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(213f, root_child1.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child1.getLayoutX(), 0.0f);
+ assertEquals(107f, root_child1_child1.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child1.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1_child1.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child1_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child1_child1_child0.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child1_child0.getLayoutWidth(), 0.0f);
+ assertEquals(106f, root_child1_child1_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child1_child2.getLayoutX(), 0.0f);
+ assertEquals(213f, root_child1_child2.getLayoutY(), 0.0f);
+ assertEquals(214f, root_child1_child2.getLayoutWidth(), 0.0f);
+ assertEquals(107f, root_child1_child2.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child2.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child2.getLayoutY(), 0.0f);
+ assertEquals(213f, root_child2.getLayoutWidth(), 0.0f);
+ assertEquals(320f, root_child2.getLayoutHeight(), 0.0f);
+ }
+
}
diff --git a/javascript/tests/Facebook.Yoga/YGRoundingTest.js b/javascript/tests/Facebook.Yoga/YGRoundingTest.js
index b41b7585..ab069ffb 100644
--- a/javascript/tests/Facebook.Yoga/YGRoundingTest.js
+++ b/javascript/tests/Facebook.Yoga/YGRoundingTest.js
@@ -709,17 +709,17 @@ it("rounding_fractial_input_3", function () {
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
- console.assert(64 === root_child0.getComputedHeight(), "64 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+ console.assert(65 === root_child0.getComputedHeight(), "65 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(64 === root_child1.getComputedTop(), "64 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(100 === root_child1.getComputedWidth(), "100 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
- console.assert(25 === root_child1.getComputedHeight(), "25 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+ console.assert(24 === root_child1.getComputedHeight(), "24 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(89 === root_child2.getComputedTop(), "89 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(100 === root_child2.getComputedWidth(), "100 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
- console.assert(24 === root_child2.getComputedHeight(), "24 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+ console.assert(25 === root_child2.getComputedHeight(), "25 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
@@ -731,17 +731,17 @@ it("rounding_fractial_input_3", function () {
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
- console.assert(64 === root_child0.getComputedHeight(), "64 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+ console.assert(65 === root_child0.getComputedHeight(), "65 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(64 === root_child1.getComputedTop(), "64 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(100 === root_child1.getComputedWidth(), "100 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
- console.assert(25 === root_child1.getComputedHeight(), "25 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+ console.assert(24 === root_child1.getComputedHeight(), "24 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(89 === root_child2.getComputedTop(), "89 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(100 === root_child2.getComputedWidth(), "100 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
- console.assert(24 === root_child2.getComputedHeight(), "24 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+ console.assert(25 === root_child2.getComputedHeight(), "25 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
@@ -827,3 +827,318 @@ it("rounding_fractial_input_4", function () {
config.free();
}
});
+it("rounding_inner_node_controversy_horizontal", function () {
+ var config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_ROUNDING, true);
+
+ try {
+ var root = Yoga.Node.create(config);
+ root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
+ root.setWidth(320);
+
+ var root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexGrow(1);
+ root_child0.setHeight(10);
+ root.insertChild(root_child0, 0);
+
+ var root_child1 = Yoga.Node.create(config);
+ root_child1.setFlexGrow(1);
+ root_child1.setHeight(10);
+ root.insertChild(root_child1, 1);
+
+ var root_child1_child0 = Yoga.Node.create(config);
+ root_child1_child0.setFlexGrow(1);
+ root_child1_child0.setHeight(10);
+ root_child1.insertChild(root_child1_child0, 0);
+
+ var root_child2 = Yoga.Node.create(config);
+ root_child2.setFlexGrow(1);
+ root_child2.setHeight(10);
+ root.insertChild(root_child2, 2);
+ root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
+
+ console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
+ console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
+ console.assert(320 === root.getComputedWidth(), "320 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
+ console.assert(10 === root.getComputedHeight(), "10 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
+
+ console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
+ console.assert(107 === root_child0.getComputedWidth(), "107 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
+ console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+
+ console.assert(107 === root_child1.getComputedLeft(), "107 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
+ console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
+ console.assert(106 === root_child1.getComputedWidth(), "106 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
+ console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
+ console.assert(106 === root_child1_child0.getComputedWidth(), "106 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
+ console.assert(10 === root_child1_child0.getComputedHeight(), "10 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
+
+ console.assert(213 === root_child2.getComputedLeft(), "213 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
+ console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
+ console.assert(107 === root_child2.getComputedWidth(), "107 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
+ console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+
+ root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
+
+ console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
+ console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
+ console.assert(320 === root.getComputedWidth(), "320 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
+ console.assert(10 === root.getComputedHeight(), "10 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
+
+ console.assert(213 === root_child0.getComputedLeft(), "213 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
+ console.assert(107 === root_child0.getComputedWidth(), "107 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
+ console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+
+ console.assert(107 === root_child1.getComputedLeft(), "107 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
+ console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
+ console.assert(106 === root_child1.getComputedWidth(), "106 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
+ console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
+ console.assert(106 === root_child1_child0.getComputedWidth(), "106 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
+ console.assert(10 === root_child1_child0.getComputedHeight(), "10 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
+ console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
+ console.assert(107 === root_child2.getComputedWidth(), "107 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
+ console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+ } finally {
+ if (typeof root !== "undefined") {
+ root.freeRecursive();
+ }
+
+ config.free();
+ }
+});
+it("rounding_inner_node_controversy_vertical", function () {
+ var config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_ROUNDING, true);
+
+ try {
+ var root = Yoga.Node.create(config);
+ root.setHeight(320);
+
+ var root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexGrow(1);
+ root_child0.setWidth(10);
+ root.insertChild(root_child0, 0);
+
+ var root_child1 = Yoga.Node.create(config);
+ root_child1.setFlexGrow(1);
+ root_child1.setWidth(10);
+ root.insertChild(root_child1, 1);
+
+ var root_child1_child0 = Yoga.Node.create(config);
+ root_child1_child0.setFlexGrow(1);
+ root_child1_child0.setWidth(10);
+ root_child1.insertChild(root_child1_child0, 0);
+
+ var root_child2 = Yoga.Node.create(config);
+ root_child2.setFlexGrow(1);
+ root_child2.setWidth(10);
+ root.insertChild(root_child2, 2);
+ root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
+
+ console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
+ console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
+ console.assert(10 === root.getComputedWidth(), "10 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
+ console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
+
+ console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
+ console.assert(10 === root_child0.getComputedWidth(), "10 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
+ console.assert(107 === root_child0.getComputedHeight(), "107 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
+ console.assert(107 === root_child1.getComputedTop(), "107 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
+ console.assert(10 === root_child1.getComputedWidth(), "10 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
+ console.assert(106 === root_child1.getComputedHeight(), "106 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
+ console.assert(10 === root_child1_child0.getComputedWidth(), "10 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
+ console.assert(106 === root_child1_child0.getComputedHeight(), "106 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
+ console.assert(213 === root_child2.getComputedTop(), "213 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
+ console.assert(10 === root_child2.getComputedWidth(), "10 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
+ console.assert(107 === root_child2.getComputedHeight(), "107 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+
+ root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
+
+ console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
+ console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
+ console.assert(10 === root.getComputedWidth(), "10 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
+ console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
+
+ console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
+ console.assert(10 === root_child0.getComputedWidth(), "10 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
+ console.assert(107 === root_child0.getComputedHeight(), "107 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
+ console.assert(107 === root_child1.getComputedTop(), "107 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
+ console.assert(10 === root_child1.getComputedWidth(), "10 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
+ console.assert(106 === root_child1.getComputedHeight(), "106 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
+ console.assert(10 === root_child1_child0.getComputedWidth(), "10 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
+ console.assert(106 === root_child1_child0.getComputedHeight(), "106 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
+ console.assert(213 === root_child2.getComputedTop(), "213 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
+ console.assert(10 === root_child2.getComputedWidth(), "10 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
+ console.assert(107 === root_child2.getComputedHeight(), "107 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+ } finally {
+ if (typeof root !== "undefined") {
+ root.freeRecursive();
+ }
+
+ config.free();
+ }
+});
+it("rounding_inner_node_controversy_combined", function () {
+ var config = Yoga.Config.create();
+
+ config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_ROUNDING, true);
+
+ try {
+ var root = Yoga.Node.create(config);
+ root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
+ root.setWidth(640);
+ root.setHeight(320);
+
+ var root_child0 = Yoga.Node.create(config);
+ root_child0.setFlexGrow(1);
+ root_child0.setHeight("100%");
+ root.insertChild(root_child0, 0);
+
+ var root_child1 = Yoga.Node.create(config);
+ root_child1.setFlexGrow(1);
+ root_child1.setHeight("100%");
+ root.insertChild(root_child1, 1);
+
+ var root_child1_child0 = Yoga.Node.create(config);
+ root_child1_child0.setFlexGrow(1);
+ root_child1_child0.setWidth("100%");
+ root_child1.insertChild(root_child1_child0, 0);
+
+ var root_child1_child1 = Yoga.Node.create(config);
+ root_child1_child1.setFlexGrow(1);
+ root_child1_child1.setWidth("100%");
+ root_child1.insertChild(root_child1_child1, 1);
+
+ var root_child1_child1_child0 = Yoga.Node.create(config);
+ root_child1_child1_child0.setFlexGrow(1);
+ root_child1_child1_child0.setWidth("100%");
+ root_child1_child1.insertChild(root_child1_child1_child0, 0);
+
+ var root_child1_child2 = Yoga.Node.create(config);
+ root_child1_child2.setFlexGrow(1);
+ root_child1_child2.setWidth("100%");
+ root_child1.insertChild(root_child1_child2, 2);
+
+ var root_child2 = Yoga.Node.create(config);
+ root_child2.setFlexGrow(1);
+ root_child2.setHeight("100%");
+ root.insertChild(root_child2, 2);
+ root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
+
+ console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
+ console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
+ console.assert(640 === root.getComputedWidth(), "640 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
+ console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
+
+ console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
+ console.assert(213 === root_child0.getComputedWidth(), "213 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
+ console.assert(320 === root_child0.getComputedHeight(), "320 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+
+ console.assert(213 === root_child1.getComputedLeft(), "213 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
+ console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
+ console.assert(214 === root_child1.getComputedWidth(), "214 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
+ console.assert(320 === root_child1.getComputedHeight(), "320 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
+ console.assert(214 === root_child1_child0.getComputedWidth(), "214 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
+ console.assert(107 === root_child1_child0.getComputedHeight(), "107 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child1.getComputedLeft(), "0 === root_child1_child1.getComputedLeft() (" + root_child1_child1.getComputedLeft() + ")");
+ console.assert(107 === root_child1_child1.getComputedTop(), "107 === root_child1_child1.getComputedTop() (" + root_child1_child1.getComputedTop() + ")");
+ console.assert(214 === root_child1_child1.getComputedWidth(), "214 === root_child1_child1.getComputedWidth() (" + root_child1_child1.getComputedWidth() + ")");
+ console.assert(106 === root_child1_child1.getComputedHeight(), "106 === root_child1_child1.getComputedHeight() (" + root_child1_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child1_child0.getComputedLeft(), "0 === root_child1_child1_child0.getComputedLeft() (" + root_child1_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child1_child0.getComputedTop(), "0 === root_child1_child1_child0.getComputedTop() (" + root_child1_child1_child0.getComputedTop() + ")");
+ console.assert(214 === root_child1_child1_child0.getComputedWidth(), "214 === root_child1_child1_child0.getComputedWidth() (" + root_child1_child1_child0.getComputedWidth() + ")");
+ console.assert(106 === root_child1_child1_child0.getComputedHeight(), "106 === root_child1_child1_child0.getComputedHeight() (" + root_child1_child1_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child2.getComputedLeft(), "0 === root_child1_child2.getComputedLeft() (" + root_child1_child2.getComputedLeft() + ")");
+ console.assert(213 === root_child1_child2.getComputedTop(), "213 === root_child1_child2.getComputedTop() (" + root_child1_child2.getComputedTop() + ")");
+ console.assert(214 === root_child1_child2.getComputedWidth(), "214 === root_child1_child2.getComputedWidth() (" + root_child1_child2.getComputedWidth() + ")");
+ console.assert(107 === root_child1_child2.getComputedHeight(), "107 === root_child1_child2.getComputedHeight() (" + root_child1_child2.getComputedHeight() + ")");
+
+ console.assert(427 === root_child2.getComputedLeft(), "427 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
+ console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
+ console.assert(213 === root_child2.getComputedWidth(), "213 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
+ console.assert(320 === root_child2.getComputedHeight(), "320 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+
+ root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
+
+ console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
+ console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
+ console.assert(640 === root.getComputedWidth(), "640 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
+ console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
+
+ console.assert(427 === root_child0.getComputedLeft(), "427 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
+ console.assert(213 === root_child0.getComputedWidth(), "213 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
+ console.assert(320 === root_child0.getComputedHeight(), "320 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
+
+ console.assert(213 === root_child1.getComputedLeft(), "213 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
+ console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
+ console.assert(214 === root_child1.getComputedWidth(), "214 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
+ console.assert(320 === root_child1.getComputedHeight(), "320 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
+ console.assert(214 === root_child1_child0.getComputedWidth(), "214 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
+ console.assert(107 === root_child1_child0.getComputedHeight(), "107 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child1.getComputedLeft(), "0 === root_child1_child1.getComputedLeft() (" + root_child1_child1.getComputedLeft() + ")");
+ console.assert(107 === root_child1_child1.getComputedTop(), "107 === root_child1_child1.getComputedTop() (" + root_child1_child1.getComputedTop() + ")");
+ console.assert(214 === root_child1_child1.getComputedWidth(), "214 === root_child1_child1.getComputedWidth() (" + root_child1_child1.getComputedWidth() + ")");
+ console.assert(106 === root_child1_child1.getComputedHeight(), "106 === root_child1_child1.getComputedHeight() (" + root_child1_child1.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child1_child0.getComputedLeft(), "0 === root_child1_child1_child0.getComputedLeft() (" + root_child1_child1_child0.getComputedLeft() + ")");
+ console.assert(0 === root_child1_child1_child0.getComputedTop(), "0 === root_child1_child1_child0.getComputedTop() (" + root_child1_child1_child0.getComputedTop() + ")");
+ console.assert(214 === root_child1_child1_child0.getComputedWidth(), "214 === root_child1_child1_child0.getComputedWidth() (" + root_child1_child1_child0.getComputedWidth() + ")");
+ console.assert(106 === root_child1_child1_child0.getComputedHeight(), "106 === root_child1_child1_child0.getComputedHeight() (" + root_child1_child1_child0.getComputedHeight() + ")");
+
+ console.assert(0 === root_child1_child2.getComputedLeft(), "0 === root_child1_child2.getComputedLeft() (" + root_child1_child2.getComputedLeft() + ")");
+ console.assert(213 === root_child1_child2.getComputedTop(), "213 === root_child1_child2.getComputedTop() (" + root_child1_child2.getComputedTop() + ")");
+ console.assert(214 === root_child1_child2.getComputedWidth(), "214 === root_child1_child2.getComputedWidth() (" + root_child1_child2.getComputedWidth() + ")");
+ console.assert(107 === root_child1_child2.getComputedHeight(), "107 === root_child1_child2.getComputedHeight() (" + root_child1_child2.getComputedHeight() + ")");
+
+ console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
+ console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
+ console.assert(213 === root_child2.getComputedWidth(), "213 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
+ console.assert(320 === root_child2.getComputedHeight(), "320 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
+ } finally {
+ if (typeof root !== "undefined") {
+ root.freeRecursive();
+ }
+
+ config.free();
+ }
+});
diff --git a/tests/YGRoundingTest.cpp b/tests/YGRoundingTest.cpp
index 93a80d50..ed79f5c3 100644
--- a/tests/YGRoundingTest.cpp
+++ b/tests/YGRoundingTest.cpp
@@ -676,17 +676,17 @@ TEST(YogaTest, rounding_fractial_input_3) {
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
- ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0));
+ ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1));
- ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1));
+ ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2));
- ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2));
+ ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child2));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
@@ -698,17 +698,17 @@ TEST(YogaTest, rounding_fractial_input_3) {
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
- ASSERT_FLOAT_EQ(64, YGNodeLayoutGetHeight(root_child0));
+ ASSERT_FLOAT_EQ(65, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(64, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1));
- ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child1));
+ ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(89, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child2));
- ASSERT_FLOAT_EQ(24, YGNodeLayoutGetHeight(root_child2));
+ ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child2));
YGNodeFreeRecursive(root);
@@ -787,3 +787,306 @@ TEST(YogaTest, rounding_fractial_input_4) {
YGConfigFree(config);
}
+
+TEST(YogaTest, rounding_inner_node_controversy_horizontal) {
+ const YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureRounding, true);
+
+ const YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
+ YGNodeStyleSetWidth(root, 320);
+
+ const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child0, 1);
+ YGNodeStyleSetHeight(root_child0, 10);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1, 1);
+ YGNodeStyleSetHeight(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+
+ const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1_child0, 1);
+ YGNodeStyleSetHeight(root_child1_child0, 10);
+ YGNodeInsertChild(root_child1, root_child1_child0, 0);
+
+ const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child2, 1);
+ YGNodeStyleSetHeight(root_child2, 10);
+ YGNodeInsertChild(root, root_child2, 2);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0));
+
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child2));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetWidth(root_child2));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetWidth(root_child1_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetWidth(root_child2));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child2));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, rounding_inner_node_controversy_vertical) {
+ const YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureRounding, true);
+
+ const YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetHeight(root, 320);
+
+ const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child0, 1);
+ YGNodeStyleSetWidth(root_child0, 10);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1, 1);
+ YGNodeStyleSetWidth(root_child1, 10);
+ YGNodeInsertChild(root, root_child1, 1);
+
+ const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1_child0, 1);
+ YGNodeStyleSetWidth(root_child1_child0, 10);
+ YGNodeInsertChild(root_child1, root_child1_child0, 0);
+
+ const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child2, 1);
+ YGNodeStyleSetWidth(root_child2, 10);
+ YGNodeInsertChild(root, root_child2, 2);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1_child0));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child2));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child2));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child1_child0));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child2));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child2));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child2));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
+TEST(YogaTest, rounding_inner_node_controversy_combined) {
+ const YGConfigRef config = YGConfigNew();
+ YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureRounding, true);
+
+ const YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
+ YGNodeStyleSetWidth(root, 640);
+ YGNodeStyleSetHeight(root, 320);
+
+ const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child0, 1);
+ YGNodeStyleSetHeightPercent(root_child0, 100);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1, 1);
+ YGNodeStyleSetHeightPercent(root_child1, 100);
+ YGNodeInsertChild(root, root_child1, 1);
+
+ const YGNodeRef root_child1_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1_child0, 1);
+ YGNodeStyleSetWidthPercent(root_child1_child0, 100);
+ YGNodeInsertChild(root_child1, root_child1_child0, 0);
+
+ const YGNodeRef root_child1_child1 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1_child1, 1);
+ YGNodeStyleSetWidthPercent(root_child1_child1, 100);
+ YGNodeInsertChild(root_child1, root_child1_child1, 1);
+
+ const YGNodeRef root_child1_child1_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1_child1_child0, 1);
+ YGNodeStyleSetWidthPercent(root_child1_child1_child0, 100);
+ YGNodeInsertChild(root_child1_child1, root_child1_child1_child0, 0);
+
+ const YGNodeRef root_child1_child2 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child1_child2, 1);
+ YGNodeStyleSetWidthPercent(root_child1_child2, 100);
+ YGNodeInsertChild(root_child1, root_child1_child2, 2);
+
+ const YGNodeRef root_child2 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetFlexGrow(root_child2, 1);
+ YGNodeStyleSetHeightPercent(root_child2, 100);
+ YGNodeInsertChild(root, root_child2, 2);
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(640, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child0));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1_child1));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1_child0));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1_child0));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child2));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child1_child2));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child2));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child2));
+
+ ASSERT_FLOAT_EQ(427, YGNodeLayoutGetLeft(root_child2));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child2));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child2));
+
+ YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
+ ASSERT_FLOAT_EQ(640, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(427, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetLeft(root_child1));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child0));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetTop(root_child1_child1));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child1_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child1_child0));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child1_child0));
+ ASSERT_FLOAT_EQ(106, YGNodeLayoutGetHeight(root_child1_child1_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child2));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetTop(root_child1_child2));
+ ASSERT_FLOAT_EQ(214, YGNodeLayoutGetWidth(root_child1_child2));
+ ASSERT_FLOAT_EQ(107, YGNodeLayoutGetHeight(root_child1_child2));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
+ ASSERT_FLOAT_EQ(213, YGNodeLayoutGetWidth(root_child2));
+ ASSERT_FLOAT_EQ(320, YGNodeLayoutGetHeight(root_child2));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
diff --git a/yoga/Yoga.c b/yoga/Yoga.c
index bf6c7327..01ea968f 100644
--- a/yoga/Yoga.c
+++ b/yoga/Yoga.c
@@ -3293,49 +3293,39 @@ void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInP
}
}
-static void YGRoundToPixelGrid(const YGNodeRef node, const float pointScaleFactor) {
+static float YGRoundValueToPixelGrid(const float value, const float pointScaleFactor) {
+ float fractial = fmodf(value, pointScaleFactor);
+ return value - fractial + (fractial >= pointScaleFactor / 2.0f ? pointScaleFactor : 0);
+}
+
+static void YGRoundToPixelGrid(const YGNodeRef node, const float pointScaleFactor, const float absoluteLeft, const float absoluteTop) {
if (pointScaleFactor == 0.0f) {
return;
}
+
const float nodeLeft = node->layout.position[YGEdgeLeft];
const float nodeTop = node->layout.position[YGEdgeTop];
- // To round correctly to the pixel grid, first we calculate left and top coordinates
- float fractialLeft = fmodf(nodeLeft, pointScaleFactor);
- float fractialTop = fmodf(nodeTop, pointScaleFactor);
- float roundedLeft = nodeLeft - fractialLeft;
- float roundedTop = nodeTop - fractialTop;
+ const float nodeWidth = node->layout.dimensions[YGDimensionWidth];
+ const float nodeHeight = node->layout.dimensions[YGDimensionHeight];
- // To do the actual rounding we check if leftover fraction is bigger or equal than half of the grid step
- if (fractialLeft >= pointScaleFactor / 2.0f) {
- roundedLeft += pointScaleFactor;
- fractialLeft -= pointScaleFactor;
- }
- if (fractialTop >= pointScaleFactor / 2.0f) {
- roundedTop += pointScaleFactor;
- fractialTop -= pointScaleFactor;
- }
- node->layout.position[YGEdgeLeft] = roundedLeft;
- node->layout.position[YGEdgeTop] = roundedTop;
+ const float absoluteNodeLeft = absoluteLeft + nodeLeft;
+ const float absoluteNodeTop = absoluteTop + nodeTop;
- // Now we round width and height in the same way accounting for fractial leftovers from rounding position
- const float adjustedWidth = fractialLeft + node->layout.dimensions[YGDimensionWidth];
- const float adjustedHeight = fractialTop + node->layout.dimensions[YGDimensionHeight];
- float roundedWidth = adjustedWidth - fmodf(adjustedWidth, pointScaleFactor);
- float roundedHeight = adjustedHeight - fmodf(adjustedHeight, pointScaleFactor);
+ const float absoluteNodeRight = absoluteNodeLeft + nodeWidth;
+ const float absoluteNodeBottom = absoluteNodeTop + nodeHeight;
- if (adjustedWidth - roundedWidth >= pointScaleFactor / 2.0f) {
- roundedWidth += pointScaleFactor;
- }
- if (adjustedHeight - roundedHeight >= pointScaleFactor / 2.0f) {
- roundedHeight += pointScaleFactor;
- }
- node->layout.dimensions[YGDimensionWidth] = roundedWidth;
- node->layout.dimensions[YGDimensionHeight] = roundedHeight;
+ node->layout.position[YGEdgeLeft] = YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor);
+ node->layout.position[YGEdgeTop] = YGRoundValueToPixelGrid(nodeTop, pointScaleFactor);
+
+ node->layout.dimensions[YGDimensionWidth] =
+ YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor) - YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor);
+ node->layout.dimensions[YGDimensionHeight] =
+ YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor) - YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor);
const uint32_t childCount = YGNodeListCount(node->children);
for (uint32_t i = 0; i < childCount; i++) {
- YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor);
+ YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop);
}
}
@@ -3395,7 +3385,7 @@ void YGNodeCalculateLayout(const YGNodeRef node,
YGNodeSetPosition(node, node->layout.direction, parentWidth, parentHeight, parentWidth);
if (YGConfigIsExperimentalFeatureEnabled(node->config, YGExperimentalFeatureRounding)) {
- YGRoundToPixelGrid(node, node->config->pointScaleFactor);
+ YGRoundToPixelGrid(node, node->config->pointScaleFactor, 0.0f, 0.0f);
}
if (gPrintTree) {