The dimension of this Vector, or the last index that has a value (plus one).
const a = new Vector(1, 1, 1);
a.dimension; // 3
const b = new Vector(1, 2, 3, 4, 5);
b.dimension; // 5
Dimensions can be dynamically updated after a Vector is created:
const v = new Vector(0);
v.dimension; // 1
v.set(3, 10);
v.dimension; // 4 (indices start at 0)
Add another Vector to this Vector. This does mutate the Vector that calls this method.
Linearly interpolate between this Vector and another Vector. This does not mutate the original Vector that calls this method, but returns a new Vector.
const a = new Vector(1, 3, -5);
const b = new Vector(4, -2);
a.lerp(b, 0); // returns a clone of Vector a
a.lerp(b, 1); // returns a clone of Vector b
const mid = a.lerp(b, 0.5); // returns a Vector halfway between a and b
mid.xyz; // returns [2.5, 0.5, -2.5]
The other vector.
The amount by which to interpolate (usually between 0 and 1, although it can be any number).
Set the value at a given index. If the index is greater than the dimension
of this Vector, the dimension will be increased to the dimensionality implied by the index.
The numerical index (0-based) or lowercase string value (e.g. "x") to set.
The value to set at this index/position.
const vector = new Vector();
vector.set(0, 10);
vector.set('y', 2);
vector.set(2, 4);
vector.xyz; // [10, 2, 4]
A
Vectorcontains multi-dimensional numeric data.Since
0.1.0