@devrals/math 0.2.0 → 0.2.1
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,9 @@ var e = class e {
|
|
|
118
118
|
clone() {
|
|
119
119
|
return new e(this.x, this.y, this.z);
|
|
120
120
|
}
|
|
121
|
-
}, n = (e) =>
|
|
121
|
+
}, n = (e) => {
|
|
122
|
+
if (e.length > 0) return e[Math.floor(Math.random() * e.length)];
|
|
123
|
+
throw Error("`chooseRand` recived an empty array which is not approved");
|
|
124
|
+
}, 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 = (e, t) => e.clone().add(t), l = (e, t) => e.clone().sub(t), u = (e, t) => e.clone().mul(t), d = (e, t) => e.clone().div(t);
|
|
122
125
|
//#endregion
|
|
123
126
|
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 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,
|
|
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)});
|
package/dist/src/functions.d.ts
CHANGED
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
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;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/src/vectors.d.ts
CHANGED
|
@@ -103,9 +103,9 @@ export declare class Vec3 {
|
|
|
103
103
|
/**
|
|
104
104
|
* Normalizes the vector
|
|
105
105
|
* @example
|
|
106
|
-
* const vec = new
|
|
106
|
+
* const vec = new Vec3(5, 0, 0)
|
|
107
107
|
* vec.normalize()
|
|
108
|
-
* console.assert(vec, new
|
|
108
|
+
* console.assert(vec, new Vec3(1, 0, 0))
|
|
109
109
|
*/
|
|
110
110
|
normalize(): this;
|
|
111
111
|
distance(target: Vec3): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devrals/math",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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
|
}
|