@devrals/math 0.2.1 → 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 +19 -3
- package/dist/math.umd.cjs +1 -1
- package/dist/src/vectors.d.ts +19 -0
- package/package.json +1 -1
package/dist/math.js
CHANGED
|
@@ -118,9 +118,25 @@ var e = class e {
|
|
|
118
118
|
clone() {
|
|
119
119
|
return new e(this.x, this.y, this.z);
|
|
120
120
|
}
|
|
121
|
-
}, n =
|
|
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) => {
|
|
122
138
|
if (e.length > 0) return e[Math.floor(Math.random() * e.length)];
|
|
123
139
|
throw Error("`chooseRand` recived an empty array which is not approved");
|
|
124
|
-
},
|
|
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);
|
|
125
141
|
//#endregion
|
|
126
|
-
export { e as Vec2, t as Vec3,
|
|
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,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
|
+
(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)});
|
package/dist/src/vectors.d.ts
CHANGED
|
@@ -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
|
+
};
|