Overview

In this section you'll find everything related to the VOLTS.Vector class

Vector is a very useful class, as it provides a way to represent N-Dimentional data

import { Vector } from 'volts';

const defaultVector = new Vector();           // Vector<3> [0,0,0]

const fromSigleArg = new Vector(1);           // Vector<3> [1,1,1]

const scalar  = new Vector<1>([1]);           // Vector<1> [1]
const vector2 = new Vector(1,2);              // Vector<2> [1, 2]
const vector3 = new Vector(1,2,3);            // Vector<3> [1, 2, 3]

const fromArray = new Vector([1,2,3, ...[]]); // Vector<number> [...]

const hardTyped = new Vector<3>(1,2,3);       // Vector<3> [1,2,3]

Creating a Vector

To create a Vector you can use

Rest parameters

To create a Vector from rest parameters, simply pass your values to the constructor

circle-exclamation

Array parameter

Vector can take in an array, and create a Vector with those values. The values will be assigned secuentially to the 1st, 2nd, 3rd, Nth dimension.

This array cannot be empty, and must be composed entirely by numbers

circle-exclamation

Another Vector

A Vector can be creating from an existing one. Changes made to either won't be reflected on the other

Types & Generics

The Vector type is genericarrow-up-right. This generic type describes the dimension of your vector, for example Vector<2> represents a two dimensional vector.

This generic type will determine which methods and properties are exposed to Typescript & Intelisense/autocompletion

You can hard-type the value, or you can leave it up to Typescript to figure out for you

Hard-typing the generic is useful when dealing with cases when inference is not possible, for example, when constructing a Vector from an array.

circle-info

Vector<number> is the same as the combination of the Vector 1,2,3 & 4 types + base. Meaning you won't get any useful information based on the dimension of your Vector

Last updated