# 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)

*** ** * ** ***


```
public final class ImmutableVec extends Vec
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.ink.geometry.Vec](https://developer.android.com/reference/androidx/ink/geometry/Vec) ||
|   | ↳ | [androidx.ink.geometry.ImmutableVec](https://developer.android.com/reference/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/androidx/ink/geometry/MutableVec` for a mutable alternative.

## Summary

| ### Nested types |
|---|
| `public static class https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec.Companion` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec#ImmutableVec(kotlin.Float,kotlin.Float)(float x, float y)` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `static 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/ImmutableVec#fromDirectionInDegreesAndMagnitude(kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/ink/geometry/AngleDegreesFloat float directionDegrees, float magnitude )` Returns an `https://developer.android.com/reference/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. |
| `float` | `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec#getX()()` The `https://developer.android.com/reference/androidx/ink/geometry/Vec`'s offset in the x-direction |
| `float` | `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec#getY()()` The `https://developer.android.com/reference/androidx/ink/geometry/Vec`'s offset in the y-direction |
| `int` | `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec#hashCode()()` |
| `@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/ImmutableVec#toImmutable()()` Returns an immutable copy of this object. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec#toString()()` |

| ### Inherited methods |
|---|
| From [androidx.ink.geometry.Vec](https://developer.android.com/reference/androidx/ink/geometry/Vec) |---|---| | `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = -180.0, to = 180.0) @https://developer.android.com/reference/androidx/ink/geometry/AngleDegreesFloat float` | `https://developer.android.com/reference/androidx/ink/geometry/Vec#computeDirectionDegrees()()` The angle between the positive x-axis and this vec, in the direction of the positive y-axis. | | `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float` | `https://developer.android.com/reference/androidx/ink/geometry/Vec#computeMagnitude()()` The length of the `https://developer.android.com/reference/androidx/ink/geometry/Vec`. | | `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float` | `https://developer.android.com/reference/androidx/ink/geometry/Vec#computeMagnitudeSquared()()` The squared length of the `https://developer.android.com/reference/androidx/ink/geometry/Vec`. | | `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/Vec#computeNegation()()` Returns a newly allocated vector with the same magnitude, but pointing in the opposite direction. | | `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/Vec#computeNegation(androidx.ink.geometry.MutableVec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVec)` Modifies `https://developer.android.com/reference/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. | | `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/Vec#computeOrthogonal()()` Returns a newly allocated vector with the same magnitude as this one, but rotated by (positive) 90 degrees. | | `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/Vec#computeOrthogonal(androidx.ink.geometry.MutableVec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVec)` Modifies `https://developer.android.com/reference/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. | | `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/Vec#computeUnitVec()()` Returns a newly allocated vector with the same direction as this one, but with a magnitude of `1`. | | `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/Vec#computeUnitVec(androidx.ink.geometry.MutableVec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVec)` Modifies `https://developer.android.com/reference/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`. | | `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec other, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float tolerance)` Compares this `https://developer.android.com/reference/androidx/ink/geometry/Vec` with `https://developer.android.com/reference/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)`, and returns true if the difference between `https://developer.android.com/reference/androidx/ink/geometry/Vec#x()` from `this` and `https://developer.android.com/reference/androidx/ink/geometry/Vec#x()` from `https://developer.android.com/reference/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)` is less than `https://developer.android.com/reference/androidx/ink/geometry/Vec#isAlmostEqual(androidx.ink.geometry.Vec,kotlin.Float)`, and likewise for `https://developer.android.com/reference/androidx/ink/geometry/Vec#y()`. | | `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Vec#isParallelTo(androidx.ink.geometry.Vec,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec other, @https://developer.android.com/reference/androidx/ink/geometry/AngleDegreesFloat @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float toleranceDegrees )` Returns true if the angle formed by `this` and `https://developer.android.com/reference/androidx/ink/geometry/Vec#isParallelTo(androidx.ink.geometry.Vec,kotlin.Float)` is within `https://developer.android.com/reference/androidx/ink/geometry/Vec#isParallelTo(androidx.ink.geometry.Vec,kotlin.Float)` of 0 degrees or 180 degrees. | | `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Vec#isPerpendicularTo(androidx.ink.geometry.Vec,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec other, @https://developer.android.com/reference/androidx/ink/geometry/AngleDegreesFloat @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float toleranceDegrees )` Returns true if the angle formed by `this` and `https://developer.android.com/reference/androidx/ink/geometry/Vec#isPerpendicularTo(androidx.ink.geometry.Vec,kotlin.Float)` is within `https://developer.android.com/reference/androidx/ink/geometry/Vec#isPerpendicularTo(androidx.ink.geometry.Vec,kotlin.Float)` of ±90 degrees. | |

## Public constructors

### ImmutableVec

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

```
public ImmutableVec(float x, float y)
```

## Public methods

### equals

```
public boolean equals(Object other)
```

### fromDirectionInDegreesAndMagnitude

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

```
public static final @NonNull ImmutableVec fromDirectionInDegreesAndMagnitude(
    @AngleDegreesFloat float directionDegrees,
    float magnitude
)
```

Returns an `https://developer.android.com/reference/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.

### getX

```
public float getX()
```

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

### getY

```
public float getY()
```

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

### hashCode

```
public int hashCode()
```

### toImmutable

```
public @NonNull ImmutableVec toImmutable()
```

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

### toString

```
public @NonNull String toString()
```