# Box

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

*** ** * ** ***


```
public abstract class Box
```

<br />

Known direct subclasses [ImmutableBox](https://developer.android.com/reference/androidx/ink/geometry/ImmutableBox), [MutableBox](https://developer.android.com/reference/androidx/ink/geometry/MutableBox)

|---|---|
| `https://developer.android.com/reference/androidx/ink/geometry/ImmutableBox` | An immutable axis-aligned rectangle. |
| `https://developer.android.com/reference/androidx/ink/geometry/MutableBox` | A mutable axis-aligned rectangle. |

*** ** * ** ***

Represents an axis-aligned rectangle. See `https://developer.android.com/reference/androidx/ink/geometry/ImmutableBox` and `https://developer.android.com/reference/androidx/ink/geometry/MutableBox` for concrete classes implementing `https://developer.android.com/reference/androidx/ink/geometry/Box`.

The `https://developer.android.com/reference/androidx/ink/geometry/Box` interface is the read-only view of the underlying data which may or may not be mutable.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCenter()()` Returns the center of the `https://developer.android.com/reference/androidx/ink/geometry/Box`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCenter(androidx.ink.geometry.MutableVec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVec)` Populates `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCenter(androidx.ink.geometry.MutableVec)` with the center of the `https://developer.android.com/reference/androidx/ink/geometry/Box`, and returns `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCenter(androidx.ink.geometry.MutableVec)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec>` | `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCorners()()` Returns a list containing the 4 corners of the `https://developer.android.com/reference/androidx/ink/geometry/Box`. |
| `final void` | `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCorners(androidx.ink.geometry.MutableVec,androidx.ink.geometry.MutableVec,androidx.ink.geometry.MutableVec,androidx.ink.geometry.MutableVec)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVecXMinYMin, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVecXMaxYMin, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVecXMaxYMax, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVecXMinYMax )` Populates the 4 output points with the corners of the `https://developer.android.com/reference/androidx/ink/geometry/Box`. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Box#contains(androidx.ink.geometry.Box)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Box otherBox)` Returns whether the other Box is contained within this Box. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Box#contains(androidx.ink.geometry.Vec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec point)` Returns whether the given point is contained within the Box. |
| `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float` | `https://developer.android.com/reference/androidx/ink/geometry/Box#getHeight()()` The height of the rectangle. |
| `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float` | `https://developer.android.com/reference/androidx/ink/geometry/Box#getWidth()()` The width of the rectangle. |
| `abstract float` | `https://developer.android.com/reference/androidx/ink/geometry/Box#getXMax()()` The upper bound in the `X` direction. |
| `abstract float` | `https://developer.android.com/reference/androidx/ink/geometry/Box#getXMin()()` The lower bound in the `X` direction. |
| `abstract float` | `https://developer.android.com/reference/androidx/ink/geometry/Box#getYMax()()` The upper bound in the `Y` direction. |
| `abstract float` | `https://developer.android.com/reference/androidx/ink/geometry/Box#getYMin()()` The lower bound in the `Y` direction. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Box#isAlmostEqual(androidx.ink.geometry.Box,kotlin.Float)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Box other, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float tolerance)` Compares this `https://developer.android.com/reference/androidx/ink/geometry/Box` with `https://developer.android.com/reference/androidx/ink/geometry/Box#isAlmostEqual(androidx.ink.geometry.Box,kotlin.Float)`, and returns true if the difference between `https://developer.android.com/reference/androidx/ink/geometry/Box#xMin()` from `this` and `https://developer.android.com/reference/androidx/ink/geometry/Box#xMin()` from `https://developer.android.com/reference/androidx/ink/geometry/Box#isAlmostEqual(androidx.ink.geometry.Box,kotlin.Float)` is less than `https://developer.android.com/reference/androidx/ink/geometry/Box#isAlmostEqual(androidx.ink.geometry.Box,kotlin.Float)`, and likewise for `https://developer.android.com/reference/androidx/ink/geometry/Box#xMax()`, `https://developer.android.com/reference/androidx/ink/geometry/Box#yMin()`, and `https://developer.android.com/reference/androidx/ink/geometry/Box#yMax()`. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableBox` | `https://developer.android.com/reference/androidx/ink/geometry/Box#toImmutable()()` Returns an immutable copy of this object. |

| ### Extension functions |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/RectF.html` | `https://developer.android.com/reference/androidx/ink/geometry/AndroidGraphicsConverter.https://developer.android.com/reference/androidx/ink/geometry/Box#(androidx.ink.geometry.Box).populateRectF(android.graphics.RectF)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Box receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/RectF.html out )` Writes the values from this `https://developer.android.com/reference/androidx/ink/geometry/Box` to `https://developer.android.com/reference/androidx/ink/geometry/package-summary#(androidx.ink.geometry.Box).populateRectF(android.graphics.RectF)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/RectF.html` | `https://developer.android.com/reference/androidx/ink/geometry/AndroidGraphicsConverter.https://developer.android.com/reference/androidx/ink/geometry/Box#(androidx.ink.geometry.Box).toRectF()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Box receiver)` Constructs a `https://developer.android.com/reference/android/graphics/RectF.html` with the same coordinates as the `https://developer.android.com/reference/androidx/ink/geometry/Box` |

## Public methods

### computeCenter

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull ImmutableVec computeCenter()
```

Returns the center of the `https://developer.android.com/reference/androidx/ink/geometry/Box`.

Performance-sensitive code should use the `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCenter()` overload that takes a pre-allocated `https://developer.android.com/reference/androidx/ink/geometry/MutableVec`, so that instance can be reused across multiple calls.

### computeCenter

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull MutableVec computeCenter(@NonNull MutableVec outVec)
```

Populates `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCenter(androidx.ink.geometry.MutableVec)` with the center of the `https://developer.android.com/reference/androidx/ink/geometry/Box`, and returns `https://developer.android.com/reference/androidx/ink/geometry/Box#computeCenter(androidx.ink.geometry.MutableVec)`.

### computeCorners

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull List<@NonNull ImmutableVec> computeCorners()
```

Returns a list containing the 4 corners of the `https://developer.android.com/reference/androidx/ink/geometry/Box`. The order of the corners is: (x_min, y_min), (x_max, y_min), (x_max, y_max), (x_min, y_max).

### computeCorners

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final void computeCorners(
    @NonNull MutableVec outVecXMinYMin,
    @NonNull MutableVec outVecXMaxYMin,
    @NonNull MutableVec outVecXMaxYMax,
    @NonNull MutableVec outVecXMinYMax
)
```

Populates the 4 output points with the corners of the `https://developer.android.com/reference/androidx/ink/geometry/Box`. The order of the corners is: (x_min, y_min), (x_max, y_min), (x_max, y_max), (x_min, y_max)

### contains

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean contains(@NonNull Box otherBox)
```

Returns whether the other Box is contained within this Box. Edges of the other Box that overlap with this one's boundary are considered to be contained.

### contains

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean contains(@NonNull Vec point)
```

Returns whether the given point is contained within the Box. Points that lie exactly on the Box's boundary are considered to be contained.

### getHeight

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @FloatRange(from = 0.0) float getHeight()
```

The height of the rectangle. This can never be negative.

### getWidth

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @FloatRange(from = 0.0) float getWidth()
```

The width of the rectangle. This can never be negative.

### getXMax

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract float getXMax()
```

The upper bound in the `X` direction.

### getXMin

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract float getXMin()
```

The lower bound in the `X` direction.

### getYMax

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract float getYMax()
```

The upper bound in the `Y` direction.

### getYMin

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract float getYMin()
```

The lower bound in the `Y` direction.

### isAlmostEqual

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean isAlmostEqual(@NonNull Box other, @FloatRange(from = 0.0) float tolerance)
```

Compares this `https://developer.android.com/reference/androidx/ink/geometry/Box` with `https://developer.android.com/reference/androidx/ink/geometry/Box#isAlmostEqual(androidx.ink.geometry.Box,kotlin.Float)`, and returns true if the difference between `https://developer.android.com/reference/androidx/ink/geometry/Box#xMin()` from `this` and `https://developer.android.com/reference/androidx/ink/geometry/Box#xMin()` from `https://developer.android.com/reference/androidx/ink/geometry/Box#isAlmostEqual(androidx.ink.geometry.Box,kotlin.Float)` is less than `https://developer.android.com/reference/androidx/ink/geometry/Box#isAlmostEqual(androidx.ink.geometry.Box,kotlin.Float)`, and likewise for `https://developer.android.com/reference/androidx/ink/geometry/Box#xMax()`, `https://developer.android.com/reference/androidx/ink/geometry/Box#yMin()`, and `https://developer.android.com/reference/androidx/ink/geometry/Box#yMax()`.

### toImmutable

Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
public abstract @NonNull ImmutableBox toImmutable()
```

Returns an immutable copy of this object. This will return itself if called on an immutable instance.

## Extension functions

### AndroidGraphicsConverter.populateRectF

Artifact: [androidx.ink:ink-geometry](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/geometry/AndroidGraphicsConversionExtensions.android.kt+function:populateRectF)

```
public final @NonNull RectF AndroidGraphicsConverter.populateRectF(
    @NonNull Box receiver,
    @NonNull RectF out
)
```

Writes the values from this `https://developer.android.com/reference/androidx/ink/geometry/Box` to `https://developer.android.com/reference/androidx/ink/geometry/package-summary#(androidx.ink.geometry.Box).populateRectF(android.graphics.RectF)`.

Returns the modified `https://developer.android.com/reference/android/graphics/RectF.html` instance to allow chaining calls.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/RectF.html` | `https://developer.android.com/reference/androidx/ink/geometry/package-summary#(androidx.ink.geometry.Box).populateRectF(android.graphics.RectF)` |

### AndroidGraphicsConverter.toRectF

Artifact: [androidx.ink:ink-geometry](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/geometry/AndroidGraphicsConversionExtensions.android.kt+function:toRectF)

```
public final @NonNull RectF AndroidGraphicsConverter.toRectF(@NonNull Box receiver)
```

Constructs a `https://developer.android.com/reference/android/graphics/RectF.html` with the same coordinates as the `https://developer.android.com/reference/androidx/ink/geometry/Box`