Class

Rect

An immutable, 2D, axis-aligned, floating-point rectangle whose coordinates are relative to a given origin.

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Source set: Common

Added in 1.11.0-rc01

data class Rect(
    /** The offset of the left edge of this rectangle from the x axis. */
    @Stable val left: Float,

    /** The offset of the top edge of this rectangle from the y axis. */
    @Stable val top: Float,

    /** The offset of the right edge of this rectangle from the x axis. */
    @Stable val right: Float,

    /** The offset of the bottom edge of this rectangle from the y axis. */
    @Stable val bottom: Float,
)

An immutable, 2D, axis-aligned, floating-point rectangle whose coordinates are relative to a given origin.

Properties

width

Source set: Common

Added in 1.11.0-rc01

inline val width: Float

The distance between the left and right edges of this rectangle.

height

Source set: Common

Added in 1.11.0-rc01

inline val height: Float

The distance between the top and bottom edges of this rectangle.

size

Source set: Common

Added in 1.11.0-rc01

val size: Size

The distance between the upper-left corner and the lower-right corner of this rectangle.

isInfinite

Source set: Common

Added in 1.11.0-rc01

val isInfinite: Boolean

Whether any of the coordinates of this rectangle are equal to positive infinity.

isFinite

Source set: Common

Added in 1.11.0-rc01

val isFinite: Boolean

Whether all coordinates of this rectangle are finite.

isEmpty

Source set: Common

Added in 1.11.0-rc01

val isEmpty: Boolean

Whether this rectangle encloses a non-zero area. Negative areas are considered empty.

minDimension

Source set: Common

Added in 1.11.0-rc01

val minDimension: Float

The lesser of the magnitudes of the width and the height of this rectangle.

maxDimension

Source set: Common

Added in 1.11.0-rc01

val maxDimension: Float

The greater of the magnitudes of the width and the height of this rectangle.

topLeft

Source set: Common

Added in 1.11.0-rc01

val topLeft: Offset

The offset to the intersection of the top and left edges of this rectangle.

topCenter

Source set: Common

Added in 1.11.0-rc01

val topCenter: Offset

The offset to the center of the top edge of this rectangle.

topRight

Source set: Common

Added in 1.11.0-rc01

val topRight: Offset

The offset to the intersection of the top and right edges of this rectangle.

centerLeft

Source set: Common

Added in 1.11.0-rc01

val centerLeft: Offset

The offset to the center of the left edge of this rectangle.

center

Source set: Common

Added in 1.11.0-rc01

val center: Offset

The offset to the point halfway between the left and right and the top and bottom edges of this rectangle.

See also Size.center.

centerRight

Source set: Common

Added in 1.11.0-rc01

val centerRight: Offset

The offset to the center of the right edge of this rectangle.

bottomLeft

Source set: Common

Added in 1.11.0-rc01

val bottomLeft: Offset

The offset to the intersection of the bottom and left edges of this rectangle.

bottomCenter

Source set: Common

Added in 1.11.0-rc01

val bottomCenter: Offset

The offset to the center of the bottom edge of this rectangle.

bottomRight

Source set: Common

Added in 1.11.0-rc01

val bottomRight: Offset

The offset to the intersection of the bottom and right edges of this rectangle.

Functions

translate

Added in 1.11.0-rc01

fun translate(offset: Offset): Rect

Returns a new rectangle translated by the given offset.

To translate a rectangle by separate x and y components rather than by an Offset, consider translate.

translate

Added in 1.11.0-rc01

fun translate(translateX: Float, translateY: Float): Rect

Returns a new rectangle with translateX added to the x components and translateY added to the y components.

inflate

Added in 1.11.0-rc01

fun inflate(delta: Float): Rect

Returns a new rectangle with edges moved outwards by the given delta.

deflate

Added in 1.11.0-rc01

fun deflate(delta: Float): Rect

Returns a new rectangle with edges moved inwards by the given delta.

intersect

Added in 1.11.0-rc01

fun intersect(other: Rect): Rect

Returns a new rectangle that is the intersection of the given rectangle and this rectangle. The two rectangles must overlap for this to be meaningful. If the two rectangles do not overlap, then the resulting Rect will have a negative width or height.

intersect

Added in 1.11.0-rc01

fun intersect(otherLeft: Float, otherTop: Float, otherRight: Float, otherBottom: Float): Rect

Returns a new rectangle that is the intersection of the given rectangle and this rectangle. The two rectangles must overlap for this to be meaningful. If the two rectangles do not overlap, then the resulting Rect will have a negative width or height.

overlaps

Added in 1.11.0-rc01

fun overlaps(other: Rect): Boolean

Whether other has a nonzero area of overlap with this rectangle.

contains

Added in 1.11.0-rc01

operator fun contains(offset: Offset): Boolean

Whether the point specified by the given offset (which is assumed to be relative to the origin) lies between the left and right and the top and bottom edges of this rectangle.

Rectangles include their top and left edges but exclude their bottom and right edges.

Companion Object

Properties

Source set: Common

Added in 1.11.0-rc01

val Zero: Rect

A rectangle with left, top, right, and bottom edges all at zero.