@visactor/vutils 0.19.4 → 0.19.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.
Files changed (70) hide show
  1. package/README.md +5 -12
  2. package/cjs/common/extent.d.ts +1 -0
  3. package/cjs/common/extent.js +30 -0
  4. package/cjs/common/extent.js.map +1 -0
  5. package/cjs/common/field.d.ts +12 -0
  6. package/cjs/common/field.js +36 -0
  7. package/cjs/common/field.js.map +1 -0
  8. package/cjs/common/index.d.ts +5 -0
  9. package/cjs/common/index.js +3 -1
  10. package/cjs/common/index.js.map +1 -1
  11. package/cjs/common/interpolate.js +1 -2
  12. package/cjs/common/isArrayLike.js +2 -1
  13. package/cjs/common/isPrototype.js +1 -2
  14. package/cjs/common/isShallowEqual.js +2 -1
  15. package/cjs/common/isValidUrl.js +1 -1
  16. package/cjs/common/lowerFirst.js +1 -1
  17. package/cjs/common/random.d.ts +2 -0
  18. package/cjs/common/random.js +18 -1
  19. package/cjs/common/random.js.map +1 -1
  20. package/cjs/common/regression-linear.d.ts +8 -0
  21. package/cjs/common/regression-linear.js +50 -0
  22. package/cjs/common/regression-linear.js.map +1 -0
  23. package/cjs/common/toPercent.d.ts +1 -0
  24. package/cjs/common/toPercent.js +17 -0
  25. package/cjs/common/toPercent.js.map +1 -0
  26. package/cjs/common/zero.d.ts +1 -0
  27. package/cjs/common/zero.js +10 -0
  28. package/cjs/common/zero.js.map +1 -0
  29. package/cjs/data-structure/bounds.d.ts +2 -0
  30. package/cjs/data-structure/bounds.js +19 -0
  31. package/cjs/data-structure/bounds.js.map +1 -1
  32. package/cjs/graphics/bounds-util.d.ts +3 -1
  33. package/cjs/graphics/bounds-util.js +38 -1
  34. package/cjs/graphics/bounds-util.js.map +1 -1
  35. package/dist/index.js +191 -2
  36. package/dist/index.min.js +1 -1
  37. package/es/common/extent.d.ts +1 -0
  38. package/es/common/extent.js +21 -0
  39. package/es/common/extent.js.map +1 -0
  40. package/es/common/field.d.ts +12 -0
  41. package/es/common/field.js +24 -0
  42. package/es/common/field.js.map +1 -0
  43. package/es/common/index.d.ts +5 -0
  44. package/es/common/index.js +10 -0
  45. package/es/common/index.js.map +1 -1
  46. package/es/common/interpolate.js +1 -2
  47. package/es/common/isArrayLike.js +2 -1
  48. package/es/common/isPrototype.js +1 -2
  49. package/es/common/isShallowEqual.js +2 -1
  50. package/es/common/isValidUrl.js +1 -1
  51. package/es/common/lowerFirst.js +1 -1
  52. package/es/common/random.d.ts +2 -0
  53. package/es/common/random.js +13 -0
  54. package/es/common/random.js.map +1 -1
  55. package/es/common/regression-linear.d.ts +8 -0
  56. package/es/common/regression-linear.js +35 -0
  57. package/es/common/regression-linear.js.map +1 -0
  58. package/es/common/toPercent.d.ts +1 -0
  59. package/es/common/toPercent.js +6 -0
  60. package/es/common/toPercent.js.map +1 -0
  61. package/es/common/zero.d.ts +1 -0
  62. package/es/common/zero.js +2 -0
  63. package/es/common/zero.js.map +1 -0
  64. package/es/data-structure/bounds.d.ts +2 -0
  65. package/es/data-structure/bounds.js +20 -1
  66. package/es/data-structure/bounds.js.map +1 -1
  67. package/es/graphics/bounds-util.d.ts +3 -1
  68. package/es/graphics/bounds-util.js +33 -0
  69. package/es/graphics/bounds-util.js.map +1 -1
  70. package/package.json +7 -4
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphics/bounds-util.ts"],"names":[],"mappings":";;;AAeO,MAAM,uBAAuB,GAAG,CAAC,MAAmB,EAAE,UAAkB,EAAE,EAAE;IACjF,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,IAAI,OAAO,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,OAAO,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAE5B,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;IAEX,QAAQ,UAAU,EAAE;QAClB,KAAK,KAAK,CAAC;QACX,KAAK,YAAY;YACf,EAAE,GAAG,CAAC,GAAG,CAAC;YACV,MAAM;QACR,KAAK,QAAQ,CAAC;QACd,KAAK,eAAe;YAClB,EAAE,GAAG,GAAG,CAAC;YACT,MAAM;QACR,KAAK,MAAM,CAAC;QACZ,KAAK,aAAa;YAChB,EAAE,GAAG,CAAC,GAAG,CAAC;YACV,MAAM;QACR,KAAK,OAAO,CAAC;QACb,KAAK,cAAc;YACjB,EAAE,GAAG,GAAG,CAAC;YACT,MAAM;QACR,KAAK,WAAW;YACd,EAAE,GAAG,GAAG,CAAC;YACT,EAAE,GAAG,CAAC,GAAG,CAAC;YACV,MAAM;QACR,KAAK,UAAU;YACb,EAAE,GAAG,CAAC,GAAG,CAAC;YACV,EAAE,GAAG,CAAC,GAAG,CAAC;YACV,MAAM;QACR,KAAK,cAAc;YACjB,EAAE,GAAG,GAAG,CAAC;YACT,EAAE,GAAG,GAAG,CAAC;YACT,MAAM;QACR,KAAK,aAAa;YAChB,EAAE,GAAG,CAAC,GAAG,CAAC;YACV,EAAE,GAAG,GAAG,CAAC;KACZ;IAED,OAAO,IAAI,EAAE,GAAG,SAAS,CAAC;IAC1B,OAAO,IAAI,EAAE,GAAG,UAAU,CAAC;IAE3B,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;AACpC,CAAC,CAAC;AAhDW,QAAA,uBAAuB,2BAgDlC","file":"bounds-util.js","sourcesContent":["import type { IBoundsLike } from '../data-structure';\n\nexport type InsideBoundsAnchorType = 'inside' | 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right';\n\nexport type BoundsAnchorType =\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'top-right'\n | 'top-left'\n | 'bottom-right'\n | 'bottom-left'\n | 'center';\n\nexport const calculateAnchorOfBounds = (bounds: IBoundsLike, anchorType: string) => {\n const { x1, x2, y1, y2 } = bounds;\n const rectWidth = Math.abs(x2 - x1);\n const rectHeight = Math.abs(y2 - y1);\n let anchorX = (x1 + x2) / 2;\n let anchorY = (y1 + y2) / 2;\n\n let sx = 0;\n let sy = 0;\n\n switch (anchorType) {\n case 'top':\n case 'inside-top':\n sy = -0.5;\n break;\n case 'bottom':\n case 'inside-bottom':\n sy = 0.5;\n break;\n case 'left':\n case 'inside-left':\n sx = -0.5;\n break;\n case 'right':\n case 'inside-right':\n sx = 0.5;\n break;\n case 'top-right':\n sx = 0.5;\n sy = -0.5;\n break;\n case 'top-left':\n sx = -0.5;\n sy = -0.5;\n break;\n case 'bottom-right':\n sx = 0.5;\n sy = 0.5;\n break;\n case 'bottom-left':\n sx = -0.5;\n sy = 0.5;\n }\n\n anchorX += sx * rectWidth;\n anchorY += sy * rectHeight;\n\n return { x: anchorX, y: anchorY };\n};\n"]}
1
+ {"version":3,"sources":["../src/graphics/bounds-util.ts"],"names":[],"mappings":";;;AAeO,MAAM,uBAAuB,GAAG,CAAC,MAAmB,EAAE,UAAkB,EAAE,EAAE;IACjF,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,IAAI,OAAO,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,OAAO,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAE5B,IAAI,EAAE,GAAG,CAAC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pB,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACvB,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACrD,IAAI,QAAQ,CAAC;QACb,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE;YAC3B,QAAQ,GAAG,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;SACpC;aAAM,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE;YAClC,QAAQ,GAAG,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;SACpC;aAAM;YACL,QAAQ,GAAG,CAAC,CAAC;SACd;QACD,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;KAC/C;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAhCW,QAAA,aAAa,iBAgCxB","file":"bounds-util.js","sourcesContent":["import type { IBoundsLike, IOBBBounds } from '../data-structure';\n\nexport type InsideBoundsAnchorType = 'inside' | 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right';\n\nexport type BoundsAnchorType =\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'top-right'\n | 'top-left'\n | 'bottom-right'\n | 'bottom-left'\n | 'center';\n\nexport const calculateAnchorOfBounds = (bounds: IBoundsLike, anchorType: string) => {\n const { x1, x2, y1, y2 } = bounds;\n const rectWidth = Math.abs(x2 - x1);\n const rectHeight = Math.abs(y2 - y1);\n let anchorX = (x1 + x2) / 2;\n let anchorY = (y1 + y2) / 2;\n\n let sx = 0;\n let sy = 0;\n\n switch (anchorType) {\n case 'top':\n case 'inside-top':\n sy = -0.5;\n break;\n case 'bottom':\n case 'inside-bottom':\n sy = 0.5;\n break;\n case 'left':\n case 'inside-left':\n sx = -0.5;\n break;\n case 'right':\n case 'inside-right':\n sx = 0.5;\n break;\n case 'top-right':\n sx = 0.5;\n sy = -0.5;\n break;\n case 'top-left':\n sx = -0.5;\n sy = -0.5;\n break;\n case 'bottom-right':\n sx = 0.5;\n sy = 0.5;\n break;\n case 'bottom-left':\n sx = -0.5;\n sy = 0.5;\n }\n\n anchorX += sx * rectWidth;\n anchorY += sy * rectHeight;\n\n return { x: anchorX, y: anchorY };\n};\n\nexport const aabbSeparation = (a: IBoundsLike, b: IBoundsLike) => {\n return Math.max(b.x1 - a.x2, a.x1 - b.x2, b.y1 - a.y2, a.y1 - b.y2);\n};\n\nexport const obbSeparation = (a: IOBBBounds, b: IOBBBounds) => {\n const axes = [\n { x: Math.cos(a.angle), y: Math.sin(a.angle) }, // Rect A's first axis\n { x: -Math.sin(a.angle), y: Math.cos(a.angle) }, // Rect A's second axis\n { x: Math.cos(b.angle), y: Math.sin(a.angle) }, // Rect B's first axis\n { x: -Math.sin(b.angle), y: Math.cos(a.angle) } // Rect B's second axis\n ];\n\n // calculate the projection range of a rectangle on a given axis\n function getProjectionRange(obb: IOBBBounds, axisX: number, axisY: number): { min: number; max: number } {\n const corners = obb.getRotatedCorners();\n const projections = corners.map(p => p.x * axisX + p.y * axisY);\n return { min: Math.min(...projections), max: Math.max(...projections) };\n }\n\n // Calculate distances for all axes\n let maxDistance = 0;\n for (const axis of axes) {\n const rangeA = getProjectionRange(a, axis.x, axis.y);\n const rangeB = getProjectionRange(b, axis.x, axis.y);\n let distance;\n if (rangeA.max < rangeB.min) {\n distance = rangeB.min - rangeA.max; // B is to the right of A\n } else if (rangeB.max < rangeA.min) {\n distance = rangeA.min - rangeB.max; // A is to the right of B\n } else {\n distance = 0; // Overlapping\n }\n maxDistance = Math.max(maxDistance, distance);\n }\n\n return maxDistance;\n};\n"]}
package/dist/index.js CHANGED
@@ -1514,7 +1514,7 @@
1514
1514
  }
