ImmutableVec


class ImmutableVec : Vec


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 MutableVec for a mutable alternative.

Summary

Public companion functions

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

Public constructors

Public functions

open operator Boolean
equals(other: Any?)
open Int
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-alpha02
fun fromDirectionAndMagnitude(
    direction: @AngleRadiansFloat Float,
    magnitude: Float
): ImmutableVec

Public constructors

ImmutableVec

Added in 1.0.0-alpha02
ImmutableVec(x: Float, y: Float)

Public functions

equals

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

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

x

Added in 1.0.0-alpha02
open val xFloat

The Vec's offset in the x-direction

y

Added in 1.0.0-alpha02
open val yFloat

The Vec's offset in the y-direction