class Vector2


Represents a position in the 2D plane.

Summary

Public companion functions

Vector2
abs(vector: Vector2)

Returns the absolute values of each component of the vector.

Float
angularDistance(vector1: Vector2, vector2: Vector2)

Returns the angle between this vector and the other vector.

Float
distance(vector1: Vector2, vector2: Vector2)

Returns the distance between this vector and the other vector.

Vector2
lerp(start: Vector2, end: Vector2, ratio: Float)

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

Public companion properties

Vector2

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

Vector2

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

Vector2

Vector with all components set to one.

Vector2

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

Vector2

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

Vector2

Vector with all components set to zero.

Public constructors

Vector2(other: Vector2)

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

Vector2(x: Float, y: Float)

Public functions

Vector2
clamp(min: Vector2, max: Vector2)

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

inline Vector2
copy(x: Float, y: Float)

Returns a copy of the vector.

inline infix Float
cross(other: Vector2)

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

inline operator Vector2
div(c: Float)

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

inline operator Vector2
div(other: Vector2)

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

inline infix Float
dot(other: Vector2)

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

open operator Boolean
equals(other: Any?)

Returns true if this vector is equal to the other.

open Int
inline operator Vector2
minus(other: Vector2)

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

operator Vector2
plus(other: Vector2)

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

inline operator Vector2

Returns a new vector multiplied by a scalar amount

inline operator Vector2
times(other: Vector2)

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

Vector2

Returns a normalized version of this vector.

open String
inline operator Vector2

Negates the values of this vector.

Public properties

Float

The length of the vector.

Float

The squared length of the vector.

Float

X component of the vector.

Float

Y component of the vector.

Public companion functions

abs

Added in 1.0.0-alpha01
fun abs(vector: Vector2): Vector2

Returns the absolute values of each component of the vector.

angularDistance

Added in 1.0.0-alpha01
fun angularDistance(vector1: Vector2, vector2: Vector2): Float

Returns the angle between this vector and the other vector.

distance

Added in 1.0.0-alpha01
fun distance(vector1: Vector2, vector2: Vector2): Float

Returns the distance between this vector and the other vector.

lerp

Added in 1.0.0-alpha01
fun lerp(start: Vector2, end: Vector2, ratio: Float): Vector2

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.

Public companion properties

Down

val DownVector2

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

Left

val LeftVector2

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

One

val OneVector2

Vector with all components set to one.

Right

val RightVector2

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

Up

val UpVector2

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

Zero

val ZeroVector2

Vector with all components set to zero.

Public constructors

Vector2

Added in 1.0.0-alpha01
Vector2(other: Vector2)

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

Vector2

Added in 1.0.0-alpha01
Vector2(x: Float = 0.0f, y: Float = 0.0f)

Public functions

clamp

Added in 1.0.0-alpha01
fun clamp(min: Vector2, max: Vector2): Vector2

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

copy

Added in 1.0.0-alpha01
inline fun copy(x: Float = this.x, y: Float = this.y): Vector2

Returns a copy of the vector.

cross

Added in 1.0.0-alpha01
inline infix fun cross(other: Vector2): Float

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

div

Added in 1.0.0-alpha01
inline operator fun div(c: Float): Vector2

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

div

Added in 1.0.0-alpha01
inline operator fun div(other: Vector2): Vector2

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

dot

Added in 1.0.0-alpha01
inline infix fun dot(other: Vector2): Float

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

equals

open operator fun equals(other: Any?): Boolean

Returns true if this vector is equal to the other.

hashCode

open fun hashCode(): Int

minus

Added in 1.0.0-alpha01
inline operator fun minus(other: Vector2): Vector2

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

plus

Added in 1.0.0-alpha01
operator fun plus(other: Vector2): Vector2

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

times

Added in 1.0.0-alpha01
inline operator fun times(c: Float): Vector2

Returns a new vector multiplied by a scalar amount

times

Added in 1.0.0-alpha01
inline operator fun times(other: Vector2): Vector2

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

toNormalized

Added in 1.0.0-alpha01
fun toNormalized(): Vector2

Returns a normalized version of this vector.

toString

open fun toString(): String

unaryMinus

Added in 1.0.0-alpha01
inline operator fun unaryMinus(): Vector2

Negates the values of this vector.

Public properties

length

Added in 1.0.0-alpha01
val lengthFloat

The length of the vector.

lengthSquared

Added in 1.0.0-alpha01
val lengthSquaredFloat

The squared length of the vector.

x

Added in 1.0.0-alpha01
val xFloat

X component of the vector.

y

Added in 1.0.0-alpha01
val yFloat

Y component of the vector.