Vec2

open class Vec2(var x: Double, var y: Double)

Two-component vector with X and Y coordinates.

Inheritors

Constructors

Link copied to clipboard
constructor(x: Double, y: Double)
constructor()

Constructs a two-component vector with X and Y both 0.

constructor(vector: Vec2)

Constructs a two-component vector with the X and Y of a specified vector.

Properties

Link copied to clipboard

Computes the magnitude of this vector.

Link copied to clipboard

Computes the squared magnitude of this vector. This is equivalent to squaring the result of magnitude but is potentially much more efficient.

Link copied to clipboard
var x: Double

The vector's X component.

Link copied to clipboard
var y: Double

The vector's Y component.

Functions

Link copied to clipboard
fun add(vector: Vec2): Vec2

Adds a specified vector to this vector.

Link copied to clipboard
fun copy(vector: Vec2): Vec2

Sets this vector to the X and Y of a specified vector.

Link copied to clipboard
fun distanceTo(vector: Vec2): Double

Computes the distance from this vector to another vector.

Link copied to clipboard

Computes the squared distance from this vector to a specified vector. This is equivalent to squaring the result of distanceTo but is potentially much more efficient.

Link copied to clipboard
open operator fun div(divisor: Double): Vec2

Creates new vector containing this vector divided by a scalar.

Link copied to clipboard
open operator fun divAssign(divisor: Double)

Divides this vector by a scalar.

Link copied to clipboard
open fun divide(divisor: Double): Vec2

Divides this vector by a scalar.

Link copied to clipboard
fun dot(vector: Vec2): Double

Computes the scalar dot product of this vector and a specified vector.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
operator fun minus(vector: Vec2): Vec2

Creates new vector containing difference of this and specified vectors.

Link copied to clipboard
operator fun minusAssign(vector: Vec2)

Subtracts a specified vector from this vector.

Link copied to clipboard
fun mix(vector: Vec2, weight: Double): Vec2

Mixes (interpolates) a specified vector with this vector, modifying this vector.

Link copied to clipboard
open fun multiply(scalar: Double): Vec2

Multiplies this vector by a scalar.

Link copied to clipboard

Multiplies this vector by a 3x3 matrix. The multiplication is performed with an implicit Z component of 1. The resultant Z component of the product is then divided through the X and Y components.

Link copied to clipboard
open fun negate(): Vec2

Negates the components of this vector.

Link copied to clipboard
open fun normalize(): Vec2

Normalizes this vector to a unit vector.

Link copied to clipboard
operator fun plus(vector: Vec2): Vec2

Creates new vector containing sum of this and specified vectors.

Link copied to clipboard
operator fun plusAssign(vector: Vec2)

Adds a specified vector to this vector.

Link copied to clipboard
fun set(x: Double, y: Double): Vec2

Sets this vector to the specified X and Y.

Link copied to clipboard
fun subtract(vector: Vec2): Vec2

Subtracts a specified vector from this vector.

Link copied to clipboard
fun swap(vector: Vec2): Vec2

Swaps this vector with the specified vector. This vector's components are set to the values of the specified vector's components, and the specified vector's components are set to the values of this vector's components.

Link copied to clipboard
open operator fun times(scalar: Double): Vec2

Creates new vector containing this vector multiplied by a scalar.

Link copied to clipboard
open operator fun timesAssign(scalar: Double)

Multiplies this vector by a scalar.

Link copied to clipboard
open fun toArray(result: FloatArray, offset: Int): FloatArray

Copies this vector's components to the specified single precision array. The result is compatible with GLSL uniform vectors, and can be passed to the function glUniform2fv.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open operator fun unaryMinus(): Vec2

Creates new vector which has components with opposite sign to the vector.