# Vector2

@Serializable
data class Vector2(val x: Double, val y: Double) : LinearType<Vector2> , EuclideanVector<Vector2> (source)

Double-precision 2D vector.

## Constructors

constructor(x: Double)
constructor(x: Double, y: Double)

object Companion

## Functions

open override fun areaBetween(other: Vector2): Double

returns the area of the parallelogram formed by extruding this over other

open fun atan2(other: Vector2): Double

atan2 style angle between this and other

Returns Vector2 whose value is limited between min and max per vector component.

infix fun cross(right: Vector2): Double

Calculates a cross product between this Vector2 and right.

open override fun distanceTo(other: Vector2): Double

Calculates the Euclidean distance to other.

open operator override fun div(scale: Double): Vector2
operator fun div(d: Vector2): Vector2
open infix override fun dot(right: Vector2): Double

Calculates a dot product between this Vector2 and right.

operator fun get(i: Int): Double
open override fun map(function: (Double) -> Double): Vector2

apply function to all components

fun Vector2.map(beforeLeft: Vector2, beforeRight: Vector2, afterLeft: Vector2, afterRight: Vector2, clamp: Boolean = false): Vector2
operator fun minus(d: Double): Vector2
open operator override fun minus(right: Vector2): Vector2
fun mix(o: Vector2, mix: Double): Vector2
fun perpendicular(polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): Vector2

Calculates a vector perpendicular to the current one.

operator fun plus(d: Double): Vector2
open operator override fun plus(right: Vector2): Vector2
open infix fun projectedOn(on: Vector2): Vector2

project this vector on on

infix fun reflect(surfaceNormal: Vector2): Vector2
open infix fun reflectedOver(surfaceNormal: Vector2): Vector2

reflect this vector over surfaceNormal

fun rotate(degrees: Double, origin: Vector2 = ZERO): Vector2

Creates a new Vector2 with the given rotation and origin.

open override fun squaredDistanceTo(other: Vector2): Double

Calculates the squared Euclidean distance to other.

open operator override fun times(scale: Double): Vector2
operator fun times(v: Vector2): Vector2

Casts to IntVector2.

operator fun unaryMinus(): Vector2
fun vector3(x: Double = this.x, y: Double = this.y, z: Double = 0.0): Vector3

Upcasts to Vector3.

fun vector4(x: Double = this.x, y: Double = this.y, z: Double = 0.0, w: Double = 0.0): Vector4

Upcasts to Vector4.

## Properties

open override val length: Double

The Euclidean length of the vector.

normalized vector

open override val squaredLength: Double

The squared Euclidean length of the vector.

val x: Double
val xx: Vector2