{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Rect

public final class Rect


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

Summary

Nested types

public static class Rect.Companion

Public constructors

Rect(float left, float top, float right, float bottom)

Public methods

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

final @NonNull Rect
deflate(float delta)

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

final float

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

final @NonNull Offset

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

final @NonNull Offset

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

final @NonNull Offset

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

final @NonNull Offset

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

final @NonNull Offset

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

final @NonNull Offset

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

final float

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

final float

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

final float

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

final float

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

final float

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

final @NonNull Size

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

final float

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

final @NonNull Offset

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

final @NonNull Offset

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

final @NonNull Offset

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

final float

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

final @NonNull Rect
inflate(float delta)

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

final @NonNull Rect

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

final boolean

Whether this rectangle encloses a non-zero area.

final boolean

Whether all coordinates of this rectangle are finite.

final boolean

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

final boolean

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

@NonNull String
final @NonNull Rect

Returns a new rectangle translated by the given offset.

final @NonNull Rect
translate(float translateX, float translateY)

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

Extension functions

final @NonNull IntRect

Rounds a Rect to an IntRect

final @NonNull Rect

This method is deprecated. Converting Rect to android.graphics.Rect is lossy, and requires rounding.

final @NonNull RectF

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

Public constructors

Rect

public Rect(float left, float top, float right, float bottom)

Public methods

contains

public final boolean contains(@NonNull 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.

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

deflate

public final @NonNull Rect deflate(float delta)

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

getBottom

public final float getBottom()

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

getBottomCenter

public final @NonNull Offset getBottomCenter()

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

getBottomLeft

public final @NonNull Offset getBottomLeft()

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

getBottomRight

public final @NonNull Offset getBottomRight()

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

getCenter

public final @NonNull Offset getCenter()

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

See also Size.center.

getCenterLeft

public final @NonNull Offset getCenterLeft()

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

getCenterRight

public final @NonNull Offset getCenterRight()

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

getHeight

public final float getHeight()

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

getLeft

public final float getLeft()

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

getMaxDimension

public final float getMaxDimension()

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

getMinDimension

public final float getMinDimension()

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

getRight

public final float getRight()

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

getSize

public final @NonNull Size getSize()

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

getTop

public final float getTop()

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

getTopCenter

public final @NonNull Offset getTopCenter()

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

getTopLeft

public final @NonNull Offset getTopLeft()

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

getTopRight

public final @NonNull Offset getTopRight()

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

getWidth

public final float getWidth()

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

inflate

public final @NonNull Rect inflate(float delta)

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

intersect

public final @NonNull Rect intersect(@NonNull Rect other)

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.

isEmpty

public final boolean isEmpty()

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

isFinite

public final boolean isFinite()

Whether all coordinates of this rectangle are finite.

isInfinite

public final boolean isInfinite()

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

overlaps

public final boolean overlaps(@NonNull Rect other)

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

toString

public @NonNull String toString()

translate

public final @NonNull Rect translate(@NonNull Offset offset)

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

public final @NonNull Rect translate(float translateX, float translateY)

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

Extension functions

IntRectKt.roundToIntRect

public final @NonNull IntRect IntRectKt.roundToIntRect(@NonNull Rect receiver)

Rounds a Rect to an IntRect

RectHelperKt.toAndroidRect

public final @NonNull Rect RectHelperKt.toAndroidRect(@NonNull Rect receiver)

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

RectHelperKt.toAndroidRectF

public final @NonNull RectF RectHelperKt.toAndroidRectF(@NonNull Rect receiver)

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