RectF

data class RectF(var left: Float = 0.0f, var top: Float = 0.0f, var right: Float = 0.0f, var bottom: Float = 0.0f)

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).

Constructors

Link copied to clipboard
constructor(left: Float = 0.0f, top: Float = 0.0f, right: Float = 0.0f, bottom: Float = 0.0f)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var left: Float
Link copied to clipboard
Link copied to clipboard
var top: Float

Functions

Link copied to clipboard
fun centerX(): Float
Link copied to clipboard
fun centerY(): Float
Link copied to clipboard
operator 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.

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.

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.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun height(): Float
Link copied to clipboard
fun inset(dx: Float, dy: Float)

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.

Link copied to clipboard

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()

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()

Link copied to clipboard
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().

Link copied to clipboard
fun offset(dx: Float, dy: Float)

Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.

Link copied to clipboard
fun offsetTo(newLeft: Float, newTop: Float)

Offset the rectangle to a specific (left, top) position, keeping its width and height the same.

Link copied to clipboard
fun round(dst: Rect)

Set the dst integer Rect by rounding this rectangle's coordinates to their nearest integer values.

Link copied to clipboard
fun roundOut(dst: Rect)

Set the dst integer Rect by rounding "out" this rectangle, choosing the floor of top and left, and the ceiling of right and bottom.

Link copied to clipboard
fun scale(scale: Float)

Scales up the rect by the given scale.

Link copied to clipboard
fun set(src: Rect)
fun set(src: RectF)

Copy the coordinates from src into this rectangle.

operator fun set(left: Float, top: Float, right: Float, bottom: Float)

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.

Link copied to clipboard
fun setEmpty()

Set the rectangle to (0,0,0,0)

Link copied to clipboard

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()

Link copied to clipboard
fun 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.

Link copied to clipboard
fun toShortString(sb: StringBuilder = StringBuilder(32)): String

Return a string representation of the rectangle in a compact form.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun union(r: RectF)
fun union(left: Float, top: Float, right: Float, bottom: Float)

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.

fun union(x: Float, y: Float)

Update this Rect to enclose itself and the x,y coordinate. There is no check to see that this rectangle is non-empty.

Link copied to clipboard
fun width(): Float