RectF
open class RectF : Parcelable
kotlin.Any | |
↳ | android.graphics.RectF |
RectF holds four float coordinates for a rectangle. The rectangle is represented by the coordinates of its 4 edges (left, top, right, bottom). These fields can be accessed directly. Use width() and height() to retrieve the rectangle's width and height. Note: most methods do not check to see that the coordinates are sorted correctly (i.e. left <= right and top <= bottom).
Summary
Inherited constants | |
---|---|
Public constructors | |
---|---|
RectF() Create a new empty RectF. |
|
Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified). |
|
Create a new rectangle with the specified coordinates. |
Public methods | |
---|---|
Float |
centerX() |
Float |
centerY() |
open Boolean |
Returns true iff the specified rectangle r is inside or equal to this rectangle. |
open Boolean |
Returns true if (x,y) is inside the rectangle. |
open Boolean |
Returns true iff the 4 specified sides of a rectangle are inside or equal to this rectangle. |
open Int |
Parcelable interface methods |
open Boolean | |
open Int |
hashCode() |
Float |
height() |
open Unit |
Inset the rectangle by (dx,dy). |
open Boolean |
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. |
open Boolean |
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. |
open Boolean |
intersects(left: Float, top: Float, right: Float, bottom: Float) Returns true if this rectangle intersects the specified rectangle. |
open static Boolean |
intersects(a: RectF, b: RectF) Returns true iff the two specified rectangles intersect. |
Boolean |
isEmpty() Returns true if the rectangle is empty (left >= right or top >= bottom) |
open Unit |
Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates. |
open Unit |
Offset the rectangle to a specific (left, top) position, keeping its width and height the same. |
open Unit |
readFromParcel(in: Parcel) Set the rectangle's coordinates from the data stored in the specified parcel. |
open Unit |
Set the dst integer Rect by rounding this rectangle's coordinates to their nearest integer values. |
open Unit |
Set the dst integer Rect by rounding "out" this rectangle, choosing the floor of top and left, and the ceiling of right and bottom. |
open Unit |
Copy the coordinates from src into this rectangle. |
open Unit |
Copy the coordinates from src into this rectangle. |
open Unit |
Set the rectangle's coordinates to the specified values. |
open Unit |
setEmpty() Set the rectangle to (0,0,0,0) |
open Boolean |
setIntersect(a: RectF, b: RectF) If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. |
open Unit |
sort() Swap top/bottom or left/right if there are flipped (i.e. left > right and/or top > bottom). |
open String |
Return a string representation of the rectangle in a compact form. |
open String |
toString() |
open Unit |
Update this Rect to enclose itself and the specified rectangle. |
open Unit |
Update this Rect to enclose itself and the [x,y] coordinate. |
open Unit |
Update this Rect to enclose itself and the specified rectangle. |
Float |
width() |
open Unit |
writeToParcel(out: Parcel, flags: Int) Write this rectangle to the specified parcel. |
Properties | |
---|---|
static Parcelable.Creator<RectF!> | |
Float | |
Float | |
Float | |
Float |
Public constructors
RectF
RectF(r: RectF?)
Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).
Parameters | |
---|---|
r |
RectF?: The rectangle whose coordinates are copied into the new rectangle. This value may be null . |
RectF
RectF(
left: Float,
top: Float,
right: Float,
bottom: Float)
Create a new rectangle with the specified coordinates. Note: no range checking is performed, so the caller must ensure that left <= right and top <= bottom.
Parameters | |
---|---|
left |
Float: The X coordinate of the left side of the rectangle |
top |
Float: The Y coordinate of the top of the rectangle |
right |
Float: The X coordinate of the right side of the rectangle |
bottom |
Float: The Y coordinate of the bottom of the rectangle |
Public methods
centerX
fun centerX(): Float
Return | |
---|---|
Float |
the horizontal center of the rectangle. This does not check for a valid rectangle (i.e. left <= right) |
centerY
fun centerY(): Float
Return | |
---|---|
Float |
the vertical center of the rectangle. This does not check for a valid rectangle (i.e. top <= bottom) |
contains
open fun contains(r: RectF): Boolean
Returns true iff the specified rectangle r is inside or equal to this rectangle. An empty rectangle never contains another rectangle.
Parameters | |
---|---|
r |
RectF: The rectangle being tested for containment. This value cannot be null . |
Return | |
---|---|
Boolean |
true iff the specified rectangle r is inside or equal to this rectangle |
contains
open fun contains(
x: Float,
y: Float
): Boolean
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.
Parameters | |
---|---|
x |
Float: The X coordinate of the point being tested for containment |
y |
Float: The Y coordinate of the point being tested for containment |
Return | |
---|---|
Boolean |
true iff (x,y) are contained by the rectangle, where containment means left <= x < right and top <= y < bottom |
contains
open fun contains(
left: Float,
top: Float,
right: Float,
bottom: Float
): Boolean
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.
Parameters | |
---|---|
left |
Float: The left side of the rectangle being tested for containment |
top |
Float: The top of the rectangle being tested for containment |
right |
Float: The right side of the rectangle being tested for containment |
bottom |
Float: The bottom of the rectangle being tested for containment |
Return | |
---|---|
Boolean |
true iff the 4 specified sides of a rectangle are inside or equal to this rectangle |
describeContents
open fun describeContents(): Int
Parcelable interface methods
Return | |
---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
equals
open fun equals(other: Any?): Boolean
Parameters | |
---|---|
obj |
the reference object with which to compare. |
Return | |
---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
hashCode
open fun hashCode(): Int
Return | |
---|---|
Int |
a hash code value for this object. |
height
fun height(): Float
Return | |
---|---|
Float |
the rectangle's height. This does not check for a valid rectangle (i.e. top <= bottom) so the result may be negative. |
inset
open fun inset(
dx: Float,
dy: Float
): Unit
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.
Parameters | |
---|---|
dx |
Float: The amount to add(subtract) from the rectangle's left(right) |
dy |
Float: The amount to add(subtract) from the rectangle's top(bottom) |
intersect
open fun intersect(r: RectF): Boolean
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()
Parameters | |
---|---|
r |
RectF: The rectangle being intersected with this rectangle. This value cannot be null . |
Return | |
---|---|
Boolean |
true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle. |
intersect
open fun intersect(
left: Float,
top: Float,
right: Float,
bottom: Float
): Boolean
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()
Parameters | |
---|---|
left |
Float: The left side of the rectangle being intersected with this rectangle |
top |
Float: The top of the rectangle being intersected with this rectangle |
right |
Float: The right side of the rectangle being intersected with this rectangle. |
bottom |
Float: The bottom of the rectangle being intersected with this rectangle. |
Return | |
---|---|
Boolean |
true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle. |
intersects
open fun intersects(
left: Float,
top: Float,
right: Float,
bottom: Float
): Boolean
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().
Parameters | |
---|---|
left |
Float: The left side of the rectangle being tested for intersection |
top |
Float: The top of the rectangle being tested for intersection |
right |
Float: The right side of the rectangle being tested for intersection |
bottom |
Float: The bottom of the rectangle being tested for intersection |
Return | |
---|---|
Boolean |
true iff the specified rectangle intersects this rectangle. In no event is this rectangle modified. |
intersects
open static fun intersects(
a: RectF,
b: RectF
): Boolean
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().
Parameters | |
---|---|
a |
RectF: The first rectangle being tested for intersection This value cannot be null . |
b |
RectF: The second rectangle being tested for intersection This value cannot be null . |
Return | |
---|---|
Boolean |
true iff the two specified rectangles intersect. In no event are either of the rectangles modified. |
isEmpty
fun isEmpty(): Boolean
Returns true if the rectangle is empty (left >= right or top >= bottom)
offset
open fun offset(
dx: Float,
dy: Float
): Unit
Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.
Parameters | |
---|---|
dx |
Float: The amount to add to the rectangle's left and right coordinates |
dy |
Float: The amount to add to the rectangle's top and bottom coordinates |
offsetTo
open fun offsetTo(
newLeft: Float,
newTop: Float
): Unit
Offset the rectangle to a specific (left, top) position, keeping its width and height the same.
Parameters | |
---|---|
newLeft |
Float: The new "left" coordinate for the rectangle |
newTop |
Float: The new "top" coordinate for the rectangle |
readFromParcel
open fun readFromParcel(in: Parcel): Unit
Set the rectangle's coordinates from the data stored in the specified parcel. To write a rectangle to a parcel, call writeToParcel().
Parameters | |
---|---|
in |
Parcel: The parcel to read the rectangle's coordinates from This value cannot be null . |
round
open fun round(dst: Rect): Unit
Set the dst integer Rect by rounding this rectangle's coordinates to their nearest integer values.
Parameters | |
---|---|
dst |
Rect: This value cannot be null . |
roundOut
open fun roundOut(dst: Rect): Unit
Set the dst integer Rect by rounding "out" this rectangle, choosing the floor of top and left, and the ceiling of right and bottom.
Parameters | |
---|---|
dst |
Rect: This value cannot be null . |
set
open fun set(src: Rect): Unit
Copy the coordinates from src into this rectangle.
Parameters | |
---|---|
src |
Rect: The rectangle whose coordinates are copied into this rectangle. This value cannot be null . |
set
open fun set(src: RectF): Unit
Copy the coordinates from src into this rectangle.
Parameters | |
---|---|
src |
RectF: The rectangle whose coordinates are copied into this rectangle. This value cannot be null . |
set
open fun set(
left: Float,
top: Float,
right: Float,
bottom: Float
): Unit
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.
Parameters | |
---|---|
left |
Float: The X coordinate of the left side of the rectangle |
top |
Float: The Y coordinate of the top of the rectangle |
right |
Float: The X coordinate of the right side of the rectangle |
bottom |
Float: The Y coordinate of the bottom of the rectangle |
setIntersect
open fun setIntersect(
a: RectF,
b: RectF
): Boolean
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()
Parameters | |
---|---|
a |
RectF: The first rectangle being intersected with This value cannot be null . |
b |
RectF: The second rectangle being intersected with This value cannot be null . |
Return | |
---|---|
Boolean |
true iff the two specified rectangles intersect. If they do, set this rectangle to that intersection. If they do not, return false and do not change this rectangle. |
sort
open fun sort(): Unit
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.
toShortString
open fun toShortString(): String
Return a string representation of the rectangle in a compact form.
Return | |
---|---|
String |
This value cannot be null . |
toString
open fun toString(): String
Return | |
---|---|
String |
a string representation of the object. |
union
open fun union(r: RectF): Unit
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.
Parameters | |
---|---|
r |
RectF: The rectangle being unioned with this rectangle This value cannot be null . |
union
open fun union(
x: Float,
y: Float
): Unit
Update this Rect to enclose itself and the [x,y] coordinate. There is no check to see that this rectangle is non-empty.
Parameters | |
---|---|
x |
Float: The x coordinate of the point to add to the rectangle |
y |
Float: The y coordinate of the point to add to the rectangle |
union
open fun union(
left: Float,
top: Float,
right: Float,
bottom: Float
): Unit
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.
Parameters | |
---|---|
left |
Float: The left edge being unioned with this rectangle |
top |
Float: The top edge being unioned with this rectangle |
right |
Float: The right edge being unioned with this rectangle |
bottom |
Float: The bottom edge being unioned with this rectangle |
width
fun width(): Float
Return | |
---|---|
Float |
the rectangle's width. This does not check for a valid rectangle (i.e. left <= right) so the result may be negative. |
writeToParcel
open fun writeToParcel(
out: Parcel,
flags: Int
): Unit
Write this rectangle to the specified parcel. To restore a rectangle from a parcel, use readFromParcel()
Parameters | |
---|---|
dest |
The Parcel in which the object should be written. This value cannot be null . |
flags |
Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE . Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |
out |
Parcel: The parcel to write the rectangle's coordinates into |