ImmutableVec


public final class ImmutableVec extends 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 constructors

ImmutableVec(float x, float y)

Public methods

boolean
equals(Object other)
static final @NonNull ImmutableVec
fromDirectionAndMagnitude(
    @AngleRadiansFloat float direction,
    float magnitude
)
float

The Vec's offset in the x-direction

float

The Vec's offset in the y-direction

int
@NonNull String

Inherited methods

From androidx.ink.geometry.Vec
final @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.

final @FloatRange(from = 0.0) float

The length of the Vec.

final @FloatRange(from = 0.0) float

The squared length of the Vec.

final @NonNull ImmutableVec

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

final @NonNull MutableVec

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

final @NonNull ImmutableVec

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

final @NonNull MutableVec

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

final @NonNull ImmutableVec

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

final @NonNull MutableVec

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

final boolean
isAlmostEqual(@NonNull Vec other, @FloatRange(from = 0.0) float tolerance)

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

final boolean
isParallelTo(
    @NonNull Vec other,
    @AngleRadiansFloat @FloatRange(from = 0.0) float angleTolerance
)

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

final boolean
isPerpendicularTo(
    @NonNull Vec other,
    @AngleRadiansFloat @FloatRange(from = 0.0) float angleTolerance
)

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

Public constructors

ImmutableVec

Added in 1.0.0-alpha01
public ImmutableVec(float x, float y)

Public methods

equals

public boolean equals(Object other)

fromDirectionAndMagnitude

Added in 1.0.0-alpha01
public static final @NonNull ImmutableVec fromDirectionAndMagnitude(
    @AngleRadiansFloat float direction,
    float magnitude
)

getX

Added in 1.0.0-alpha01
public float getX()

The Vec's offset in the x-direction

getY

Added in 1.0.0-alpha01
public float getY()

The Vec's offset in the y-direction

hashCode

public int hashCode()

toString

public @NonNull String toString()