core-ktx / androidx.graphics / android.graphics.Rect

Extensions for android.graphics.Rect

and

infix fun Rect.and(r: Rect): Rect

Returns the union of two rectangles as a new rectangle.

component1

operator fun Rect.component1(): Int

Returns "left", the first component of the rectangle.

component2

operator fun Rect.component2(): Int

Returns "top", the second component of the rectangle.

component3

operator fun Rect.component3(): Int

Returns "right", the third component of the rectangle.

component4

operator fun Rect.component4(): Int

Returns "bottom", the fourth component of the rectangle.

contains

operator fun Rect.contains(p: Point): Boolean

Returns true if the specified point 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 point to be contained: left <= x < right and top <= y < bottom. An empty rectangle never contains any point.

minus

operator fun Rect.minus(r: Rect): Region

Returns the difference of this rectangle and the specified rectangle as a new region.

operator fun Rect.minus(xy: Int): Rect

Returns a new rectangle representing this rectangle offset by the negation of the specified amount on both X and Y axis.

operator fun Rect.minus(xy: Point): Rect

Returns a new rectangle representing this rectangle offset by the negation of the specified point.

or

infix fun Rect.or(r: Rect): Rect

Returns the intersection of two rectangles as a new rectangle. If the rectangles do not intersect, returns a copy of the left hand side rectangle.

plus

operator fun Rect.plus(r: Rect): Rect

Performs the union of this rectangle and the specified rectangle and returns the result as a new rectangle.

operator fun Rect.plus(xy: Int): Rect

Returns a new rectangle representing this rectangle offset by the specified amount on both X and Y axis.

operator fun Rect.plus(xy: Point): Rect

Returns a new rectangle representing this rectangle offset by the specified point.

toRectF

fun Rect.toRectF(): RectF

Returns a RectF representation of this rectangle.

toRegion

fun Rect.toRegion(): Region

Returns a Region representation of this rectangle.

xor

infix fun Rect.xor(r: Rect): Region

Returns the union minus the intersection of two rectangles as a new region.