toosoon-utils 1.1.0 → 1.2.0

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/lib/maths.d.ts CHANGED
@@ -30,10 +30,10 @@ export declare function toPowerOf2(value: number, mode?: 'floor' | 'ceil' | 'rou
30
30
  /**
31
31
  * Return the sign (positive or negative) of a number
32
32
  *
33
- * @param {number} number Value to check
33
+ * @param {number} value Value to check
34
34
  * @returns {number} 1 if the given number is positive, -1 if it is negative, otherwise 0
35
35
  */
36
- export declare function sign(number: number): number;
36
+ export declare function sign(value: number): number;
37
37
  /**
38
38
  * Clamp a value between two bounds
39
39
  *
@@ -65,12 +65,14 @@ export declare function triLerp(value: number, min: number, max: number, target:
65
65
  /**
66
66
  * Exponential interpolation between two values
67
67
  *
68
- * @param {number} value Normalized value to interpolate
69
- * @param {number} min Minimum value
70
- * @param {number} max Maximum value
68
+ * @param {number} value Value to interpolate
69
+ * @param {number} currentMin Lower bound of the value's current range
70
+ * @param {number} currentMax Upper bound of the value's current range
71
+ * @param {number} targetMin Lower bound of the value's target range
72
+ * @param {number} targetMax Upper bound of the value's target range
71
73
  * @returns {number} Interpolated value
72
74
  */
73
- export declare function expLerp(value: number, min: number, max: number): number;
75
+ export declare function expLerp(value: number, currentMin: number, currentMax: number, targetMin: number, targetMax: number): number;
74
76
  /**
75
77
  * Normalize a value between two bounds
76
78
  *
@@ -95,7 +97,7 @@ export declare function map(value: number, currentMin: number, currentMax: numbe
95
97
  * Round a number up to a nearest multiple
96
98
  *
97
99
  * @param {number} value Value to round
98
- * @param {number} [multiple=1] Multiple
100
+ * @param {number} [multiple=1] Multiple to round to
99
101
  * @returns {number} Closest multiple
100
102
  */
101
103
  export declare function roundTo(value: number, multiple?: number): number;
@@ -136,14 +138,14 @@ export declare function parabola(x: number, power?: number): number;
136
138
  /**
137
139
  * Return the sum of numbers
138
140
  *
139
- * @param {number[]} array Array of number
141
+ * @param {number[]} array Array of numbers
140
142
  * @returns {number} Total sum
141
143
  */
142
144
  export declare function sum(array: number[]): number;
143
145
  /**
144
146
  * Return the average of numbers
145
147
  *
146
- * @param {number[]} array Array of number
148
+ * @param {number[]} array Array of numbers
147
149
  * @returns {number} Total average
148
150
  */
149
151
  export declare function average(array: number[]): number;
package/lib/maths.js CHANGED
@@ -1,36 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.damp = exports.average = exports.sum = exports.parabola = exports.smoothstep = exports.pingPong = exports.modAbs = exports.roundTo = exports.map = exports.normalize = exports.expLerp = exports.triLerp = exports.lerp = exports.clamp = exports.sign = exports.toPowerOf2 = exports.isPowerOf2 = exports.isOdd = exports.isEven = void 0;
4
1
  /**
5
2
  * Check if a number is even
6
3
  *
7
4
  * @param {number} value Value to check
8
5
  * @returns {boolean} True if the given number is even, false otherwise
9
6
  */
10
- function isEven(value) {
7
+ export function isEven(value) {
11
8
  return !(value & 1);
12
9
  }
13
- exports.isEven = isEven;
14
10
  /**
15
11
  * Check if a number is odd
16
12
  *
17
13
  * @param {number} value Value to check
18
14
  * @returns {boolean} True if the given number is odd, false otherwise
19
15
  */
20
- function isOdd(value) {
16
+ export function isOdd(value) {
21
17
  return !!(value & 1);
22
18
  }
23
- exports.isOdd = isOdd;
24
19
  /**
25
20
  * Check if a number is a power of 2
26
21
  *
27
22
  * @param {number} value Value to check
28
23
  * @returns {boolean} True if the given number is a power of 2, false otherwise
29
24
  */
30
- function isPowerOf2(value) {
25
+ export function isPowerOf2(value) {
31
26
  return (value & (value - 1)) === 0;
32
27
  }
33
- exports.isPowerOf2 = isPowerOf2;
34
28
  /**
35
29
  * Find closest power of 2 that fits a number
36
30
  *
@@ -38,25 +32,23 @@ exports.isPowerOf2 = isPowerOf2;
38
32
  * @param {string} [mode='ceil'] Can be 'floor' | 'ceil' | 'round'
39
33
  * @returns {number} Power of 2
40
34
  */
41
- function toPowerOf2(value, mode) {
35
+ export function toPowerOf2(value, mode) {
42
36
  if (mode === void 0) { mode = 'ceil'; }
43
37
  return Math.pow(2, Math[mode](Math.log(value) / Math.log(2)));
44
38
  }
45
- exports.toPowerOf2 = toPowerOf2;
46
39
  /**
47
40
  * Return the sign (positive or negative) of a number
48
41
  *
49
- * @param {number} number Value to check
42
+ * @param {number} value Value to check
50
43
  * @returns {number} 1 if the given number is positive, -1 if it is negative, otherwise 0
51
44
  */
52
- function sign(number) {
53
- if (number > 0)
45
+ export function sign(value) {
46
+ if (value > 0)
54
47
  return 1;
55
- else if (number < 0)
48
+ else if (value < 0)
56
49
  return -1;
57
50
  return 0;
58
51
  }
59
- exports.sign = sign;
60
52
  /**
61
53
  * Clamp a value between two bounds
62
54
  *
@@ -65,12 +57,11 @@ exports.sign = sign;
65
57
  * @param {number} [max=1] Maximum boundary
66
58
  * @returns {number} Clamped value
67
59
  */
68
- function clamp(value, min, max) {
60
+ export function clamp(value, min, max) {
69
61
  if (min === void 0) { min = 0; }
70
62
  if (max === void 0) { max = 1; }
71
63
  return Math.min(max, Math.max(min, value));
72
64
  }
73
- exports.clamp = clamp;
74
65
  /**
75
66
  * Linear interpolation between two values (lerping)
76
67
  *
@@ -79,10 +70,9 @@ exports.clamp = clamp;
79
70
  * @param {number} max Maximum value
80
71
  * @returns {number} Lerped value
81
72
  */
82
- function lerp(value, min, max) {
73
+ export function lerp(value, min, max) {
83
74
  return min + (max - min) * value;
84
75
  }
85
- exports.lerp = lerp;
86
76
  /**
87
77
  * Triangular interpolation between two values
88
78
  *
@@ -92,23 +82,24 @@ exports.lerp = lerp;
92
82
  * @param {number} target Triangle target value
93
83
  * @returns {number} Interpolated value
94
84
  */
95
- function triLerp(value, min, max, target) {
85
+ export function triLerp(value, min, max, target) {
96
86
  var x = Math.pow(1 + Math.abs(target - max) / Math.abs(target - min), -1);
97
87
  return value <= x ? min - (min - target) * (value / x) : target - (target - max) * ((value - x) / (1 - x));
98
88
  }
99
- exports.triLerp = triLerp;
100
89
  /**
101
90
  * Exponential interpolation between two values
102
91
  *
103
- * @param {number} value Normalized value to interpolate
104
- * @param {number} min Minimum value
105
- * @param {number} max Maximum value
92
+ * @param {number} value Value to interpolate
93
+ * @param {number} currentMin Lower bound of the value's current range
94
+ * @param {number} currentMax Upper bound of the value's current range
95
+ * @param {number} targetMin Lower bound of the value's target range
96
+ * @param {number} targetMax Upper bound of the value's target range
106
97
  * @returns {number} Interpolated value
107
98
  */
108
- function expLerp(value, min, max) {
109
- return Math.pow(min, 1 - value) * Math.pow(max, value);
99
+ export function expLerp(value, currentMin, currentMax, targetMin, targetMax) {
100
+ return (targetMin *
101
+ Math.pow(targetMax / targetMin, (clamp(value, currentMin, currentMax) - currentMin) / (currentMax - currentMin)));
110
102
  }
111
- exports.expLerp = expLerp;
112
103
  /**
113
104
  * Normalize a value between two bounds
114
105
  *
@@ -117,10 +108,9 @@ exports.expLerp = expLerp;
117
108
  * @param {number} max Maximum boundary
118
109
  * @returns {number} Normalized value
119
110
  */
120
- function normalize(value, min, max) {
111
+ export function normalize(value, min, max) {
121
112
  return (value - min) / (max - min);
122
113
  }
123
- exports.normalize = normalize;
124
114
  /**
125
115
  * Re-map a number from one range to another
126
116
  *
@@ -131,24 +121,22 @@ exports.normalize = normalize;
131
121
  * @param {number} targetMax Upper bound of the value's target range
132
122
  * @returns {number} Re-mapped value
133
123
  */
134
- function map(value, currentMin, currentMax, targetMin, targetMax) {
124
+ export function map(value, currentMin, currentMax, targetMin, targetMax) {
135
125
  return ((value - currentMin) / (currentMax - currentMin)) * (targetMax - targetMin) + targetMin;
136
126
  }
137
- exports.map = map;
138
127
  /**
139
128
  * Round a number up to a nearest multiple
140
129
  *
141
130
  * @param {number} value Value to round
142
- * @param {number} [multiple=1] Multiple
131
+ * @param {number} [multiple=1] Multiple to round to
143
132
  * @returns {number} Closest multiple
144
133
  */
145
- function roundTo(value, multiple) {
134
+ export function roundTo(value, multiple) {
146
135
  if (multiple === void 0) { multiple = 1; }
147
136
  if (multiple === 0)
148
137
  return value;
149
138
  return Math.round(value / multiple) * multiple;
150
139
  }
151
- exports.roundTo = roundTo;
152
140
  /**
153
141
  * Modulo absolute a value based on a length
154
142
  *
@@ -156,13 +144,12 @@ exports.roundTo = roundTo;
156
144
  * @param {number} length Total length
157
145
  * @returns {number} Modulated value
158
146
  */
159
- function modAbs(value, length) {
147
+ export function modAbs(value, length) {
160
148
  if (value < 0) {
161
149
  return length + (value % length);
162
150
  }
163
151
  return value % length;
164
152
  }
165
- exports.modAbs = modAbs;
166
153
  /**
167
154
  * Move back and forth a value between 0 and length, so that it is never larger than length and never smaller than 0
168
155
  *
@@ -170,11 +157,10 @@ exports.modAbs = modAbs;
170
157
  * @param {number} length Total length
171
158
  * @returns {number} PingPonged value
172
159
  */
173
- function pingPong(value, length) {
160
+ export function pingPong(value, length) {
174
161
  value = modAbs(value, length * 2);
175
162
  return length - Math.abs(value - length);
176
163
  }
177
- exports.pingPong = pingPong;
178
164
  /**
179
165
  * Smooth a value using cubic Hermite interpolation
180
166
  *
@@ -183,13 +169,12 @@ exports.pingPong = pingPong;
183
169
  * @param {number} [max=1] Maximum boundary
184
170
  * @returns {number} Normalized smoothed value
185
171
  */
186
- function smoothstep(value, min, max) {
172
+ export function smoothstep(value, min, max) {
187
173
  if (min === void 0) { min = 0; }
188
174
  if (max === void 0) { max = 1; }
189
175
  var x = clamp(normalize(value, min, max));
190
176
  return x * x * (3 - 2 * x);
191
177
  }
192
- exports.smoothstep = smoothstep;
193
178
  /**
194
179
  * Re-map the [0, 1] interval into [0, 1] parabola, such that corners are remaped to 0 and the center to 1
195
180
  * -> parabola(0) = parabola(1) = 0, and parabola(0.5) = 1
@@ -198,31 +183,28 @@ exports.smoothstep = smoothstep;
198
183
  * @param {number} [power=1] Parabola power
199
184
  * @returns {number} Normalized re-mapped value
200
185
  */
201
- function parabola(x, power) {
186
+ export function parabola(x, power) {
202
187
  if (power === void 0) { power = 1; }
203
188
  return Math.pow(4 * x * (1 - x), power);
204
189
  }
205
- exports.parabola = parabola;
206
190
  /**
207
191
  * Return the sum of numbers
208
192
  *
209
- * @param {number[]} array Array of number
193
+ * @param {number[]} array Array of numbers
210
194
  * @returns {number} Total sum
211
195
  */
212
- function sum(array) {
196
+ export function sum(array) {
213
197
  return array.reduce(function (previous, current) { return previous + current; });
214
198
  }
215
- exports.sum = sum;
216
199
  /**
217
200
  * Return the average of numbers
218
201
  *
219
- * @param {number[]} array Array of number
202
+ * @param {number[]} array Array of numbers
220
203
  * @returns {number} Total average
221
204
  */
222
- function average(array) {
205
+ export function average(array) {
223
206
  return sum(array) / array.length;
224
207
  }
225
- exports.average = average;
226
208
  /**
227
209
  * Smoothly interpolate a number toward another
228
210
  *
@@ -232,7 +214,6 @@ exports.average = average;
232
214
  * @param {number} delta Delta time (in seconds)
233
215
  * @returns {number} Interpolated number
234
216
  */
235
- function damp(value, target, damping, delta) {
217
+ export function damp(value, target, damping, delta) {
236
218
  return lerp(1 - Math.exp(-damping * delta), value, target);
237
219
  }
238
- exports.damp = damp;
package/lib/random.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Vector2, Vector3 } from './types';
2
2
  /**
3
- * Generate a random boolean (true or false)
3
+ * Generate a random boolean (`true` or `false`)
4
4
  *
5
- * @param {number} [probability=0.5] Probability to get true
6
- * @returns {boolean} Either true or false
5
+ * @param {number} [probability=0.5] Probability to get `true`
6
+ * @returns {boolean} Either `true` or `false`
7
7
  */
8
8
  export declare function randomBoolean(probability?: number): boolean;
9
9
  /**
@@ -14,16 +14,16 @@ export declare function randomBoolean(probability?: number): boolean;
14
14
  */
15
15
  export declare function randomSign(probability?: number): number;
16
16
  /**
17
- * Generate a random float number
17
+ * Generate a random floating-point number within a specified range
18
18
  *
19
- * @param {number} [min=0] Minimum boundary
20
- * @param {number} [max=1] Maximum boundary
21
- * @param {number} [precision=2] Number of digits after the decimal point
19
+ * @param {number} [min=0] Minimum boundary
20
+ * @param {number} [max=1] Maximum boundary
21
+ * @param {number} [precision=2] Number of digits after the decimal point
22
22
  * @returns {number} Generated float
23
23
  */
24
24
  export declare function randomFloat(min?: number, max?: number, precision?: number): number;
25
25
  /**
26
- * Generate a random integer number
26
+ * Generate a random integer number within a specified range
27
27
  *
28
28
  * @param {number} min Minimum boundary
29
29
  * @param {number} max Maximum boundary
@@ -33,61 +33,61 @@ export declare function randomInt(min: number, max: number): number;
33
33
  /**
34
34
  * Generate a random hexadecimal color
35
35
  *
36
- * @returns {string} Hexadecimal color
36
+ * @returns {string} Generated hexadecimal color
37
37
  */
38
38
  export declare function randomHexColor(): string;
39
39
  /**
40
- * Pick a random item from an array
40
+ * Pick a random item from a given array
41
41
  *
42
- * @param {T[]} [array=[]] Array to pick the item from
42
+ * @param {T[]} array Array to pick the item from
43
43
  * @returns {T|undefined} Random item picked
44
44
  */
45
- export declare function randomItem<T = unknown>(array?: T[]): T | undefined;
45
+ export declare function randomItem<T = unknown>(array: T[]): T | undefined;
46
46
  /**
47
- * Pick a random property from an object
47
+ * Pick a random property value from a given object
48
48
  *
49
49
  * @param {object} object Object to pick the property from
50
- * @returns {unknown|undefined} Random item picked
50
+ * @returns {T|undefined} Random item picked
51
51
  */
52
52
  export declare function randomObjectProperty<T = unknown>(object: {
53
53
  [key: string]: T;
54
54
  }): T | undefined;
55
55
  /**
56
- * Return a random index from an array of weights
56
+ * Select a random index from an array of weighted items
57
57
  *
58
58
  * @param {number[]} weights Array of weights
59
59
  * @returns {number} Random index based on weights
60
60
  */
61
- export declare function randomIndex(weights?: number[]): number;
61
+ export declare function randomIndex(weights: number[]): number;
62
62
  /**
63
63
  * Produce a random 2D point around the perimiter of a unit circle
64
64
  *
65
- * @param {number} [radius=1] Radius of the circle
66
- * @param {Vector2} target Target vector
65
+ * @param {number} [radius=1] Radius of the circle
66
+ * @param {Vector2} [target] Target vector
67
67
  * @returns {Vector2} Random 2D point on circle
68
68
  */
69
69
  export declare function onCircle(radius?: number, target?: Vector2): Vector2;
70
70
  /**
71
71
  * Produce a random 2D point inside a unit circle
72
72
  *
73
- * @param {number} [radius=1] Radius of the circle
74
- * @param {Vector2} target Target vector
73
+ * @param {number} [radius=1] Radius of the circle
74
+ * @param {Vector2} [target] Target vector
75
75
  * @returns {Vector2} Random 2D point inside circle
76
76
  */
77
77
  export declare function insideCircle(radius?: number, target?: Vector2): Vector2;
78
78
  /**
79
79
  * Produce a random 3D point on the surface of a unit sphere
80
80
  *
81
- * @param {number} [radius=1] Radius of the sphere
82
- * @param {Vector3} target Target vector
81
+ * @param {number} [radius=1] Radius of the sphere
82
+ * @param {Vector3} [target] Target vector
83
83
  * @returns {Vector3} Random 3D point on sphere
84
84
  */
85
85
  export declare function onSphere(radius?: number, target?: Vector3): Vector3;
86
86
  /**
87
87
  * Produce a random 3D point inside a unit sphere
88
88
  *
89
- * @param {number} [radius=1] Radius of the sphere
90
- * @param {Vector3} target Target vector
89
+ * @param {number} [radius=1] Radius of the sphere
90
+ * @param {Vector3} [target] Target vector
91
91
  * @returns {Vector3} Random 3D point inside sphere
92
92
  */
93
93
  export declare function insideSphere(radius?: number, target?: Vector3): Vector3;
package/lib/random.js CHANGED
@@ -1,99 +1,87 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.insideSphere = exports.onSphere = exports.insideCircle = exports.onCircle = exports.randomIndex = exports.randomObjectProperty = exports.randomItem = exports.randomHexColor = exports.randomInt = exports.randomFloat = exports.randomSign = exports.randomBoolean = void 0;
4
- var geometry_1 = require("./geometry");
1
+ import { radToSphere } from './geometry';
5
2
  /**
6
- * Generate a random boolean (true or false)
3
+ * Generate a random boolean (`true` or `false`)
7
4
  *
8
- * @param {number} [probability=0.5] Probability to get true
9
- * @returns {boolean} Either true or false
5
+ * @param {number} [probability=0.5] Probability to get `true`
6
+ * @returns {boolean} Either `true` or `false`
10
7
  */
11
- function randomBoolean(probability) {
8
+ export function randomBoolean(probability) {
12
9
  if (probability === void 0) { probability = 0.5; }
13
10
  return Math.random() < probability;
14
11
  }
15
- exports.randomBoolean = randomBoolean;
16
12
  /**
17
13
  * Generate a random sign (1 or -1)
18
14
  *
19
15
  * @param {number} [probability=0.5] Probability to get 1
20
16
  * @returns {number} Either 1 or -1
21
17
  */
22
- function randomSign(probability) {
18
+ export function randomSign(probability) {
23
19
  if (probability === void 0) { probability = 0.5; }
24
20
  return randomBoolean(probability) ? 1 : -1;
25
21
  }
26
- exports.randomSign = randomSign;
27
22
  /**
28
- * Generate a random float number
23
+ * Generate a random floating-point number within a specified range
29
24
  *
30
- * @param {number} [min=0] Minimum boundary
31
- * @param {number} [max=1] Maximum boundary
32
- * @param {number} [precision=2] Number of digits after the decimal point
25
+ * @param {number} [min=0] Minimum boundary
26
+ * @param {number} [max=1] Maximum boundary
27
+ * @param {number} [precision=2] Number of digits after the decimal point
33
28
  * @returns {number} Generated float
34
29
  */
35
- function randomFloat(min, max, precision) {
30
+ export function randomFloat(min, max, precision) {
36
31
  if (min === void 0) { min = 0; }
37
32
  if (max === void 0) { max = 1; }
38
33
  if (precision === void 0) { precision = 2; }
39
34
  return parseFloat(Math.min(min + Math.random() * (max - min), max).toFixed(precision));
40
35
  }
41
- exports.randomFloat = randomFloat;
42
36
  /**
43
- * Generate a random integer number
37
+ * Generate a random integer number within a specified range
44
38
  *
45
39
  * @param {number} min Minimum boundary
46
40
  * @param {number} max Maximum boundary
47
41
  * @returns {number} Generated integer
48
42
  */
49
- function randomInt(min, max) {
43
+ export function randomInt(min, max) {
50
44
  return Math.floor(Math.random() * (max - min + 1) + min);
51
45
  }
52
- exports.randomInt = randomInt;
53
46
  /**
54
47
  * Generate a random hexadecimal color
55
48
  *
56
- * @returns {string} Hexadecimal color
49
+ * @returns {string} Generated hexadecimal color
57
50
  */
58
- function randomHexColor() {
51
+ export function randomHexColor() {
59
52
  return '#' + ('00000' + ((Math.random() * (1 << 24)) | 0).toString(16)).slice(-6);
60
53
  }
61
- exports.randomHexColor = randomHexColor;
62
54
  /**
63
- * Pick a random item from an array
55
+ * Pick a random item from a given array
64
56
  *
65
- * @param {T[]} [array=[]] Array to pick the item from
57
+ * @param {T[]} array Array to pick the item from
66
58
  * @returns {T|undefined} Random item picked
67
59
  */
68
- function randomItem(array) {
69
- if (array === void 0) { array = []; }
60
+ export function randomItem(array) {
70
61
  if (array.length === 0)
71
62
  return undefined;
72
63
  return array[randomInt(0, array.length - 1)];
73
64
  }
74
- exports.randomItem = randomItem;
75
65
  /**
76
- * Pick a random property from an object
66
+ * Pick a random property value from a given object
77
67
  *
78
68
  * @param {object} object Object to pick the property from
79
- * @returns {unknown|undefined} Random item picked
69
+ * @returns {T|undefined} Random item picked
80
70
  */
81
- function randomObjectProperty(object) {
71
+ export function randomObjectProperty(object) {
82
72
  var keys = Object.keys(object);
83
73
  var key = randomItem(keys);
84
74
  if (key && object.hasOwnProperty(key)) {
85
75
  return object[key];
86
76
  }
87
77
  }
88
- exports.randomObjectProperty = randomObjectProperty;
89
78
  /**
90
- * Return a random index from an array of weights
79
+ * Select a random index from an array of weighted items
91
80
  *
92
81
  * @param {number[]} weights Array of weights
93
82
  * @returns {number} Random index based on weights
94
83
  */
95
- function randomIndex(weights) {
96
- if (weights === void 0) { weights = []; }
84
+ export function randomIndex(weights) {
97
85
  if (weights.length === 0)
98
86
  return -1;
99
87
  var totalWeight = 0;
@@ -112,18 +100,17 @@ function randomIndex(weights) {
112
100
  }
113
101
  return 0;
114
102
  }
115
- exports.randomIndex = randomIndex;
116
103
  // *********************
117
104
  // Geometry
118
105
  // *********************
119
106
  /**
120
107
  * Produce a random 2D point around the perimiter of a unit circle
121
108
  *
122
- * @param {number} [radius=1] Radius of the circle
123
- * @param {Vector2} target Target vector
109
+ * @param {number} [radius=1] Radius of the circle
110
+ * @param {Vector2} [target] Target vector
124
111
  * @returns {Vector2} Random 2D point on circle
125
112
  */
126
- function onCircle(radius, target) {
113
+ export function onCircle(radius, target) {
127
114
  if (radius === void 0) { radius = 1; }
128
115
  if (target === void 0) { target = { x: 0, y: 0 }; }
129
116
  var angle = Math.random() * 2.0 * Math.PI;
@@ -131,49 +118,45 @@ function onCircle(radius, target) {
131
118
  target.y = radius * Math.sin(angle);
132
119
  return target;
133
120
  }
134
- exports.onCircle = onCircle;
135
121
  /**
136
122
  * Produce a random 2D point inside a unit circle
137
123
  *
138
- * @param {number} [radius=1] Radius of the circle
139
- * @param {Vector2} target Target vector
124
+ * @param {number} [radius=1] Radius of the circle
125
+ * @param {Vector2} [target] Target vector
140
126
  * @returns {Vector2} Random 2D point inside circle
141
127
  */
142
- function insideCircle(radius, target) {
128
+ export function insideCircle(radius, target) {
143
129
  if (radius === void 0) { radius = 1; }
144
130
  if (target === void 0) { target = { x: 0, y: 0 }; }
145
131
  radius *= Math.random();
146
132
  return onCircle(radius, target);
147
133
  }
148
- exports.insideCircle = insideCircle;
149
134
  /**
150
135
  * Produce a random 3D point on the surface of a unit sphere
151
136
  *
152
- * @param {number} [radius=1] Radius of the sphere
153
- * @param {Vector3} target Target vector
137
+ * @param {number} [radius=1] Radius of the sphere
138
+ * @param {Vector3} [target] Target vector
154
139
  * @returns {Vector3} Random 3D point on sphere
155
140
  */
156
- function onSphere(radius, target) {
141
+ export function onSphere(radius, target) {
157
142
  if (radius === void 0) { radius = 1; }
158
143
  if (target === void 0) { target = { x: 0, y: 0, z: 0 }; }
159
144
  var u = Math.random() * Math.PI * 2;
160
145
  var v = Math.random() * 2 - 1;
161
146
  var phi = u;
162
147
  var theta = Math.acos(v);
163
- return (0, geometry_1.radToSphere)(radius, phi, theta, target);
148
+ return radToSphere(radius, phi, theta, target);
164
149
  }
165
- exports.onSphere = onSphere;
166
150
  /**
167
151
  * Produce a random 3D point inside a unit sphere
168
152
  *
169
- * @param {number} [radius=1] Radius of the sphere
170
- * @param {Vector3} target Target vector
153
+ * @param {number} [radius=1] Radius of the sphere
154
+ * @param {Vector3} [target] Target vector
171
155
  * @returns {Vector3} Random 3D point inside sphere
172
156
  */
173
- function insideSphere(radius, target) {
157
+ export function insideSphere(radius, target) {
174
158
  if (radius === void 0) { radius = 1; }
175
159
  if (target === void 0) { target = { x: 0, y: 0, z: 0 }; }
176
160
  radius *= Math.random();
177
161
  return onSphere(radius, target);
178
162
  }
179
- exports.insideSphere = insideSphere;
package/lib/strings.js CHANGED
@@ -1,23 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanPath = exports.capitalize = void 0;
4
1
  /**
5
2
  * Capitalize a string
6
3
  *
7
4
  * @param {string} string String to capitalize
8
5
  * @returns {string} Capitalized string
9
6
  */
10
- function capitalize(string) {
7
+ export function capitalize(string) {
11
8
  return string.charAt(0).toUpperCase() + string.slice(1);
12
9
  }
13
- exports.capitalize = capitalize;
14
10
  /**
15
11
  * Clean a path by removing params
16
12
  *
17
13
  * @param {string} path Path to clean
18
14
  * @returns {string} Cleaned path
19
15
  */
20
- function cleanPath(path) {
16
+ export function cleanPath(path) {
21
17
  return path.split('#')[0].split('?')[0];
22
18
  }
23
- exports.cleanPath = cleanPath;