public final class Vector2


Represents a position in the 2D plane.

Summary

Public fields

final @NonNull Vector2

Vector with y set to negative one and all other components set to zero.

final @NonNull Vector2

Vector with x set to negative one and all other components set to zero.

final @NonNull Vector2

Vector with all components set to one.

final @NonNull Vector2

Vector with x set to one and all other components set to zero.

final @NonNull Vector2

Vector with y set to one and all other components set to zero.

final @NonNull Vector2

Vector with all components set to zero.

Public constructors

Creates a new vector with the same values as the other vector.

Vector2(float x, float y)

Public methods

static final @NonNull Vector2
abs(@NonNull Vector2 vector)

Returns the absolute values of each component of the vector.

static final float

Returns the angle between this vector and the other vector.

final @NonNull Vector2

Returns a new vector with the values clamped between min and max vectors.

final @NonNull Vector2
copy(float x, float y)

Returns a copy of the vector.

final float

Returns the cross product of this vector and the other vector.

static final float
distance(@NonNull Vector2 vector1, @NonNull Vector2 vector2)

Returns the distance between this vector and the other vector.

final @NonNull Vector2
div(float c)

Returns a new vector with this vector divided by a scalar amount.

final @NonNull Vector2

Returns a new vector with this vector divided by the other vector.

final float

Returns the dot product of this vector and the other vector.

boolean
equals(Object other)

Returns true if this vector is equal to the other.

final float

The length of the vector.

final float

The squared length of the vector.

final float

X component of the vector.

final float

Y component of the vector.

int
static final @NonNull Vector2
lerp(@NonNull Vector2 start, @NonNull Vector2 end, float ratio)

Returns a new vector that is linearly interpolated between start and end using the interpolation amount ratio.

final @NonNull Vector2

Returns a new vector with the difference of this vector and the other vector.

final @NonNull Vector2

Returns a new vector with the sum of this vector and the other vector.

final @NonNull Vector2
times(float c)

Returns a new vector multiplied by a scalar amount

final @NonNull Vector2

Returns a new vector with the product of this vector and the other vector.

final @NonNull Vector2

Returns a normalized version of this vector.

@NonNull String
final @NonNull Vector2

Negates the values of this vector.

Public fields

Down

public final @NonNull Vector2 Down

Vector with y set to negative one and all other components set to zero.

Left

public final @NonNull Vector2 Left

Vector with x set to negative one and all other components set to zero.

One

public final @NonNull Vector2 One

Vector with all components set to one.

Right

public final @NonNull Vector2 Right

Vector with x set to one and all other components set to zero.

Up

public final @NonNull Vector2 Up

Vector with y set to one and all other components set to zero.

Zero

public final @NonNull Vector2 Zero

Vector with all components set to zero.

Public constructors

Vector2

Added in 1.0.0-alpha01
public Vector2(@NonNull Vector2 other)

Creates a new vector with the same values as the other vector.

Vector2

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

Public methods

abs

Added in 1.0.0-alpha01
public static final @NonNull Vector2 abs(@NonNull Vector2 vector)

Returns the absolute values of each component of the vector.

angularDistance

Added in 1.0.0-alpha01
public static final float angularDistance(@NonNull Vector2 vector1, @NonNull Vector2 vector2)

Returns the angle between this vector and the other vector.

clamp

Added in 1.0.0-alpha01
public final @NonNull Vector2 clamp(@NonNull Vector2 min, @NonNull Vector2 max)

Returns a new vector with the values clamped between min and max vectors.

copy

Added in 1.0.0-alpha01
public final @NonNull Vector2 copy(float x, float y)

Returns a copy of the vector.

cross

Added in 1.0.0-alpha01
public final float cross(@NonNull Vector2 other)

Returns the cross product of this vector and the other vector.

distance

Added in 1.0.0-alpha01
public static final float distance(@NonNull Vector2 vector1, @NonNull Vector2 vector2)

Returns the distance between this vector and the other vector.

div

Added in 1.0.0-alpha01
public final @NonNull Vector2 div(float c)

Returns a new vector with this vector divided by a scalar amount.

div

Added in 1.0.0-alpha01
public final @NonNull Vector2 div(@NonNull Vector2 other)

Returns a new vector with this vector divided by the other vector.

dot

Added in 1.0.0-alpha01
public final float dot(@NonNull Vector2 other)

Returns the dot product of this vector and the other vector.

equals

public boolean equals(Object other)

Returns true if this vector is equal to the other.

getLength

Added in 1.0.0-alpha01
public final float getLength()

The length of the vector.

getLengthSquared

Added in 1.0.0-alpha01
public final float getLengthSquared()

The squared length of the vector.

getX

Added in 1.0.0-alpha01
public final float getX()

X component of the vector.

getY

Added in 1.0.0-alpha01
public final float getY()

Y component of the vector.

hashCode

public int hashCode()

lerp

Added in 1.0.0-alpha01
public static final @NonNull Vector2 lerp(@NonNull Vector2 start, @NonNull Vector2 end, float ratio)

Returns a new vector that is linearly interpolated between start and end using the interpolation amount ratio.

If ratio is outside of the range [0, 1], the returned vector will be extrapolated.

minus

Added in 1.0.0-alpha01
public final @NonNull Vector2 minus(@NonNull Vector2 other)

Returns a new vector with the difference of this vector and the other vector.

plus

Added in 1.0.0-alpha01
public final @NonNull Vector2 plus(@NonNull Vector2 other)

Returns a new vector with the sum of this vector and the other vector.

times

Added in 1.0.0-alpha01
public final @NonNull Vector2 times(float c)

Returns a new vector multiplied by a scalar amount

times

Added in 1.0.0-alpha01
public final @NonNull Vector2 times(@NonNull Vector2 other)

Returns a new vector with the product of this vector and the other vector.

toNormalized

Added in 1.0.0-alpha01
public final @NonNull Vector2 toNormalized()

Returns a normalized version of this vector.

toString

public @NonNull String toString()

unaryMinus

Added in 1.0.0-alpha01
public final @NonNull Vector2 unaryMinus()

Negates the values of this vector.