Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c45b1d4a authored by Alan Viverette's avatar Alan Viverette
Browse files

Use correct rounding in View for potentially negative values

Fast rounding doesn't work for negative values, so use Math.round()
where we might encounter negative values. Use Math.floor() and ceil()
for rounding down and up, respectively.

Bug: 25695621
Change-Id: I94831b8eb7552fc24cbe5808e923de1674d8ba6d
parent 19c3f7fa
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -6329,8 +6329,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        position.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop);
        outRect.set((int) (position.left + 0.5f), (int) (position.top + 0.5f),
                (int) (position.right + 0.5f), (int) (position.bottom + 0.5f));
        outRect.set(Math.round(position.left), Math.round(position.top),
                Math.round(position.right), Math.round(position.bottom));
    }
    /**
@@ -18548,8 +18548,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            position[1] -= vr.mCurScrollY;
        }
        inOutLocation[0] = (int) (position[0] + 0.5f);
        inOutLocation[1] = (int) (position[1] + 0.5f);
        inOutLocation[0] = Math.round(position[0]);
        inOutLocation[1] = Math.round(position[1]);
    }
    /**
+12 −12
Original line number Diff line number Diff line
@@ -5114,10 +5114,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                    transformMatrix = childMatrix;
                }
                transformMatrix.mapRect(boundingRect);
                dirty.set((int) (boundingRect.left - 0.5f),
                        (int) (boundingRect.top - 0.5f),
                        (int) (boundingRect.right + 0.5f),
                        (int) (boundingRect.bottom + 0.5f));
                dirty.set((int) Math.floor(boundingRect.left),
                        (int) Math.floor(boundingRect.top),
                        (int) Math.ceil(boundingRect.right),
                        (int) Math.ceil(boundingRect.bottom));
            }

            do {
@@ -5154,10 +5154,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                        RectF boundingRect = attachInfo.mTmpTransformRect;
                        boundingRect.set(dirty);
                        m.mapRect(boundingRect);
                        dirty.set((int) (boundingRect.left - 0.5f),
                                (int) (boundingRect.top - 0.5f),
                                (int) (boundingRect.right + 0.5f),
                                (int) (boundingRect.bottom + 0.5f));
                        dirty.set((int) Math.floor(boundingRect.left),
                                (int) Math.floor(boundingRect.top),
                                (int) Math.ceil(boundingRect.right),
                                (int) Math.ceil(boundingRect.bottom));
                    }
                }
            } while (parent != null);
@@ -5457,8 +5457,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                position[0] = offset.x;
                position[1] = offset.y;
                child.getMatrix().mapPoints(position);
                offset.x = (int) (position[0] + 0.5f);
                offset.y = (int) (position[1] + 0.5f);
                offset.x = Math.round(position[0]);
                offset.y = Math.round(position[1]);
            }
            offset.x += dx;
            offset.y += dy;
@@ -5485,8 +5485,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            rectIsVisible = rect.intersect(mClipBounds.left, mClipBounds.top, mClipBounds.right,
                    mClipBounds.bottom);
        }
        r.set((int) (rect.left + 0.5f), (int) (rect.top + 0.5f), (int) (rect.right + 0.5f),
                (int) (rect.bottom + 0.5f));
        r.set((int) Math.floor(rect.left), (int) Math.floor(rect.top),
                (int) Math.ceil(rect.right), (int) Math.ceil(rect.bottom));
        if (rectIsVisible && mParent != null) {
            rectIsVisible = mParent.getChildVisibleRect(this, r, offset);
        }