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

final @NonNull MutableVec
populateFromDirectionInDegreesAndMagnitude(
    @AngleDegreesFloat float directionDegrees,
    float magnitude
)

Fills this MutableVec to have the given magnitude and direction in degrees rotated from the positive x-axis in the direction of positive y-axis.

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

Extension functions

final @NonNull MutableVec

Fills this MutableVec with the values from point.

Inherited methods

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

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,
    @AngleDegreesFloat @FloatRange(from = 0.0) float toleranceDegrees
)

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

final boolean
isPerpendicularTo(
    @NonNull Vec other,
    @AngleDegreesFloat @FloatRange(from = 0.0) float toleranceDegrees
)

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

Public constructors

MutableVec

Added in 1.0.0
public MutableVec()

MutableVec

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

Public methods

equals

public boolean equals(Object other)

getX

public float getX()

The Vec's offset in the x-direction

getY

public float getY()

The Vec's offset in the y-direction

hashCode

public int hashCode()

populateFrom

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

Fills this MutableVec with the same values contained in input.

populateFromDirectionInDegreesAndMagnitude

Added in 1.0.0
public final @NonNull MutableVec populateFromDirectionInDegreesAndMagnitude(
    @AngleDegreesFloat float directionDegrees,
    float magnitude
)

Fills this MutableVec to have the given magnitude and direction in degrees rotated from the positive x-axis in the direction of positive y-axis.

setX

Added in 1.0.0
public void setX(float x)

The Vec's offset in the x-direction

setY

Added in 1.0.0
public void setY(float y)

The Vec's offset in the y-direction

toString

public @NonNull String toString()

Extension functions

AndroidGraphicsConverter.populateFrom

public final @NonNull MutableVec AndroidGraphicsConverter.populateFrom(
    @NonNull MutableVec receiver,
    @NonNull PointF point
)

Fills this MutableVec with the values from point.

Leaves point unchanged. Returns the modified instance to allow chaining calls.

Returns
@NonNull MutableVec

this