@khanacademy/kmath 0.0.5 → 0.0.6
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/.babelrc.js +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +124 -85
- package/dist/es/index.js +499 -1
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +511 -1
- package/dist/index.js.map +1 -1
- package/package.json +14 -6
- package/src/logo.js +5 -3
- package/src/point.js +4 -4
- package/src/ray.js +2 -2
- package/src/vector.js +6 -14
package/dist/index.js
CHANGED
|
@@ -1,2 +1,512 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _ = require('underscore');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Number Utils
|
|
13
|
+
* A number is a js-number, e.g. 5.12
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_TOLERANCE = 1e-9; // TODO: Should this just be Number.Epsilon
|
|
16
|
+
|
|
17
|
+
const EPSILON = Math.pow(2, -42);
|
|
18
|
+
function is$2(x) {
|
|
19
|
+
return ___default["default"].isNumber(x) && !___default["default"].isNaN(x);
|
|
20
|
+
}
|
|
21
|
+
function equal$4(x, y, tolerance) {
|
|
22
|
+
// Checking for undefined makes this function behave nicely
|
|
23
|
+
// with vectors of different lengths that are _.zip'd together
|
|
24
|
+
if (x == null || y == null) {
|
|
25
|
+
return x === y;
|
|
26
|
+
} // We check === here so that +/-Infinity comparisons work correctly
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if (x === y) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (tolerance == null) {
|
|
34
|
+
tolerance = DEFAULT_TOLERANCE;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return Math.abs(x - y) < tolerance;
|
|
38
|
+
}
|
|
39
|
+
function sign(x, tolerance)
|
|
40
|
+
/* Should be: 0 | 1 | -1 */
|
|
41
|
+
{
|
|
42
|
+
return equal$4(x, 0, tolerance) ? 0 : Math.abs(x) / x;
|
|
43
|
+
}
|
|
44
|
+
function isInteger(num, tolerance) {
|
|
45
|
+
return equal$4(Math.round(num), num, tolerance);
|
|
46
|
+
} // Round a number to a certain number of decimal places
|
|
47
|
+
|
|
48
|
+
function round$2(num, precision) {
|
|
49
|
+
const factor = Math.pow(10, precision);
|
|
50
|
+
return Math.round(num * factor) / factor;
|
|
51
|
+
} // Round num to the nearest multiple of increment
|
|
52
|
+
// i.e. roundTo(83, 5) -> 85
|
|
53
|
+
|
|
54
|
+
function roundTo$2(num, increment) {
|
|
55
|
+
return Math.round(num / increment) * increment;
|
|
56
|
+
}
|
|
57
|
+
function floorTo$2(num, increment) {
|
|
58
|
+
return Math.floor(num / increment) * increment;
|
|
59
|
+
}
|
|
60
|
+
function ceilTo$2(num, increment) {
|
|
61
|
+
return Math.ceil(num / increment) * increment;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* toFraction
|
|
65
|
+
*
|
|
66
|
+
* Returns a [numerator, denominator] array rational representation
|
|
67
|
+
* of `decimal`
|
|
68
|
+
*
|
|
69
|
+
* See http://en.wikipedia.org/wiki/Continued_fraction for implementation
|
|
70
|
+
* details
|
|
71
|
+
*
|
|
72
|
+
* toFraction(4/8) => [1, 2]
|
|
73
|
+
* toFraction(0.66) => [33, 50]
|
|
74
|
+
* toFraction(0.66, 0.01) => [2/3]
|
|
75
|
+
* toFraction(283 + 1/3) => [850, 3]
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
function toFraction(decimal) {
|
|
79
|
+
let tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EPSILON;
|
|
80
|
+
let maxDenominator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
|
|
81
|
+
// Initialize everything to compute successive terms of
|
|
82
|
+
// continued-fraction approximations via recurrence relation
|
|
83
|
+
let n = [1, 0];
|
|
84
|
+
let d = [0, 1];
|
|
85
|
+
let a = Math.floor(decimal);
|
|
86
|
+
let rem = decimal - a;
|
|
87
|
+
|
|
88
|
+
while (d[0] <= maxDenominator) {
|
|
89
|
+
if (equal$4(n[0] / d[0], decimal, tolerance)) {
|
|
90
|
+
return [n[0], d[0]];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
n = [a * n[0] + n[1], n[0]];
|
|
94
|
+
d = [a * d[0] + d[1], d[0]];
|
|
95
|
+
a = Math.floor(1 / rem);
|
|
96
|
+
rem = 1 / rem - a;
|
|
97
|
+
} // We failed to find a nice rational representation,
|
|
98
|
+
// so return an irrational "fraction"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
return [decimal, 1];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var number = /*#__PURE__*/Object.freeze({
|
|
105
|
+
__proto__: null,
|
|
106
|
+
DEFAULT_TOLERANCE: DEFAULT_TOLERANCE,
|
|
107
|
+
EPSILON: EPSILON,
|
|
108
|
+
is: is$2,
|
|
109
|
+
equal: equal$4,
|
|
110
|
+
sign: sign,
|
|
111
|
+
isInteger: isInteger,
|
|
112
|
+
round: round$2,
|
|
113
|
+
roundTo: roundTo$2,
|
|
114
|
+
floorTo: floorTo$2,
|
|
115
|
+
ceilTo: ceilTo$2,
|
|
116
|
+
toFraction: toFraction
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Vector Utils
|
|
121
|
+
* A vector is an array of numbers e.g. [0, 3, 4].
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
function arraySum(array) {
|
|
125
|
+
return array.reduce((memo, arg) => memo + arg, 0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function arrayProduct(array) {
|
|
129
|
+
return array.reduce((memo, arg) => memo * arg, 1);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Checks if the given vector contains only numbers and, optionally, is of the
|
|
133
|
+
* right dimension (length).
|
|
134
|
+
*
|
|
135
|
+
* is([1, 2, 3]) -> true
|
|
136
|
+
* is([1, "Hello", 3]) -> false
|
|
137
|
+
* is([1, 2, 3], 1) -> false
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
function is$1(vec, dimension) {
|
|
142
|
+
if (!___default["default"].isArray(vec)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (dimension !== undefined && vec.length !== dimension) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return vec.every(is$2);
|
|
151
|
+
} // Normalize to a unit vector
|
|
152
|
+
|
|
153
|
+
function normalize(v) {
|
|
154
|
+
return scale(v, 1 / length(v));
|
|
155
|
+
} // Length/magnitude of a vector
|
|
156
|
+
|
|
157
|
+
function length(v) {
|
|
158
|
+
return Math.sqrt(dot(v, v));
|
|
159
|
+
} // Dot product of two vectors
|
|
160
|
+
|
|
161
|
+
function dot(a, b) {
|
|
162
|
+
// $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
|
|
163
|
+
const zipped = ___default["default"].zip(a, b);
|
|
164
|
+
|
|
165
|
+
const multiplied = zipped.map(arrayProduct);
|
|
166
|
+
return arraySum(multiplied);
|
|
167
|
+
}
|
|
168
|
+
/* vector-add multiple [x, y] coords/vectors
|
|
169
|
+
*
|
|
170
|
+
* add([1, 2], [3, 4]) -> [4, 6]
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
function add() {
|
|
174
|
+
// $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
|
|
175
|
+
const zipped = ___default["default"].zip(...arguments);
|
|
176
|
+
|
|
177
|
+
return zipped.map(arraySum);
|
|
178
|
+
}
|
|
179
|
+
function subtract(v1, v2) {
|
|
180
|
+
// $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
|
|
181
|
+
return ___default["default"].zip(v1, v2).map(dim => dim[0] - dim[1]);
|
|
182
|
+
}
|
|
183
|
+
function negate(v) {
|
|
184
|
+
// $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
|
|
185
|
+
return v.map(x => {
|
|
186
|
+
return -x;
|
|
187
|
+
});
|
|
188
|
+
} // Scale a vector
|
|
189
|
+
|
|
190
|
+
function scale(v1, scalar) {
|
|
191
|
+
// $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
|
|
192
|
+
return v1.map(x => {
|
|
193
|
+
return x * scalar;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function equal$3(v1, v2, tolerance) {
|
|
197
|
+
// _.zip will nicely deal with the lengths, going through
|
|
198
|
+
// the length of the longest vector. knumber.equal then
|
|
199
|
+
// returns false for any number compared to the undefined
|
|
200
|
+
// passed in if one of the vectors is shorter.
|
|
201
|
+
// $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
|
|
202
|
+
return ___default["default"].zip(v1, v2).every(pair => equal$4(pair[0], pair[1], tolerance));
|
|
203
|
+
}
|
|
204
|
+
function codirectional(v1, v2, tolerance) {
|
|
205
|
+
// The origin is trivially codirectional with all other vectors.
|
|
206
|
+
// This gives nice semantics for codirectionality between points when
|
|
207
|
+
// comparing their difference vectors.
|
|
208
|
+
if (equal$4(length(v1), 0, tolerance) || equal$4(length(v2), 0, tolerance)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
v1 = normalize(v1);
|
|
213
|
+
v2 = normalize(v2);
|
|
214
|
+
return equal$3(v1, v2, tolerance);
|
|
215
|
+
}
|
|
216
|
+
function collinear(v1, v2, tolerance) {
|
|
217
|
+
return codirectional(v1, v2, tolerance) || codirectional(v1, negate(v2), tolerance);
|
|
218
|
+
} // TODO(jeremy) These coordinate conversion functions really only handle 2D points (ie. [number, number])
|
|
219
|
+
// Convert a cartesian coordinate into a radian polar coordinate
|
|
220
|
+
|
|
221
|
+
function polarRadFromCart$1(v) {
|
|
222
|
+
const radius = length(v);
|
|
223
|
+
let theta = Math.atan2(v[1], v[0]); // Convert angle range from [-pi, pi] to [0, 2pi]
|
|
224
|
+
|
|
225
|
+
if (theta < 0) {
|
|
226
|
+
theta += 2 * Math.PI;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return [radius, theta];
|
|
230
|
+
} // Converts a cartesian coordinate into a degree polar coordinate
|
|
231
|
+
|
|
232
|
+
function polarDegFromCart$1(v)
|
|
233
|
+
/* TODO: convert to tuple/Point */
|
|
234
|
+
{
|
|
235
|
+
const polar = polarRadFromCart$1(v);
|
|
236
|
+
return [polar[0], polar[1] * 180 / Math.PI];
|
|
237
|
+
}
|
|
238
|
+
/* Convert a polar coordinate into a cartesian coordinate
|
|
239
|
+
*
|
|
240
|
+
* Examples:
|
|
241
|
+
* cartFromPolarRad(5, Math.PI)
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
function cartFromPolarRad$1(radius)
|
|
245
|
+
/* TODO: convert to tuple/Point */
|
|
246
|
+
{
|
|
247
|
+
let theta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
248
|
+
return [radius * Math.cos(theta), radius * Math.sin(theta)];
|
|
249
|
+
}
|
|
250
|
+
/* Convert a polar coordinate into a cartesian coordinate
|
|
251
|
+
*
|
|
252
|
+
* Examples:
|
|
253
|
+
* cartFromPolarDeg(5, 30)
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
function cartFromPolarDeg$1(radius) {
|
|
257
|
+
let theta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
258
|
+
return cartFromPolarRad$1(radius, theta * Math.PI / 180);
|
|
259
|
+
} // Rotate vector
|
|
260
|
+
|
|
261
|
+
function rotateRad$1(v, theta) {
|
|
262
|
+
const polar = polarRadFromCart$1(v);
|
|
263
|
+
const angle = polar[1] + theta;
|
|
264
|
+
return cartFromPolarRad$1(polar[0], angle);
|
|
265
|
+
}
|
|
266
|
+
function rotateDeg$1(v, theta) {
|
|
267
|
+
const polar = polarDegFromCart$1(v);
|
|
268
|
+
const angle = polar[1] + theta;
|
|
269
|
+
return cartFromPolarDeg$1(polar[0], angle);
|
|
270
|
+
} // Angle between two vectors
|
|
271
|
+
|
|
272
|
+
function angleRad(v1, v2) {
|
|
273
|
+
return Math.acos(dot(v1, v2) / (length(v1) * length(v2)));
|
|
274
|
+
}
|
|
275
|
+
function angleDeg(v1, v2) {
|
|
276
|
+
return angleRad(v1, v2) * 180 / Math.PI;
|
|
277
|
+
} // Vector projection of v1 onto v2
|
|
278
|
+
|
|
279
|
+
function projection(v1, v2) {
|
|
280
|
+
const scalar = dot(v1, v2) / dot(v2, v2);
|
|
281
|
+
return scale(v2, scalar);
|
|
282
|
+
} // Round each number to a certain number of decimal places
|
|
283
|
+
|
|
284
|
+
function round$1(vec, precision) {
|
|
285
|
+
// $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
|
|
286
|
+
return vec.map((elem, i) => // $FlowFixMe[prop-missing]
|
|
287
|
+
// $FlowFixMe[incompatible-call]
|
|
288
|
+
round$2(elem, precision[i] || precision));
|
|
289
|
+
} // Round each number to the nearest increment
|
|
290
|
+
|
|
291
|
+
function roundTo$1(vec, increment) {
|
|
292
|
+
// $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
|
|
293
|
+
return vec.map((elem, i) => // $FlowFixMe[prop-missing]
|
|
294
|
+
// $FlowFixMe[incompatible-call]
|
|
295
|
+
roundTo$2(elem, increment[i] || increment));
|
|
296
|
+
}
|
|
297
|
+
function floorTo$1(vec, increment) {
|
|
298
|
+
// $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
|
|
299
|
+
return vec.map((elem, i) => // $FlowFixMe[prop-missing]
|
|
300
|
+
// $FlowFixMe[incompatible-call]
|
|
301
|
+
floorTo$2(elem, increment[i] || increment));
|
|
302
|
+
}
|
|
303
|
+
function ceilTo$1(vec, increment) {
|
|
304
|
+
// $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
|
|
305
|
+
return vec.map((elem, i) => // $FlowFixMe[prop-missing]
|
|
306
|
+
// $FlowFixMe[incompatible-call]
|
|
307
|
+
ceilTo$2(elem, increment[i] || increment));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var vector = /*#__PURE__*/Object.freeze({
|
|
311
|
+
__proto__: null,
|
|
312
|
+
is: is$1,
|
|
313
|
+
normalize: normalize,
|
|
314
|
+
length: length,
|
|
315
|
+
dot: dot,
|
|
316
|
+
add: add,
|
|
317
|
+
subtract: subtract,
|
|
318
|
+
negate: negate,
|
|
319
|
+
scale: scale,
|
|
320
|
+
equal: equal$3,
|
|
321
|
+
codirectional: codirectional,
|
|
322
|
+
collinear: collinear,
|
|
323
|
+
polarRadFromCart: polarRadFromCart$1,
|
|
324
|
+
polarDegFromCart: polarDegFromCart$1,
|
|
325
|
+
cartFromPolarRad: cartFromPolarRad$1,
|
|
326
|
+
cartFromPolarDeg: cartFromPolarDeg$1,
|
|
327
|
+
rotateRad: rotateRad$1,
|
|
328
|
+
rotateDeg: rotateDeg$1,
|
|
329
|
+
angleRad: angleRad,
|
|
330
|
+
angleDeg: angleDeg,
|
|
331
|
+
projection: projection,
|
|
332
|
+
round: round$1,
|
|
333
|
+
roundTo: roundTo$1,
|
|
334
|
+
floorTo: floorTo$1,
|
|
335
|
+
ceilTo: ceilTo$1
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Point Utils
|
|
340
|
+
* A point is an array of two numbers e.g. [0, 0].
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
// Rotate point (around origin unless a center is specified)
|
|
344
|
+
function rotateRad(point, theta, center) {
|
|
345
|
+
if (center === undefined) {
|
|
346
|
+
return rotateRad$1(point, theta);
|
|
347
|
+
} else {
|
|
348
|
+
return add(center, rotateRad$1(subtract(point, center), theta));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function rotateDeg(point, theta, center) {
|
|
352
|
+
if (center === undefined) {
|
|
353
|
+
return rotateDeg$1(point, theta);
|
|
354
|
+
} else {
|
|
355
|
+
return add(center, rotateDeg$1(subtract(point, center), theta));
|
|
356
|
+
}
|
|
357
|
+
} // Distance between two points
|
|
358
|
+
|
|
359
|
+
function distanceToPoint$1(point1, point2) {
|
|
360
|
+
return length(subtract(point1, point2));
|
|
361
|
+
} // Distance between point and line
|
|
362
|
+
|
|
363
|
+
function distanceToLine(point, line) {
|
|
364
|
+
const lv = subtract(line[1], line[0]);
|
|
365
|
+
const pv = subtract(point, line[0]);
|
|
366
|
+
const projectedPv = projection(pv, lv);
|
|
367
|
+
const distancePv = subtract(projectedPv, pv);
|
|
368
|
+
return length(distancePv);
|
|
369
|
+
} // Reflect point over line
|
|
370
|
+
|
|
371
|
+
function reflectOverLine(point, line) {
|
|
372
|
+
const lv = subtract(line[1], line[0]);
|
|
373
|
+
const pv = subtract(point, line[0]);
|
|
374
|
+
const projectedPv = projection(pv, lv);
|
|
375
|
+
const reflectedPv = subtract(scale(projectedPv, 2), pv);
|
|
376
|
+
return add(line[0], reflectedPv);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Compares two points, returning -1, 0, or 1, for use with
|
|
380
|
+
* Array.prototype.sort
|
|
381
|
+
*
|
|
382
|
+
* Note: This technically doesn't satisfy the total-ordering
|
|
383
|
+
* requirements of Array.prototype.sort unless equalityTolerance
|
|
384
|
+
* is 0. In some cases very close points that compare within a
|
|
385
|
+
* few equalityTolerances could appear in the wrong order.
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
function compare(point1, point2, equalityTolerance)
|
|
389
|
+
/* TODO: convert to -1 | 0 | 1 type */
|
|
390
|
+
{
|
|
391
|
+
if (point1.length !== point2.length) {
|
|
392
|
+
return point1.length - point2.length;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
for (let i = 0; i < point1.length; i++) {
|
|
396
|
+
if (!equal$4(point1[i], point2[i], equalityTolerance)) {
|
|
397
|
+
return point1[i] - point2[i];
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return 0;
|
|
402
|
+
} // Check if a value is a point
|
|
403
|
+
|
|
404
|
+
const is = is$1; // Add and subtract vector(s)
|
|
405
|
+
|
|
406
|
+
const addVector = add;
|
|
407
|
+
const addVectors = add;
|
|
408
|
+
const subtractVector = subtract;
|
|
409
|
+
const equal$2 = equal$3; // Convert from cartesian to polar and back
|
|
410
|
+
|
|
411
|
+
const polarRadFromCart = polarRadFromCart$1;
|
|
412
|
+
const polarDegFromCart = polarDegFromCart$1;
|
|
413
|
+
const cartFromPolarRad = cartFromPolarRad$1;
|
|
414
|
+
const cartFromPolarDeg = cartFromPolarDeg$1; // Rounding
|
|
415
|
+
|
|
416
|
+
const round = round$1;
|
|
417
|
+
const roundTo = roundTo$1;
|
|
418
|
+
const floorTo = floorTo$1;
|
|
419
|
+
const ceilTo = ceilTo$1;
|
|
420
|
+
|
|
421
|
+
var point = /*#__PURE__*/Object.freeze({
|
|
422
|
+
__proto__: null,
|
|
423
|
+
rotateRad: rotateRad,
|
|
424
|
+
rotateDeg: rotateDeg,
|
|
425
|
+
distanceToPoint: distanceToPoint$1,
|
|
426
|
+
distanceToLine: distanceToLine,
|
|
427
|
+
reflectOverLine: reflectOverLine,
|
|
428
|
+
compare: compare,
|
|
429
|
+
is: is,
|
|
430
|
+
addVector: addVector,
|
|
431
|
+
addVectors: addVectors,
|
|
432
|
+
subtractVector: subtractVector,
|
|
433
|
+
equal: equal$2,
|
|
434
|
+
polarRadFromCart: polarRadFromCart,
|
|
435
|
+
polarDegFromCart: polarDegFromCart,
|
|
436
|
+
cartFromPolarRad: cartFromPolarRad,
|
|
437
|
+
cartFromPolarDeg: cartFromPolarDeg,
|
|
438
|
+
round: round,
|
|
439
|
+
roundTo: roundTo,
|
|
440
|
+
floorTo: floorTo,
|
|
441
|
+
ceilTo: ceilTo
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Line Utils
|
|
446
|
+
* A line is an array of two points e.g. [[-5, 0], [5, 0]].
|
|
447
|
+
*/
|
|
448
|
+
function distanceToPoint(line, point$1) {
|
|
449
|
+
return distanceToLine(point$1, line);
|
|
450
|
+
}
|
|
451
|
+
function reflectPoint(line, point$1) {
|
|
452
|
+
return reflectOverLine(point$1, line);
|
|
453
|
+
}
|
|
454
|
+
function midpoint(line) {
|
|
455
|
+
return [(line[0][0] + line[1][0]) / 2, (line[0][1] + line[1][1]) / 2];
|
|
456
|
+
}
|
|
457
|
+
function equal$1(line1, line2, tolerance) {
|
|
458
|
+
// TODO: A nicer implementation might just check collinearity of
|
|
459
|
+
// vectors using underscore magick
|
|
460
|
+
// Compare the directions of the lines
|
|
461
|
+
const v1 = subtract(line1[1], line1[0]);
|
|
462
|
+
const v2 = subtract(line2[1], line2[0]);
|
|
463
|
+
|
|
464
|
+
if (!collinear(v1, v2, tolerance)) {
|
|
465
|
+
return false;
|
|
466
|
+
} // If the start point is the same for the two lines, then they are the same
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
if (equal$2(line1[0], line2[0])) {
|
|
470
|
+
return true;
|
|
471
|
+
} // Make sure that the direction to get from line1 to
|
|
472
|
+
// line2 is the same as the direction of the lines
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
const line1ToLine2Vector = subtract(line2[0], line1[0]);
|
|
476
|
+
return collinear(v1, line1ToLine2Vector, tolerance);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
var line = /*#__PURE__*/Object.freeze({
|
|
480
|
+
__proto__: null,
|
|
481
|
+
distanceToPoint: distanceToPoint,
|
|
482
|
+
reflectPoint: reflectPoint,
|
|
483
|
+
midpoint: midpoint,
|
|
484
|
+
equal: equal$1
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Ray Utils
|
|
489
|
+
* A ray (→) is an array of an endpoint and another point along the ray.
|
|
490
|
+
* For example, [[0, 0], [1, 0]] is the ray starting at the origin and
|
|
491
|
+
* traveling along the positive x-axis.
|
|
492
|
+
*/
|
|
493
|
+
function equal(ray1, ray2, tolerance) {
|
|
494
|
+
// Compare the directions of the rays
|
|
495
|
+
const v1 = subtract(ray1[1], ray1[0]);
|
|
496
|
+
const v2 = subtract(ray2[1], ray2[0]);
|
|
497
|
+
const sameOrigin = equal$2(ray1[0], ray2[0]);
|
|
498
|
+
const codirectional$1 = codirectional(v1, v2, tolerance);
|
|
499
|
+
return sameOrigin && codirectional$1;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
var ray = /*#__PURE__*/Object.freeze({
|
|
503
|
+
__proto__: null,
|
|
504
|
+
equal: equal
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
exports.line = line;
|
|
508
|
+
exports.number = number;
|
|
509
|
+
exports.point = point;
|
|
510
|
+
exports.ray = ray;
|
|
511
|
+
exports.vector = vector;
|
|
2
512
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/number.js","../src/vector.js","../src/point.js","../src/line.js","../src/ray.js"],"sourcesContent":["// @flow\n/**\n * Number Utils\n * A number is a js-number, e.g. 5.12\n */\n\nimport _ from \"underscore\";\n\nexport const DEFAULT_TOLERANCE: number = 1e-9;\n\n// TODO: Should this just be Number.Epsilon\nexport const EPSILON: number = Math.pow(2, -42);\n\nexport function is(x: any): boolean {\n return _.isNumber(x) && !_.isNaN(x);\n}\n\nexport function equal(x: number, y: number, tolerance?: number): boolean {\n // Checking for undefined makes this function behave nicely\n // with vectors of different lengths that are _.zip'd together\n if (x == null || y == null) {\n return x === y;\n }\n // We check === here so that +/-Infinity comparisons work correctly\n if (x === y) {\n return true;\n }\n if (tolerance == null) {\n tolerance = DEFAULT_TOLERANCE;\n }\n return Math.abs(x - y) < tolerance;\n}\n\nexport function sign(\n x: number,\n tolerance?: number,\n): number /* Should be: 0 | 1 | -1 */ {\n return equal(x, 0, tolerance) ? 0 : Math.abs(x) / x;\n}\n\nexport function isInteger(num: number, tolerance?: number): boolean {\n return equal(Math.round(num), num, tolerance);\n}\n\n// Round a number to a certain number of decimal places\nexport function round(num: number, precision: number): number {\n const factor = Math.pow(10, precision);\n return Math.round(num * factor) / factor;\n}\n\n// Round num to the nearest multiple of increment\n// i.e. roundTo(83, 5) -> 85\nexport function roundTo(num: number, increment: number): number {\n return Math.round(num / increment) * increment;\n}\n\nexport function floorTo(num: number, increment: number): number {\n return Math.floor(num / increment) * increment;\n}\n\nexport function ceilTo(num: number, increment: number): number {\n return Math.ceil(num / increment) * increment;\n}\n\n/**\n * toFraction\n *\n * Returns a [numerator, denominator] array rational representation\n * of `decimal`\n *\n * See http://en.wikipedia.org/wiki/Continued_fraction for implementation\n * details\n *\n * toFraction(4/8) => [1, 2]\n * toFraction(0.66) => [33, 50]\n * toFraction(0.66, 0.01) => [2/3]\n * toFraction(283 + 1/3) => [850, 3]\n */\nexport function toFraction(\n decimal: number,\n tolerance: number = EPSILON, // can't be 0\n maxDenominator: number = 1000,\n): [number, number] {\n // Initialize everything to compute successive terms of\n // continued-fraction approximations via recurrence relation\n let n = [1, 0];\n let d = [0, 1];\n let a = Math.floor(decimal);\n let rem = decimal - a;\n\n while (d[0] <= maxDenominator) {\n if (equal(n[0] / d[0], decimal, tolerance)) {\n return [n[0], d[0]];\n }\n n = [a * n[0] + n[1], n[0]];\n d = [a * d[0] + d[1], d[0]];\n a = Math.floor(1 / rem);\n rem = 1 / rem - a;\n }\n\n // We failed to find a nice rational representation,\n // so return an irrational \"fraction\"\n return [decimal, 1];\n}\n","// @flow\n/**\n * Vector Utils\n * A vector is an array of numbers e.g. [0, 3, 4].\n */\n\nimport _ from \"underscore\";\nimport * as knumber from \"./number.js\";\n\ntype Vector = $ReadOnlyArray<number>;\n\nfunction arraySum(array: $ReadOnlyArray<number>): number {\n return array.reduce((memo, arg) => memo + arg, 0);\n}\n\nfunction arrayProduct(array: $ReadOnlyArray<number>): number {\n return array.reduce((memo, arg) => memo * arg, 1);\n}\n\n/**\n * Checks if the given vector contains only numbers and, optionally, is of the\n * right dimension (length).\n *\n * is([1, 2, 3]) -> true\n * is([1, \"Hello\", 3]) -> false\n * is([1, 2, 3], 1) -> false\n */\nexport function is<T>(vec: $ReadOnlyArray<T>, dimension?: number): boolean {\n if (!_.isArray(vec)) {\n return false;\n }\n if (dimension !== undefined && vec.length !== dimension) {\n return false;\n }\n return vec.every(knumber.is);\n}\n\n// Normalize to a unit vector\nexport function normalize<V: Vector>(v: V): V {\n return scale(v, 1 / length(v));\n}\n\n// Length/magnitude of a vector\nexport function length(v: Vector): number {\n return Math.sqrt(dot(v, v));\n}\n// Dot product of two vectors\nexport function dot(a: Vector, b: Vector): number {\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n const zipped = _.zip(a, b);\n const multiplied = zipped.map(arrayProduct);\n return arraySum(multiplied);\n}\n\n/* vector-add multiple [x, y] coords/vectors\n *\n * add([1, 2], [3, 4]) -> [4, 6]\n */\nexport function add<V: Vector>(...vecs: $ReadOnlyArray<V>): V {\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n const zipped = _.zip(...vecs);\n return zipped.map(arraySum);\n}\n\nexport function subtract<V: Vector>(v1: V, v2: V): V {\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n return _.zip(v1, v2).map((dim) => dim[0] - dim[1]);\n}\n\nexport function negate<V: Vector>(v: V): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return v.map((x) => {\n return -x;\n });\n}\n\n// Scale a vector\nexport function scale<V: Vector>(v1: V, scalar: number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return v1.map((x) => {\n return x * scalar;\n });\n}\n\nexport function equal(v1: Vector, v2: Vector, tolerance?: number): boolean {\n // _.zip will nicely deal with the lengths, going through\n // the length of the longest vector. knumber.equal then\n // returns false for any number compared to the undefined\n // passed in if one of the vectors is shorter.\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n return _.zip(v1, v2).every((pair) =>\n knumber.equal(pair[0], pair[1], tolerance),\n );\n}\n\nexport function codirectional(\n v1: Vector,\n v2: Vector,\n tolerance?: number,\n): boolean {\n // The origin is trivially codirectional with all other vectors.\n // This gives nice semantics for codirectionality between points when\n // comparing their difference vectors.\n if (\n knumber.equal(length(v1), 0, tolerance) ||\n knumber.equal(length(v2), 0, tolerance)\n ) {\n return true;\n }\n\n v1 = normalize(v1);\n v2 = normalize(v2);\n\n return equal(v1, v2, tolerance);\n}\n\nexport function collinear(v1: Vector, v2: Vector, tolerance?: number): boolean {\n return (\n codirectional(v1, v2, tolerance) ||\n codirectional(v1, negate(v2), tolerance)\n );\n}\n\n// Convert a cartesian coordinate into a radian polar coordinate\nexport function polarRadFromCart(\n v: $ReadOnlyArray<number>,\n): $ReadOnlyArray<number> {\n const radius = length(v);\n let theta = Math.atan2(v[1], v[0]);\n\n // Convert angle range from [-pi, pi] to [0, 2pi]\n if (theta < 0) {\n theta += 2 * Math.PI;\n }\n\n return [radius, theta];\n}\n\n// Converts a cartesian coordinate into a degree polar coordinate\nexport function polarDegFromCart(\n v: $ReadOnlyArray<number>,\n): $ReadOnlyArray<number> /* TODO: convert to tuple/Point */ {\n const polar = polarRadFromCart(v);\n return [polar[0], (polar[1] * 180) / Math.PI];\n}\n\n/* Convert a polar coordinate into a cartesian coordinate\n *\n * Examples:\n * cartFromPolarRad(5, Math.PI)\n * cartFromPolarRad([5, Math.PI])\n */\nexport function cartFromPolarRad(\n radius: number,\n theta?: number = 0,\n): $ReadOnlyArray<number> /* TODO: convert to tuple/Point */ {\n return [radius * Math.cos(theta), radius * Math.sin(theta)];\n}\n\n/* Convert a polar coordinate into a cartesian coordinate\n *\n * Examples:\n * cartFromPolarDeg(5, 30)\n * cartFromPolarDeg([5, 30])\n */\nexport function cartFromPolarDeg(\n radius: number,\n theta?: number = 0,\n): $ReadOnlyArray<number> {\n return cartFromPolarRad(radius, (theta * Math.PI) / 180);\n}\n\n// Rotate vector\nexport function rotateRad(\n v: $ReadOnlyArray<number>,\n theta: number,\n): $ReadOnlyArray<number> {\n const polar = polarRadFromCart(v);\n const angle = polar[1] + theta;\n return cartFromPolarRad(polar[0], angle);\n}\n\nexport function rotateDeg(\n v: $ReadOnlyArray<number>,\n theta: number,\n): $ReadOnlyArray<number> {\n const polar = polarDegFromCart(v);\n const angle = polar[1] + theta;\n return cartFromPolarDeg(polar[0], angle);\n}\n\n// Angle between two vectors\nexport function angleRad(\n v1: $ReadOnlyArray<number>,\n v2: $ReadOnlyArray<number>,\n): number {\n return Math.acos(dot(v1, v2) / (length(v1) * length(v2)));\n}\n\nexport function angleDeg(\n v1: $ReadOnlyArray<number>,\n v2: $ReadOnlyArray<number>,\n): number {\n return (angleRad(v1, v2) * 180) / Math.PI;\n}\n\n// Vector projection of v1 onto v2\nexport function projection(\n v1: $ReadOnlyArray<number>,\n v2: $ReadOnlyArray<number>,\n): $ReadOnlyArray<number> {\n const scalar = dot(v1, v2) / dot(v2, v2);\n return scale(v2, scalar);\n}\n\n// Round each number to a certain number of decimal places\nexport function round<V: Vector>(vec: V, precision: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.round(elem, precision[i] || precision),\n );\n}\n\n// Round each number to the nearest increment\nexport function roundTo<V: Vector>(vec: V, increment: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.roundTo(elem, increment[i] || increment),\n );\n}\n\nexport function floorTo<V: Vector>(vec: V, increment: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.floorTo(elem, increment[i] || increment),\n );\n}\n\nexport function ceilTo<V: Vector>(vec: V, increment: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.ceilTo(elem, increment[i] || increment),\n );\n}\n","// @flow\n/**\n * Point Utils\n * A point is an array of two numbers e.g. [0, 0].\n */\n\nimport _ from \"underscore\";\n\nimport * as kvector from \"./vector.js\";\nimport * as knumber from \"./number.js\";\n\n// A point, in 2D, 3D, or nD space.\nexport type Point = $ReadOnlyArray<number>;\n\n// Rotate point (around origin unless a center is specified)\nexport function rotateRad(point: Point, theta: number, center: Point): Point {\n if (center === undefined) {\n return kvector.rotateRad(point, theta);\n } else {\n return kvector.add(\n center,\n kvector.rotateRad(kvector.subtract(point, center), theta),\n );\n }\n}\n\nexport function rotateDeg(point: Point, theta: number, center: Point): Point {\n if (center === undefined) {\n return kvector.rotateDeg(point, theta);\n } else {\n return kvector.add(\n center,\n kvector.rotateDeg(kvector.subtract(point, center), theta),\n );\n }\n}\n\n// Distance between two points\nexport function distanceToPoint(point1: Point, point2: Point): number {\n return kvector.length(kvector.subtract(point1, point2));\n}\n\n// Distance between point and line\nexport function distanceToLine(point: Point, line: [Point, Point]): number {\n const lv = kvector.subtract(line[1], line[0]);\n const pv = kvector.subtract(point, line[0]);\n const projectedPv = kvector.projection(pv, lv);\n const distancePv = kvector.subtract(projectedPv, pv);\n return kvector.length(distancePv);\n}\n\n// Reflect point over line\nexport function reflectOverLine(point: Point, line: [Point, Point]): Point {\n const lv = kvector.subtract(line[1], line[0]);\n const pv = kvector.subtract(point, line[0]);\n const projectedPv = kvector.projection(pv, lv);\n const reflectedPv = kvector.subtract(kvector.scale(projectedPv, 2), pv);\n return kvector.add(line[0], reflectedPv);\n}\n\n/**\n * Compares two points, returning -1, 0, or 1, for use with\n * Array.prototype.sort\n *\n * Note: This technically doesn't satisfy the total-ordering\n * requirements of Array.prototype.sort unless equalityTolerance\n * is 0. In some cases very close points that compare within a\n * few equalityTolerances could appear in the wrong order.\n */\nexport function compare(\n point1: Point,\n point2: Point,\n equalityTolerance?: number,\n): number /* TODO: convert to -1 | 0 | 1 type */ {\n if (point1.length !== point2.length) {\n return point1.length - point2.length;\n }\n for (let i = 0; i < point1.length; i++) {\n if (!knumber.equal(point1[i], point2[i], equalityTolerance)) {\n return point1[i] - point2[i];\n }\n }\n return 0;\n}\n\n// Check if a value is a point\nexport const is = kvector.is;\n\n// Add and subtract vector(s)\nexport const addVector = kvector.add;\nexport const addVectors = kvector.add;\nexport const subtractVector = kvector.subtract;\nexport const equal = kvector.equal;\n\n// Convert from cartesian to polar and back\nexport const polarRadFromCart = kvector.polarRadFromCart;\nexport const polarDegFromCart = kvector.polarDegFromCart;\nexport const cartFromPolarRad = kvector.cartFromPolarRad;\nexport const cartFromPolarDeg = kvector.cartFromPolarDeg;\n\n// Rounding\nexport const round = kvector.round;\nexport const roundTo = kvector.roundTo;\nexport const floorTo = kvector.floorTo;\nexport const ceilTo = kvector.ceilTo;\n","// @flow\n/**\n * Line Utils\n * A line is an array of two points e.g. [[-5, 0], [5, 0]].\n */\n\nimport * as kpoint from \"./point.js\";\nimport * as kvector from \"./vector.js\";\n\nimport type {Point} from \"./point.js\";\n\nexport type Line = [Point, Point];\n\nexport function distanceToPoint(line: Line, point: Point): number {\n return kpoint.distanceToLine(point, line);\n}\n\nexport function reflectPoint(line: Line, point: Point): Point {\n return kpoint.reflectOverLine(point, line);\n}\n\nexport function midpoint(line: Line): Point {\n return [(line[0][0] + line[1][0]) / 2, (line[0][1] + line[1][1]) / 2];\n}\n\nexport function equal(line1: Line, line2: Line, tolerance?: number): boolean {\n // TODO: A nicer implementation might just check collinearity of\n // vectors using underscore magick\n // Compare the directions of the lines\n const v1 = kvector.subtract(line1[1], line1[0]);\n const v2 = kvector.subtract(line2[1], line2[0]);\n if (!kvector.collinear(v1, v2, tolerance)) {\n return false;\n }\n // If the start point is the same for the two lines, then they are the same\n if (kpoint.equal(line1[0], line2[0])) {\n return true;\n }\n // Make sure that the direction to get from line1 to\n // line2 is the same as the direction of the lines\n const line1ToLine2Vector = kvector.subtract(line2[0], line1[0]);\n return kvector.collinear(v1, line1ToLine2Vector, tolerance);\n}\n","// @flow\n/**\n * Ray Utils\n * A ray (→) is an array of an endpoint and another point along the ray.\n * For example, [[0, 0], [1, 0]] is the ray starting at the origin and\n * traveling along the positive x-axis.\n */\n\nimport * as kvector from \"./vector.js\";\nimport * as kpoint from \"./point.js\";\n\nimport type {Point} from \"./point\";\n\nexport type Ray = [Point, Point];\n\nexport function equal(ray1: Ray, ray2: Ray, tolerance: number): boolean {\n // Compare the directions of the rays\n const v1 = kvector.subtract(ray1[1], ray1[0]);\n const v2 = kvector.subtract(ray2[1], ray2[0]);\n\n const sameOrigin = kpoint.equal(ray1[0], ray2[0]);\n const codirectional = kvector.codirectional(v1, v2, tolerance);\n\n return sameOrigin && codirectional;\n}\n"],"names":["EPSILON","Math","pow","is","x","_","isNumber","isNaN","equal","y","tolerance","abs","round","num","precision","factor","roundTo","increment","floorTo","floor","ceilTo","ceil","decimal","maxDenominator","n","d","a","rem","arraySum","array","reduce","memo","arg","arrayProduct","vec","dimension","isArray","undefined","length","every","knumber","normalize","v","scale","sqrt","dot","b","zip","map","add","zipped","subtract","v1","v2","dim","negate","scalar","pair","codirectional","collinear","polarRadFromCart","radius","theta","atan2","PI","polarDegFromCart","polar","cartFromPolarRad","cos","sin","cartFromPolarDeg","rotateRad","angle","rotateDeg","angleRad","acos","projection","elem","i","distanceToLine","point","line","lv","kvector","pv","reflectOverLine","reflectedPv","addVector","addVectors","subtractVector","center","point1","point2","equalityTolerance","kpoint","line1","line2","ray1","ray2","sameOrigin"],"mappings":"2KA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D,SAAyB6B,EAAeC,GAC3C,OAAOT,EAAeA,EAAiBQ,EAAQC,gDA8B5C,SACHD,EACAC,EACAC,GAEA,GAAIF,EAAOrD,SAAWsD,EAAOtD,OACzB,OAAOqD,EAAOrD,OAASsD,EAAOtD,OAElC,IAAK,IAAIwC,EAAI,EAAGA,EAAIa,EAAOrD,OAAQwC,IAC/B,IAAKtC,EAAcmD,EAAOb,GAAIc,EAAOd,GAAIe,GAC9BF,OAAAA,EAAOb,GAAKc,EAAOd,GAGlC,OAAO,iOCrEJ,SAAyBG,EAAYD,GACxC,OAAOc,EAAsBd,EAAOC,iBAGjC,SAAsBA,EAAYD,GACrC,OAAOc,EAAuBd,EAAOC,aAGlC,SAAkBA,GACrB,MAAO,EAAEA,EAAK,GAAG,GAAKA,EAAK,GAAG,IAAM,GAAIA,EAAK,GAAG,GAAKA,EAAK,GAAG,IAAM,UAGhE,SAAec,EAAaC,EAAatF,GAI5C,MAAM0C,EAAK+B,EAAiBY,EAAM,GAAIA,EAAM,IAExC,QAACZ,EAAkB/B,EADZ+B,EAAiBa,EAAM,GAAIA,EAAM,IACbtF,OAI3BoF,EAAaC,EAAM,GAAIC,EAAM,KAM1Bb,EAAkB/B,EADE+B,EAAiBa,EAAM,GAAID,EAAM,IACXrF,iDC1B9C,SAAeuF,EAAWC,EAAWxF,GAExC,MAAM0C,EAAK+B,EAAiBc,EAAK,GAAIA,EAAK,IACpC5C,EAAK8B,EAAiBe,EAAK,GAAIA,EAAK,IAEpCC,EAAaL,EAAaG,EAAK,GAAIC,EAAK,IACxCxC,EAAgByB,EAAsB/B,EAAIC,EAAI3C,GAE7CyF,OAAAA,GAAczC"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/number.js","../src/vector.js","../src/point.js","../src/line.js","../src/ray.js"],"sourcesContent":["// @flow\n/**\n * Number Utils\n * A number is a js-number, e.g. 5.12\n */\n\nimport _ from \"underscore\";\n\nexport const DEFAULT_TOLERANCE: number = 1e-9;\n\n// TODO: Should this just be Number.Epsilon\nexport const EPSILON: number = Math.pow(2, -42);\n\nexport function is(x: any): boolean {\n return _.isNumber(x) && !_.isNaN(x);\n}\n\nexport function equal(x: number, y: number, tolerance?: number): boolean {\n // Checking for undefined makes this function behave nicely\n // with vectors of different lengths that are _.zip'd together\n if (x == null || y == null) {\n return x === y;\n }\n // We check === here so that +/-Infinity comparisons work correctly\n if (x === y) {\n return true;\n }\n if (tolerance == null) {\n tolerance = DEFAULT_TOLERANCE;\n }\n return Math.abs(x - y) < tolerance;\n}\n\nexport function sign(\n x: number,\n tolerance?: number,\n): number /* Should be: 0 | 1 | -1 */ {\n return equal(x, 0, tolerance) ? 0 : Math.abs(x) / x;\n}\n\nexport function isInteger(num: number, tolerance?: number): boolean {\n return equal(Math.round(num), num, tolerance);\n}\n\n// Round a number to a certain number of decimal places\nexport function round(num: number, precision: number): number {\n const factor = Math.pow(10, precision);\n return Math.round(num * factor) / factor;\n}\n\n// Round num to the nearest multiple of increment\n// i.e. roundTo(83, 5) -> 85\nexport function roundTo(num: number, increment: number): number {\n return Math.round(num / increment) * increment;\n}\n\nexport function floorTo(num: number, increment: number): number {\n return Math.floor(num / increment) * increment;\n}\n\nexport function ceilTo(num: number, increment: number): number {\n return Math.ceil(num / increment) * increment;\n}\n\n/**\n * toFraction\n *\n * Returns a [numerator, denominator] array rational representation\n * of `decimal`\n *\n * See http://en.wikipedia.org/wiki/Continued_fraction for implementation\n * details\n *\n * toFraction(4/8) => [1, 2]\n * toFraction(0.66) => [33, 50]\n * toFraction(0.66, 0.01) => [2/3]\n * toFraction(283 + 1/3) => [850, 3]\n */\nexport function toFraction(\n decimal: number,\n tolerance: number = EPSILON, // can't be 0\n maxDenominator: number = 1000,\n): [number, number] {\n // Initialize everything to compute successive terms of\n // continued-fraction approximations via recurrence relation\n let n = [1, 0];\n let d = [0, 1];\n let a = Math.floor(decimal);\n let rem = decimal - a;\n\n while (d[0] <= maxDenominator) {\n if (equal(n[0] / d[0], decimal, tolerance)) {\n return [n[0], d[0]];\n }\n n = [a * n[0] + n[1], n[0]];\n d = [a * d[0] + d[1], d[0]];\n a = Math.floor(1 / rem);\n rem = 1 / rem - a;\n }\n\n // We failed to find a nice rational representation,\n // so return an irrational \"fraction\"\n return [decimal, 1];\n}\n","// @flow\n/**\n * Vector Utils\n * A vector is an array of numbers e.g. [0, 3, 4].\n */\n\nimport _ from \"underscore\";\n\nimport * as knumber from \"./number.js\";\n\ntype Vector = $ReadOnlyArray<number>;\n\nfunction arraySum(array: $ReadOnlyArray<number>): number {\n return array.reduce((memo, arg) => memo + arg, 0);\n}\n\nfunction arrayProduct(array: $ReadOnlyArray<number>): number {\n return array.reduce((memo, arg) => memo * arg, 1);\n}\n\n/**\n * Checks if the given vector contains only numbers and, optionally, is of the\n * right dimension (length).\n *\n * is([1, 2, 3]) -> true\n * is([1, \"Hello\", 3]) -> false\n * is([1, 2, 3], 1) -> false\n */\nexport function is<T>(vec: $ReadOnlyArray<T>, dimension?: number): boolean {\n if (!_.isArray(vec)) {\n return false;\n }\n if (dimension !== undefined && vec.length !== dimension) {\n return false;\n }\n return vec.every(knumber.is);\n}\n\n// Normalize to a unit vector\nexport function normalize<V: Vector>(v: V): V {\n return scale(v, 1 / length(v));\n}\n\n// Length/magnitude of a vector\nexport function length(v: Vector): number {\n return Math.sqrt(dot(v, v));\n}\n// Dot product of two vectors\nexport function dot(a: Vector, b: Vector): number {\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n const zipped = _.zip(a, b);\n const multiplied = zipped.map(arrayProduct);\n return arraySum(multiplied);\n}\n\n/* vector-add multiple [x, y] coords/vectors\n *\n * add([1, 2], [3, 4]) -> [4, 6]\n */\nexport function add<V: Vector>(...vecs: $ReadOnlyArray<V>): V {\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n const zipped = _.zip(...vecs);\n return zipped.map(arraySum);\n}\n\nexport function subtract<V: Vector>(v1: V, v2: V): V {\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n return _.zip(v1, v2).map((dim) => dim[0] - dim[1]);\n}\n\nexport function negate<V: Vector>(v: V): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return v.map((x) => {\n return -x;\n });\n}\n\n// Scale a vector\nexport function scale<V: Vector>(v1: V, scalar: number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return v1.map((x) => {\n return x * scalar;\n });\n}\n\nexport function equal(v1: Vector, v2: Vector, tolerance?: number): boolean {\n // _.zip will nicely deal with the lengths, going through\n // the length of the longest vector. knumber.equal then\n // returns false for any number compared to the undefined\n // passed in if one of the vectors is shorter.\n // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray\n return _.zip(v1, v2).every((pair) =>\n knumber.equal(pair[0], pair[1], tolerance),\n );\n}\n\nexport function codirectional(\n v1: Vector,\n v2: Vector,\n tolerance?: number,\n): boolean {\n // The origin is trivially codirectional with all other vectors.\n // This gives nice semantics for codirectionality between points when\n // comparing their difference vectors.\n if (\n knumber.equal(length(v1), 0, tolerance) ||\n knumber.equal(length(v2), 0, tolerance)\n ) {\n return true;\n }\n\n v1 = normalize(v1);\n v2 = normalize(v2);\n\n return equal(v1, v2, tolerance);\n}\n\nexport function collinear(v1: Vector, v2: Vector, tolerance?: number): boolean {\n return (\n codirectional(v1, v2, tolerance) ||\n codirectional(v1, negate(v2), tolerance)\n );\n}\n\n// TODO(jeremy) These coordinate conversion functions really only handle 2D points (ie. [number, number])\n\n// Convert a cartesian coordinate into a radian polar coordinate\nexport function polarRadFromCart(\n v: $ReadOnlyArray<number>,\n): $ReadOnlyArray<number> {\n const radius = length(v);\n let theta = Math.atan2(v[1], v[0]);\n\n // Convert angle range from [-pi, pi] to [0, 2pi]\n if (theta < 0) {\n theta += 2 * Math.PI;\n }\n\n return [radius, theta];\n}\n\n// Converts a cartesian coordinate into a degree polar coordinate\nexport function polarDegFromCart(\n v: $ReadOnlyArray<number>,\n): $ReadOnlyArray<number> /* TODO: convert to tuple/Point */ {\n const polar = polarRadFromCart(v);\n return [polar[0], (polar[1] * 180) / Math.PI];\n}\n\n/* Convert a polar coordinate into a cartesian coordinate\n *\n * Examples:\n * cartFromPolarRad(5, Math.PI)\n */\nexport function cartFromPolarRad(\n radius: number,\n theta?: number = 0,\n): $ReadOnlyArray<number> /* TODO: convert to tuple/Point */ {\n return [radius * Math.cos(theta), radius * Math.sin(theta)];\n}\n\n/* Convert a polar coordinate into a cartesian coordinate\n *\n * Examples:\n * cartFromPolarDeg(5, 30)\n */\nexport function cartFromPolarDeg(\n radius: number,\n theta?: number = 0,\n): $ReadOnlyArray<number> {\n return cartFromPolarRad(radius, (theta * Math.PI) / 180);\n}\n\n// Rotate vector\nexport function rotateRad(\n v: $ReadOnlyArray<number>,\n theta: number,\n): $ReadOnlyArray<number> {\n const polar = polarRadFromCart(v);\n const angle = polar[1] + theta;\n return cartFromPolarRad(polar[0], angle);\n}\n\nexport function rotateDeg(\n v: $ReadOnlyArray<number>,\n theta: number,\n): $ReadOnlyArray<number> {\n const polar = polarDegFromCart(v);\n const angle = polar[1] + theta;\n return cartFromPolarDeg(polar[0], angle);\n}\n\n// Angle between two vectors\nexport function angleRad(v1: Vector, v2: Vector): number {\n return Math.acos(dot(v1, v2) / (length(v1) * length(v2)));\n}\n\nexport function angleDeg(v1: Vector, v2: Vector): number {\n return (angleRad(v1, v2) * 180) / Math.PI;\n}\n\n// Vector projection of v1 onto v2\nexport function projection<V: Vector>(v1: V, v2: V): V {\n const scalar = dot(v1, v2) / dot(v2, v2);\n return scale(v2, scalar);\n}\n\n// Round each number to a certain number of decimal places\nexport function round<V: Vector>(vec: V, precision: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.round(elem, precision[i] || precision),\n );\n}\n\n// Round each number to the nearest increment\nexport function roundTo<V: Vector>(vec: V, increment: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.roundTo(elem, increment[i] || increment),\n );\n}\n\nexport function floorTo<V: Vector>(vec: V, increment: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.floorTo(elem, increment[i] || increment),\n );\n}\n\nexport function ceilTo<V: Vector>(vec: V, increment: V | number): V {\n // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.ceilTo(elem, increment[i] || increment),\n );\n}\n","// @flow\n/**\n * Point Utils\n * A point is an array of two numbers e.g. [0, 0].\n */\n\nimport _ from \"underscore\";\n\nimport * as knumber from \"./number.js\";\nimport * as kvector from \"./vector.js\";\n\n// A point, in 2D, 3D, or nD space.\nexport type Point = $ReadOnlyArray<number>;\n\n// Rotate point (around origin unless a center is specified)\nexport function rotateRad(point: Point, theta: number, center?: Point): Point {\n if (center === undefined) {\n return kvector.rotateRad(point, theta);\n } else {\n return kvector.add(\n center,\n kvector.rotateRad(kvector.subtract(point, center), theta),\n );\n }\n}\n\nexport function rotateDeg(point: Point, theta: number, center?: Point): Point {\n if (center === undefined) {\n return kvector.rotateDeg(point, theta);\n } else {\n return kvector.add(\n center,\n kvector.rotateDeg(kvector.subtract(point, center), theta),\n );\n }\n}\n\n// Distance between two points\nexport function distanceToPoint(point1: Point, point2: Point): number {\n return kvector.length(kvector.subtract(point1, point2));\n}\n\n// Distance between point and line\nexport function distanceToLine(point: Point, line: [Point, Point]): number {\n const lv = kvector.subtract(line[1], line[0]);\n const pv = kvector.subtract(point, line[0]);\n const projectedPv = kvector.projection(pv, lv);\n const distancePv = kvector.subtract(projectedPv, pv);\n return kvector.length(distancePv);\n}\n\n// Reflect point over line\nexport function reflectOverLine<P: Point>(point: P, line: [P, P]): P {\n const lv = kvector.subtract(line[1], line[0]);\n const pv = kvector.subtract(point, line[0]);\n const projectedPv = kvector.projection(pv, lv);\n const reflectedPv = kvector.subtract(kvector.scale(projectedPv, 2), pv);\n return kvector.add(line[0], reflectedPv);\n}\n\n/**\n * Compares two points, returning -1, 0, or 1, for use with\n * Array.prototype.sort\n *\n * Note: This technically doesn't satisfy the total-ordering\n * requirements of Array.prototype.sort unless equalityTolerance\n * is 0. In some cases very close points that compare within a\n * few equalityTolerances could appear in the wrong order.\n */\nexport function compare(\n point1: Point,\n point2: Point,\n equalityTolerance?: number,\n): number /* TODO: convert to -1 | 0 | 1 type */ {\n if (point1.length !== point2.length) {\n return point1.length - point2.length;\n }\n for (let i = 0; i < point1.length; i++) {\n if (!knumber.equal(point1[i], point2[i], equalityTolerance)) {\n return point1[i] - point2[i];\n }\n }\n return 0;\n}\n\n// Check if a value is a point\nexport const is = kvector.is;\n\n// Add and subtract vector(s)\nexport const addVector = kvector.add;\nexport const addVectors = kvector.add;\nexport const subtractVector = kvector.subtract;\nexport const equal = kvector.equal;\n\n// Convert from cartesian to polar and back\nexport const polarRadFromCart = kvector.polarRadFromCart;\nexport const polarDegFromCart = kvector.polarDegFromCart;\nexport const cartFromPolarRad = kvector.cartFromPolarRad;\nexport const cartFromPolarDeg = kvector.cartFromPolarDeg;\n\n// Rounding\nexport const round = kvector.round;\nexport const roundTo = kvector.roundTo;\nexport const floorTo = kvector.floorTo;\nexport const ceilTo = kvector.ceilTo;\n","// @flow\n/**\n * Line Utils\n * A line is an array of two points e.g. [[-5, 0], [5, 0]].\n */\n\nimport * as kpoint from \"./point.js\";\nimport * as kvector from \"./vector.js\";\n\nimport type {Point} from \"./point.js\";\n\nexport type Line = [Point, Point];\n\nexport function distanceToPoint(line: Line, point: Point): number {\n return kpoint.distanceToLine(point, line);\n}\n\nexport function reflectPoint(line: Line, point: Point): Point {\n return kpoint.reflectOverLine(point, line);\n}\n\nexport function midpoint(line: Line): Point {\n return [(line[0][0] + line[1][0]) / 2, (line[0][1] + line[1][1]) / 2];\n}\n\nexport function equal(line1: Line, line2: Line, tolerance?: number): boolean {\n // TODO: A nicer implementation might just check collinearity of\n // vectors using underscore magick\n // Compare the directions of the lines\n const v1 = kvector.subtract(line1[1], line1[0]);\n const v2 = kvector.subtract(line2[1], line2[0]);\n if (!kvector.collinear(v1, v2, tolerance)) {\n return false;\n }\n // If the start point is the same for the two lines, then they are the same\n if (kpoint.equal(line1[0], line2[0])) {\n return true;\n }\n // Make sure that the direction to get from line1 to\n // line2 is the same as the direction of the lines\n const line1ToLine2Vector = kvector.subtract(line2[0], line1[0]);\n return kvector.collinear(v1, line1ToLine2Vector, tolerance);\n}\n","// @flow\n/**\n * Ray Utils\n * A ray (→) is an array of an endpoint and another point along the ray.\n * For example, [[0, 0], [1, 0]] is the ray starting at the origin and\n * traveling along the positive x-axis.\n */\n\nimport * as kpoint from \"./point.js\";\nimport * as kvector from \"./vector.js\";\n\nimport type {Point} from \"./point\";\n\nexport type Ray = [Point, Point];\n\nexport function equal(ray1: Ray, ray2: Ray, tolerance?: number): boolean {\n // Compare the directions of the rays\n const v1 = kvector.subtract(ray1[1], ray1[0]);\n const v2 = kvector.subtract(ray2[1], ray2[0]);\n\n const sameOrigin = kpoint.equal(ray1[0], ray2[0]);\n const codirectional = kvector.codirectional(v1, v2, tolerance);\n\n return sameOrigin && codirectional;\n}\n"],"names":["DEFAULT_TOLERANCE","EPSILON","Math","pow","is","x","_","isNumber","isNaN","equal","y","tolerance","abs","sign","isInteger","num","round","precision","factor","roundTo","increment","floorTo","floor","ceilTo","ceil","toFraction","decimal","maxDenominator","n","d","a","rem","arraySum","array","reduce","memo","arg","arrayProduct","vec","dimension","isArray","undefined","length","every","knumber","normalize","v","scale","sqrt","dot","b","zipped","zip","multiplied","map","add","subtract","v1","v2","dim","negate","scalar","pair","codirectional","collinear","polarRadFromCart","radius","theta","atan2","PI","polarDegFromCart","polar","cartFromPolarRad","cos","sin","cartFromPolarDeg","rotateRad","angle","rotateDeg","angleRad","acos","angleDeg","projection","elem","i","point","center","kvector","distanceToPoint","point1","point2","distanceToLine","line","lv","pv","projectedPv","distancePv","reflectOverLine","reflectedPv","compare","equalityTolerance","addVector","addVectors","subtractVector","kpoint","reflectPoint","midpoint","line1","line2","line1ToLine2Vector","ray1","ray2","sameOrigin"],"mappings":";;;;;;;;;;AACA;AACA;AACA;AACA;AAIO,MAAMA,iBAAyB,GAAG,IAAlC;;AAGA,MAAMC,OAAe,GAAGC,IAAI,CAACC,GAAL,CAAS,CAAT,EAAY,CAAC,EAAb,CAAxB,CAAA;AAEA,SAASC,IAAT,CAAYC,CAAZ,EAA6B;AAChC,EAAA,OAAOC,qBAAC,CAACC,QAAF,CAAWF,CAAX,CAAA,IAAiB,CAACC,qBAAC,CAACE,KAAF,CAAQH,CAAR,CAAzB,CAAA;AACH,CAAA;AAEM,SAASI,OAAT,CAAeJ,CAAf,EAA0BK,CAA1B,EAAqCC,SAArC,EAAkE;AACrE;AACA;AACA,EAAA,IAAIN,CAAC,IAAI,IAAL,IAAaK,CAAC,IAAI,IAAtB,EAA4B;AACxB,IAAOL,OAAAA,CAAC,KAAKK,CAAb,CAAA;AACH,GALoE;;;AAOrE,EAAIL,IAAAA,CAAC,KAAKK,CAAV,EAAa;AACT,IAAA,OAAO,IAAP,CAAA;AACH,GAAA;;AACD,EAAIC,IAAAA,SAAS,IAAI,IAAjB,EAAuB;AACnBA,IAAAA,SAAS,GAAGX,iBAAZ,CAAA;AACH,GAAA;;AACD,EAAOE,OAAAA,IAAI,CAACU,GAAL,CAASP,CAAC,GAAGK,CAAb,IAAkBC,SAAzB,CAAA;AACH,CAAA;AAEM,SAASE,IAAT,CACHR,CADG,EAEHM,SAFG;AAGG;AAA4B;AAClC,EAAA,OAAOF,OAAK,CAACJ,CAAD,EAAI,CAAJ,EAAOM,SAAP,CAAL,GAAyB,CAAzB,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