MutableVec


class MutableVec : Vec


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 ImmutableVec for an immutable alternative.

Summary

Public companion functions

MutableVec
fromDirectionAndMagnitude(
    direction: @AngleRadiansFloat Float,
    magnitude: Float
)

Public constructors

Public functions

open operator Boolean
equals(other: Any?)
open Int
MutableVec
populateFrom(input: Vec)

Fills this MutableVec with the same values contained in input.

open String

Public properties

open Float

The Vec's offset in the x-direction

open Float

The Vec's offset in the y-direction

Inherited functions

From androidx.ink.geometry.Vec
@FloatRange(from = -3.141592653589793, to = 3.141592653589793) @AngleRadiansFloat Float

The direction of the vec, represented as the angle between the positive x-axis and this vec.

@FloatRange(from = 0.0) Float

The length of the Vec.

@FloatRange(from = 0.0) Float

The squared length of the Vec.

ImmutableVec

Returns a newly allocated vector with the same magnitude, but pointing in the opposite direction.

MutableVec

Modifies outVec into a vector with the same magnitude, but pointing in the opposite direction.

ImmutableVec

Returns a newly allocated vector with the same magnitude as this one, but rotated by (positive) 90 degrees.

MutableVec

Modifies outVec into a vector with the same magnitude as this one, but rotated by (positive) 90 degrees.

ImmutableVec

Returns a newly allocated vector with the same direction as this one, but with a magnitude of 1.

MutableVec

Modifies outVec into a vector with the same direction as this one, but with a magnitude of 1.

Boolean
isAlmostEqual(other: Vec, tolerance: @FloatRange(from = 0.0) Float)

Compares this Vec with other, and returns true if the difference between x and other.x is less than tolerance, and likewise for y.

Boolean
isParallelTo(
    other: Vec,
    angleTolerance: @AngleRadiansFloat @FloatRange(from = 0.0) Float
)

Returns true if the angle formed by this and other is within angleTolerance of 0 radians or π radians (0 degrees or 180 degrees).

Boolean
isPerpendicularTo(
    other: Vec,
    angleTolerance: @AngleRadiansFloat @FloatRange(from = 0.0) Float
)

Returns true if the angle formed by this and other is within angleTolerance of ±π/2 radians (±90 degrees).

Public companion functions

fromDirectionAndMagnitude

Added in 1.0.0-alpha01
fun fromDirectionAndMagnitude(
    direction: @AngleRadiansFloat Float,
    magnitude: Float
): MutableVec

Public constructors

MutableVec

Added in 1.0.0-alpha01
MutableVec()

MutableVec

Added in 1.0.0-alpha01
MutableVec(x: Float, y: Float)

Public functions

equals

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

hashCode

open fun hashCode(): Int

populateFrom

Added in 1.0.0-alpha01
fun populateFrom(input: Vec): MutableVec

Fills this MutableVec with the same values contained in input.

toString

open fun toString(): String

Public properties

x

Added in 1.0.0-alpha01
open var xFloat

The Vec's offset in the x-direction

y

Added in 1.0.0-alpha01
open var yFloat

The Vec's offset in the y-direction