From 59b44017bffea3dc8b799572da0d1a7245a3f2f1 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Wed, 26 Jun 2019 12:02:05 -0400 Subject: [PATCH] Reduce floating point error in PerimeterPathGuide. Instead of dividing before adding up the lengths, add up the lengths and then divide. Before this change, the end point of the last region was not 1.0, after this change it is. Bug: 136084565 Test: Verified values via logging. No visible change in behavior. Change-Id: Iddc87bed3c8b427af41f247589a9f1a99ad03555 --- .../com/android/systemui/assist/ui/PerimeterPathGuide.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/assist/ui/PerimeterPathGuide.java b/packages/SystemUI/src/com/android/systemui/assist/ui/PerimeterPathGuide.java index 8eea36892aa75..65a9fcc3a9552 100644 --- a/packages/SystemUI/src/com/android/systemui/assist/ui/PerimeterPathGuide.java +++ b/packages/SystemUI/src/com/android/systemui/assist/ui/PerimeterPathGuide.java @@ -287,9 +287,12 @@ public class PerimeterPathGuide { float accum = 0; for (int i = 0; i < mRegions.length; i++) { mRegions[i].normalizedLength = mRegions[i].absoluteLength / perimeterLength; - accum += mRegions[i].normalizedLength; - mRegions[i].endCoordinate = accum; + accum += mRegions[i].absoluteLength; + mRegions[i].endCoordinate = accum / perimeterLength; } + // Ensure that the last coordinate is 1. Setting it explicitly to avoid floating point + // error. + mRegions[mRegions.length - 1].endCoordinate = 1f; } private CircularCornerPathRenderer.Corner getRotatedCorner(