Vector
The Vector type represents a 2D point or vector. Each element is stored as a 32-bit floating point number.
Specify a vector using the @(x, y)
syntax:
// Create V2s using the @(x, y) syntax
let a = @(-1, 1)
let b = a * 5 // b is @(-5, 5)
let c = b.Rotate(180deg) // c is @(5, -5)
To access individual elements of the Vector, use the X and Y functions:
let a = @(1, 2)
let x = a.X // x is 1
let y = a.Y // y is 2
Vectors are immutable, which means they cannot be changed.
If you would like to modify a vector, you must create a new one.
This can be done using the usual @(x, y)
syntax,
or using the WithX and WithY functions
which return a new vector with the specified component replaced:
let a = @(1, 2)
let b = @(3, a.Y) // b is @(3, 2)
let c = a.WithX(3) // c is also @(3, 2)