# MutableVec

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

*** ** * ** ***


```
public final class MutableVec 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.MutableVec](https://developer.android.com/reference/androidx/ink/geometry/MutableVec) |

*** ** * ** ***

A mutable 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 mutable and is not inherently thread-safe, so callers should apply their own synchronization logic or use this object from a single thread. See `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec` for an immutable alternative.

## Summary

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

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/ink/geometry/MutableVec#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `float` | `https://developer.android.com/reference/androidx/ink/geometry/MutableVec#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/MutableVec#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/MutableVec#hashCode()()` |
| `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/MutableVec#populateFrom(androidx.ink.geometry.Vec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec input)` Fills this `https://developer.android.com/reference/androidx/ink/geometry/MutableVec` with the same values contained in `https://developer.android.com/reference/androidx/ink/geometry/MutableVec#populateFrom(androidx.ink.geometry.Vec)`. |
| `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/MutableVec#populateFromDirectionInDegreesAndMagnitude(kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/ink/geometry/AngleDegreesFloat float directionDegrees, float magnitude )` Fills this `https://developer.android.com/reference/androidx/ink/geometry/MutableVec` to have the given magnitude and direction in degrees rotated from the positive x-axis in the direction of positive y-axis. |
| `void` | `https://developer.android.com/reference/androidx/ink/geometry/MutableVec#setX(kotlin.Float)(float value)` The `https://developer.android.com/reference/androidx/ink/geometry/Vec`'s offset in the x-direction |
| `void` | `https://developer.android.com/reference/androidx/ink/geometry/MutableVec#setY(kotlin.Float)(float value)` The `https://developer.android.com/reference/androidx/ink/geometry/Vec`'s offset in the y-direction |
| `@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/MutableVec#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/MutableVec#toString()()` |

| ### Extension functions |
|---|---|
| `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/AndroidGraphicsConverter.https://developer.android.com/reference/androidx/ink/geometry/MutableVec#(androidx.ink.geometry.MutableVec).populateFrom(android.graphics.PointF)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/PointF.html point )` Fills this `https://developer.android.com/reference/androidx/ink/geometry/MutableVec` with the values from `https://developer.android.com/reference/androidx/ink/geometry/package-summary#(androidx.ink.geometry.MutableVec).populateFrom(android.graphics.PointF)`. |

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

### MutableVec

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

```
public MutableVec()
```

### MutableVec

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

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

## Public methods

### equals

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

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

### populateFrom

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

```
public final @NonNull MutableVec populateFrom(@NonNull Vec input)
```

Fills this `https://developer.android.com/reference/androidx/ink/geometry/MutableVec` with the same values contained in `https://developer.android.com/reference/androidx/ink/geometry/MutableVec#populateFrom(androidx.ink.geometry.Vec)`.

### populateFromDirectionInDegreesAndMagnitude

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

```
public final @NonNull MutableVec populateFromDirectionInDegreesAndMagnitude(
    @AngleDegreesFloat float directionDegrees,
    float magnitude
)
```

Fills this `https://developer.android.com/reference/androidx/ink/geometry/MutableVec` to have the given magnitude and direction in degrees rotated from the positive x-axis in the direction of positive y-axis.

### setX

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

```
public void setX(float value)
```

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

### setY

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

```
public void setY(float value)
```

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

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

## Extension functions

### AndroidGraphicsConverter.populateFrom

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:populateFrom)

```
public final @NonNull MutableVec AndroidGraphicsConverter.populateFrom(
    @NonNull MutableVec receiver,
    @NonNull PointF point
)
```

Fills this `https://developer.android.com/reference/androidx/ink/geometry/MutableVec` with the values from `https://developer.android.com/reference/androidx/ink/geometry/package-summary#(androidx.ink.geometry.MutableVec).populateFrom(android.graphics.PointF)`.

Leaves `https://developer.android.com/reference/androidx/ink/geometry/package-summary#(androidx.ink.geometry.MutableVec).populateFrom(android.graphics.PointF)` unchanged. Returns the modified instance to allow chaining calls.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec` | `this` |