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

Summary

Nested types

Public companion functions

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

Returns an ImmutableVec with the given magnitude and direction in degrees rotated from the positive x-axis in the direction of positive y-axis.

android

Public constructors

android

Public functions

open operator Boolean
equals(other: Any?)
android
open Int
android
open String
android

Public properties

open Float

The Vec's offset in the x-direction

android
open Float

The Vec's offset in the y-direction

android

Inherited functions

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

The angle between the positive x-axis and this vec, in the direction of the positive y-axis.

android
@FloatRange(from = 0.0) Float

The length of the Vec.

android
@FloatRange(from = 0.0) Float

The squared length of the Vec.

android
ImmutableVec

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

android
MutableVec

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

android
ImmutableVec

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

android
MutableVec

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

android
ImmutableVec

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

android
MutableVec

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

android
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.

android
Boolean
isParallelTo(
    other: Vec,
    toleranceDegrees: @AngleDegreesFloat @FloatRange(from = 0.0) Float
)

Returns true if the angle formed by this and other is within toleranceDegrees of 0 degrees or 180 degrees.

android
Boolean
isPerpendicularTo(
    other: Vec,
    toleranceDegrees: @AngleDegreesFloat @FloatRange(from = 0.0) Float
)

Returns true if the angle formed by this and other is within toleranceDegrees of ±90 degrees.

android

Public companion functions

fromDirectionInDegreesAndMagnitude

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

Returns an 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

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

open val xFloat

The Vec's offset in the x-direction

y

open val yFloat

The Vec's offset in the y-direction