Skip to content

Vector

The Vector library offers a numeric vector data structure and methods to work with them.

They are intended to be used as immutables. All methods and operators return a new instance of the output vector.

Vector objects implement various operators; the binary ones only usable for vectors of the same arity:

  • +: sum of components.
  • -: subtraction of components.
  • *: dot product.
  • ^: negation; inverts the sign of all components.

Additionally, vector.Arity or vector.Length will return the amount of elements in the vector.

In Epip, their primary use is semantic clarity for functions that require 2D coordinates as parameters.

VectorLib Class

Inherits from Library.

Methods

AreEqual
function VectorLib.AreEqual(v1, v2)

Returns whether 2 vectors are equal.

Vectors are equal if they have the same arity and components.

@param v1 Vector

@param v2 Vector

Clone
function VectorLib.Clone(vector)
   -> Vector

@param vector Vector

Create
function VectorLib.Create()
   -> Vector

Creates a vector of variable length.

DotProduct
function VectorLib.DotProduct(v1, v2)
   -> number

Performs a dot product between two vectors of the same dimensions.

@param v1 Vector

@param v2 Vector

GetLength
function VectorLib.GetLength(vector)
   -> number

@param vector Vector

GetNormalized
function VectorLib.GetNormalized(vector)
   -> Vector New instance; does not mutate.-- instance; does not mutate.

@param vector Vector

Negate
function VectorLib.Negate(v)
   -> Vector

@param v Vector

ScalarProduct
function VectorLib.ScalarProduct(v, scalar)
   -> Vector

Performs a scalar product of a vector, multiplying each of its components.

@param v Vector

@param scalar number

Subtract
function VectorLib.Subtract(v1, v2)
   -> Vector

Subtracts the components of two vectors of the same dimension.

@param v1 Vector

@param v2 Vector

Sum
function VectorLib.Sum(v1, v2)
   -> Vector

Sums the components of two vectors of the same dimensions.

@param v1 Vector

@param v2 Vector