Merge "Proper equals/hashCode impls in Rect and RectF"
This commit is contained in:
@@ -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));
|
||||
return (int)((lx + 0x800000) >> 24);
|
||||
public static int round(float value) {
|
||||
long lx = (long) (value * (65536 * 256f));
|
||||
return (int) ((lx + 0x800000) >> 24);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
return false;
|
||||
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;
|
||||
result = 31 * result + top;
|
||||
result = 31 * result + right;
|
||||
result = 31 * result + bottom;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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 + ")";
|
||||
|
||||
Reference in New Issue
Block a user