Vec2

class Vec2(x: Double, y: Double)

2D Vectors class

Parameters

x

Sets x value.

y

Sets y value.

Constructors

Link copied to clipboard
fun Vec2(vector: Vec2)

Copy constructor.

Link copied to clipboard
fun Vec2(direction: Double)

Constructs a normalised direction vector.

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

Types

Link copied to clipboard
object Companion

Functions

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

Adds a vector to the current instance and return this.

Link copied to clipboard
fun copy(): Vec2

Copy method to return a new copy of the current instance vector.

Link copied to clipboard
fun copyNegative(): Vec2

Negates the current instance vector and return this.

Link copied to clipboard
fun cross(v1: Vec2): Double

Finds cross product between two vectors.

fun cross(a: Double): Vec2
Link copied to clipboard
fun distance(v: Vec2): Double

Finds the distance between two vectors.

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

Finds dotproduct between two vectors.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun length(): Double

Gets the length of instance vector.

Link copied to clipboard
operator fun minus(v1: Vec2): Vec2

Subtract a vector from the current instance vector.

Link copied to clipboard
fun normal(): Vec2

Generates a normal of a vector. Normal facing to the right clock wise 90 degrees.

Link copied to clipboard
fun normalize(): Vec2

Normalizes the current instance vector to length 1 and returns this.

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

Adds a vector and the current instance vector together and returns a new vector of them added together.

Link copied to clipboard
fun scalar(a: Double): Vec2
Link copied to clipboard
fun set(v1: Vec2): Vec2

Sets a vector to another vector and returns this.

operator fun set(x: Double, y: Double): Vec2

Sets a vector to equal an x/y value and returns this.

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

Negates the current instance vector and return this.

Properties

Link copied to clipboard
val isValid: Boolean

Checks to see if a vector has valid values set for x and y.

Link copied to clipboard
val isZero: Boolean

Checks to see if a vector is set to (0,0).

Link copied to clipboard
val normalized: Vec2

Finds the normalised version of a vector and returns a new vector of it.

Link copied to clipboard
var x: Double = 0.0
Link copied to clipboard
var y: Double = 0.0