1515
1515
  const reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
1516
1516
  const reB = new RegExp(reA.source, 'g');
1517
- function zero(b) {
1517
+ function zero$1(b) {
1518
1518
  return function () {
1519
1519
  return b;
1520
1520
  };
@@ -1569,7 +1569,7 @@
1569
1569
  return s.length < 2
1570
1570
  ? q[0]
1571
1571
  ? one(q[0].x)
1572
- : zero(b)
1572
+ : zero$1(b)
1573
1573
  : ((b = q.length),
1574
1574
  function (t) {
1575
1575
  for (let i = 0, o; i < b; ++i) {
@@ -1635,6 +1635,137 @@
1635
1635
  function seedRandom(seed) {
1636
1636
  return parseFloat('0.' + Math.sin(seed).toString().substring(6));
1637
1637
  }
1638
+ const a = 1664525;
1639
+ const c = 1013904223;
1640
+ const m = 4294967296;
1641
+ function randomLCG(initS = 1) {
1642
+ let s = initS;
1643
+ return () => (s = (a * s + c) % m) / m;
1644
+ }
1645
+ const fakeRandom = () => {
1646
+ let i = -1;
1647
+ const arr = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9];
1648
+ return () => {
1649
+ i = (i + 1) % arr.length;
1650
+ return arr[i];
1651
+ };
1652
+ };
1653
+
1654
+ const getter = (path) => {
1655
+ return (obj) => get(obj, path);
1656
+ };
1657
+ const fieldSingle = (fieldStr, opt = {}) => {
1658
+ if (isFunction(fieldStr)) {
1659
+ return fieldStr;
1660
+ }
1661
+ const path = [fieldStr];
1662
+ return ((opt && opt.get) || getter)(path);
1663
+ };
1664
+ const field = (fieldStr, opt = {}) => {
1665
+ if (isArray(fieldStr)) {
1666
+ const funcs = fieldStr.map(entry => fieldSingle(entry, opt));
1667
+ return (datum) => {
1668
+ return funcs.map(func => func(datum));
1669
+ };
1670
+ }
1671
+ return fieldSingle(fieldStr, opt);
1672
+ };
1673
+ const simpleField = (option) => {
1674
+ if (!option) {
1675
+ return null;
1676
+ }
1677
+ if (typeof option === 'string' || typeof option === 'number') {
1678
+ return () => option;
1679
+ }
1680
+ else if (isFunction(option)) {
1681
+ return option;
1682
+ }
1683
+ return (datum) => datum[option.field];
1684
+ };
1685
+
1686
+ const toPercent = (percent, total) => {
1687
+ if (isNil(percent)) {
1688
+ return total;
1689
+ }
1690
+ return isString(percent) ? (total * parseFloat(percent)) / 100 : percent;
1691
+ };
1692
+
1693
+ const zero = (_) => 0;
1694
+
1695
+ const extent = (array, func) => {
1696
+ const valueGetter = isFunction(func) ? func : (val) => val;
1697
+ let min;
1698
+ let max;
1699
+ if (array && array.length) {
1700
+ const n = array.length;
1701
+ for (let i = 0; i < n; i += 1) {
1702
+ let value = valueGetter(array[i]);
1703
+ if (!isNil(value) && isNumber((value = +value)) && !Number.isNaN(value)) {
1704
+ if (isNil(min)) {
1705
+ min = value;
1706
+ max = value;
1707
+ }
1708
+ else {
1709
+ min = Math.min(min, value);
1710
+ max = Math.max(max, value);
1711
+ }
1712
+ }
1713
+ }
1714
+ return [min, max];
1715
+ }
1716
+ return [min, max];
1717
+ };
1718
+
1719
+ function ordinaryLeastSquares(uX, uY, uXY, uX2) {
1720
+ const delta = uX2 - uX * uX;
1721
+ const slope = Math.abs(delta) < 1e-24 ? 0 : (uXY - uX * uY) / delta;
1722
+ const intercept = uY - slope * uX;
1723
+ return [intercept, slope];
1724
+ }
1725
+ function visitPoints(data, x, y, callback) {
1726
+ let i = -1;
1727
+ let u;
1728
+ let v;
1729
+ data.forEach(d => {
1730
+ u = x(d);
1731
+ v = y(d);
1732
+ if (!isNil(u) && (u = +u) >= u && !isNil(v) && (v = +v) >= v) {
1733
+ callback(u, v, ++i);
1734
+ }
1735
+ });
1736
+ }
1737
+ function rSquared(data, x, y, uY, predict) {
1738
+ let SSE = 0;
1739
+ let SST = 0;
1740
+ visitPoints(data, x, y, (dx, dy) => {
1741
+ const sse = dy - predict(dx);
1742
+ const sst = dy - uY;
1743
+ SSE += sse * sse;
1744
+ SST += sst * sst;
1745
+ });
1746
+ return 1 - SSE / SST;
1747
+ }
1748
+ function regressionLinear(data, x = datum => datum.x, y = datum => datum.y) {
1749
+ let X = 0;
1750
+ let Y = 0;
1751
+ let XY = 0;
1752
+ let X2 = 0;
1753
+ let n = 0;
1754
+ visitPoints(data, x, y, (dx, dy) => {
1755
+ ++n;
1756
+ X += (dx - X) / n;
1757
+ Y += (dy - Y) / n;
1758
+ XY += (dx * dy - XY) / n;
1759
+ X2 += (dx * dx - X2) / n;
1760
+ });
1761
+ const coef = ordinaryLeastSquares(X, Y, XY, X2);
1762
+ const predict = (x) => coef[0] + coef[1] * x;
1763
+ return {
1764
+ coef: coef,
1765
+ predict: predict,
1766
+ rSquared: rSquared(data, x, y, Y, predict)
1767
+ };
1768
+ }
1638
1769
 
1639
1770
  class HashValue {
1640
1771
  }
@@ -3252,6 +3383,39 @@
3252
3383
  anchorY += sy * rectHeight;
3253
3384
  return { x: anchorX, y: anchorY };
3254
3385
  };
3386
+ const aabbSeparation = (a, b) => {
3387
+ return Math.max(b.x1 - a.x2, a.x1 - b.x2, b.y1 - a.y2, a.y1 - b.y2);
3388
+ };
3389
+ const obbSeparation = (a, b) => {
3390
+ const axes = [
3391
+ { x: Math.cos(a.angle), y: Math.sin(a.angle) },
3392
+ { x: -Math.sin(a.angle), y: Math.cos(a.angle) },
3393
+ { x: Math.cos(b.angle), y: Math.sin(a.angle) },
3394
+ { x: -Math.sin(b.angle), y: Math.cos(a.angle) }
3395
+ ];
3396
+ function getProjectionRange(obb, axisX, axisY) {
3397
+ const corners = obb.getRotatedCorners();
3398
+ const projections = corners.map(p => p.x * axisX + p.y * axisY);
3399
+ return { min: Math.min(...projections), max: Math.max(...projections) };
3400
+ }
3401
+ let maxDistance = 0;
3402
+ for (const axis of axes) {
3403
+ const rangeA = getProjectionRange(a, axis.x, axis.y);
3404
+ const rangeB = getProjectionRange(b, axis.x, axis.y);
3405
+ let distance;
3406
+ if (rangeA.max < rangeB.min) {
3407
+ distance = rangeB.min - rangeA.max;
3408
+ }
3409
+ else if (rangeB.max < rangeA.min) {
3410
+ distance = rangeA.min - rangeB.max;
3411
+ }
3412
+ else {
3413
+ distance = 0;
3414
+ }
3415
+ maxDistance = Math.max(maxDistance, distance);
3416
+ }
3417
+ return maxDistance;
3418
+ };
3255
3419
 
3256
3420
  function transformBoundsWithMatrix(out, bounds, matrix) {
3257
3421
  const { x1, y1, x2, y2 } = bounds;
@@ -3513,6 +3677,17 @@
3513
3677
  clone() {
3514
3678
  return new OBBBounds(this);
3515
3679
  }
3680
+ getRotatedCorners() {
3681
+ const cx = (this.x1 + this.x2) / 2;
3682
+ const cy = (this.y1 + this.y2) / 2;
3683
+ const originPoint = { x: cx, y: cy };
3684
+ return [
3685
+ rotatePoint({ x: this.x1, y: this.y1 }, this.angle, originPoint),
3686
+ rotatePoint({ x: this.x2, y: this.y1 }, this.angle, originPoint),
3687
+ rotatePoint({ x: this.x1, y: this.y2 }, this.angle, originPoint),
3688
+ rotatePoint({ x: this.x2, y: this.y2 }, this.angle, originPoint)
3689
+ ];
3690
+ }
3516
3691
  }
3517
3692
 
3518
3693
  class Matrix {
@@ -6161,6 +6336,7 @@
6161
6336
  exports.TextMeasure = TextMeasure;
6162
6337
  exports.TimeUtil = TimeUtil;
6163
6338
  exports.YEAR = YEAR;
6339
+ exports.aabbSeparation = aabbSeparation;
6164
6340
  exports.abs = abs;
6165
6341
  exports.acos = acos;
6166
6342
  exports.array = array;
@@ -6210,6 +6386,9 @@
6210
6386
  exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
6211
6387
  exports.epsilon = epsilon;
6212
6388
  exports.exponent = exponent;
6389
+ exports.extent = extent;
6390
+ exports.fakeRandom = fakeRandom;
6391
+ exports.field = field;
6213
6392
  exports.findBoundaryAngles = findBoundaryAngles;
6214
6393
  exports.findZeroOfFunction = findZeroOfFunction;
6215
6394
  exports.fixPrecision = fixPrecision;
@@ -6245,6 +6424,7 @@
6245
6424
  exports.getScrollLeft = getScrollLeft;
6246
6425
  exports.getScrollTop = getScrollTop;
6247
6426
  exports.getTimeFormatter = getTimeFormatter;
6427
+ exports.getter = getter;
6248
6428
  exports.halfPi = halfPi;
6249
6429
  exports.has = has;
6250
6430
  exports.hasParentElement = hasParentElement;
@@ -6332,6 +6512,8 @@
6332
6512
  exports.normalizeAngle = normalizeAngle;
6333
6513
  exports.normalizePadding = normalizePadding;
6334
6514
  exports.numberSpecifierReg = numberSpecifierReg;
6515
+ exports.obbSeparation = obbSeparation;
6516
+ exports.ordinaryLeastSquares = ordinaryLeastSquares;
6335
6517
  exports.pad = pad;
6336
6518
  exports.parseUint8ToImageData = parseUint8ToImageData;
6337
6519
  exports.pi = pi;
@@ -6351,9 +6533,12 @@
6351
6533
  exports.precisionAdd = precisionAdd;
6352
6534
  exports.precisionSub = precisionSub;
6353
6535
  exports.quantileSorted = quantileSorted;
6536
+ exports.rSquared = rSquared;
6354
6537
  exports.radianToDegree = radianToDegree;
6538
+ exports.randomLCG = randomLCG;
6355
6539
  exports.range = range;
6356
6540
  exports.rectInsideAnotherRect = rectInsideAnotherRect;
6541
+ exports.regressionLinear = regressionLinear;
6357
6542
  exports.rgbToHex = rgbToHex;
6358
6543
  exports.rgbToHsl = rgbToHsl;
6359
6544
  exports.rotatePoint = rotatePoint;
@@ -6366,6 +6551,7 @@
6366
6551
  exports.secondsSetterName = secondsSetterName;
6367
6552
  exports.seedRandom = seedRandom;
6368
6553
  exports.shuffleArray = shuffleArray;
6554
+ exports.simpleField = simpleField;
6369
6555
  exports.sin = sin;
6370
6556
  exports.span = span;
6371
6557
  exports.sqrt = sqrt;
@@ -6378,6 +6564,7 @@
6378
6564
  exports.toCamelCase = toCamelCase;
6379
6565
  exports.toDate = toDate;
6380
6566
  exports.toNumber = toNumber;
6567
+ exports.toPercent = toPercent;
6381
6568
  exports.toValidNumber = toValidNumber;
6382
6569
  exports.transformBounds = transformBounds;
6383
6570
  exports.transformBoundsWithMatrix = transformBoundsWithMatrix;
@@ -6408,11 +6595,13 @@
6408
6595
  exports.utcYearOffset = utcYearOffset;
6409
6596
  exports.uuid = uuid;
6410
6597
  exports.variance = variance;
6598
+ exports.visitPoints = visitPoints;
6411
6599
  exports.weightedSum = weightedSum;
6412
6600
  exports.yearCount = yearCount;
6413
6601
  exports.yearField = yearField;
6414
6602
  exports.yearFloor = yearFloor;
6415
6603
  exports.yearOffset = yearOffset;
6604
+ exports.zero = zero;
6416
6605
  exports.zeros = zeros;
6417
6606
  exports.zerosM = zerosM;
6418
6607