@multiplekex/shallot 0.1.6 → 0.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplekex/shallot",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/core/math.ts CHANGED
@@ -174,18 +174,10 @@ export function lookAt(
174
174
  let xLen = Math.sqrt(xx * xx + xy * xy + xz * xz);
175
175
 
176
176
  if (xLen === 0) {
177
- if (upZ !== 0) {
178
- upX += 1e-4 * upX;
179
- upY += 1e-4 * upY;
180
- upZ += 1e-4 * upZ;
181
- } else if (upY !== 0) {
182
- upX += 1e-4 * upX;
183
- upY += 1e-4 * upY;
184
- upZ += 1e-4 * upZ;
177
+ if (Math.abs(zz) > Math.abs(zx)) {
178
+ upX += 1e-4;
185
179
  } else {
186
- upX += 1e-4 * upX;
187
- upY += 1e-4 * upY;
188
- upZ += 1e-4 * upZ;
180
+ upZ += 1e-4;
189
181
  }
190
182
  xx = upY * zz - upZ * zy;
191
183
  xy = upZ * zx - upX * zz;
@@ -50,7 +50,8 @@ setTraits(Orbit, {
50
50
  });
51
51
 
52
52
  function smoothLerp(smoothness: number, dt: number): number {
53
- return 1 - Math.pow(1 - smoothness, dt * 60);
53
+ const s = Math.max(0, Math.min(1, smoothness));
54
+ return 1 - Math.pow(1 - s, dt * 60);
54
55
  }
55
56
 
56
57
  function normalizeAngle(a: number): number {
@@ -44,6 +44,9 @@ export function ensureRenderTextures(
44
44
  }
45
45
 
46
46
  export function perspective(fov: number, aspect: number, near: number, far: number): Float32Array {
47
+ if (fov <= 0) throw new Error(`Invalid FOV: ${fov} (must be > 0)`);
48
+ if (aspect <= 0) throw new Error(`Invalid aspect ratio: ${aspect} (must be > 0)`);
49
+ if (near === far) throw new Error(`Invalid depth planes: near === far (${near})`);
47
50
  const f = 1 / Math.tan((fov * Math.PI) / 360);
48
51
  const nf = 1 / (near - far);
49
52
  return new Float32Array([
@@ -72,6 +75,9 @@ export function orthographic(
72
75
  near: number,
73
76
  far: number
74
77
  ): Float32Array {
78
+ if (size <= 0) throw new Error(`Invalid orthographic size: ${size} (must be > 0)`);
79
+ if (aspect <= 0) throw new Error(`Invalid aspect ratio: ${aspect} (must be > 0)`);
80
+ if (near === far) throw new Error(`Invalid depth planes: near === far (${near})`);
75
81
  const lr = 1 / (size * aspect);
76
82
  const bt = 1 / size;
77
83
  const nf = 1 / (near - far);
@@ -188,7 +188,7 @@ function updateTweens(state: State, dt: number): void {
188
188
 
189
189
  const elapsed = Tween.elapsed[tweenEid];
190
190
  const duration = Tween.duration[tweenEid];
191
- const rawProgress = Math.min(elapsed / duration, 1);
191
+ const rawProgress = duration === 0 ? 1 : Math.min(elapsed / duration, 1);
192
192
 
193
193
  const easingFn = getEasing(Tween.easingIndex[tweenEid]);
194
194
  const easedProgress = easingFn(rawProgress);