@devrals/math 0.1.0 → 0.1.2

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/dist/math.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/vec.ts
1
+ //#region src/vectors.ts
2
2
  var e = class e {
3
3
  constructor(e, t) {
4
4
  this.x = e, this.y = t;
@@ -66,6 +66,6 @@ var e = class e {
66
66
  this.z
67
67
  ];
68
68
  }
69
- }, n = (e) => e[Math.floor(Math.random() * e.length)], r = (e, t) => (e % t + t) % t, i = (e, t) => e + Math.random() * t, a = (e, t, n) => Math.max(Math.min(e, n), t), o = (e, t, n) => e * (1 - n) + t * n, s = (e, t, n) => e < t ? Math.min(e + n, t) : Math.max(e - n, t), c = (n, r) => "z" in n && "z" in r ? new t(n.x + r.x, n.y + n.y, n.z + n.z) : new e(n.x + r.x, n.y + n.y), l = (n, r) => "z" in n && "z" in r ? new t(n.x - r.x, n.y - n.y, n.z - n.z) : new e(n.x - r.x, n.y - n.y), u = (n, r) => "z" in n && "z" in r ? new t(n.x * r.x, n.y * n.y, n.z * n.z) : new e(n.x * r.x, n.y * n.y), d = (n, r) => "z" in n && "z" in r ? new t(n.x / r.x, n.y / n.y, n.z / n.z) : new e(n.x / r.x, n.y / n.y);
69
+ }, n = (e) => e[Math.floor(Math.random() * e.length)], r = (e, t) => (e % t + t) % t, i = (e, t) => e + Math.random() * (t - e), a = (e, t, n) => Math.max(Math.min(e, n), t), o = (e, t, n) => e * (1 - n) + t * n, s = (e, t, n) => e < t ? Math.min(e + n, t) : Math.max(e - n, t), c = (n, r) => "z" in n && "z" in r ? new t(n.x + r.x, n.y + n.y, n.z + n.z) : new e(n.x + r.x, n.y + n.y), l = (n, r) => "z" in n && "z" in r ? new t(n.x - r.x, n.y - n.y, n.z - n.z) : new e(n.x - r.x, n.y - n.y), u = (n, r) => "z" in n && "z" in r ? new t(n.x * r.x, n.y * n.y, n.z * n.z) : new e(n.x * r.x, n.y * n.y), d = (n, r) => "z" in n && "z" in r ? new t(n.x / r.x, n.y / n.y, n.z / n.z) : new e(n.x / r.x, n.y / n.y);
70
70
  //#endregion
71
71
  export { e as Vec2, t as Vec3, c as add, s as approach, n as chooseRand, a as clamp, d as div, o as lerp, r as mod, u as mul, i as randRange, l as sub };
package/dist/math.umd.cjs CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.index={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class e{constructor(e,t){this.x=e,this.y=t}static initial(t){return new e(t,t)}static empty(){return new e(0,0)}add(e){return typeof e==`number`?this.x+=e:this.x+=e.x,typeof e==`number`?this.y+=e:this.y+=e.y,this}sub(e){return typeof e==`number`?this.x-=e:this.x-=e.x,typeof e==`number`?this.y-=e:this.y-=e.y,this}mul(e){return typeof e==`number`?this.x*=e:this.x*=e.x,typeof e==`number`?this.y*=e:this.y*=e.y,this}div(e){return typeof e==`number`?this.x/=e:this.x/=e.x,typeof e==`number`?this.y/=e:this.y/=e.y,this}map(e){return this.x=e(this.x),this.y=e(this.y),this}toArr(){return[this.x,this.y,0]}},n=class e extends t{constructor(e,t,n){super(e,t),this.z=n}static initial(t){return new e(t,t,t)}static empty(){return new e(0,0,0)}static fromHex(t){return new e(parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16))}add(e){return typeof e==`number`?this.x+=e:this.x+=e.x,typeof e==`number`?this.y+=e:this.y+=e.y,typeof e==`number`?this.z+=e:this.z+=e.z,this}sub(e){return typeof e==`number`?this.x-=e:this.x-=e.x,typeof e==`number`?this.y-=e:this.y-=e.y,typeof e==`number`?this.z-=e:this.z-=e.z,this}mul(e){return this.x*=typeof e==`number`?e:e.x,this.y*=typeof e==`number`?e:e.y,this.z*=typeof e==`number`?e:e.z,this}div(e){return typeof e==`number`?this.x/=e:this.x/=e.x,typeof e==`number`?this.y/=e:this.y/=e.y,typeof e==`number`?this.z/=e:this.z/=e.z,this}map(e){return this.x=e(this.x),this.y=e(this.y),this.z=e(this.z),this}toArr(){return[this.x,this.y,this.z]}};e.Vec2=t,e.Vec3=n,e.add=(e,r)=>`z`in e&&`z`in r?new n(e.x+r.x,e.y+e.y,e.z+e.z):new t(e.x+r.x,e.y+e.y),e.approach=(e,t,n)=>e<t?Math.min(e+n,t):Math.max(e-n,t),e.chooseRand=e=>e[Math.floor(Math.random()*e.length)],e.clamp=(e,t,n)=>Math.max(Math.min(e,n),t),e.div=(e,r)=>`z`in e&&`z`in r?new n(e.x/r.x,e.y/e.y,e.z/e.z):new t(e.x/r.x,e.y/e.y),e.lerp=(e,t,n)=>e*(1-n)+t*n,e.mod=(e,t)=>(e%t+t)%t,e.mul=(e,r)=>`z`in e&&`z`in r?new n(e.x*r.x,e.y*e.y,e.z*e.z):new t(e.x*r.x,e.y*e.y),e.randRange=(e,t)=>e+Math.random()*t,e.sub=(e,r)=>`z`in e&&`z`in r?new n(e.x-r.x,e.y-e.y,e.z-e.z):new t(e.x-r.x,e.y-e.y)});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.index={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class e{constructor(e,t){this.x=e,this.y=t}static initial(t){return new e(t,t)}static empty(){return new e(0,0)}add(e){return typeof e==`number`?this.x+=e:this.x+=e.x,typeof e==`number`?this.y+=e:this.y+=e.y,this}sub(e){return typeof e==`number`?this.x-=e:this.x-=e.x,typeof e==`number`?this.y-=e:this.y-=e.y,this}mul(e){return typeof e==`number`?this.x*=e:this.x*=e.x,typeof e==`number`?this.y*=e:this.y*=e.y,this}div(e){return typeof e==`number`?this.x/=e:this.x/=e.x,typeof e==`number`?this.y/=e:this.y/=e.y,this}map(e){return this.x=e(this.x),this.y=e(this.y),this}toArr(){return[this.x,this.y,0]}},n=class e extends t{constructor(e,t,n){super(e,t),this.z=n}static initial(t){return new e(t,t,t)}static empty(){return new e(0,0,0)}static fromHex(t){return new e(parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16))}add(e){return typeof e==`number`?this.x+=e:this.x+=e.x,typeof e==`number`?this.y+=e:this.y+=e.y,typeof e==`number`?this.z+=e:this.z+=e.z,this}sub(e){return typeof e==`number`?this.x-=e:this.x-=e.x,typeof e==`number`?this.y-=e:this.y-=e.y,typeof e==`number`?this.z-=e:this.z-=e.z,this}mul(e){return this.x*=typeof e==`number`?e:e.x,this.y*=typeof e==`number`?e:e.y,this.z*=typeof e==`number`?e:e.z,this}div(e){return typeof e==`number`?this.x/=e:this.x/=e.x,typeof e==`number`?this.y/=e:this.y/=e.y,typeof e==`number`?this.z/=e:this.z/=e.z,this}map(e){return this.x=e(this.x),this.y=e(this.y),this.z=e(this.z),this}toArr(){return[this.x,this.y,this.z]}};e.Vec2=t,e.Vec3=n,e.add=(e,r)=>`z`in e&&`z`in r?new n(e.x+r.x,e.y+e.y,e.z+e.z):new t(e.x+r.x,e.y+e.y),e.approach=(e,t,n)=>e<t?Math.min(e+n,t):Math.max(e-n,t),e.chooseRand=e=>e[Math.floor(Math.random()*e.length)],e.clamp=(e,t,n)=>Math.max(Math.min(e,n),t),e.div=(e,r)=>`z`in e&&`z`in r?new n(e.x/r.x,e.y/e.y,e.z/e.z):new t(e.x/r.x,e.y/e.y),e.lerp=(e,t,n)=>e*(1-n)+t*n,e.mod=(e,t)=>(e%t+t)%t,e.mul=(e,r)=>`z`in e&&`z`in r?new n(e.x*r.x,e.y*e.y,e.z*e.z):new t(e.x*r.x,e.y*e.y),e.randRange=(e,t)=>e+Math.random()*(t-e),e.sub=(e,r)=>`z`in e&&`z`in r?new n(e.x-r.x,e.y-e.y,e.z-e.z):new t(e.x-r.x,e.y-e.y)});
@@ -0,0 +1,11 @@
1
+ import { Vec2, Vec3 } from './vectors.js';
2
+ export declare const chooseRand: <T>(arr: T[]) => T;
3
+ export declare const mod: (x: number, m: number) => number;
4
+ export declare const randRange: (min: number, max: number) => number;
5
+ export declare const clamp: (value: number, min: number, max: number) => number;
6
+ export declare const lerp: (a: number, b: number, t: number) => number;
7
+ export declare const approach: (current: number, target: number, dt: number) => number;
8
+ export declare const add: <V extends Vec2 | Vec3>(x: V, y: V) => V;
9
+ export declare const sub: <V extends Vec2 | Vec3>(x: V, y: V) => V;
10
+ export declare const mul: <V extends Vec2 | Vec3>(x: V, y: V) => V;
11
+ export declare const div: <V extends Vec2 | Vec3>(x: V, y: V) => V;
@@ -1 +1,2 @@
1
- export * from './vec.js';
1
+ export * from './vectors.js';
2
+ export * from './functions.js';
@@ -34,13 +34,3 @@ export type VertexPositionColor = {
34
34
  pos: Vec2;
35
35
  color: Vec3;
36
36
  };
37
- export declare const chooseRand: <T>(arr: T[]) => T;
38
- export declare const mod: (x: number, m: number) => number;
39
- export declare const randRange: (x: number, y: number) => number;
40
- export declare const clamp: (value: number, min: number, max: number) => number;
41
- export declare const lerp: (a: number, b: number, t: number) => number;
42
- export declare const approach: (current: number, target: number, dt: number) => number;
43
- export declare const add: <V extends Vec2 | Vec3>(x: V, y: V) => V;
44
- export declare const sub: <V extends Vec2 | Vec3>(x: V, y: V) => V;
45
- export declare const mul: <V extends Vec2 | Vec3>(x: V, y: V) => V;
46
- export declare const div: <V extends Vec2 | Vec3>(x: V, y: V) => V;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@devrals/math",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Vector2/3 Utils",
7
+ "repository": "https://github.com/devRals/webgl-backdrops/",
7
8
  "files": [
8
9
  "dist"
9
10
  ],