2.0.0 • Published 5 years ago

vector-fun v2.0.0

Weekly downloads
3
License
MIT
Repository
-
Last release
5 years ago

Vector-Fun

A simple functional vector mathematics library written in Typescript.

Vector object shape

2d:

// { x: 0, y: 0 };

3d:

// { x: 0, y: 0, z: 0 };

Creating a vector object

Null vector

const vector2d = vector2();
// {x: 0, y: 0}

const vector3d = vector3();
// {x: 0, y: 0, z: 0}

Vector with equal components

const vector2d = vector2(1);
// {x: 1, y: 1}

const vector3d = vector3(1);
// {x: 1, y: 1, z: 1}

Vector from individual components

const vector2d = vector2(1, 2.6);
// {x: 1, y: 2.6}

const vector3d = vector3(1, 2.6, 3);
// {x: 1, y: 2.6, z: 3}

Vector from an array

const vector2d = vector2([1, 2]);
// {x: 1, y: 2}

const vector3d = vector3([1, 2, 3]);
// {x: 1, y: 2, z: 3}

Copied vector

const source2d = vector2(1, 2);
const vector2d = vector2(source2d);
// {x: 1, y: 2}

vector2d !== source2d;
// true

const source3d = vector3(1, 2, 3);
const vector3d = vector2(source3d);
// {x: 1, y: 2, z: 3}

vector3d !== source3d;
// true

Single vector operations

2d only

  • Direction in radians
  • Normalization
  • Rotation by radians
  • Scaling to a new magnitude

Both 2d and 3d

  • Convert to array
  • Division by a scalar
  • Magnitude
  • Multiplication by a scalar
  • Type guard (isVector2 and isVector3)
  • Vector inversion

Two vector operations

  • Addition
  • Equality
  • Subtraction
2.0.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago