@devrals/math 0.2.0 → 0.2.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
@@ -118,6 +118,25 @@ var e = class e {
118
118
  clone() {
119
119
  return new e(this.x, this.y, this.z);
120
120
  }
121
- }, 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);
121
+ }, n = {
122
+ red: new t(255, 0, 0),
123
+ green: new t(0, 255, 0),
124
+ blue: new t(0, 0, 255),
125
+ cyan: new t(0, 255, 255),
126
+ purple: new t(255, 0, 255),
127
+ yellow: new t(255, 255, 0),
128
+ electric_blue: new t(127, 255, 255),
129
+ pink: new t(255, 127, 255),
130
+ lemon: new t(255, 255, 127),
131
+ light_red: new t(255, 127, 127),
132
+ lime: new t(127, 255, 127),
133
+ light_blue: new t(127, 127, 255),
134
+ black: new t(0, 0, 0),
135
+ gray: new t(127, 127, 127),
136
+ white: new t(255, 255, 255)
137
+ }, r = (e) => {
138
+ if (e.length > 0) return e[Math.floor(Math.random() * e.length)];
139
+ throw Error("`chooseRand` recived an empty array which is not approved");
140
+ }, i = (e, t) => (e % t + t) % t, a = (e, t) => e + Math.random() * (t - e), o = (e, t, n) => Math.max(Math.min(e, n), t), s = (e, t, n) => e * (1 - n) + t * n, c = (e, t, n) => e < t ? Math.min(e + n, t) : Math.max(e - n, t), l = (e, t) => e.clone().add(t), u = (e, t) => e.clone().sub(t), d = (e, t) => e.clone().mul(t), f = (e, t) => e.clone().div(t);
122
141
  //#endregion
123
- 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 };
142
+ export { n as SOLID_COLORS, e as Vec2, t as Vec3, l as add, c as approach, r as chooseRand, o as clamp, f as div, s as lerp, i as mod, d as mul, a as randRange, u 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 zero(){return new e(0,0)}static one(){return new e(1,1)}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}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}map(e){return this.x=e(this.x),this.y=e(this.y),this}toArr(){return[this.x,this.y,0]}length(){return Math.hypot(this.x,this.y)}lengthSquared(){return this.x*this.x+this.y*this.y}normalize(){let e=this.length();return e!==0&&this.div(e),this}distance(e){let t=e.x-this.x,n=e.y-this.y;return Math.hypot(t,n)}clone(){return new e(this.x,this.y)}},n=class e{constructor(e,t,n){this.x=e,this.y=t,this.z=n}static initial(t){return new e(t,t,t)}static zero(){return e.initial(0)}static one(){return e.initial(1)}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}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}cross(t){return new e(this.y*t.z-this.z*t.y,this.z*t.x-this.x*t.z,this.x*t.y-this.y*t.x)}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]}length(){return Math.hypot(this.x,this.y,this.z)}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){let e=this.length();return e!==0&&this.div(e),this}distance(e){let t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.hypot(t,n,r)}clone(){return new e(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)});
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 zero(){return new e(0,0)}static one(){return new e(1,1)}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}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}map(e){return this.x=e(this.x),this.y=e(this.y),this}toArr(){return[this.x,this.y,0]}length(){return Math.hypot(this.x,this.y)}lengthSquared(){return this.x*this.x+this.y*this.y}normalize(){let e=this.length();return e!==0&&this.div(e),this}distance(e){let t=e.x-this.x,n=e.y-this.y;return Math.hypot(t,n)}clone(){return new e(this.x,this.y)}},n=class e{constructor(e,t,n){this.x=e,this.y=t,this.z=n}static initial(t){return new e(t,t,t)}static zero(){return e.initial(0)}static one(){return e.initial(1)}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}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}cross(t){return new e(this.y*t.z-this.z*t.y,this.z*t.x-this.x*t.z,this.x*t.y-this.y*t.x)}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]}length(){return Math.hypot(this.x,this.y,this.z)}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){let e=this.length();return e!==0&&this.div(e),this}distance(e){let t=e.x-this.x,n=e.y-this.y,r=e.z-this.z;return Math.hypot(t,n,r)}clone(){return new e(this.x,this.y,this.z)}};e.SOLID_COLORS={red:new n(255,0,0),green:new n(0,255,0),blue:new n(0,0,255),cyan:new n(0,255,255),purple:new n(255,0,255),yellow:new n(255,255,0),electric_blue:new n(127,255,255),pink:new n(255,127,255),lemon:new n(255,255,127),light_red:new n(255,127,127),lime:new n(127,255,127),light_blue:new n(127,127,255),black:new n(0,0,0),gray:new n(127,127,127),white:new n(255,255,255)},e.Vec2=t,e.Vec3=n,e.add=(e,t)=>e.clone().add(t),e.approach=(e,t,n)=>e<t?Math.min(e+n,t):Math.max(e-n,t),e.chooseRand=e=>{if(e.length>0)return e[Math.floor(Math.random()*e.length)];throw Error("`chooseRand` recived an empty array which is not approved")},e.clamp=(e,t,n)=>Math.max(Math.min(e,n),t),e.div=(e,t)=>e.clone().div(t),e.lerp=(e,t,n)=>e*(1-n)+t*n,e.mod=(e,t)=>(e%t+t)%t,e.mul=(e,t)=>e.clone().mul(t),e.randRange=(e,t)=>e+Math.random()*(t-e),e.sub=(e,t)=>e.clone().sub(t)});
@@ -1,23 +1,17 @@
1
1
  import { Vec2, Vec3 } from './vectors.js';
