From 76fbd628e1878b3d63678c3e7f2d443f56e8987c Mon Sep 17 00:00:00 2001 From: Dustin Shahidehpour Date: Sat, 11 Feb 2017 19:45:35 -0800 Subject: [PATCH] Use correct rounding function when rounding pixels. Summary: While debugging something at Instagram, I kept seeing a UILabel be truncated when it clearly had enough room to display all its' text. What I realized is that during our pixel rounding, we were losing precision because we were using the incorrect rounding function for floats. Changing from `round()` (which is for doubles) to `roundf()` fixed it. Reviewed By: amonshiz Differential Revision: D4549069 fbshipit-source-id: 78a1bb33e315e7c066b7fb625b1f5a28def76515 --- YogaKit/CHANGELOG.md | 4 ++++ YogaKit/Source/YGLayout.m | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/YogaKit/CHANGELOG.md b/YogaKit/CHANGELOG.md index 6a7dda86..49c46f2f 100644 --- a/YogaKit/CHANGELOG.md +++ b/YogaKit/CHANGELOG.md @@ -21,3 +21,7 @@ view.yoga.margin = 10 view.yoga.marginTop // 0 view.yoga.marginLeft // 0 ``` + +### Enhancements + +- Pixel Rounding now uses `roundf()` instead of `round()`. diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 07c0a77d..d7240a8b 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -353,7 +353,7 @@ static CGFloat YGRoundPixelValue(CGFloat value) scale = [UIScreen mainScreen].scale; }); - return round(value * scale) / scale; + return roundf(value * scale) / scale; } static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin)