glmaths 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,13 +44,16 @@ You can pass vector in a vector, just like in GLSL: `vec4(vec2(0, 1), 2, 3)`
44
44
  If you code in TypeScript, you can opt for [a fork of TypeScript](https://github.com/dkaraush/Typescript) to enable operator overloading in code! `glmaths` implements functions needed to overload these operators: `+ - * / % == ===`
45
45
 
46
46
  ```ts
47
- mat4.perspective(Math.PI / 2) * vec4(vec2(1, 2) / 4.0 + 2.0, 1.0, 1.0)
47
+ const ndc = proj * view * vertex
48
+ let model = mat4()
49
+ model *= mat4.fromRotation(Math.PI / 2, vec3(0, 1, 0))
50
+ vec4(vec2(1.0, 2.0) / 2.0 + 4.0, 0.0, 1.0) + vec4(1) * vec4(4, 2, 0, 0)
48
51
  ```
49
52
  _With this done, it totally looks like GLSL! :D_
50
53
 
51
54
  ## `out` argument
52
55
 
53
- Like `gl-matrix`, all functions have `out` argument, but it is located at the end as an optional argument.
56
+ Like `gl-matrix`, all functions have `out` argument, but it is located at the end as an optional argument:
54
57
  ```ts
55
58
  const a = vec3(0, 1, 2)
56
59
  const b = vec3(2, 3, 4)
@@ -58,15 +61,14 @@ const c = vec3()
58
61
  a.plus(b, /* out = */ c)
59
62
  ```
60
63
 
61
- By default, default value of `out` is always a new clone of a structure. Not using `out` will create overhead to GC leading to worse performance, so for production pre-allocating structures and passing them in `out` argument is recommended.
62
-
63
- You can also opt for modifying existing structure when using instance methods, by setting `glmaths.ALWAYS_COPY = false`. This way every operation, by default, will update its own structure. This might bring confusion, when saving structures in variables, as it modifies itself, hence why this is not the default behaviour. Example below:
64
+ The idea behind `glmaths` is to make tinkering fun — so by default every operation returns a new copy, and you can just write `a.plus(b)` without thinking about memory. But when you need performance, you can pre-allocate structures and pass them as `out`, just like you would in `gl-matrix`.
64
65
 
66
+ You can also set `glmaths.ALWAYS_COPY = false` to make instance methods modify the structure in place by default, skipping the copy entirely. But this can bring confusion, hence why this is not the default:
65
67
  ```ts
66
68
  glmaths.ALWAYS_COPY = false
67
69
  const a = vec3(0, 1, 2)
68
70
  const b = a.plus(5)
69
- // a.x === 5
71
+ // a.x === 5, a was modified in place
70
72
  ```
71
73
 
72
74
  ## Docs
@@ -899,7 +901,7 @@ Suprisingly, in most operations `glmaths` comes faster than its simpler `gl-matr
899
901
 
900
902
  This benchmark, though, doesn't tell the difference in loading up a library. When I started running benchmarks, I noticed how on first test `glmaths` was consistently slower, than `gl-matrix`; and I believe this is a setup cost for extending `Float32Array` with all methods and getters for swizzles. There is a hack in `bencmark.js` to overcome this.
901
903
 
902
- ## Benchmark Results
904
+ Benchmark is run with `glmaths.ALWAYS_COPY = false`.
903
905
 
904
906
  | Operation | gl-matrix | glmaths | Diff |
905
907
  |:---|---:|---:|---:|
@@ -945,8 +947,6 @@ This benchmark, though, doesn't tell the difference in loading up a library. Whe
945
947
  | Quat2 multiply | — | 89.9M ops/s ±2.2% | — |
946
948
  | Quat2 getTranslation | — | 42.5M ops/s ±1.1% | — |
947
949
 
948
- _Benchmark was run on my Macbook Pro M4._
949
-
950
950
  ### Tests
951
951
 
952
952
  You can run tests with `npm run test`
package/benchmark.js CHANGED
@@ -196,7 +196,7 @@ function vec3Benchmarks() {
196
196
  glm.vec3.distance(a1, b1);
197
197
  });
198
198
  s8.add('glmaths Vec3.distance(a, b)', () => {
199
- glmaths.Vec3.distance(a2, b2);
199
+ const c = glmaths.Vec3.distance(a2, b2);
200
200
  });
201
201
 
202
202
 
@@ -207,7 +207,7 @@ function vec3Benchmarks() {
207
207
  glm.vec3.lerp(lerpOut1, a1, b1, 0.5);
208
208
  });
209
209
  s9.add('glmaths Vec3.lerp(a, b, 0.5, out)', () => {
210
- glmaths.Vec3.lerp(a2, b2, 0.5, lerpOut2);
210
+ const c = glmaths.Vec3.lerp(a2, b2, 0.5, lerpOut2);
211
211
  });
212
212
 
213
213
  return runSuite(s1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glmaths",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "test": "TS_NODE_PROJECT=tsconfig.test.json node --require ts-node/register --test tests/*.test.ts",