# Offset

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/Offset.kt+class:androidx.compose.ui.geometry.Offset) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/All
- Cmn

  ```
  value class Offset
  ```

*** ** * ** ***

An immutable 2D floating-point offset.

Generally speaking, Offsets can be interpreted in two ways:

1. As representing a point in Cartesian space a specified distance from a separately-maintained origin. For example, the top-left position of children in the RenderBox protocol is typically represented as an `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` from the top left of the parent box.

2. As a vector that can be applied to coordinates. For example, when painting a widget, the parent is passed an `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` from the screen's origin which it can add to the offsets of its children to find the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` from the screen's origin to each of the children.

Because a particular `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` can be interpreted as one sense at one time then as the other sense at a later time, the same class is used for both senses.

See also:

- `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size`, which represents a vector describing the size of a rectangle.

To create an `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset`, call the top-level function that accepts an x/y pair of coordinates:

```kotlin
val offset = Offset(x, y)
```

The primary constructor of `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` is intended to be used with the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#packedValue()` property to allow storing offsets in arrays or collections of primitives without boxing.

## Summary

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

| ### Public companion properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Infinite()` An offset with infinite x and y components. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` Represents an unspecified `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` value, usually a replacement for `null` when a primitive value is desired. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Zero()` An offset with zero magnitude. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Offset(kotlin.Long)(packedValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` | Cmn |

| ### Public functions |
|---|---|---|
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#component1()()` | Cmn |
| `inline operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#component2()()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#copy(kotlin.Float,kotlin.Float)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, y: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a copy of this Offset instance optionally overriding the x or y parameter | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#div(kotlin.Float)(operand: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Division operator. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#getDistance()()` The magnitude of the offset. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#getDistanceSquared()()` The square of the magnitude of the offset. | Cmn |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#isValid()()` Returns: | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#minus(androidx.compose.ui.geometry.Offset)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` Binary subtraction operator. | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#plus(androidx.compose.ui.geometry.Offset)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` Binary addition operator. | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#rem(kotlin.Float)(operand: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Modulo (remainder) operator. | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#times(kotlin.Float)(operand: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Multiplication operator. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#toString()()` | Cmn |
| `inline operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#unaryMinus()()` Unary negation operator. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#packedValue()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` value encoding the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` components of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` | Cmn |

| ### Extension functions |
|---|---|---|
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#(androidx.compose.ui.geometry.Offset).minus(androidx.compose.ui.unit.IntOffset)(offset: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntOffset)` | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#(androidx.compose.ui.geometry.Offset).plus(androidx.compose.ui.unit.IntOffset)(offset: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntOffset)` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntOffset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#(androidx.compose.ui.geometry.Offset).round()()` Round a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` down to the nearest `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` coordinates. | Cmn |
| `inline https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#(androidx.compose.ui.geometry.Offset).takeOrElse(kotlin.Function0)(block: () -> https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` If this `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Offset).isSpecified()` then this is returned, otherwise `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Offset).takeOrElse(kotlin.Function0)` is executed and its result is returned. | Cmn |

| ### Extension properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#(androidx.compose.ui.geometry.Offset).isFinite()` True if both x and y values of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` are finite. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#(androidx.compose.ui.geometry.Offset).isSpecified()` `false` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset.https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#(androidx.compose.ui.geometry.Offset).isUnspecified()` `true` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()`. | Cmn |

## Public companion properties

### Infinite

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

```
val Infinite: Offset
```

An offset with infinite x and y components.

See also `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Offset).isFinite()` to check whether both components are finite.

### Unspecified

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

```
val Unspecified: Offset
```

Represents an unspecified `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` value, usually a replacement for `null` when a primitive value is desired.

### Zero

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

```
val Zero: Offset
```

An offset with zero magnitude.

This can be used to represent the origin of a coordinate space.

## Public constructors

### Offset

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

```
Offset(packedValue: Long)
```

| Parameters |
|---|---|
| `packedValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` value encoding the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` components of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset`. Encoded values can be obtained by using the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#packedValue()` property of existing `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` instances. |

