MutableVec


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

MutableVec(float x, float y)

Public methods

boolean
equals(Object other)
static final @NonNull MutableVec
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
final @NonNull MutableVec

Fills this MutableVec with the same values contained in input.

void
setX(float x)

The Vec's offset in the x-direction

void
setY(float y)

The Vec's offset in the y-direction

@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

MutableVec

Added in 1.0.0-alpha01
public MutableVec()

MutableVec

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

Public methods

equals

public boolean equals(Object other)

fromDirectionAndMagnitude

Added in 1.0.0-alpha01
public static final @NonNull MutableVec 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()

populateFrom

Added in 1.0.0-alpha01
public final @NonNull MutableVec populateFrom(@NonNull Vec input)

Fills this MutableVec with the same values contained in input.

setX

Added in 1.0.0-alpha01
public void setX(float x)

The Vec's offset in the x-direction

setY

Added in 1.0.0-alpha01
public void setY(float y)

The Vec's offset in the y-direction

toString

public @NonNull String toString()