@khanacademy/kmath 0.0.8 → 0.1.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/.babelrc.js CHANGED
@@ -5,4 +5,4 @@
5
5
  *
6
6
  * We should remove this when jest is fixed.
7
7
  */
8
- module.exports = require("../../config/build/babel.config.js");
8
+ module.exports = require("../../config/build/babel.config");
package/.eslintrc.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
1
2
  /* eslint-disable import/no-commonjs */
2
3
  const path = require("path");
3
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @khanacademy/kmath
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 53fd3768: Migrate source code to TypeScript
8
+
3
9
  ## 0.0.8
4
10
 
5
11
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -4,8 +4,9 @@ import _ from 'underscore';
4
4
  * Number Utils
5
5
  * A number is a js-number, e.g. 5.12
6
6
  */
7
- var DEFAULT_TOLERANCE = 1e-9; // TODO: Should this just be Number.Epsilon
7
+ var DEFAULT_TOLERANCE = 1e-9;
8
8
 
9
+ // TODO: Should this just be Number.Epsilon
9
10
  var EPSILON = Math.pow(2, -42);
10
11
  function is$2(x) {
11
12
  return _.isNumber(x) && !_.isNaN(x);
@@ -15,34 +16,31 @@ function equal$4(x, y, tolerance) {
15
16
  // with vectors of different lengths that are _.zip'd together
16
17
  if (x == null || y == null) {
17
18
  return x === y;
18
- } // We check === here so that +/-Infinity comparisons work correctly
19
-
20
-
19
+ }
20
+ // We check === here so that +/-Infinity comparisons work correctly
21
21
  if (x === y) {
22
22
  return true;
23
23
  }
24
-
25
24
  if (tolerance == null) {
26
25
  tolerance = DEFAULT_TOLERANCE;
27
26
  }
28
-
29
27
  return Math.abs(x - y) < tolerance;
30
28
  }
31
- function sign(x, tolerance)
32
- /* Should be: 0 | 1 | -1 */
33
- {
29
+ function sign(x, tolerance) /* Should be: 0 | 1 | -1 */{
34
30
  return equal$4(x, 0, tolerance) ? 0 : Math.abs(x) / x;
35
31
  }
36
32
  function isInteger(num, tolerance) {
37
33
  return equal$4(Math.round(num), num, tolerance);
38
- } // Round a number to a certain number of decimal places
34
+ }
39
35
 
36
+ // Round a number to a certain number of decimal places
40
37
  function round$2(num, precision) {
41
38
  var factor = Math.pow(10, precision);
42
39
  return Math.round(num * factor) / factor;
43
- } // Round num to the nearest multiple of increment
44
- // i.e. roundTo(83, 5) -> 85
40
+ }
45
41
 
42
+ // Round num to the nearest multiple of increment
43
+ // i.e. roundTo(83, 5) -> 85
46
44
  function roundTo$2(num, increment) {
47
45
  return Math.round(num / increment) * increment;
48
46
  }
@@ -52,6 +50,7 @@ function floorTo$2(num, increment) {
52
50
  function ceilTo$2(num, increment) {
53
51
  return Math.ceil(num / increment) * increment;
54
52
  }
53
+
55
54
  /**
56
55
  * toFraction
57
56
  *
@@ -66,7 +65,6 @@ function ceilTo$2(num, increment) {
66
65
  * toFraction(0.66, 0.01) => [2/3]
67
66
  * toFraction(283 + 1/3) => [850, 3]
68
67
  */
69
-
70
68
  function toFraction(decimal) {
71
69
  var tolerance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EPSILON;
72
70
  var maxDenominator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
@@ -76,20 +74,18 @@ function toFraction(decimal) {
76
74
  var d = [0, 1];
77
75
  var a = Math.floor(decimal);
78
76
  var rem = decimal - a;
79
-
80
77
  while (d[0] <= maxDenominator) {
81
78
  if (equal$4(n[0] / d[0], decimal, tolerance)) {
82
79
  return [n[0], d[0]];
83
80
  }
84
-
85
81
  n = [a * n[0] + n[1], n[0]];
86
82
  d = [a * d[0] + d[1], d[0]];
87
83
  a = Math.floor(1 / rem);
88
84
  rem = 1 / rem - a;
89
- } // We failed to find a nice rational representation,
90
- // so return an irrational "fraction"
91
-
85
+ }
92
86
 
87
+ // We failed to find a nice rational representation,
88
+ // so return an irrational "fraction"
93
89
  return [decimal, 1];
94
90
  }
95
91
 
@@ -112,14 +108,13 @@ var number = /*#__PURE__*/Object.freeze({
112
108
  * Vector Utils
113
109
  * A vector is an array of numbers e.g. [0, 3, 4].
114
110
  */
115
-
116
111
  function arraySum(array) {
117
112
  return array.reduce((memo, arg) => memo + arg, 0);
118
113
  }
119
-
120
114
  function arrayProduct(array) {
121
115
  return array.reduce((memo, arg) => memo * arg, 1);
122
116
  }
117
+
123
118
  /**
124
119
  * Checks if the given vector contains only numbers and, optionally, is of the
125
120
  * right dimension (length).
@@ -128,59 +123,55 @@ function arrayProduct(array) {
128
123
  * is([1, "Hello", 3]) -> false
129
124
  * is([1, 2, 3], 1) -> false
130
125
  */
131
-
132
-
133
126
  function is$1(vec, dimension) {
134
127
  if (!_.isArray(vec)) {
135
128
  return false;
136
129
  }
137
-
138
130
  if (dimension !== undefined && vec.length !== dimension) {
139
131
  return false;
140
132
  }
141
-
142
133
  return vec.every(is$2);
143
- } // Normalize to a unit vector
134
+ }
144
135
 
136
+ // Normalize to a unit vector
145
137
  function normalize(v) {
146
138
  return scale(v, 1 / length(v));
147
- } // Length/magnitude of a vector
139
+ }
148
140
 
141
+ // Length/magnitude of a vector
149
142
  function length(v) {
150
143
  return Math.sqrt(dot(v, v));
151
- } // Dot product of two vectors
152
-
144
+ }
145
+ // Dot product of two vectors
153
146
  function dot(a, b) {
154
- // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
155
147
  var zipped = _.zip(a, b);
156
-
157
148
  var multiplied = zipped.map(arrayProduct);
158
149
  return arraySum(multiplied);
159
150
  }
151
+
160
152
  /* vector-add multiple [x, y] coords/vectors
161
153
  *
162
154
  * add([1, 2], [3, 4]) -> [4, 6]
163
155
  */
164
-
165
156
  function add() {
166
- // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
167
157
  var zipped = _.zip(...arguments);
168
-
158
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
169
159
  return zipped.map(arraySum);
170
160
  }
171
161
  function subtract(v1, v2) {
172
- // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
162
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
173
163
  return _.zip(v1, v2).map(dim => dim[0] - dim[1]);
174
164
  }
175
165
  function negate(v) {
176
- // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
166
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
177
167
  return v.map(x => {
178
168
  return -x;
179
169
  });
180
- } // Scale a vector
170
+ }
181
171
 
172
+ // Scale a vector
182
173
  function scale(v1, scalar) {
183
- // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
174
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
184
175
  return v1.map(x => {
185
176
  return x * scalar;
186
177
  });
@@ -190,7 +181,6 @@ function equal$3(v1, v2, tolerance) {
190
181
  // the length of the longest vector. knumber.equal then
191
182
  // returns false for any number compared to the undefined
192
183
  // passed in if one of the vectors is shorter.
193
- // $FlowFixMe[incompatible-call] underscore doesn't like $ReadOnlyArray
194
184
  return _.zip(v1, v2).every(pair => equal$4(pair[0], pair[1], tolerance));
195
185
  }
196
186
  function codirectional(v1, v2, tolerance) {
@@ -200,56 +190,55 @@ function codirectional(v1, v2, tolerance) {
200
190
  if (equal$4(length(v1), 0, tolerance) || equal$4(length(v2), 0, tolerance)) {
201
191
  return true;
202
192
  }
203
-
204
193
  v1 = normalize(v1);
205
194
  v2 = normalize(v2);
206
195
  return equal$3(v1, v2, tolerance);
207
196
  }
208
197
  function collinear(v1, v2, tolerance) {
209
198
  return codirectional(v1, v2, tolerance) || codirectional(v1, negate(v2), tolerance);
210
- } // TODO(jeremy) These coordinate conversion functions really only handle 2D points (ie. [number, number])
211
- // Convert a cartesian coordinate into a radian polar coordinate
199
+ }
200
+
201
+ // TODO(jeremy) These coordinate conversion functions really only handle 2D points (ie. [number, number])
212
202
 
203
+ // Convert a cartesian coordinate into a radian polar coordinate
213
204
  function polarRadFromCart$1(v) {
214
205
  var radius = length(v);
215
- var theta = Math.atan2(v[1], v[0]); // Convert angle range from [-pi, pi] to [0, 2pi]
206
+ var theta = Math.atan2(v[1], v[0]);
216
207
 
208
+ // Convert angle range from [-pi, pi] to [0, 2pi]
217
209
  if (theta < 0) {
218
210
  theta += 2 * Math.PI;
219
211
  }
220
-
221
212
  return [radius, theta];
222
- } // Converts a cartesian coordinate into a degree polar coordinate
213
+ }
223
214
 
224
- function polarDegFromCart$1(v)
225
- /* TODO: convert to tuple/Point */
226
- {
215
+ // Converts a cartesian coordinate into a degree polar coordinate
216
+ function polarDegFromCart$1(v) /* TODO: convert to tuple/Point */{
227
217
  var polar = polarRadFromCart$1(v);
228
218
  return [polar[0], polar[1] * 180 / Math.PI];
229
219
  }
220
+
230
221
  /* Convert a polar coordinate into a cartesian coordinate
231
222
  *
232
223
  * Examples:
233
224
  * cartFromPolarRad(5, Math.PI)
234
225
  */
235
-
236
- function cartFromPolarRad$1(radius)
237
- /* TODO: convert to tuple/Point */
238
- {
226
+ function cartFromPolarRad$1(radius) /* TODO: convert to tuple/Point */{
239
227
  var theta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
240
228
  return [radius * Math.cos(theta), radius * Math.sin(theta)];
241
229
  }
230
+
242
231
  /* Convert a polar coordinate into a cartesian coordinate
243
232
  *
244
233
  * Examples:
245
234
  * cartFromPolarDeg(5, 30)
246
235
  */
247
-
248
236
  function cartFromPolarDeg$1(radius) {
249
237
  var theta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
250
238
  return cartFromPolarRad$1(radius, theta * Math.PI / 180);
251
- } // Rotate vector
239
+ }
252
240
 
241
+ // Rotate vector
253
242
  function rotateRad$1(v, theta) {
254
243
  var polar = polarRadFromCart$1(v);
255
244
  var angle = polar[1] + theta;
@@ -259,42 +248,50 @@ function rotateDeg$1(v, theta) {
259
248
  var polar = polarDegFromCart$1(v);
260
249
  var angle = polar[1] + theta;
261
250
  return cartFromPolarDeg$1(polar[0], angle);
262
- } // Angle between two vectors
251
+ }
263
252
 
253
+ // Angle between two vectors
264
254
  function angleRad(v1, v2) {
265
255
  return Math.acos(dot(v1, v2) / (length(v1) * length(v2)));
266
256
  }
267
257
  function angleDeg(v1, v2) {
268
258
  return angleRad(v1, v2) * 180 / Math.PI;
269
- } // Vector projection of v1 onto v2
259
+ }
270
260
 
261
+ // Vector projection of v1 onto v2
271
262
  function projection(v1, v2) {
272
263
  var scalar = dot(v1, v2) / dot(v2, v2);
273
264
  return scale(v2, scalar);
274
- } // Round each number to a certain number of decimal places
265
+ }
275
266
 
267
+ // Round each number to a certain number of decimal places
276
268
  function round$1(vec, precision) {
277
- // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
278
- return vec.map((elem, i) => // $FlowFixMe[prop-missing]
269
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
270
+ return vec.map((elem, i) =>
271
+ // $FlowFixMe[prop-missing]
279
272
  // $FlowFixMe[incompatible-call]
280
273
  round$2(elem, precision[i] || precision));
281
- } // Round each number to the nearest increment
274
+ }
282
275
 
