From 75708262fccdfaabd0b682b2d1205a35c41e8593 Mon Sep 17 00:00:00 2001 From: Pat Manning Date: Thu, 6 Jul 2023 15:12:49 +0000 Subject: [PATCH] Update scaleRectAboutCenter to correctly account for negative left/top values and floating point errors using centerX/Y. Fix: 290211274 Test: manual. Change-Id: Ieddce683d76c696b5ac3eae4fb9f73a5827a50ad --- src/com/android/launcher3/Utilities.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 4f5de0566b..e8c6ff9be7 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -334,14 +334,12 @@ public final class Utilities { public static void scaleRectAboutCenter(Rect r, float scale) { if (scale != 1.0f) { - int cx = r.centerX(); - int cy = r.centerY(); - r.offset(-cx, -cy); - r.left = (int) (r.left * scale + 0.5f); - r.top = (int) (r.top * scale + 0.5f); - r.right = (int) (r.right * scale + 0.5f); - r.bottom = (int) (r.bottom * scale + 0.5f); - r.offset(cx, cy); + float cx = r.exactCenterX(); + float cy = r.exactCenterY(); + r.left = Math.round(cx + (r.left - cx) * scale); + r.top = Math.round(cy + (r.top - cy) * scale); + r.right = Math.round(cx + (r.right - cx) * scale); + r.bottom = Math.round(cy + (r.bottom - cy) * scale); } }