# Rect

Artifact: [androidx.compose.ui:ui-geometry](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/geometry/Rect.kt+class:androidx.compose.ui.geometry.Rect) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/All
- Cmn

  ```
  data class Rect
  ```

*** ** * ** ***

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

## Summary

| ### Nested types |
|---|
| `object https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect.Companion` |

| ### Public companion properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#Zero()` A rectangle with left, top, right, and bottom edges all at zero. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#Rect(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)(left: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, top: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, right: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, bottom: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` | Cmn |

| ### Public functions |
|---|---|---|
| `operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#contains(androidx.compose.ui.geometry.Offset)(offset: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/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. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#deflate(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new rectangle with edges moved inwards by the given delta. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#inflate(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new rectangle with edges moved outwards by the given delta. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#intersect(androidx.compose.ui.geometry.Rect)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect)` Returns a new rectangle that is the intersection of the given rectangle and this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#intersect(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)( otherLeft: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, otherTop: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, otherRight: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, otherBottom: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Returns a new rectangle that is the intersection of the given rectangle and this rectangle. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#overlaps(androidx.compose.ui.geometry.Rect)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect)` Whether `other` has a nonzero area of overlap with this rectangle. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#toString()()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#translate(androidx.compose.ui.geometry.Offset)(offset: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` Returns a new rectangle translated by the given offset. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#translate(kotlin.Float,kotlin.Float)(translateX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, translateY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new rectangle with translateX added to the x components and translateY added to the y components. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#bottom()` The offset of the bottom edge of this rectangle from the y axis. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#bottomCenter()` The offset to the center of the bottom edge of this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#bottomLeft()` The offset to the intersection of the bottom and left edges of this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#bottomRight()` The offset to the intersection of the bottom and right edges of this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#center()` The offset to the point halfway between the left and right and the top and bottom edges of this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#centerLeft()` The offset to the center of the left edge of this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#centerRight()` The offset to the center of the right edge of this rectangle. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#height()` The distance between the top and bottom edges of this rectangle. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#isEmpty()` Whether this rectangle encloses a non-zero area. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#isFinite()` Whether all coordinates of this rectangle are finite. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#isInfinite()` Whether any of the coordinates of this rectangle are equal to positive infinity. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#left()` The offset of the left edge of this rectangle from the x axis. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#maxDimension()` The greater of the magnitudes of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#width()` and the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#height()` of this rectangle. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#minDimension()` The lesser of the magnitudes of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#width()` and the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#height()` of this rectangle. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#right()` The offset of the right edge of this rectangle from the x axis. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#size()` The distance between the upper-left corner and the lower-right corner of this rectangle. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#top()` The offset of the top edge of this rectangle from the y axis. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#topCenter()` The offset to the center of the top edge of this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#topLeft()` The offset to the intersection of the top and left edges of this rectangle. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#topRight()` The offset to the intersection of the top and right edges of this rectangle. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#width()` The distance between the left and right edges of this rectangle. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntRect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#(androidx.compose.ui.geometry.Rect).roundToIntRect()()` Rounds a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` to an `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntRect` | Cmn |
| `https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect.[toAndroidRect](https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#(androidx.compose.ui.geometry.Rect).toAndroidRect())()` **This function is deprecated.** Converting Rect to android.graphics.Rect is lossy, and requires rounding. | android |
| `https://developer.android.com/reference/android/graphics/RectF.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#(androidx.compose.ui.geometry.Rect).toAndroidRectF()()` Creates a new instance of `https://developer.android.com/reference/android/graphics/RectF.html` with the same bounds specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | android |

## Public companion properties

### Zero

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val Zero: Rect
```

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

## Public constructors

### Rect

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

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

## Public functions

### contains

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

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

### deflate

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
fun deflate(delta: Float): Rect
```

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

### inflate

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
fun inflate(delta: Float): Rect
```

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

### intersect

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
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

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.6.0)

```
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

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
fun overlaps(other: Rect): Boolean
```

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

### toString

Cmn

```
open fun toString(): String
```

### translate

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset`, consider `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#translate(androidx.compose.ui.geometry.Offset)`.

### translate

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

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

## Public properties

### bottom

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val bottom: Float
```

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

### bottomCenter

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val bottomCenter: Offset
```

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

### bottomLeft

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val bottomLeft: Offset
```

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

### bottomRight

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val bottomRight: Offset
```

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

### center

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Size).center()`.

### centerLeft

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val centerLeft: Offset
```

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

### centerRight

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val centerRight: Offset
```

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

### height

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val height: Float
```

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

### isEmpty

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val isEmpty: Boolean
```

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

### isFinite

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val isFinite: Boolean
```

Whether all coordinates of this rectangle are finite.

### isInfinite

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val isInfinite: Boolean
```

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

### left

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val left: Float
```

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

### maxDimension

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val maxDimension: Float
```

The greater of the magnitudes of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#width()` and the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#height()` of this rectangle.

### minDimension

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val minDimension: Float
```

The lesser of the magnitudes of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#width()` and the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#height()` of this rectangle.

### right

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val right: Float
```

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

### size

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val size: Size
```

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

### top

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val top: Float
```

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

### topCenter

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val topCenter: Offset
```

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

### topLeft

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val topLeft: Offset
```

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

### topRight

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val topRight: Offset
```

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

### width

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val width: Float
```

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

## Extension functions

### Rect.roundToIntRect

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/IntRect.kt+function:roundToIntRect)

```
fun Rect.roundToIntRect(): IntRect
```

Rounds a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` to an `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntRect`

### Rect.toAndroidRect

android Artifact: [androidx.compose.ui:ui-graphics](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/graphics/RectHelper.android.kt+function:toAndroidRect)

```
fun Rect.[toAndroidRect](https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect#(androidx.compose.ui.geometry.Rect).toAndroidRect())(): Rect
```

> [!CAUTION]
> **This function is deprecated.**   
> Converting Rect to android.graphics.Rect is lossy, and requires rounding. The behavior of toAndroidRect() truncates to an integral Rect, but you should choose the method of rounding most suitable for your use case, use this instead:
>
> ```kotlin
> android.graphics.Rect(left.toInt(), top.toInt(), right.toInt(), bottom.toInt())
> ```

Creates a new instance of `https://developer.android.com/reference/android/graphics/Rect.html` with the same bounds specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect`

### Rect.toAndroidRectF

android Artifact: [androidx.compose.ui:ui-graphics](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/graphics/RectHelper.android.kt+function:toAndroidRectF)

```
fun Rect.toAndroidRectF(): RectF
```

Creates a new instance of `https://developer.android.com/reference/android/graphics/RectF.html` with the same bounds specified in the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect`