@equinor/videx-math 1.0.12 → 1.1.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/LICENSE +21 -21
- package/README.md +0 -21
- package/dist/index.d.ts +83 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +18 -16
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Equinor
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Equinor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -22,25 +22,4 @@ const lerp = someVar.lerp;
|
|
|
22
22
|
```
|
|
23
23
|
Where X.X.X is desired version number.
|
|
24
24
|
|
|
25
|
-
## Available functions
|
|
26
|
-
|
|
27
|
-
<table style="width:auto;">
|
|
28
|
-
<tr>
|
|
29
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#clamp">clamp</a></td>
|
|
30
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#degrees">degrees</a></td>
|
|
31
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#lerp">lerp</a></td>
|
|
32
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#nrad">nrad</a></td>
|
|
33
|
-
</tr>
|
|
34
|
-
<tr>
|
|
35
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#radians">radians</a></td>
|
|
36
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#round">round</a></td>
|
|
37
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#seq">seq</a></td>
|
|
38
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#seqI">seqI</a></td>
|
|
39
|
-
</tr>
|
|
40
|
-
<tr>
|
|
41
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#smoothstep">smoothstep</a></td>
|
|
42
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#step">step</a></td>
|
|
43
|
-
</tr>
|
|
44
|
-
</table>
|
|
45
|
-
|
|
46
25
|

|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,17 @@ export declare function smoothstep(edge0: number, edge1: number, x: number): num
|
|
|
35
35
|
* lerp(2, 4, 0.5); // Returns 3
|
|
36
36
|
*/
|
|
37
37
|
export declare function lerp(a: number, b: number, t: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Get the interpolant [t] that produces given value within the range [a, b].
|
|
40
|
+
* @param a Start value
|
|
41
|
+
* @param b End value
|
|
42
|
+
* @param value Value between start and end
|
|
43
|
+
* @return Percentage of value between start and end
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* inverseLerp(2, 4, 3); // Returns 0.5
|
|
47
|
+
*/
|
|
48
|
+
export declare function inverseLerp(a: number, b: number, value: number): number;
|
|
38
49
|
/**
|
|
39
50
|
* Rounds number to a specific amount of digits.
|
|
40
51
|
* @param value Value to round
|
|
@@ -93,3 +104,75 @@ export declare function seq(start: number, end: number, steps: number): number[]
|
|
|
93
104
|
* seqI(3); // Returns [0, 0.5, 1]
|
|
94
105
|
*/
|
|
95
106
|
export declare function seqI(steps: number): number[];
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves the minimum value of an array.
|
|
109
|
+
* @param values Array with values
|
|
110
|
+
* @returns Minimum value
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* min([2, 1, 3]); // Returns 1
|
|
114
|
+
*/
|
|
115
|
+
export declare function min(values: number[]): number;
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves the minimum value among a collection of values.
|
|
118
|
+
* @param values Collection of values
|
|
119
|
+
* @returns Minimum value
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* min(2, 1, 3); // Returns 1
|
|
123
|
+
*/
|
|
124
|
+
export declare function min(...values: number[]): number;
|
|
125
|
+
/**
|
|
126
|
+
* Retrieves the maximum value of an array.
|
|
127
|
+
* @param values Array with values
|
|
128
|
+
* @returns Maximum value
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* min([2, 1, 3]); // Returns 3
|
|
132
|
+
*/
|
|
133
|
+
export declare function max(values: number[]): number;
|
|
134
|
+
/**
|
|
135
|
+
* Retrieves the maximum value among a collection of values.
|
|
136
|
+
* @param values Collection of values
|
|
137
|
+
* @returns Maximum value
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* min(2, 1, 3); // Returns 3
|
|
141
|
+
*/
|
|
142
|
+
export declare function max(...values: number[]): number;
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves the extent of an array.
|
|
145
|
+
* @param values Array with values
|
|
146
|
+
* @returns Extent on format [min, max]
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* min([2, 1, 3]); // Returns [1, 3]
|
|
150
|
+
*/
|
|
151
|
+
export declare function extent(values: number[]): [number, number];
|
|
152
|
+
/**
|
|
153
|
+
* Retrieves the extent of a collection of values.
|
|
154
|
+
* @param values Collection of values
|
|
155
|
+
* @returns Extent on format [min, max]
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* min(2, 1, 3); // Returns [1, 3]
|
|
159
|
+
*/
|
|
160
|
+
export declare function extent(...values: number[]): [number, number];
|
|
161
|
+
/**
|
|
162
|
+
* Find the mean of a numeric array.
|
|
163
|
+
* @param values Array with values
|
|
164
|
+
* @returns Mean of values
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* mean([2, 1, 3]); // Returns 2
|
|
168
|
+
*/
|
|
169
|
+
export declare function mean(values: number[]): number;
|
|
170
|
+
/**
|
|
171
|
+
* Find the mean of a collection of values.
|
|
172
|
+
* @param values Collection of values
|
|
173
|
+
* @returns Mean of values
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* mean(2, 1, 3); // Returns 2
|
|
177
|
+
*/
|
|
178
|
+
export declare function mean(...values: number[]): number;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const RAD2DEG=180/Math.PI,DEG2RAD=Math.PI/180,TAU=2*Math.PI;function clamp(value,min=0,max=1){return value<min?min:value>max?max:value}function step(edge,x){return x>=edge?1:0}function smoothstep(edge0,edge1,x){const t=clamp((x-edge0)/(edge1-edge0));return t*t*(3-2*t)}function lerp(a,b,t){const m=clamp(t,0,1);return a*(1-m)+b*m}function inverseLerp(a,b,value){return clamp((value-a)/(b-a),0,1)}function round(value,digits=1){const f=Math.pow(10,digits);return Math.round(value*f)/f}function radians(deg){return deg*DEG2RAD}function degrees(rad){return rad*RAD2DEG}function nrad(rad){const v=rad%TAU;return v<0?v+TAU:v}function seq(start,end,steps){const target=new Array(steps),incr=(end-start)/(steps-1);target[0]=start;for(let i=1;i<steps-1;i++)target[i]=start+i*incr;return target[steps-1]=end,target}function seqI(steps){const target=new Array(steps),incr=1/(steps-1);target[0]=0;for(let i=1;i<steps-1;i++)target[i]=i*incr;return target[steps-1]=1,target}function min(a,...b){let min;if(Array.isArray(a)){min=a[0];for(let i=1;i<a.length;i++)a[i]<min&&(min=a[i])}else{min=a;for(let i=0;i<b.length;i++)b[i]<min&&(min=b[i])}return min}function max(a,...b){let max;if(Array.isArray(a)){max=a[0];for(let i=1;i<a.length;i++)a[i]>max&&(max=a[i])}else{max=a;for(let i=0;i<b.length;i++)b[i]>max&&(max=b[i])}return max}function extent(a,...b){let min,max;if(Array.isArray(a)){min=max=a[0];for(let i=1;i<a.length;i++)a[i]<min&&(min=a[i]),a[i]>max&&(max=a[i])}else{min=max=a;for(let i=0;i<b.length;i++)b[i]<min&&(min=b[i]),b[i]>max&&(max=b[i])}return[min,max]}function mean(a,...b){let sum=0;if(Array.isArray(a)){for(let i=0;i<a.length;i++)sum+=a[i];return sum/a.length}for(let i=0;i<b.length;i++)sum+=b[i];return(sum+a)/(b.length+1)}export{clamp,degrees,extent,inverseLerp,lerp,max,mean,min,nrad,radians,round,seq,seqI,smoothstep,step};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";const RAD2DEG=180/Math.PI,DEG2RAD=Math.PI/180,TAU=2*Math.PI;function clamp(value,min=0,max=1){return value<min?min:value>max?max:value}exports.clamp=clamp,exports.degrees=function(rad){return rad*RAD2DEG},exports.extent=function(a,...b){let min,max;if(Array.isArray(a)){min=max=a[0];for(let i=1;i<a.length;i++)a[i]<min&&(min=a[i]),a[i]>max&&(max=a[i])}else{min=max=a;for(let i=0;i<b.length;i++)b[i]<min&&(min=b[i]),b[i]>max&&(max=b[i])}return[min,max]},exports.inverseLerp=function(a,b,value){return clamp((value-a)/(b-a),0,1)},exports.lerp=function(a,b,t){const m=clamp(t,0,1);return a*(1-m)+b*m},exports.max=function(a,...b){let max;if(Array.isArray(a)){max=a[0];for(let i=1;i<a.length;i++)a[i]>max&&(max=a[i])}else{max=a;for(let i=0;i<b.length;i++)b[i]>max&&(max=b[i])}return max},exports.mean=function(a,...b){let sum=0;if(Array.isArray(a)){for(let i=0;i<a.length;i++)sum+=a[i];return sum/a.length}for(let i=0;i<b.length;i++)sum+=b[i];return(sum+a)/(b.length+1)},exports.min=function(a,...b){let min;if(Array.isArray(a)){min=a[0];for(let i=1;i<a.length;i++)a[i]<min&&(min=a[i])}else{min=a;for(let i=0;i<b.length;i++)b[i]<min&&(min=b[i])}return min},exports.nrad=function(rad){const v=rad%TAU;return v<0?v+TAU:v},exports.radians=function(deg){return deg*DEG2RAD},exports.round=function(value,digits=1){const f=Math.pow(10,digits);return Math.round(value*f)/f},exports.seq=function(start,end,steps){const target=new Array(steps),incr=(end-start)/(steps-1);target[0]=start;for(let i=1;i<steps-1;i++)target[i]=start+i*incr;return target[steps-1]=end,target},exports.seqI=function(steps){const target=new Array(steps),incr=1/(steps-1);target[0]=0;for(let i=1;i<steps-1;i++)target[i]=i*incr;return target[steps-1]=1,target},exports.smoothstep=function(edge0,edge1,x){const t=clamp((x-edge0)/(edge1-edge0));return t*t*(3-2*t)},exports.step=function(edge,x){return x>=edge?1:0};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global=global||self)
|
|
1
|
+
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self)["videx-math"]={})}(this,(function(exports){"use strict";const RAD2DEG=180/Math.PI,DEG2RAD=Math.PI/180,TAU=2*Math.PI;function clamp(value,min=0,max=1){return value<min?min:value>max?max:value}exports.clamp=clamp,exports.degrees=function(rad){return rad*RAD2DEG},exports.extent=function(a,...b){let min,max;if(Array.isArray(a)){min=max=a[0];for(let i=1;i<a.length;i++)a[i]<min&&(min=a[i]),a[i]>max&&(max=a[i])}else{min=max=a;for(let i=0;i<b.length;i++)b[i]<min&&(min=b[i]),b[i]>max&&(max=b[i])}return[min,max]},exports.inverseLerp=function(a,b,value){return clamp((value-a)/(b-a),0,1)},exports.lerp=function(a,b,t){const m=clamp(t,0,1);return a*(1-m)+b*m},exports.max=function(a,...b){let max;if(Array.isArray(a)){max=a[0];for(let i=1;i<a.length;i++)a[i]>max&&(max=a[i])}else{max=a;for(let i=0;i<b.length;i++)b[i]>max&&(max=b[i])}return max},exports.mean=function(a,...b){let sum=0;if(Array.isArray(a)){for(let i=0;i<a.length;i++)sum+=a[i];return sum/a.length}for(let i=0;i<b.length;i++)sum+=b[i];return(sum+a)/(b.length+1)},exports.min=function(a,...b){let min;if(Array.isArray(a)){min=a[0];for(let i=1;i<a.length;i++)a[i]<min&&(min=a[i])}else{min=a;for(let i=0;i<b.length;i++)b[i]<min&&(min=b[i])}return min},exports.nrad=function(rad){const v=rad%TAU;return v<0?v+TAU:v},exports.radians=function(deg){return deg*DEG2RAD},exports.round=function(value,digits=1){const f=Math.pow(10,digits);return Math.round(value*f)/f},exports.seq=function(start,end,steps){const target=new Array(steps),incr=(end-start)/(steps-1);target[0]=start;for(let i=1;i<steps-1;i++)target[i]=start+i*incr;return target[steps-1]=end,target},exports.seqI=function(steps){const target=new Array(steps),incr=1/(steps-1);target[0]=0;for(let i=1;i<steps-1;i++)target[i]=i*incr;return target[steps-1]=1,target},exports.smoothstep=function(edge0,edge1,x){const t=clamp((x-edge0)/(edge1-edge0));return t*t*(3-2*t)},exports.step=function(edge,x){return x>=edge?1:0}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/videx-math",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A library with math used by Videx.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
"pub": "npm publish --access=public",
|
|
17
17
|
"test": "jest",
|
|
18
18
|
"test:watch": "jest --watchAll",
|
|
19
|
+
"lint": "eslint --ext .js,.jsx,.ts,.tsx src --color",
|
|
19
20
|
"predocs": "rimraf docs",
|
|
20
21
|
"docs": "typedoc --out docs src",
|
|
21
|
-
"postdocs": "
|
|
22
|
+
"postdocs": "node postdocs.copyfiles.mjs"
|
|
22
23
|
},
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|
|
@@ -34,20 +35,21 @@
|
|
|
34
35
|
},
|
|
35
36
|
"homepage": "https://github.com/equinor/videx-math#readme",
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@types/jest": "^
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"ts-jest": "^
|
|
49
|
-
"
|
|
50
|
-
"
|
|
38
|
+
"@types/jest": "^29.5.12",
|
|
39
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
40
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
41
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
|
+
"rollup": "^3.29.4",
|
|
43
|
+
"eslint": "^8.57.0",
|
|
44
|
+
"eslint-plugin-import": "^2.30.0",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
46
|
+
"@typescript-eslint/parser": "^8.4.0",
|
|
47
|
+
"jest": "^29.5.0",
|
|
48
|
+
"rimraf": "^6.0.1",
|
|
49
|
+
"ts-jest": "^29.1.0",
|
|
50
|
+
"tslib": "^2.7.0",
|
|
51
|
+
"typedoc": "^0.24.8",
|
|
52
|
+
"typescript": "^4.7.4"
|
|
51
53
|
},
|
|
52
54
|
"jest": {
|
|
53
55
|
"transform": {
|