# ImmutableVec

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/ImmutableVec.kt+class:androidx.ink.geometry.ImmutableVec) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOS
- Cmn

  ```
  class ImmutableVec : Vec
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.ink.geometry.Vec](https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec) ||
|   | ↳ | [androidx.ink.geometry.ImmutableVec](https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec) |

*** ** * ** ***

An immutable two-dimensional vector, i.e. an (x, y) coordinate pair. It can be used to represent either:

1. A two-dimensional offset, i.e. the difference between two points

2. A point in space, i.e. treating the vector as an offset from the origin

This object is immutable, so it is inherently thread-safe. See `https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec` for a mutable alternative.

## Summary

| ### Nested types |
|---|
| `object https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec.Companion` |

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#fromDirectionInDegreesAndMagnitude(kotlin.Float,kotlin.Float)( directionDegrees: @https://developer.android.com/reference/kotlin/androidx/ink/geometry/AngleDegreesFloat https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, magnitude: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Returns an `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec` with the given magnitude and direction in degrees rotated from the positive x-axis in the direction of positive y-axis. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#ImmutableVec(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)` | Cmn |

| ### Public functions |
|---|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#hashCode()()` | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#toImmutable()()` Returns an immutable copy of this object. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#x()` The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec`'s offset in the x-direction | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec#y()` The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec`'s offset in the y-direction | Cmn |

### Inherited functions

From [androidx.ink.geometry.Vec](https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec) `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -180.0, to = 180.0) @https://developer.android.com/reference/kotlin/androidx/ink/geometry/AngleDegreesFloat https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeDirectionDegrees()()`

The angle between the positive x-axis and this vec, in the direction of the positive y-axis.
Cmn `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeMagnitude()()`

The length of the `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec`.
Cmn `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeMagnitudeSquared()()`

The squared length of the `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec`.
Cmn `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeNegation()()`

Returns a newly allocated vector with the same magnitude, but pointing in the opposite direction.
Cmn `https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeNegation(androidx.ink.geometry.MutableVec)(outVec: https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec)`

Modifies `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeNegation(androidx.ink.geometry.MutableVec)`, which may be `this`, into a vector with the same magnitude, but pointing in the opposite direction.
Cmn `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeOrthogonal()()`

Returns a newly allocated vector with the same magnitude as this one, but rotated by (positive) 90 degrees.
Cmn `https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeOrthogonal(androidx.ink.geometry.MutableVec)(outVec: https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec)`

Modifies `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeOrthogonal(androidx.ink.geometry.MutableVec)`, which may be `this`, into a vector with the same magnitude as this one, but rotated by (positive) 90 degrees.
Cmn `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeUnitVec()()`

Returns a newly allocated vector with the same direction as this one, but with a magnitude of `1`.
Cmn `https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeUnitVec(androidx.ink.geometry.MutableVec)(outVec: https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec)`

Modifies `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#computeUnitVec(androidx.ink.geometry.MutableVec)`, which may be `this`, into a vector with the same direction as this one, but with a magnitude of `1`.
Cmn `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)(other: https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec, tolerance: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`

Compares this `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec` with `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)`, and returns true if the difference between `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#x()` from `this` and `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#x()` from `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)` is less than `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)`, and likewise for `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#y()`.
Cmn `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isParallelTo(androidx.ink.geometry.Vec,kotlin.Float)(
other: https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec,
toleranceDegrees: @https://developer.android.com/reference/kotlin/androidx/ink/geometry/AngleDegreesFloat @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html
)`

Returns true if the angle formed by `this` and `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isParallelTo(androidx.ink.geometry.Vec,kotlin.Float)` is within `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isParallelTo(androidx.ink.geometry.Vec,kotlin.Float)` of 0 degrees or 180 degrees.
Cmn `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isPerpendicularTo(androidx.ink.geometry.Vec,kotlin.Float)(
other: https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec,
toleranceDegrees: @https://developer.android.com/reference/kotlin/androidx/ink/geometry/AngleDegreesFloat @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html
)`

Returns true if the angle formed by `this` and `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isPerpendicularTo(androidx.ink.geometry.Vec,kotlin.Float)` is within `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec#isPerpendicularTo(androidx.ink.geometry.Vec,kotlin.Float)` of ±90 degrees.
Cmn

## Public companion functions

### fromDirectionInDegreesAndMagnitude

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

```
fun fromDirectionInDegreesAndMagnitude(
    directionDegrees: @AngleDegreesFloat Float,
    magnitude: Float
): ImmutableVec
```

Returns an `https://developer.android.com/reference/kotlin/androidx/ink/geometry/ImmutableVec` with the given magnitude and direction in degrees rotated from the positive x-axis in the direction of positive y-axis.

## Public constructors

### ImmutableVec

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

```
ImmutableVec(x: Float, y: Float)
```

## Public functions

### equals

Cmn

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

Cmn

```
open fun hashCode(): Int
```

### toImmutable

Cmn

```
open fun toImmutable(): ImmutableVec
```

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

### toString

Cmn

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

## Public properties

### x

Cmn

```
open val x: Float
```

The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec`'s offset in the x-direction

### y

Cmn

```
open val y: Float
```

The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec`'s offset in the y-direction