2
+ /**
3
+ *
4
+ * @param arr
5
+ * @returns A random object from the given list
6
+ * @throws An `Error` object if the `arr` is empty
7
+ */
2
8
  export declare const chooseRand: <T>(arr: T[]) => T;
3
9
  export declare const mod: (x: number, m: number) => number;
4
10
  export declare const randRange: (min: number, max: number) => number;
5
11
  export declare const clamp: (value: number, min: number, max: number) => number;
6
12
  export declare const lerp: (a: number, b: number, t: number) => number;
7
13
  export declare const approach: (current: number, target: number, dt: number) => number;
8
- /**
9
- * @deprecated use `Vec2` || `Vec3` instead
10
- */
11
- export declare const add: <V extends Vec2 | Vec3>(x: V, y: V) => V;
12
- /**
13
- * @deprecated use `Vec2` || `Vec3` instead
14
- */
15
- export declare const sub: <V extends Vec2 | Vec3>(x: V, y: V) => V;
16
- /**
17
- * @deprecated use `Vec2` || `Vec3` instead
18
- */
19
- export declare const mul: <V extends Vec2 | Vec3>(x: V, y: V) => V;
20
- /**
21
- * @deprecated use `Vec2` || `Vec3` instead
22
- */
23
- export declare const div: <V extends Vec2 | Vec3>(x: V, y: V) => V;
14
+ export declare const add: <V extends Vec2 | Vec3>(a: V, b: V) => V;
15
+ export declare const sub: <V extends Vec2 | Vec3>(a: V, b: V) => V;
16
+ export declare const mul: <V extends Vec2 | Vec3>(a: V, b: V) => V;
17
+ export declare const div: <V extends Vec2 | Vec3>(a: V, b: V) => V;
@@ -1,2 +1,3 @@
1
1
  export * from './vectors.js';
2
2
  export * from './functions.js';
3
+ export * from './types.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -103,9 +103,9 @@ export declare class Vec3 {
103
103
  /**
104
104
  * Normalizes the vector
105
105
  * @example
106
- * const vec = new Vec2(5, 0, 0)
106
+ * const vec = new Vec3(5, 0, 0)
107
107
  * vec.normalize()
108
- * console.assert(vec, new Vec2(1, 0, 0))
108
+ * console.assert(vec, new Vec3(1, 0, 0))
109
109
  */
110
110
  normalize(): this;
111
111
  distance(target: Vec3): number;
@@ -114,3 +114,22 @@ export declare class Vec3 {
114
114
  */
115
115
  clone(): Vec3;
116
116
  }
117
+ /** Don't forget to use `clone` method of these */
118
+ export declare const SOLID_COLORS: {
119
+ readonly red: Vec3;
120
+ readonly green: Vec3;
121
+ readonly blue: Vec3;
122
+ readonly cyan: Vec3;
123
+ readonly purple: Vec3;
124
+ readonly yellow: Vec3;
125
+ /** Don't judge please */
126
+ readonly electric_blue: Vec3;
127
+ readonly pink: Vec3;
128
+ readonly lemon: Vec3;
129
+ readonly light_red: Vec3;
130
+ readonly lime: Vec3;
131
+ readonly light_blue: Vec3;
132
+ readonly black: Vec3;
133
+ readonly gray: Vec3;
134
+ readonly white: Vec3;
135
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devrals/math",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Vector2/3 Utils",
@@ -23,6 +23,7 @@
23
23
  }
24
24
  },
25
25
  "scripts": {
26
- "build": "vite build"
26
+ "build": "vite build",
27
+ "test": "vitest"
27
28
  }
28
29
  }