Google is committed to advancing racial equity for Black communities. See how.

Rect

@Immutable data class Rect
kotlin.Any
   ↳ androidx.compose.ui.geometry.Rect

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

Summary

Public constructors
<init>(left: Float, top: Float, right: Float, bottom: Float)

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

Public methods
Boolean
contains(offset: Offset)

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.

Rect
deflate(delta: Float)

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

Rect
inflate(delta: Float)

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

Rect
intersect(other: Rect)

Returns a new rectangle that is the intersection of the given rectangle and this rectangle.

Boolean
overlaps(other: Rect)

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

Rect
shift(offset: Offset)

Returns a new rectangle translated by the given offset.

String

Rect
translate(offset: Offset)

Returns a new rectangle translated by the given offset.

Rect
translate(translateX: Float, translateY: Float)

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

Extension functions
From androidx.compose.ui.graphics
Rect

Creates a new instance of android.graphics.Rect with the same bounds specified in the given Rect

RectF

Creates a new instance of android.graphics.RectF with the same bounds specified in the given Rect

Properties
Float

The offset of the bottom edge of this rectangle from the y axis.

Offset

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

Offset

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

Offset

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

Offset

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

Offset

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

Offset

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

Float

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

Boolean

Whether this rectangle encloses a non-zero area.

Boolean

Whether all coordinates of this rectangle are finite.

Boolean

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

Float

The offset of the left edge of this rectangle from the x axis.

Float

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

Float

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

Float

The offset of the right edge of this rectangle from the x axis.

Size

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

Float

The offset of the top edge of this rectangle from the y axis.

Offset

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

Offset

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

Offset

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

Float

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

Companion properties
Rect

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

Public constructors

<init>

Rect(
    left: Float,
    top: Float,
    right: Float,
    bottom: Float)

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

Public methods

contains

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.

deflate

@Stable fun deflate(delta: Float): Rect

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

inflate

@Stable fun inflate(delta: Float): Rect

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

intersect

@Stable 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.

overlaps

fun overlaps(other: Rect): Boolean

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

shift

@Stable fun shift(offset: Offset): Rect

Deprecated.

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.

toString

fun toString(): String

translate

@Stable 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

@Stable 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.

Properties

bottom

@Stable val bottom: Float

The offset of the bottom edge of this rectangle from the y axis.

bottomCenter

val bottomCenter: Offset

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

bottomLeft

val bottomLeft: Offset

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

bottomRight

val bottomRight: Offset

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

center

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.

centerLeft

val centerLeft: Offset

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

centerRight

val centerRight: Offset

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

height

@Stable val height: Float

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

isEmpty

@Stable val isEmpty: Boolean

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

isFinite

@Stable val isFinite: Boolean

Whether all coordinates of this rectangle are finite.

isInfinite

@Stable val isInfinite: Boolean

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

left

@Stable val left: Float

The offset of the left edge of this rectangle from the x axis.

maxDimension

val maxDimension: Float

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

minDimension

val minDimension: Float

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

@Stable val right: Float

The offset of the right edge of this rectangle from the x axis.

size

@Stable val size: Size

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

top

@Stable val top: Float

The offset of the top edge of this rectangle from the y axis.

topCenter

val topCenter: Offset

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

topLeft

val topLeft: Offset

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

topRight

val topRight: Offset

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

width

@Stable val width: Float

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

Companion properties

Zero

@Stable val Zero: Rect

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