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

Commit b74b84f1 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Proper equals/hashCode impls in Rect and RectF"

parents ed734404 74d7ca13
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ public class FastMath {
     * thought it may return slightly different results. It does not try to
     * handle (in any meaningful way) NaN or infinities.
     */
    public static int round(float x) {
        long lx = (long)(x * (65536 * 256f));
    public static int round(float value) {
        long lx = (long) (value * (65536 * 256f));
        return (int) ((lx + 0x800000) >> 24);
    }
}
+15 −7
Original line number Diff line number Diff line
@@ -76,13 +76,21 @@ public final class Rect implements Parcelable {
    }

    @Override
    public boolean equals(Object obj) {
        Rect r = (Rect) obj;
        if (r != null) {
            return left == r.left && top == r.top && right == r.right
                    && bottom == r.bottom;
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Rect r = (Rect) o;
        return left == r.left && top == r.top && right == r.right && bottom == r.bottom;
    }
        return false;

    @Override
    public int hashCode() {
        int result = left;
        result = 31 * result + top;
        result = 31 * result + right;
        result = 31 * result + bottom;
        return result;
    }

    @Override
+18 −0
Original line number Diff line number Diff line
@@ -79,6 +79,24 @@ public class RectF implements Parcelable {
        bottom = r.bottom;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Rect r = (Rect) o;
        return left == r.left && top == r.top && right == r.right && bottom == r.bottom;
    }

    @Override
    public int hashCode() {
        int result = (left != +0.0f ? Float.floatToIntBits(left) : 0);
        result = 31 * result + (top != +0.0f ? Float.floatToIntBits(top) : 0);
        result = 31 * result + (right != +0.0f ? Float.floatToIntBits(right) : 0);
        result = 31 * result + (bottom != +0.0f ? Float.floatToIntBits(bottom) : 0);
        return result;
    }

    public String toString() {
        return "RectF(" + left + ", " + top + ", "
                      + right + ", " + bottom + ")";