0.30.0 ā€¢ Published 2 months ago

linearly v0.30.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Documentation āŒ‡ Become a Sponsor

A collection of utility functions that relates to linear algebra and graphics programming.

šŸ” I'd appreciate receiving PRs from anyone willing to help with tedious tasks like writing JSDoc, adding necessary functions, or writing tests.

This library is based on glMatrix, but adopts an immutable data structure. So you don't need to specify a receiver matrix as the first argument.

glMatrix

// In glMatrix, you have to manually pass an output vector by reference to reuse allocated memory space efficiently.
const dir = vec3.fromValues(2, 1, 3)
vec3.normalize(dir, dir)

const out = vec3.create()
vec3.cross(out, dir, [0, 1, 0])
vec2.scale(out, out, 3)

Linearly

// In linearly, you can simply write like this:
import {mat2d, vec3} from 'linearly'

const dir = vec3.normalize([2, 1, 3])
let out = vec3.cross(dir, [0, 1, 0])
out = vec3.scale(out, 3)

// As the values of Linearly are plain 1D arrays, you can initialize a vector by either way.
const a: vec2 = [1, 2]
const b = vec2.of(1, 2)

// But since vector and matrix are immutable and annotated with read-only flags, a mutation such as below is handled as an error in TypeScript.
a[0] = 3
// ^
// Cannot assign to '0' because it is a read-only property.

// Some constants such as mat2.identity are also read-only and defined as frozen array (applied Object.freeze). You can use `clone` to mutate them.
const m = mat2d.clone(mat2d.ident)
m[4] *= 2.0
m[5] = -4.5

In addition to functions that can be found on glMatrix docs, the library also provides some useful functions. For example:

Development

git clone https://github.com/baku89/lnearly
cd linearly
yarn install
yarn test --watch

License

This repository is published under an MIT License. See the included LICENSE file.

0.30.0

2 months ago

0.29.0

3 months ago

0.28.1

3 months ago

0.28.0

3 months ago

0.28.2

3 months ago

0.27.0

3 months ago

0.24.3

3 months ago

0.26.0

3 months ago

0.24.2

3 months ago

0.25.0

3 months ago

0.24.0

3 months ago

0.23.0

3 months ago

0.22.0

3 months ago

0.21.0

6 months ago

0.20.3

7 months ago

0.20.2

7 months ago

0.20.1

7 months ago

0.20.0

7 months ago

0.19.0

7 months ago

0.18.0

7 months ago

0.17.0

7 months ago

0.16.0

7 months ago

0.15.0

7 months ago

0.14.0

7 months ago

0.13.0

7 months ago

0.12.1

7 months ago

0.12.0

8 months ago

0.11.0

8 months ago

0.10.0

8 months ago

0.9.0

8 months ago

0.8.2

8 months ago

0.8.1

8 months ago

0.8.0

8 months ago

0.7.0

8 months ago

0.6.1

8 months ago

0.6.0

8 months ago

0.5.0

8 months ago

0.4.3

8 months ago

0.4.2

8 months ago

0.4.1

8 months ago

0.3.0

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago

0.0.0

8 months ago