## Public functions

### component1

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

```
inline operator fun component1(): Float
```

### component2

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

```
inline operator fun component2(): Float
```

### copy

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

```
fun copy(
    x: Float = unpackFloat1(packedValue),
    y: Float = unpackFloat2(packedValue)
): Offset
```

Returns a copy of this Offset instance optionally overriding the x or y parameter

### div

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

```
operator fun div(operand: Float): Offset
```

Division operator.

Returns an offset whose coordinates are the coordinates of the left-hand-side operand (an Offset) divided by the scalar right-hand-side operand (a Float).

### getDistance

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

```
fun getDistance(): Float
```

The magnitude of the offset.

If you need this value to compare it to another `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset`'s distance, consider using `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#getDistanceSquared()` instead, since it is cheaper to compute.

### getDistanceSquared

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

```
fun getDistanceSquared(): Float
```

The square of the magnitude of the offset.

This is cheaper than computing the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#getDistance()` itself.

### isValid

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

```
inline fun isValid(): Boolean
```

Returns:

- False if `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` is a NaN

- True if `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` is infinite

- True otherwise

### minus

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

```
operator fun minus(other: Offset): Offset
```

Binary subtraction operator.

Returns an offset whose `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` value is the left-hand-side operand's `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` minus the right-hand-side operand's `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` and whose `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` value is the left-hand-side operand's `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` minus the right-hand-side operand's `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()`.

### plus

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

```
operator fun plus(other: Offset): Offset
```

Binary addition operator.

Returns an offset whose `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` value is the sum of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` values of the two operands, and whose `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` value is the sum of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` values of the two operands.

### rem

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

```
operator fun rem(operand: Float): Offset
```

Modulo (remainder) operator.

Returns an offset whose coordinates are the remainder of dividing the coordinates of the left-hand-side operand (an Offset) by the scalar right-hand-side operand (a Float).

### times

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

```
operator fun times(operand: Float): Offset
```

Multiplication operator.

Returns an offset whose coordinates are the coordinates of the left-hand-side operand (an Offset) multiplied by the scalar right-hand-side operand (a Float).

### toString

Cmn

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

### unaryMinus

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

```
inline operator fun unaryMinus(): Offset
```

Unary negation operator.

Returns an offset with the coordinates negated.

If the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` represents an arrow on a plane, this operator returns the same arrow but pointing in the reverse direction.

## Public properties

### packedValue

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

```
val packedValue: Long
```

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` value encoding the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#x()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#y()` components of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset`. Encoded values can be obtained by using the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#packedValue()` property of existing `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` instances.

### x

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

```
val x: Float
```

### y

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

```
val y: Float
```

## Extension functions

### Offset.minus

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/IntOffset.kt+function:minus)

```
operator fun Offset.minus(offset: IntOffset): Offset
```

### Offset.plus

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/IntOffset.kt+function:plus)

```
operator fun Offset.plus(offset: IntOffset): Offset
```

### Offset.round

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/IntOffset.kt+function:round)

```
fun Offset.round(): IntOffset
```

Round a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` down to the nearest `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` coordinates.

### Offset.takeOrElse

Cmn 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/Offset.kt+function:takeOrElse)

```
inline fun Offset.takeOrElse(block: () -> Offset): Offset
```

If this `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Offset).isSpecified()` then this is returned, otherwise `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/package-summary#(androidx.compose.ui.geometry.Offset).takeOrElse(kotlin.Function0)` is executed and its result is returned.

## Extension properties

### Offset.isFinite

Cmn 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/Offset.kt+symbol:isFinite)

```
val Offset.isFinite: Boolean
```

True if both x and y values of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` are finite. NaN values are not considered finite.

### Offset.isSpecified

Cmn 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/Offset.kt+symbol:isSpecified)

```
val Offset.isSpecified: Boolean
```

`false` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()`.

### Offset.isUnspecified

Cmn 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/Offset.kt+symbol:isUnspecified)

```
val Offset.isUnspecified: Boolean
```

`true` when this is `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()`.