Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix negative value rounding issue for nodes across an axis #688

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jmaurice-unity
Copy link

This fix issue #683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@matthargett
Copy link

can you add the new test to the PR please?

@jmaurice-unity
Copy link
Author

There's already a test above that reproduce the issue.

@lunarraid
Copy link

What is the status of this? This bug is pretty heavily impacting my project and forcing me to run a branch with this fix. It would be nice to get this merged in.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidaurelio has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidaurelio has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidaurelio has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidaurelio has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidaurelio has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@rozele has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@rozele has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook facebook deleted a comment from facebook-github-bot Jan 24, 2023
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Feb 2, 2023
Summary:
This fix issue facebook/yoga#683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

```
TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}
```

X-link: facebook/yoga#688

Reviewed By: NickGerleman

Differential Revision: D13866122

Pulled By: rozele

fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
@facebook-github-bot
Copy link
Contributor

@rozele merged this pull request in 4266409.

facebook-github-bot pushed a commit to facebook/litho that referenced this pull request Feb 2, 2023
Summary:
This fix issue facebook/yoga#683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

```
TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}
```

X-link: facebook/yoga#688

Reviewed By: NickGerleman

Differential Revision: D13866122

Pulled By: rozele

fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
@facebook-github-bot
Copy link
Contributor

This pull request has been reverted by 996267d.

@NickGerleman
Copy link
Contributor

As a heads up, it looks like this change ended up making subtle shifts to existing layouts in many of our screenshot tests, so this change was reverted to investigate.

@rozele rozele reopened this Feb 3, 2023
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
)

Summary:
This fix issue facebook/yoga#683 the rounding calculation is incorrect if a node is crossing an axis and it will shrink it's width/height on layout calculation.

The following test reproduce the issue :

```
TEST(YogaTest, node_shrink_on_axis)
{
  const YGConfigRef config = YGConfigNew();
  const YGNodeRef root = YGNodeNewWithConfig(config);
  const YGNodeRef child = YGNodeNewWithConfig(config);

  YGNodeInsertChild(root, child, 0);

  YGNodeStyleSetWidth(child, 10);
  YGNodeStyleSetHeight(child, 10);
  YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f);
  YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

  ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10);
  ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10);

  YGNodeFreeRecursive(root);

  YGConfigFree(config);
}
```

X-link: facebook/yoga#688

Reviewed By: NickGerleman

Differential Revision: D13866122

Pulled By: rozele

fbshipit-source-id: 4faf8a9efc86723c303f600d730660a2e13d8a73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants