Vec2

data class Vec2<T : Number, Comparable<T>>(val x: T, val y: T, val type: KClass<T>) : Vec<T>

2D vector with coordinates (x, y).

Can also be used to specify texture coordinates in UV mapping.

Constructors

Link copied to clipboard
constructor(x: T, y: T, type: KClass<T>)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun atan(): Angle<T>

Returns the arc tangent of value y/x for this vector.

Link copied to clipboard
infix fun cross(other: Vec2<T>): Vec3<T>

Calculates cross product of this vector and the other vector.

Link copied to clipboard
operator fun div(number: T): Vec2<T>

Divides this vector by the specified number.

Link copied to clipboard
infix fun dot(other: Vec2<T>): T

Calculates dot product of this vector and the other vector.

Link copied to clipboard
fun magnitude(): T

Returns the magnitude of this vector.

Link copied to clipboard
operator fun minus(other: Vec2<T>): Vec2<T>

Subtracts the other vector from this vector.

Link copied to clipboard
fun normalize(): Vec2<T>

Returns a unit vector in the direction of this vector.

Link copied to clipboard
operator fun plus(other: Vec2<T>): Vec2<T>

Adds the other vector to this vector.

Link copied to clipboard
operator fun times(number: T): Vec2<T>

Multiplies this vector by the specified number.

Link copied to clipboard

Returns an array of coordinates of this vector.

Link copied to clipboard

Returns a 2D double-precision float vector equal to this vector.

Link copied to clipboard

Returns an array of coordinates of this vector.

Link copied to clipboard

Returns a 2D float vector equal to this vector.

Link copied to clipboard

Returns an array of coordinates of this vector.

Link copied to clipboard

Returns a 2D integer vector equal to this vector.

Link copied to clipboard
open override fun toList(): List<T>

Returns a list of coordinates of this vector.

Link copied to clipboard

Returns an array of coordinates of this vector.

Link copied to clipboard

Returns a 2D long integer vector equal to this vector.

Link copied to clipboard
fun toVec3(z: T = zero(this.type)): Vec3<T>

Returns a 3D vector with x and y coordinates of this vector and the given z coordinate.

Link copied to clipboard
fun toVec4(z: T = zero(this.type), w: T = zero(this.type)): Vec4<T>

Returns a 4D vector with x and y coordinates of this vector and the given z and w coordinates.

Link copied to clipboard
operator fun unaryMinus(): Vec2<T>

Returns a vector opposite to this vector.

Link copied to clipboard
operator fun unaryPlus(): Vec2<T>

Returns this vector.

Properties

Link copied to clipboard
val type: KClass<T>

Type of vector coordinates.

Link copied to clipboard
val u: T

U coordinate for UV mapping.

Link copied to clipboard
val v: T

V coordinate for UV mapping.

Link copied to clipboard
val x: T

X coordinate of this vector.

Link copied to clipboard
val y: T

Y coordinate of this vector.