3.0.1 • Published 19 days ago

@leodeslf/vec.js v3.0.1

Weekly downloads
256
License
MIT
Repository
github
Last release
19 days ago

Vec.js

version license

            .                 .
    <--------\               /-------->
      <-------\.           ./------->
        <------\\         //------>
          <-----\\.     .//----->
            <----\\\   ///---->
              <---\\\ ///--->
                <--\\Y//-->
                  <-\|/->
                     V

Table of contents

About

JavaScript vector library.

A set of classes that provide functionality related to basic linear-algebra, geometry, and more, for 2, 3, and 4-dimensional vectors.

Installation

npm i @leodeslf/vec.js
pnpm i @leodeslf/vec.js
yarn add @leodeslf/vec.js

CDNs

https://unpkg.com/@leodeslf/vec.js@3.0.1
https://cdn.jsdelivr.net/npm/@leodeslf/vec.js@3.0.1

Usage

Most methods are available as both instance and static members. The ones that modify the current vector return this, thus we can chain method calls. Other than e.g.: vector.x, vector.y, and vector.xy (as an array), vectors are iterable, so it's possible to iterate trough their components using for-of or spread operator (e.g.: ...vector).

// E.g.:
import { Vec2 } from '@leodeslf/vec.js';

const position = new Vec2(1, 1.8);
const target = new Vec2(1, 10);
const distance = position.distance(target); // 8.2
const direction = Vec2.subtract(target, position).normalize(); // { x: 0, y: 1 }

Linear Algebra

NameVec2Vec3Vec4
add
angleBetween
cross
distance
distanceChebyshev
distanceManhattan
distanceMinkowski
distanceSq
dot
lerp
negate
normalize
project
rotateX
rotateY
rotateZ
scale
subtract

Copying & Creating

NameVec2Vec3Vec4
clone
copy
fromCylindricalCoords
fromPolarCoords
fromSphericalCoords
random

Boolean Conditions

NameVec2Vec3Vec4
satisfyEquality
satisfyOpposition
isInfinite
isNaN
isZero

Magnitude Manipulation

NameVec2Vec3Vec4
limitMax
limitMin
clamp
zero

Miscellaneous

NameVec2Vec3Vec4
lookAt
turnLeft
turnRight

Getters & Setters

NameVec2Vec3Vec4
angleW✓*
angleX*✓*
angleY*✓*
angleZ*✓*
magnitude
magnitudeSq**✓*
a (alias for w)
r (alias for x)
g (alias for y)
b (alias for z)

*read only.

Shortcuts

Use them to get/set components as/from arrays.

NameVec2Vec3Vec4
xy
xyz (or alias rgb)
xyzw (or alias rgba)

Author

Copyright (c) Leonardo de S.L.F, 2018-present.

License

MIT License.

3.0.1

19 days ago

3.0.0

9 months ago

2.0.2

9 months ago

2.0.1

9 months ago

2.0.0

1 year ago

1.6.8

2 years ago

1.6.6

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.5

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.6

3 years ago

1.1.5

4 years ago