Methods Summary |
---|
public final float | centerX()
return (left + right) * 0.5f;
|
public final float | centerY()
return (top + bottom) * 0.5f;
|
public boolean | contains(float x, float y)Returns true if (x,y) is inside the rectangle. The left and top are
considered to be inside, while the right and bottom are not. This means
that for a x,y to be contained: left <= x < right and top <= y < bottom.
An empty rectangle never contains any point.
return left < right && top < bottom // check for empty first
&& x >= left && x < right && y >= top && y < bottom;
|
public boolean | contains(float left, float top, float right, float bottom)Returns true iff the 4 specified sides of a rectangle are inside or equal
to this rectangle. i.e. is this rectangle a superset of the specified
rectangle. An empty rectangle never contains another rectangle.
// check for empty first
return this.left < this.right && this.top < this.bottom
// now check for containment
&& this.left <= left && this.top <= top
&& this.right >= right && this.bottom >= bottom;
|
public boolean | contains(android.graphics.RectF r)Returns true iff the specified rectangle r is inside or equal to this
rectangle. An empty rectangle never contains another rectangle.
// check for empty first
return this.left < this.right && this.top < this.bottom
// now check for containment
&& left <= r.left && top <= r.top
&& right >= r.right && bottom >= r.bottom;
|
public int | describeContents()Parcelable interface methods
return 0;
|
public final float | height()
return bottom - top;
|
public void | inset(float dx, float dy)Inset the rectangle by (dx,dy). If dx is positive, then the sides are
moved inwards, making the rectangle narrower. If dx is negative, then the
sides are moved outwards, making the rectangle wider. The same holds true
for dy and the top and bottom.
left += dx;
top += dy;
right -= dx;
bottom -= dy;
|
public boolean | intersect(float left, float top, float right, float bottom)If the rectangle specified by left,top,right,bottom intersects this
rectangle, return true and set this rectangle to that intersection,
otherwise return false and do not change this rectangle. No check is
performed to see if either rectangle is empty. Note: To just test for
intersection, use intersects()
if (this.left < right && left < this.right
&& this.top < bottom && top < this.bottom) {
if (this.left < left) {
this.left = left;
}
if (this.top < top) {
this.top = top;
}
if (this.right > right) {
this.right = right;
}
if (this.bottom > bottom) {
this.bottom = bottom;
}
return true;
}
return false;
|
public boolean | intersect(android.graphics.RectF r)If the specified rectangle intersects this rectangle, return true and set
this rectangle to that intersection, otherwise return false and do not
change this rectangle. No check is performed to see if either rectangle
is empty. To just test for intersection, use intersects()
return intersect(r.left, r.top, r.right, r.bottom);
|
public boolean | intersects(float left, float top, float right, float bottom)Returns true if this rectangle intersects the specified rectangle.
In no event is this rectangle modified. No check is performed to see
if either rectangle is empty. To record the intersection, use intersect()
or setIntersect().
return this.left < right && left < this.right
&& this.top < bottom && top < this.bottom;
|
public static boolean | intersects(android.graphics.RectF a, android.graphics.RectF b)Returns true iff the two specified rectangles intersect. In no event are
either of the rectangles modified. To record the intersection,
use intersect() or setIntersect().
return a.left < b.right && b.left < a.right
&& a.top < b.bottom && b.top < a.bottom;
|
public final boolean | isEmpty()Returns true if the rectangle is empty (left >= right or top >= bottom)
return left >= right || top >= bottom;
|
public void | offset(float dx, float dy)Offset the rectangle by adding dx to its left and right coordinates, and
adding dy to its top and bottom coordinates.
left += dx;
top += dy;
right += dx;
bottom += dy;
|
public void | offsetTo(float newLeft, float newTop)Offset the rectangle to a specific (left, top) position,
keeping its width and height the same.
right += newLeft - left;
bottom += newTop - top;
left = newLeft;
top = newTop;
|
public void | readFromParcel(android.os.Parcel in)Set the rectangle's coordinates from the data stored in the specified
parcel. To write a rectangle to a parcel, call writeToParcel().
left = in.readFloat();
top = in.readFloat();
right = in.readFloat();
bottom = in.readFloat();
|
public void | round(Rect dst)Set the dst integer Rect by rounding this rectangle's coordinates
to their nearest integer values.
dst.set(FastMath.round(left), FastMath.round(top),
FastMath.round(right), FastMath.round(bottom));
|
public void | roundOut(Rect dst)Set the dst integer Rect by rounding "out" this rectangle, choosing the
floor of top and left, and the ceiling of right and bottom.
dst.set((int) FloatMath.floor(left), (int) FloatMath.floor(top),
(int) FloatMath.ceil(right), (int) FloatMath.ceil(bottom));
|
public void | set(float left, float top, float right, float bottom)Set the rectangle's coordinates to the specified values. Note: no range
checking is performed, so it is up to the caller to ensure that
left <= right and top <= bottom.
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
|
public void | set(android.graphics.RectF src)Copy the coordinates from src into this rectangle.
this.left = src.left;
this.top = src.top;
this.right = src.right;
this.bottom = src.bottom;
|
public void | set(Rect src)Copy the coordinates from src into this rectangle.
this.left = src.left;
this.top = src.top;
this.right = src.right;
this.bottom = src.bottom;
|
public void | setEmpty()Set the rectangle to (0,0,0,0)
left = right = top = bottom = 0;
|
public boolean | setIntersect(android.graphics.RectF a, android.graphics.RectF b)If rectangles a and b intersect, return true and set this rectangle to
that intersection, otherwise return false and do not change this
rectangle. No check is performed to see if either rectangle is empty.
To just test for intersection, use intersects()
if (a.left < b.right && b.left < a.right
&& a.top < b.bottom && b.top < a.bottom) {
left = Math.max(a.left, b.left);
top = Math.max(a.top, b.top);
right = Math.min(a.right, b.right);
bottom = Math.min(a.bottom, b.bottom);
return true;
}
return false;
|
public void | sort()Swap top/bottom or left/right if there are flipped (i.e. left > right
and/or top > bottom). This can be called if
the edges are computed separately, and may have crossed over each other.
If the edges are already correct (i.e. left <= right and top <= bottom)
then nothing is done.
if (left > right) {
float temp = left;
left = right;
right = temp;
}
if (top > bottom) {
float temp = top;
top = bottom;
bottom = temp;
}
|
public java.lang.String | toString()
return "RectF(" + left + ", " + top + ", "
+ right + ", " + bottom + ")";
|
public void | union(float left, float top, float right, float bottom)Update this Rect to enclose itself and the specified rectangle. If the
specified rectangle is empty, nothing is done. If this rectangle is empty
it is set to the specified rectangle.
if ((left < right) && (top < bottom)) {
if ((this.left < this.right) && (this.top < this.bottom)) {
if (this.left > left)
this.left = left;
if (this.top > top)
this.top = top;
if (this.right < right)
this.right = right;
if (this.bottom < bottom)
this.bottom = bottom;
} else {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
|
public void | union(android.graphics.RectF r)Update this Rect to enclose itself and the specified rectangle. If the
specified rectangle is empty, nothing is done. If this rectangle is empty
it is set to the specified rectangle.
union(r.left, r.top, r.right, r.bottom);
|
public void | union(float x, float y)Update this Rect to enclose itself and the [x,y] coordinate. There is no
check to see that this rectangle is non-empty.
if (x < left) {
left = x;
} else if (x > right) {
right = x;
}
if (y < top) {
top = y;
} else if (y > bottom) {
bottom = y;
}
|
public final float | width()
return right - left;
|
public void | writeToParcel(android.os.Parcel out, int flags)Write this rectangle to the specified parcel. To restore a rectangle from
a parcel, use readFromParcel()
out.writeFloat(left);
out.writeFloat(top);
out.writeFloat(right);
out.writeFloat(bottom);
|