use > || YGFloatsEqual instead of >= for computing round value to pixel grid

Summary: YGRoundValueToPixelGrid does not handle float point values correctly. It causes layout bugs in arm 32 devices. The way values are rounded to pixel grid is the following: if value is close to the left pixel - discard error and set it equal to left pixel. If value is close to right pixel - set it equal to the right pixel. Otherwise if value is closer to the left - set it equal to the left, closer to the right - set it equal to the right. The problem is when values are close to the middle. Old implementation could produce either left or right boundaries. This patch moves all values that are close to the middle to right boundary. This way results are consistent.

Reviewed By: emilsjolander

Differential Revision: D6202484

fbshipit-source-id: bb80235452208caec388775574cc4f07bfd649c4
This commit is contained in:
Chandra Patni
2017-11-01 15:42:41 -07:00
committed by Facebook Github Bot
parent bfb4dabf0c
commit ff0a3f39d9

View File

@@ -3322,7 +3322,7 @@ float YGRoundValueToPixelGrid(const float value,
scaledValue = scaledValue - fractial;
} else {
// Finally we just round the value
scaledValue = scaledValue - fractial + (fractial >= 0.5f ? 1.0f : 0.0f);
scaledValue = scaledValue - fractial + (fractial > 0.5f || YGFloatsEqual(fractial, 0.5f) ? 1.0f : 0.0f);
}
return scaledValue / pointScaleFactor;
}