react / react/yoga

both YGRoundToPixelGrid and YGRoundValueToPixelGrid accumulated errror

Open
#901 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Algorithm
Dominant language
C++
Stars
18.9k
Forks
1.6k
Avg merge
1m
Merged PRs (30d)
1

Description

Report

Issues and Steps to Reproduce

Replaces this with steps to repro your issue.
node {
position = 5 5 0 0
dimensions = 365, 252
}
NodeType = Text;
others pading boder margin = 0;
pointScaleFactor = 3
absoluteLeft = 5
absoluteTop = 411.666656

1 YGRoundToPixelGrid

const float absoluteNodeTop = absoluteTop + nodeTop;
const float absoluteNodeBottom = absoluteNodeTop + nodeHeight;
const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) &&
!YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0);
node->setLayoutDimension(
YGRoundValueToPixelGrid(
absoluteNodeBottom,
pointScaleFactor,
(textRounding && hasFractionalHeight),
(textRounding && !hasFractionalHeight)) -
YGRoundValueToPixelGrid(
absoluteNodeTop, pointScaleFactor, false, textRounding),
YGDimensionHeight);
This is unreasonable, maybe we just want YGRoundValueToPixelGrid(nodeHeight);

2 YGRoundValueToPixelGrid
used too much YGFloatsEqual

bool YGFloatsEqual(const float a, const float b) { if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) { return fabs(a - b) < 0.0001f; } return YGFloatIsUndefined(a) && YGFloatIsUndefined(b); }
screen one pixel is not < 0.0001f, nicer precision at this place is 1/pointScaleFactor

Expected Behavior

Describe what you expected would happen.
nodeHeight beginWith 252 ,after 251.666656
Except nodeHeight never lost precision

Actual Behavior

Describe what actually happened.

Link to Code

https://github.com/facebook/yoga/pull/902/commits/19035c90e9107226cc53d91f6722ee331339624a

When applicable, use this fiddle to post a web repro.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting YGRoundToPixelGrid and YGRoundValueToPixelGrid, using the linked commit and the supplied node values (pointScaleFactor 3, absoluteTop 411.666656, height 252) to reproduce the rounding behavior. Done means the node height does not lose the reported precision while pixel-grid rounding remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.