@equinor/videx-math 1.1.0 → 1.1.3
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 +2 -28
- package/dist/const.d.ts +15 -15
- package/dist/index.d.ts +178 -178
- 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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://scm-compliance-api.radix.equinor.com/repos/equinor/videx-math/badge)
|
|
2
|
+
|
|
1
3
|
# Videx math
|
|
2
4
|
|
|
3
5
|
A library with math functions used by Videx.
|
|
@@ -22,32 +24,4 @@ const lerp = someVar.lerp;
|
|
|
22
24
|
```
|
|
23
25
|
Where X.X.X is desired version number.
|
|
24
26
|
|
|
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#extent">extent</a></td>
|
|
32
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#inverseLerp">inverseLerp</a></td>
|
|
33
|
-
</tr>
|
|
34
|
-
<tr>
|
|
35
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#lerp">lerp</a></td>
|
|
36
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#max">max</a></td>
|
|
37
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#mean">mean</a></td>
|
|
38
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#min">min</a></td>
|
|
39
|
-
</tr>
|
|
40
|
-
<tr>
|
|
41
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#nrad">nrad</a></td>
|
|
42
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#radians">radians</a></td>
|
|
43
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#round">round</a></td>
|
|
44
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#seq">seq</a></td>
|
|
45
|
-
</tr>
|
|
46
|
-
<tr>
|
|
47
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#seqI">seqI</a></td>
|
|
48
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#smoothstep">smoothstep</a></td>
|
|
49
|
-
<td><a href="https://equinor.github.io/videx-math/modules/_index_.html#step">step</a></td>
|
|
50
|
-
</tr>
|
|
51
|
-
</table>
|
|
52
|
-
|
|
53
27
|

|
package/dist/const.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constant for converting radians to degrees.
|
|
3
|
-
* @private
|
|
4
|
-
*/
|
|
5
|
-
export declare const RAD2DEG: number;
|
|
6
|
-
/**
|
|
7
|
-
* Constant for converting degrees to radians.
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
export declare const DEG2RAD: number;
|
|
11
|
-
/**
|
|
12
|
-
* Constant for 2π.
|
|
13
|
-
* @private
|
|
14
|
-
*/
|
|
15
|
-
export declare const TAU: number;
|
|
1
|
+
/**
|
|
2
|
+
* Constant for converting radians to degrees.
|
|
3
|
+
* @private
|
|
4
|
+
*/
|
|
5
|
+
export declare const RAD2DEG: number;
|
|
6
|
+
/**
|
|
7
|
+
* Constant for converting degrees to radians.
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEG2RAD: number;
|
|
11
|
+
/**
|
|
12
|
+
* Constant for 2π.
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
export declare const TAU: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Clamps the value to min or max if value is less than min or greater than max.
|
|
3
|
-
* @param value Value to clamp
|
|
4
|
-
* @param min Minimum value (Default: 0)
|
|
5
|
-
* @param max Maximum value (Default: 1)
|
|
6
|
-
* @return Clamped value
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* clamp(8, 3, 7); // Returns: 7
|
|
10
|
-
*/
|
|
11
|
-
export declare function clamp(value: number, min?: number, max?: number): number;
|
|
12
|
-
/**
|
|
13
|
-
* Generate a step function by comparing two values.
|
|
14
|
-
* @param edge Edge of the step function
|
|
15
|
-
* @param x Value used to generate the step function
|
|
16
|
-
* @return Returns either 0 or 1
|
|
17
|
-
*/
|
|
18
|
-
export declare function step(edge: number, x: number): number;
|
|
19
|
-
/**
|
|
20
|
-
* Perform Hermite interpolation between two values.
|
|
21
|
-
* @param edge0 Lower edge of the Hermite function
|
|
22
|
-
* @param edge1 Upper edge of the Hermite function
|
|
23
|
-
* @param x Source value for interpolation
|
|
24
|
-
* @return Hermite interpolated value
|
|
25
|
-
*/
|
|
26
|
-
export declare function smoothstep(edge0: number, edge1: number, x: number): number;
|
|
27
|
-
/**
|
|
28
|
-
* Linear interpolation between two numbers.
|
|
29
|
-
* @param a Number to interpolate from
|
|
30
|
-
* @param b Number to interpolate to
|
|
31
|
-
* @param t Interpolation parameter, 0 = a and 1 = b
|
|
32
|
-
* @return The interpolated value
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* lerp(2, 4, 0.5); // Returns 3
|
|
36
|
-
*/
|
|
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;
|
|
49
|
-
/**
|
|
50
|
-
* Rounds number to a specific amount of digits.
|
|
51
|
-
* @param value Value to round
|
|
52
|
-
* @param digits Number of digits (Default: 1)
|
|
53
|
-
* @return Rounded value
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* round(Math.PI, 3); // Returns 3.142
|
|
57
|
-
*/
|
|
58
|
-
export declare function round(value: number, digits?: number): number;
|
|
59
|
-
/**
|
|
60
|
-
* Convert degrees to radians.
|
|
61
|
-
* @param deg Angle in degrees
|
|
62
|
-
* @returns Angle in radians
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* radians(90); // Returns π / 2
|
|
66
|
-
*/
|
|
67
|
-
export declare function radians(deg: number): number;
|
|
68
|
-
/**
|
|
69
|
-
* Convert radians to degrees.
|
|
70
|
-
* @param rad Angle in radians
|
|
71
|
-
* @returns Angle in degrees
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* degrees(Math.PI); // Returns 180
|
|
75
|
-
*/
|
|
76
|
-
export declare function degrees(rad: number): number;
|
|
77
|
-
/**
|
|
78
|
-
* Normalise an angle to be between -π and +π.
|
|
79
|
-
* @param rad Angle in radians
|
|
80
|
-
* @return Normalised angle
|
|
81
|
-
*/
|
|
82
|
-
export declare function nrad(rad: number): number;
|
|
83
|
-
/**
|
|
84
|
-
* Generates a list of interpolated values between start and end,
|
|
85
|
-
* where the number of elements returned is equal to the amount
|
|
86
|
-
* of steps.
|
|
87
|
-
* @param start Start of interpolated range
|
|
88
|
-
* @param end End of interpolated range
|
|
89
|
-
* @param steps Steps of interpolation
|
|
90
|
-
* @returns Interpolated series
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* seq(2, 4, 5); // Returns [2, 2.5, 3, 3.5, 4]
|
|
94
|
-
*/
|
|
95
|
-
export declare function seq(start: number, end: number, steps: number): number[];
|
|
96
|
-
/**
|
|
97
|
-
* Generates a list of interpolated values between 0 and 1,
|
|
98
|
-
* where the number of elements returned is equal to the amount
|
|
99
|
-
* of steps.
|
|
100
|
-
* @param steps Steps of interpolation
|
|
101
|
-
* @returns Interpolated series
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* seqI(3); // Returns [0, 0.5, 1]
|
|
105
|
-
*/
|
|
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;
|
|
1
|
+
/**
|
|
2
|
+
* Clamps the value to min or max if value is less than min or greater than max.
|
|
3
|
+
* @param value Value to clamp
|
|
4
|
+
* @param min Minimum value (Default: 0)
|
|
5
|
+
* @param max Maximum value (Default: 1)
|
|
6
|
+
* @return Clamped value
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* clamp(8, 3, 7); // Returns: 7
|
|
10
|
+
*/
|
|
11
|
+
export declare function clamp(value: number, min?: number, max?: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Generate a step function by comparing two values.
|
|
14
|
+
* @param edge Edge of the step function
|
|
15
|
+
* @param x Value used to generate the step function
|
|
16
|
+
* @return Returns either 0 or 1
|
|
17
|
+
*/
|
|
18
|
+
export declare function step(edge: number, x: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Perform Hermite interpolation between two values.
|
|
21
|
+
* @param edge0 Lower edge of the Hermite function
|
|
22
|
+
* @param edge1 Upper edge of the Hermite function
|
|
23
|
+
* @param x Source value for interpolation
|
|
24
|
+
* @return Hermite interpolated value
|
|
25
|
+
*/
|
|
26
|
+
export declare function smoothstep(edge0: number, edge1: number, x: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Linear interpolation between two numbers.
|
|
29
|
+
* @param a Number to interpolate from
|
|
30
|
+
* @param b Number to interpolate to
|
|
31
|
+
* @param t Interpolation parameter, 0 = a and 1 = b
|
|
32
|
+
* @return The interpolated value
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* lerp(2, 4, 0.5); // Returns 3
|
|
36
|
+
*/
|
|
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;
|
|
49
|
+
/**
|
|
50
|
+
* Rounds number to a specific amount of digits.
|
|
51
|
+
* @param value Value to round
|
|
52
|
+
* @param digits Number of digits (Default: 1)
|
|
53
|
+
* @return Rounded value
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* round(Math.PI, 3); // Returns 3.142
|
|
57
|
+
*/
|
|
58
|
+
export declare function round(value: number, digits?: number): number;
|
|
59
|
+
/**
|
|
60
|
+
* Convert degrees to radians.
|
|
61
|
+
* @param deg Angle in degrees
|
|
62
|
+
* @returns Angle in radians
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* radians(90); // Returns π / 2
|
|
66
|
+
*/
|
|
67
|
+
export declare function radians(deg: number): number;
|
|
68
|
+
/**
|
|
69
|
+
* Convert radians to degrees.
|
|
70
|
+
* @param rad Angle in radians
|
|
71
|
+
* @returns Angle in degrees
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* degrees(Math.PI); // Returns 180
|
|
75
|
+
*/
|
|
76
|
+
export declare function degrees(rad: number): number;
|
|
77
|
+
/**
|
|
78
|
+
* Normalise an angle to be between -π and +π.
|
|
79
|
+
* @param rad Angle in radians
|
|
80
|
+
* @return Normalised angle
|
|
81
|
+
*/
|
|
82
|
+
export declare function nrad(rad: number): number;
|
|
83
|
+
/**
|
|
84
|
+
* Generates a list of interpolated values between start and end,
|
|
85
|
+
* where the number of elements returned is equal to the amount
|
|
86
|
+
* of steps.
|
|
87
|
+
* @param start Start of interpolated range
|
|
88
|
+
* @param end End of interpolated range
|
|
89
|
+
* @param steps Steps of interpolation
|
|
90
|
+
* @returns Interpolated series
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* seq(2, 4, 5); // Returns [2, 2.5, 3, 3.5, 4]
|
|
94
|
+
*/
|
|
95
|
+
export declare function seq(start: number, end: number, steps: number): number[];
|
|
96
|
+
/**
|
|
97
|
+
* Generates a list of interpolated values between 0 and 1,
|
|
98
|
+
* where the number of elements returned is equal to the amount
|
|
99
|
+
* of steps.
|
|
100
|
+
* @param steps Steps of interpolation
|
|
101
|
+
* @returns Interpolated series
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* seqI(3); // Returns [0, 0.5, 1]
|
|
105
|
+
*/
|
|
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.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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 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
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"rollup
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"typedoc": "^0.
|
|
50
|
-
"typescript": "^
|
|
38
|
+
"@eslint/js": "^9.32.0",
|
|
39
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
40
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
41
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
|
+
"@types/jest": "^29.5.12",
|
|
43
|
+
"eslint": "^9.32.0",
|
|
44
|
+
"eslint-plugin-import": "^2.31.0",
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"rimraf": "^6.0.1",
|
|
47
|
+
"rollup": "^3.29.5",
|
|
48
|
+
"ts-jest": "^29.1.0",
|
|
49
|
+
"tslib": "^2.7.0",
|
|
50
|
+
"typedoc": "^0.26.6",
|
|
51
|
+
"typescript": "^4.9.5",
|
|
52
|
+
"typescript-eslint": "^8.26.1"
|
|
51
53
|
},
|
|
52
54
|
"jest": {
|
|
53
55
|
"transform": {
|