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¶
Returns whether 2 vectors are equal.
Vectors are equal if they have the same arity and components.
@param v1 Vector
@param v2 Vector
Clone¶
@param vector Vector
Create¶
Creates a vector of variable length.
DotProduct¶
Performs a dot product between two vectors of the same dimensions.
@param v1 Vector
@param v2 Vector
GetLength¶
@param vector Vector
GetNormalized¶
function VectorLib.GetNormalized(vector)
-> Vector New instance; does not mutate.-- instance; does not mutate.
@param vector Vector
Negate¶
@param v Vector
ScalarProduct¶
Performs a scalar product of a vector, multiplying each of its components.
@param v Vector
@param scalar number
Subtract¶
Subtracts the components of two vectors of the same dimension.
@param v1 Vector
@param v2 Vector
Sum¶
Sums the components of two vectors of the same dimensions.
@param v1 Vector
@param v2 Vector