276
+ // Round each number to the nearest increment
283
277
  function roundTo$1(vec, increment) {
284
- // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
285
- return vec.map((elem, i) => // $FlowFixMe[prop-missing]
278
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
279
+ return vec.map((elem, i) =>
280
+ // $FlowFixMe[prop-missing]
286
281
  // $FlowFixMe[incompatible-call]
287
282
  roundTo$2(elem, increment[i] || increment));
288
283
  }
289
284
  function floorTo$1(vec, increment) {
290
- // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
291
- return vec.map((elem, i) => // $FlowFixMe[prop-missing]
285
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
286
+ return vec.map((elem, i) =>
287
+ // $FlowFixMe[prop-missing]
292
288
  // $FlowFixMe[incompatible-call]
293
289
  floorTo$2(elem, increment[i] || increment));
294
290
  }
295
291
  function ceilTo$1(vec, increment) {
296
- // $FlowFixMe[incompatible-return] Flow's `.map()` libdef is lacking
297
- return vec.map((elem, i) => // $FlowFixMe[prop-missing]
292
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.
293
+ return vec.map((elem, i) =>
294
+ // $FlowFixMe[prop-missing]
298
295
  // $FlowFixMe[incompatible-call]
299
296
  ceilTo$2(elem, increment[i] || increment));
300
297
  }
@@ -332,6 +329,8 @@ var vector = /*#__PURE__*/Object.freeze({
332
329
  * A point is an array of two numbers e.g. [0, 0].
333
330
  */
334
331
 
332
+ // A point, in 2D, 3D, or nD space.
333
+
335
334
  // Rotate point (around origin unless a center is specified)
336
335
  function rotateRad(point, theta, center) {
337
336
  if (center === undefined) {
@@ -346,20 +345,23 @@ function rotateDeg(point, theta, center) {
346
345
  } else {
347
346
  return add(center, rotateDeg$1(subtract(point, center), theta));
348
347
  }
349
- } // Distance between two points
348
+ }
350
349
 
350
+ // Distance between two points
351
351
  function distanceToPoint$1(point1, point2) {
352
352
  return length(subtract(point1, point2));
353
- } // Distance between point and line
353
+ }
354
354
 
355
+ // Distance between point and line
355
356
  function distanceToLine(point, line) {
356
357
  var lv = subtract(line[1], line[0]);
357
358
  var pv = subtract(point, line[0]);
358
359
  var projectedPv = projection(pv, lv);
359
360
  var distancePv = subtract(projectedPv, pv);
360
361
  return length(distancePv);
361
- } // Reflect point over line
362
+ }
362
363
 
364
+ // Reflect point over line
363
365
  function reflectOverLine(point, line) {
364
366
  var lv = subtract(line[1], line[0]);
365
367
  var pv = subtract(point, line[0]);
@@ -367,6 +369,7 @@ function reflectOverLine(point, line) {
367
369
  var reflectedPv = subtract(scale(projectedPv, 2), pv);
368
370
  return add(line[0], reflectedPv);
369
371
  }
372
+
370
373
  /**
371
374
  * Compares two points, returning -1, 0, or 1, for use with
372
375
  * Array.prototype.sort
@@ -376,35 +379,34 @@ function reflectOverLine(point, line) {
376
379
  * is 0. In some cases very close points that compare within a
377
380
  * few equalityTolerances could appear in the wrong order.
378
381
  */
379
-
380
- function compare(point1, point2, equalityTolerance)
381
- /* TODO: convert to -1 | 0 | 1 type */
382
- {
382
+ function compare(point1, point2, equalityTolerance) /* TODO: convert to -1 | 0 | 1 type */{
383
383
  if (point1.length !== point2.length) {
384
384
  return point1.length - point2.length;
385
385
  }
386
-
387
386
  for (var i = 0; i < point1.length; i++) {
388
387
  if (!equal$4(point1[i], point2[i], equalityTolerance)) {
389
388
  return point1[i] - point2[i];
390
389
  }
391
390
  }
392
-
393
391
  return 0;
394
- } // Check if a value is a point
392
+ }
395
393
 
396
- var is = is$1; // Add and subtract vector(s)
394
+ // Check if a value is a point
395
+ var is = is$1;
397
396
 
397
+ // Add and subtract vector(s)
398
398
  var addVector = add;
399
399
  var addVectors = add;
400
400
  var subtractVector = subtract;
401
- var equal$2 = equal$3; // Convert from cartesian to polar and back
401
+ var equal$2 = equal$3;
402
402
 
403
+ // Convert from cartesian to polar and back
403
404
  var polarRadFromCart = polarRadFromCart$1;
404
405
  var polarDegFromCart = polarDegFromCart$1;
405
406
  var cartFromPolarRad = cartFromPolarRad$1;
406
- var cartFromPolarDeg = cartFromPolarDeg$1; // Rounding
407
+ var cartFromPolarDeg = cartFromPolarDeg$1;
407
408
 
409
+ // Rounding
408
410
  var round = round$1;
409
411
  var roundTo = roundTo$1;
410
412
  var floorTo = floorTo$1;
@@ -452,18 +454,15 @@ function equal$1(line1, line2, tolerance) {
452
454
  // Compare the directions of the lines
453
455
  var v1 = subtract(line1[1], line1[0]);
454
456
  var v2 = subtract(line2[1], line2[0]);
455
-
456
457
  if (!collinear(v1, v2, tolerance)) {
457
458
  return false;
458
- } // If the start point is the same for the two lines, then they are the same
459
-
460
-
459
+ }
460
+ // If the start point is the same for the two lines, then they are the same
461
461
  if (equal$2(line1[0], line2[0])) {
462
462
  return true;
463
- } // Make sure that the direction to get from line1 to
463
+ }
464
+ // Make sure that the direction to get from line1 to
464
465
  // line2 is the same as the direction of the lines
465
-
466
-
467
466
  var line1ToLine2Vector = subtract(line2[0], line1[0]);
468
467
  return collinear(v1, line1ToLine2Vector, tolerance);
469
468
  }
@@ -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\";\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,IAAMA,iBAAyB,GAAG,IAAlC;;AAGA,IAAMC,OAAe,GAAGC,IAAI,CAACC,GAAL,CAAS,CAAT,EAAY,CAAC,EAAb,CAAxB,CAAA;AAEA,SAASC,IAAT,CAAYC,CAAZ,EAA6B;AAChC,EAAA,OAAOC,CAAC,CAACC,QAAF,CAAWF,CAAX,CAAA,IAAiB,CAACC,CAAC,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,CAA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,CAAA;AACH;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/number.ts","../../src/vector.ts","../../src/point.ts","../../src/line.ts","../../src/ray.ts"],"sourcesContent":["/**\n * Number Utils\n * A number is a js-number, e.g. 5.12\n */\n\nimport _ from \"underscore\";\n\nexport const DEFAULT_TOLERANCE = 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 // can't be 0\n tolerance: number = EPSILON,\n maxDenominator = 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","/**\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\";\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 extends 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 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 extends Vector>(...vecs: ReadonlyArray<V>): V {\n const zipped = _.zip(...vecs);\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\n return zipped.map(arraySum);\n}\n\nexport function subtract<V extends Vector>(v1: V, v2: V): V {\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\n return _.zip(v1, v2).map((dim) => dim[0] - dim[1]);\n}\n\nexport function negate<V extends Vector>(v: V): V {\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\n return v.map((x) => {\n return -x;\n });\n}\n\n// Scale a vector\nexport function scale<V extends Vector>(v1: V, scalar: number): V {\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\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 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 = 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 = 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 extends 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 extends Vector>(vec: V, precision: V | number): V {\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\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 extends Vector>(vec: V, increment: V | number): V {\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\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 extends Vector>(vec: V, increment: V | number): V {\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\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 extends Vector>(vec: V, increment: V | number): V {\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'.\n return vec.map((elem, i) =>\n // $FlowFixMe[prop-missing]\n // $FlowFixMe[incompatible-call]\n knumber.ceilTo(elem, increment[i] || increment),\n );\n}\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\";\nimport * as kvector from \"./vector\";\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 extends 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","/**\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\";\nimport * as kvector from \"./vector\";\n\nimport type {Point} from \"./point\";\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","/**\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\";\nimport * as kvector from \"./vector\";\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","arguments","length","undefined","maxDenominator","n","d","a","rem","arraySum","array","reduce","memo","arg","arrayProduct","vec","dimension","isArray","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":";;AAAA;AACA;AACA;AACA;AAIO,IAAMA,iBAAiB,GAAG,IAAI,CAAA;;AAErC;AACO,IAAMC,OAAe,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;AAExC,SAASC,IAAEA,CAACC,CAAM,EAAW;AAChC,EAAA,OAAOC,CAAC,CAACC,QAAQ,CAACF,CAAC,CAAC,IAAI,CAACC,CAAC,CAACE,KAAK,CAACH,CAAC,CAAC,CAAA;AACvC,CAAA;AAEO,SAASI,OAAKA,CAACJ,CAAS,EAAEK,CAAS,EAAEC,SAAkB,EAAW;AACrE;AACA;AACA,EAAA,IAAIN,CAAC,IAAI,IAAI,IAAIK,CAAC,IAAI,IAAI,EAAE;IACxB,OAAOL,CAAC,KAAKK,CAAC,CAAA;AAClB,GAAA;AACA;EACA,IAAIL,CAAC,KAAKK,CAAC,EAAE;AACT,IAAA,OAAO,IAAI,CAAA;AACf,GAAA;EACA,IAAIC,SAAS,IAAI,IAAI,EAAE;AACnBA,IAAAA,SAAS,GAAGX,iBAAiB,CAAA;AACjC,GAAA;EACA,OAAOE,IAAI,CAACU,GAAG,CAACP,CAAC,GAAGK,CAAC,CAAC,GAAGC,SAAS,CAAA;AACtC,CAAA;AAEO,SAASE,IAAIA,C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CAAA;EAC/C,IAAI,CAACrB,SAAiB,CAAC9B,EAAE,EAAEC,EAAE,EAAEhD,SAAS,CAAC,EAAE;AACvC,IAAA,OAAO,KAAK,CAAA;AAChB,GAAA;AACA;AACA,EAAA,IAAI8F,OAAY,CAACG,KAAK,CAAC,CAAC,CAAC,EAAEC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;AAClC,IAAA,OAAO,IAAI,CAAA;AACf,GAAA;AACA;AACA;AACA,EAAA,IAAMC,kBAAkB,GAAGtB,QAAgB,CAACqB,KAAK,CAAC,CAAC,CAAC,EAAED,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;EAC/D,OAAOpB,SAAiB,CAAC9B,EAAE,EAAEoD,kBAAkB,EAAEnG,SAAS,CAAC,CAAA;AAC/D;;;;;;;;;;ACzCA;AACA;AACA;AACA;AACA;AACA;AASO,SAASF,KAAKA,CAACsG,IAAS,EAAEC,IAAS,EAAErG,SAAkB,EAAW;AACrE;AACA,EAAA,IAAM+C,EAAE,GAAG8B,QAAgB,CAACuB,IAAI,CAAC,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7C,EAAA,IAAMpD,EAAE,GAAG6B,QAAgB,CAACwB,IAAI,CAAC,CAAC,CAAC,EAAEA,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7C,EAAA,IAAMC,UAAU,GAAGR,OAAY,CAACM,IAAI,CAAC,CAAC,CAAC,EAAEC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;EACjD,IAAMhD,eAAa,GAAGwB,aAAqB,CAAC9B,EAAE,EAAEC,EAAE,EAAEhD,SAAS,CAAC,CAAA;EAE9D,OAAOsG,UAAU,IAAIjD,eAAa,CAAA;AACtC;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- // @flow
2
- export * from "../src/index.js";
1
+ export * as number from "./number";
2
+ export * as vector from "./vector";
3
+ export * as point from "./point";
4
+ export * as line from "./line";
5
+ export * as ray from "./ray";