@visactor/vutils 0.18.1 → 0.18.2

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 (73) hide show
  1. package/cjs/fmin/bisect.d.ts +1 -0
  2. package/cjs/fmin/bisect.js +27 -0
  3. package/cjs/fmin/bisect.js.map +1 -0
  4. package/cjs/fmin/blas1.d.ts +6 -0
  5. package/cjs/fmin/blas1.js +39 -0
  6. package/cjs/fmin/blas1.js.map +1 -0
  7. package/cjs/fmin/conjugate-gradient.d.ts +5 -0
  8. package/cjs/fmin/conjugate-gradient.js +49 -0
  9. package/cjs/fmin/conjugate-gradient.js.map +1 -0
  10. package/cjs/fmin/index.d.ts +4 -0
  11. package/cjs/fmin/index.js +22 -0
  12. package/cjs/fmin/index.js.map +1 -0
  13. package/cjs/fmin/linesearch.d.ts +1 -0
  14. package/cjs/fmin/linesearch.js +33 -0
  15. package/cjs/fmin/linesearch.js.map +1 -0
  16. package/cjs/fmin/nelder-mead.d.ts +4 -0
  17. package/cjs/fmin/nelder-mead.js +70 -0
  18. package/cjs/fmin/nelder-mead.js.map +1 -0
  19. package/cjs/geo/circle-intersection.d.ts +11 -0
  20. package/cjs/geo/circle-intersection.js +132 -0
  21. package/cjs/geo/circle-intersection.js.map +1 -0
  22. package/cjs/geo/constant.d.ts +1 -0
  23. package/cjs/geo/constant.js +6 -0
  24. package/cjs/geo/constant.js.map +1 -0
  25. package/cjs/geo/index.d.ts +2 -0
  26. package/cjs/geo/index.js +2 -1
  27. package/cjs/geo/index.js.map +1 -1
  28. package/cjs/geo/interface.d.ts +24 -0
  29. package/cjs/geo/interface.js.map +1 -1
  30. package/cjs/index.d.ts +1 -0
  31. package/cjs/index.js +1 -1
  32. package/cjs/index.js.map +1 -1
  33. package/cjs/math.d.ts +1 -0
  34. package/cjs/math.js +8 -2
  35. package/cjs/math.js.map +1 -1
  36. package/dist/index.js +452 -0
  37. package/dist/index.min.js +1 -1
  38. package/es/fmin/bisect.d.ts +1 -0
  39. package/es/fmin/bisect.js +19 -0
  40. package/es/fmin/bisect.js.map +1 -0
  41. package/es/fmin/blas1.d.ts +6 -0
  42. package/es/fmin/blas1.js +30 -0
  43. package/es/fmin/blas1.js.map +1 -0
  44. package/es/fmin/conjugate-gradient.d.ts +5 -0
  45. package/es/fmin/conjugate-gradient.js +43 -0
  46. package/es/fmin/conjugate-gradient.js.map +1 -0
  47. package/es/fmin/index.d.ts +4 -0
  48. package/es/fmin/index.js +8 -0
  49. package/es/fmin/index.js.map +1 -0
  50. package/es/fmin/linesearch.d.ts +1 -0
  51. package/es/fmin/linesearch.js +27 -0
  52. package/es/fmin/linesearch.js.map +1 -0
  53. package/es/fmin/nelder-mead.d.ts +4 -0
  54. package/es/fmin/nelder-mead.js +62 -0
  55. package/es/fmin/nelder-mead.js.map +1 -0
  56. package/es/geo/circle-intersection.d.ts +11 -0
  57. package/es/geo/circle-intersection.js +124 -0
  58. package/es/geo/circle-intersection.js.map +1 -0
  59. package/es/geo/constant.d.ts +1 -0
  60. package/es/geo/constant.js +2 -0
  61. package/es/geo/constant.js.map +1 -0
  62. package/es/geo/index.d.ts +2 -0
  63. package/es/geo/index.js +4 -0
  64. package/es/geo/index.js.map +1 -1
  65. package/es/geo/interface.d.ts +24 -0
  66. package/es/geo/interface.js.map +1 -1
  67. package/es/index.d.ts +1 -0
  68. package/es/index.js +2 -0
  69. package/es/index.js.map +1 -1
  70. package/es/math.d.ts +1 -0
  71. package/es/math.js +6 -0
  72. package/es/math.js.map +1 -1
  73. package/package.json +1 -1
package/cjs/math.d.ts CHANGED
@@ -61,6 +61,7 @@ export declare function crossProductPoint(dir1: {
61
61
  x: number;
62
62
  y: number;
63
63
  }): number;
64
+ export declare function dotProduct(a: number[] | Float32Array, b: number[] | Float32Array): number;
64
65
  export declare function fuzzyEqualNumber(a: number, b: number): boolean;
65
66
  export declare function fuzzyEqualVec(a: vec2, b: vec2): boolean;
66
67
  export declare function fixPrecision(num: number, precision?: number): number;
package/cjs/math.js CHANGED
@@ -30,6 +30,12 @@ function crossProductPoint(dir1, dir2) {
30
30
  return dir1.x * dir2.y - dir1.y * dir2.x;
31
31
  }
32
32
 
33
+ function dotProduct(a, b) {
34
+ let ret = 0;
35
+ for (let i = 0; i < a.length; ++i) ret += a[i] * b[i];
36
+ return ret;
37
+ }
38
+
33
39
  function fuzzyEqualNumber(a, b) {
34
40
  return (0, exports.abs)(a - b) < exports.epsilon;
35
41
  }
@@ -57,7 +63,7 @@ function precisionSub(a, b) {
57
63
 
58
64
  Object.defineProperty(exports, "__esModule", {
59
65
  value: !0
60
- }), exports.precisionSub = exports.precisionAdd = exports.getDecimalPlaces = exports.fixPrecision = exports.fuzzyEqualVec = exports.fuzzyEqualNumber = exports.crossProductPoint = exports.crossProduct = exports.lengthFromPointToLine = exports.pointAt = exports.asin = exports.acos = exports.pow = exports.sqrt = exports.sin = exports.min = exports.max = exports.cos = exports.atan2 = exports.abs = exports.pi2 = exports.SUBDIVISION_MAX_ITERATIONS = exports.SUBDIVISION_PRECISION = exports.NEWTON_MIN_SLOPE = exports.NEWTON_ITERATIONS = exports.tau = exports.halfPi = exports.pi = exports.epsilon = void 0,
66
+ }), exports.precisionSub = exports.precisionAdd = exports.getDecimalPlaces = exports.fixPrecision = exports.fuzzyEqualVec = exports.fuzzyEqualNumber = exports.dotProduct = exports.crossProductPoint = exports.crossProduct = exports.lengthFromPointToLine = exports.pointAt = exports.asin = exports.acos = exports.pow = exports.sqrt = exports.sin = exports.min = exports.max = exports.cos = exports.atan2 = exports.abs = exports.pi2 = exports.SUBDIVISION_MAX_ITERATIONS = exports.SUBDIVISION_PRECISION = exports.NEWTON_MIN_SLOPE = exports.NEWTON_ITERATIONS = exports.tau = exports.halfPi = exports.pi = exports.epsilon = void 0,
61
67
  exports.epsilon = 1e-12, exports.pi = Math.PI, exports.halfPi = exports.pi / 2,
62
68
  exports.tau = 2 * exports.pi, exports.NEWTON_ITERATIONS = 4, exports.NEWTON_MIN_SLOPE = .001,
63
69
  exports.SUBDIVISION_PRECISION = 1e-7, exports.SUBDIVISION_MAX_ITERATIONS = 10, exports.pi2 = 2 * Math.PI,
@@ -65,7 +71,7 @@ exports.abs = Math.abs, exports.atan2 = Math.atan2, exports.cos = Math.cos, expo
65
71
  exports.min = Math.min, exports.sin = Math.sin, exports.sqrt = Math.sqrt, exports.pow = Math.pow,
66
72
  exports.acos = acos, exports.asin = asin, exports.pointAt = pointAt, exports.lengthFromPointToLine = lengthFromPointToLine,
67
73
  exports.crossProduct = crossProduct, exports.crossProductPoint = crossProductPoint,
68
- exports.fuzzyEqualNumber = fuzzyEqualNumber, exports.fuzzyEqualVec = fuzzyEqualVec,
74
+ exports.dotProduct = dotProduct, exports.fuzzyEqualNumber = fuzzyEqualNumber, exports.fuzzyEqualVec = fuzzyEqualVec,
69
75
  exports.fixPrecision = fixPrecision, exports.getDecimalPlaces = getDecimalPlaces,
70
76
  exports.precisionAdd = precisionAdd, exports.precisionSub = precisionSub;
71
77
  //# sourceMappingURL=math.js.map
package/cjs/math.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/math.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,KAAK,CAAC;AAChB,QAAA,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;AACb,QAAA,MAAM,GAAG,UAAE,GAAG,CAAC,CAAC;AAChB,QAAA,GAAG,GAAG,CAAC,GAAG,UAAE,CAAC;AACb,QAAA,iBAAiB,GAAG,CAAC,CAAC;AACtB,QAAA,gBAAgB,GAAG,KAAK,CAAC;AACzB,QAAA,qBAAqB,GAAG,SAAS,CAAC;AAClC,QAAA,0BAA0B,GAAG,EAAE,CAAC;AAChC,QAAA,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AA2BlB,QAAA,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;AACf,QAAA,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;AACnB,QAAA,GAAG,GAAG,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C,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC;AAFD,oCAEC","file":"math.js","sourcesContent":["export const epsilon = 1e-12;\nexport const pi = Math.PI;\nexport const halfPi = pi / 2;\nexport const tau = 2 * pi;\nexport const NEWTON_ITERATIONS = 4;\nexport const NEWTON_MIN_SLOPE = 0.001;\nexport const SUBDIVISION_PRECISION = 0.0000001;\nexport const SUBDIVISION_MAX_ITERATIONS = 10;\nexport const pi2 = Math.PI * 2;\n\nexport type vec2 = [number, number] | Float32Array;\nexport type vec3 = [number, number, number] | Float32Array;\nexport type vec4 = [number, number, number, number] | Float32Array;\nexport type vec8 = [number, number, number, number, number, number, number, number] | Float32Array;\nexport type mat4 =\n | [\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number\n ]\n | Float32Array;\n\nexport const abs = Math.abs;\nexport const atan2 = Math.atan2;\nexport const cos = Math.cos;\nexport const max = Math.max;\nexport const min = Math.min;\nexport const sin = Math.sin;\nexport const sqrt = Math.sqrt;\nexport const pow = Math.pow;\n\nexport function acos(x: number) {\n return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);\n}\n\nexport function asin(x: number) {\n return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);\n}\n\n/**\n * 根据比例获直线上的点\n * @param {number} x1 起始点 x\n * @param {number} y1 起始点 y\n * @param {number} x2 结束点 x\n * @param {number} y2 结束点 y\n * @param {number} t 指定比例\n * @return {object} 包含 x, y 的点\n */\nexport function pointAt(\n x1: number | null | undefined,\n y1: number | null | undefined,\n x2: number | null | undefined,\n y2: number | null | undefined,\n t: number\n): {\n x: undefined | number;\n y: undefined | number;\n} {\n let x: number | undefined;\n let y: number | undefined;\n if (typeof x1 === 'number' && typeof x2 === 'number') {\n x = (1 - t) * x1 + t * x2;\n }\n if (typeof y1 === 'number' && typeof y2 === 'number') {\n y = (1 - t) * y1 + t * y2;\n }\n return {\n x,\n y\n };\n}\n\nexport function lengthFromPointToLine(\n point: { x: number; y: number },\n point1: { x: number; y: number },\n point2: { x: number; y: number }\n): number {\n // 面积\n const dir1X = point2.x - point1.x;\n const dir1Y = point2.y - point1.y;\n const dir2X = point.x - point1.x;\n const dir2Y = point.y - point1.y;\n const s = Math.abs(dir1X * dir2Y - dir2X * dir1Y);\n const length = Math.sqrt(dir1X * dir1X + dir1Y * dir1Y);\n return s / length;\n}\n\nexport function crossProduct(dir1: vec2, dir2: vec2): number {\n return dir1[0] * dir2[1] - dir1[1] * dir2[0];\n}\n\nexport function crossProductPoint(dir1: { x: number; y: number }, dir2: { x: number; y: number }): number {\n return dir1.x * dir2.y - dir1.y * dir2.x;\n}\n\nexport function fuzzyEqualNumber(a: number, b: number): boolean {\n return abs(a - b) < epsilon;\n}\n\nexport function fuzzyEqualVec(a: vec2, b: vec2): boolean {\n return abs(a[0] - b[0]) + abs(a[1] - b[1]) < epsilon;\n}\n\nexport function fixPrecision(num: number, precision = 10) {\n return Math.round(num * precision) / precision;\n}\n\nexport function getDecimalPlaces(n: number): number {\n const dStr = n.toString().split(/[eE]/);\n const s = (dStr[0].split('.')[1] || '').length - (+dStr[1] || 0);\n return s > 0 ? s : 0;\n}\n\nexport function precisionAdd(a: number, b: number) {\n return fixPrecision(a + b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));\n}\n\nexport function precisionSub(a: number, b: number) {\n return fixPrecision(a - b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));\n}\n"]}
1
+ {"version":3,"sources":["../src/math.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,KAAK,CAAC;AAChB,QAAA,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;AACb,QAAA,MAAM,GAAG,UAAE,GAAG,CAAC,CAAC;AAChB,QAAA,GAAG,GAAG,CAAC,GAAG,UAAE,CAAC;AACb,QAAA,iBAAiB,GAAG,CAAC,CAAC;AACtB,QAAA,gBAAgB,GAAG,KAAK,CAAC;AACzB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I,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAJD,4CAIC;AAED,SAAgB,YAAY,CAAC,CAAS,EAAE,CAAS;IAC/C,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC;AAFD,oCAEC;AAED,SAAgB,YAAY,CAAC,CAAS,EAAE,CAAS;IAC/C,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC;AAFD,oCAEC","file":"math.js","sourcesContent":["export const epsilon = 1e-12;\nexport const pi = Math.PI;\nexport const halfPi = pi / 2;\nexport const tau = 2 * pi;\nexport const NEWTON_ITERATIONS = 4;\nexport const NEWTON_MIN_SLOPE = 0.001;\nexport const SUBDIVISION_PRECISION = 0.0000001;\nexport const SUBDIVISION_MAX_ITERATIONS = 10;\nexport const pi2 = Math.PI * 2;\n\nexport type vec2 = [number, number] | Float32Array;\nexport type vec3 = [number, number, number] | Float32Array;\nexport type vec4 = [number, number, number, number] | Float32Array;\nexport type vec8 = [number, number, number, number, number, number, number, number] | Float32Array;\nexport type mat4 =\n | [\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number\n ]\n | Float32Array;\n\nexport const abs = Math.abs;\nexport const atan2 = Math.atan2;\nexport const cos = Math.cos;\nexport const max = Math.max;\nexport const min = Math.min;\nexport const sin = Math.sin;\nexport const sqrt = Math.sqrt;\nexport const pow = Math.pow;\n\nexport function acos(x: number) {\n return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);\n}\n\nexport function asin(x: number) {\n return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);\n}\n\n/**\n * 根据比例获直线上的点\n * @param {number} x1 起始点 x\n * @param {number} y1 起始点 y\n * @param {number} x2 结束点 x\n * @param {number} y2 结束点 y\n * @param {number} t 指定比例\n * @return {object} 包含 x, y 的点\n */\nexport function pointAt(\n x1: number | null | undefined,\n y1: number | null | undefined,\n x2: number | null | undefined,\n y2: number | null | undefined,\n t: number\n): {\n x: undefined | number;\n y: undefined | number;\n} {\n let x: number | undefined;\n let y: number | undefined;\n if (typeof x1 === 'number' && typeof x2 === 'number') {\n x = (1 - t) * x1 + t * x2;\n }\n if (typeof y1 === 'number' && typeof y2 === 'number') {\n y = (1 - t) * y1 + t * y2;\n }\n return {\n x,\n y\n };\n}\n\nexport function lengthFromPointToLine(\n point: { x: number; y: number },\n point1: { x: number; y: number },\n point2: { x: number; y: number }\n): number {\n // 面积\n const dir1X = point2.x - point1.x;\n const dir1Y = point2.y - point1.y;\n const dir2X = point.x - point1.x;\n const dir2Y = point.y - point1.y;\n const s = Math.abs(dir1X * dir2Y - dir2X * dir1Y);\n const length = Math.sqrt(dir1X * dir1X + dir1Y * dir1Y);\n return s / length;\n}\n\nexport function crossProduct(dir1: vec2, dir2: vec2): number {\n return dir1[0] * dir2[1] - dir1[1] * dir2[0];\n}\n\nexport function crossProductPoint(dir1: { x: number; y: number }, dir2: { x: number; y: number }): number {\n return dir1.x * dir2.y - dir1.y * dir2.x;\n}\n\nexport function dotProduct(a: number[] | Float32Array, b: number[] | Float32Array): number {\n let ret = 0;\n for (let i = 0; i < a.length; ++i) {\n ret += a[i] * b[i];\n }\n return ret;\n}\n\nexport function fuzzyEqualNumber(a: number, b: number): boolean {\n return abs(a - b) < epsilon;\n}\n\nexport function fuzzyEqualVec(a: vec2, b: vec2): boolean {\n return abs(a[0] - b[0]) + abs(a[1] - b[1]) < epsilon;\n}\n\nexport function fixPrecision(num: number, precision = 10) {\n return Math.round(num * precision) / precision;\n}\n\nexport function getDecimalPlaces(n: number): number {\n const dStr = n.toString().split(/[eE]/);\n const s = (dStr[0].split('.')[1] || '').length - (+dStr[1] || 0);\n return s > 0 ? s : 0;\n}\n\nexport function precisionAdd(a: number, b: number) {\n return fixPrecision(a + b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));\n}\n\nexport function precisionSub(a: number, b: number) {\n return fixPrecision(a - b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));\n}\n"]}
package/dist/index.js CHANGED
@@ -1664,6 +1664,13 @@
1664
1664
  function crossProductPoint(dir1, dir2) {
1665
1665
  return dir1.x * dir2.y - dir1.y * dir2.x;
1666
1666
  }
1667
+ function dotProduct(a, b) {
1668
+ let ret = 0;
1669
+ for (let i = 0; i < a.length; ++i) {
1670
+ ret += a[i] * b[i];
1671
+ }
1672
+ return ret;
1673
+ }
1667
1674
  function fuzzyEqualNumber(a, b) {
1668
1675
  return abs(a - b) < epsilon;
1669
1676
  }
@@ -4784,6 +4791,163 @@
4784
4791
  return { x: lng, y: lat };
4785
4792
  }
4786
4793
 
4794
+ const SMALL = 1e-10;
4795
+
4796
+ function intersectionArea(circles, stats) {
4797
+ const intersectionPoints = getIntersectionPoints(circles);
4798
+ const innerPoints = intersectionPoints.filter(function (p) {
4799
+ return containedInCircles(p, circles);
4800
+ });
4801
+ let arcArea = 0;
4802
+ let polygonArea = 0;
4803
+ const arcs = [];
4804
+ if (innerPoints.length > 1) {
4805
+ const center = getCenter(innerPoints);
4806
+ for (let i = 0; i < innerPoints.length; ++i) {
4807
+ const p = innerPoints[i];
4808
+ p.angle = Math.atan2(p.x - center.x, p.y - center.y);
4809
+ }
4810
+ innerPoints.sort(function (a, b) {
4811
+ return b.angle - a.angle;
4812
+ });
4813
+ let p2 = innerPoints[innerPoints.length - 1];
4814
+ for (let i = 0; i < innerPoints.length; ++i) {
4815
+ const p1 = innerPoints[i];
4816
+ polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
4817
+ const midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
4818
+ let arc = null;
4819
+ for (let j = 0; j < p1.parentIndex.length; ++j) {
4820
+ if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {
4821
+ const circle = circles[p1.parentIndex[j]];
4822
+ const a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y);
4823
+ const a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);
4824
+ let angleDiff = a2 - a1;
4825
+ if (angleDiff < 0) {
4826
+ angleDiff += 2 * Math.PI;
4827
+ }
4828
+ const a = a2 - angleDiff / 2;
4829
+ let width = PointService.distancePP(midPoint, {
4830
+ x: circle.x + circle.radius * Math.sin(a),
4831
+ y: circle.y + circle.radius * Math.cos(a)
4832
+ });
4833
+ if (width > circle.radius * 2) {
4834
+ width = circle.radius * 2;
4835
+ }
4836
+ if (arc === null || arc.width > width) {
4837
+ arc = { circle: circle, width: width, p1: p1, p2: p2 };
4838
+ }
4839
+ }
4840
+ }
4841
+ if (arc !== null) {
4842
+ arcs.push(arc);
4843
+ arcArea += circleArea(arc.circle.radius, arc.width);
4844
+ p2 = p1;
4845
+ }
4846
+ }
4847
+ }
4848
+ else {
4849
+ let smallest = circles[0];
4850
+ for (let i = 1; i < circles.length; ++i) {
4851
+ if (circles[i].radius < smallest.radius) {
4852
+ smallest = circles[i];
4853
+ }
4854
+ }
4855
+ let disjoint = false;
4856
+ for (let i = 0; i < circles.length; ++i) {
4857
+ if (PointService.distancePP(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {
4858
+ disjoint = true;
4859
+ break;
4860
+ }
4861
+ }
4862
+ if (disjoint) {
4863
+ arcArea = polygonArea = 0;
4864
+ }
4865
+ else {
4866
+ arcArea = smallest.radius * smallest.radius * Math.PI;
4867
+ arcs.push({
4868
+ circle: smallest,
4869
+ p1: { x: smallest.x, y: smallest.y + smallest.radius },
4870
+ p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius },
4871
+ width: smallest.radius * 2
4872
+ });
4873
+ }
4874
+ }
4875
+ polygonArea /= 2;
4876
+ if (stats) {
4877
+ stats.area = arcArea + polygonArea;
4878
+ stats.arcArea = arcArea;
4879
+ stats.polygonArea = polygonArea;
4880
+ stats.arcs = arcs;
4881
+ stats.innerPoints = innerPoints;
4882
+ stats.intersectionPoints = intersectionPoints;
4883
+ }
4884
+ return arcArea + polygonArea;
4885
+ }
4886
+ function containedInCircles(point, circles) {
4887
+ for (let i = 0; i < circles.length; ++i) {
4888
+ if (PointService.distancePP(point, circles[i]) > circles[i].radius + SMALL) {
4889
+ return false;
4890
+ }
4891
+ }
4892
+ return true;
4893
+ }
4894
+ function getIntersectionPoints(circles) {
4895
+ const ret = [];
4896
+ for (let i = 0; i < circles.length; ++i) {
4897
+ for (let j = i + 1; j < circles.length; ++j) {
4898
+ const intersect = circleCircleIntersection(circles[i], circles[j]);
4899
+ for (let k = 0; k < intersect.length; ++k) {
4900
+ const p = intersect[k];
4901
+ p.parentIndex = [i, j];
4902
+ ret.push(p);
4903
+ }
4904
+ }
4905
+ }
4906
+ return ret;
4907
+ }
4908
+ function circleArea(r, width) {
4909
+ return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));
4910
+ }
4911
+ function circleOverlap(r1, r2, d) {
4912
+ if (d >= r1 + r2) {
4913
+ return 0;
4914
+ }
4915
+ if (d <= Math.abs(r1 - r2)) {
4916
+ return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
4917
+ }
4918
+ const w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d);
4919
+ const w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
4920
+ return circleArea(r1, w1) + circleArea(r2, w2);
4921
+ }
4922
+ function circleCircleIntersection(p1, p2) {
4923
+ const d = PointService.distancePP(p1, p2);
4924
+ const r1 = p1.radius;
4925
+ const r2 = p2.radius;
4926
+ if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {
4927
+ return [];
4928
+ }
4929
+ const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d);
4930
+ const h = Math.sqrt(r1 * r1 - a * a);
4931
+ const x0 = p1.x + (a * (p2.x - p1.x)) / d;
4932
+ const y0 = p1.y + (a * (p2.y - p1.y)) / d;
4933
+ const rx = -(p2.y - p1.y) * (h / d);
4934
+ const ry = -(p2.x - p1.x) * (h / d);
4935
+ return [
4936
+ { x: x0 + rx, y: y0 - ry },
4937
+ { x: x0 - rx, y: y0 + ry }
4938
+ ];
4939
+ }
4940
+ function getCenter(points) {
4941
+ const center = { x: 0, y: 0 };
4942
+ for (let i = 0; i < points.length; ++i) {
4943
+ center.x += points[i].x;
4944
+ center.y += points[i].y;
4945
+ }
4946
+ center.x /= points.length;
4947
+ center.y /= points.length;
4948
+ return center;
4949
+ }
4950
+
4787
4951
  class TimeUtil {
4788
4952
  static getInstance() {
4789
4953
  if (!TimeUtil.instance) {
@@ -5462,6 +5626,277 @@
5462
5626
  };
5463
5627
  }
5464
5628
 
5629
+ function zeros(x) {
5630
+ const r = new Array(x);
5631
+ for (let i = 0; i < x; ++i) {
5632
+ r[i] = 0;
5633
+ }
5634
+ return r;
5635
+ }
5636
+ function zerosM(x, y) {
5637
+ return zeros(x).map(function () {
5638
+ return zeros(y);
5639
+ });
5640
+ }
5641
+ function norm2(a) {
5642
+ return Math.sqrt(dotProduct(a, a));
5643
+ }
5644
+ function scale(ret, value, c) {
5645
+ for (let i = 0; i < value.length; ++i) {
5646
+ ret[i] = value[i] * c;
5647
+ }
5648
+ }
5649
+ function weightedSum(ret, w1, v1, w2, v2) {
5650
+ for (let j = 0; j < ret.length; ++j) {
5651
+ ret[j] = w1 * v1[j] + w2 * v2[j];
5652
+ }
5653
+ }
5654
+ function gemv(output, A, x) {
5655
+ for (let i = 0; i < output.length; ++i) {
5656
+ output[i] = dotProduct(A[i], x);
5657
+ }
5658
+ }
5659
+
5660
+ function nelderMead(f, x0, parameters) {
5661
+ parameters = parameters || {};
5662
+ const maxIterations = parameters.maxIterations || x0.length * 200;
5663
+ const nonZeroDelta = parameters.nonZeroDelta || 1.05;
5664
+ const zeroDelta = parameters.zeroDelta || 0.001;
5665
+ const minErrorDelta = parameters.minErrorDelta || 1e-6;
5666
+ const minTolerance = parameters.minErrorDelta || 1e-5;
5667
+ const rho = parameters.rho !== undefined ? parameters.rho : 1;
5668
+ const chi = parameters.chi !== undefined ? parameters.chi : 2;
5669
+ const psi = parameters.psi !== undefined ? parameters.psi : -0.5;
5670
+ const sigma = parameters.sigma !== undefined ? parameters.sigma : 0.5;
5671
+ let maxDiff;
5672
+ const N = x0.length;
5673
+ const simplex = new Array(N + 1);
5674
+ simplex[0] = x0;
5675
+ simplex[0].fx = f(x0);
5676
+ simplex[0].id = 0;
5677
+ for (let i = 0; i < N; ++i) {
5678
+ const point = x0.slice();
5679
+ point[i] = point[i] ? point[i] * nonZeroDelta : zeroDelta;
5680
+ simplex[i + 1] = point;
5681
+ simplex[i + 1].fx = f(point);
5682
+ simplex[i + 1].id = i + 1;
5683
+ }
5684
+ function updateSimplex(value) {
5685
+ for (let i = 0; i < value.length; i++) {
5686
+ simplex[N][i] = value[i];
5687
+ }
5688
+ simplex[N].fx = value.fx;
5689
+ }
5690
+ const sortOrder = function (a, b) {
5691
+ return a.fx - b.fx;
5692
+ };
5693
+ const centroid = x0.slice();
5694
+ const reflected = x0.slice();
5695
+ const contracted = x0.slice();
5696
+ const expanded = x0.slice();
5697
+ for (let iteration = 0; iteration < maxIterations; ++iteration) {
5698
+ simplex.sort(sortOrder);
5699
+ if (parameters.history) {
5700
+ const sortedSimplex = simplex.map(function (x) {
5701
+ const state = x.slice();
5702
+ state.fx = x.fx;
5703
+ state.id = x.id;
5704
+ return state;
5705
+ });
5706
+ sortedSimplex.sort(function (a, b) {
5707
+ return a.id - b.id;
5708
+ });
5709
+ parameters.history.push({ x: simplex[0].slice(), fx: simplex[0].fx, simplex: sortedSimplex });
5710
+ }
5711
+ maxDiff = 0;
5712
+ for (let i = 0; i < N; ++i) {
5713
+ maxDiff = Math.max(maxDiff, Math.abs(simplex[0][i] - simplex[1][i]));
5714
+ }
5715
+ if (Math.abs(simplex[0].fx - simplex[N].fx) < minErrorDelta && maxDiff < minTolerance) {
5716
+ break;
5717
+ }
5718
+ for (let i = 0; i < N; ++i) {
5719
+ centroid[i] = 0;
5720
+ for (let j = 0; j < N; ++j) {
5721
+ centroid[i] += simplex[j][i];
5722
+ }
5723
+ centroid[i] /= N;
5724
+ }
5725
+ const worst = simplex[N];
5726
+ weightedSum(reflected, 1 + rho, centroid, -rho, worst);
5727
+ reflected.fx = f(reflected);
5728
+ if (reflected.fx < simplex[0].fx) {
5729
+ weightedSum(expanded, 1 + chi, centroid, -chi, worst);
5730
+ expanded.fx = f(expanded);
5731
+ if (expanded.fx < reflected.fx) {
5732
+ updateSimplex(expanded);
5733
+ }
5734
+ else {
5735
+ updateSimplex(reflected);
5736
+ }
5737
+ }
5738
+ else if (reflected.fx >= simplex[N - 1].fx) {
5739
+ let shouldReduce = false;
5740
+ if (reflected.fx > worst.fx) {
5741
+ weightedSum(contracted, 1 + psi, centroid, -psi, worst);
5742
+ contracted.fx = f(contracted);
5743
+ if (contracted.fx < worst.fx) {
5744
+ updateSimplex(contracted);
5745
+ }
5746
+ else {
5747
+ shouldReduce = true;
5748
+ }
5749
+ }
5750
+ else {
5751
+ weightedSum(contracted, 1 - psi * rho, centroid, psi * rho, worst);
5752
+ contracted.fx = f(contracted);
5753
+ if (contracted.fx < reflected.fx) {
5754
+ updateSimplex(contracted);
5755
+ }
5756
+ else {
5757
+ shouldReduce = true;
5758
+ }
5759
+ }
5760
+ if (shouldReduce) {
5761
+ if (sigma >= 1) {
5762
+ break;
5763
+ }
5764
+ for (let i = 1; i < simplex.length; ++i) {
5765
+ weightedSum(simplex[i], 1 - sigma, simplex[0], sigma, simplex[i]);
5766
+ simplex[i].fx = f(simplex[i]);
5767
+ }
5768
+ }
5769
+ }
5770
+ else {
5771
+ updateSimplex(reflected);
5772
+ }
5773
+ }
5774
+ simplex.sort(sortOrder);
5775
+ return { fx: simplex[0].fx, x: simplex[0] };
5776
+ }
5777
+
5778
+ function wolfeLineSearch(f, pk, current, next, a, c1, c2) {
5779
+ const phi0 = current.fx;
5780
+ const phiPrime0 = dotProduct(current.fxprime, pk);
5781
+ let phi = phi0;
5782
+ let phi_old = phi0;
5783
+ let phiPrime = phiPrime0;
5784
+ let a0 = 0;
5785
+ a = a || 1;
5786
+ c1 = c1 || 1e-6;
5787
+ c2 = c2 || 0.1;
5788
+ function zoom(a_lo, a_high, phi_lo) {
5789
+ for (let iteration = 0; iteration < 16; ++iteration) {
5790
+ a = (a_lo + a_high) / 2;
5791
+ weightedSum(next.x, 1.0, current.x, a, pk);
5792
+ phi = next.fx = f(next.x, next.fxprime);
5793
+ phiPrime = dotProduct(next.fxprime, pk);
5794
+ if (phi > phi0 + c1 * a * phiPrime0 || phi >= phi_lo) {
5795
+ a_high = a;
5796
+ }
5797
+ else {
5798
+ if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
5799
+ return a;
5800
+ }
5801
+ if (phiPrime * (a_high - a_lo) >= 0) {
5802
+ a_high = a_lo;
5803
+ }
5804
+ a_lo = a;
5805
+ phi_lo = phi;
5806
+ }
5807
+ }
5808
+ return 0;
5809
+ }
5810
+ for (let iteration = 0; iteration < 10; ++iteration) {
5811
+ weightedSum(next.x, 1.0, current.x, a, pk);
5812
+ phi = next.fx = f(next.x, next.fxprime);
5813
+ phiPrime = dotProduct(next.fxprime, pk);
5814
+ if (phi > phi0 + c1 * a * phiPrime0 || (iteration && phi >= phi_old)) {
5815
+ return zoom(a0, a, phi_old);
5816
+ }
5817
+ if (Math.abs(phiPrime) <= -c2 * phiPrime0) {
5818
+ return a;
5819
+ }
5820
+ if (phiPrime >= 0) {
5821
+ return zoom(a, a0, phi);
5822
+ }
5823
+ phi_old = phi;
5824
+ a0 = a;
5825
+ a *= 2;
5826
+ }
5827
+ return a;
5828
+ }
5829
+
5830
+ function conjugateGradient(f, initial, params) {
5831
+ let current = { x: initial.slice(), fx: 0, fxprime: initial.slice() };
5832
+ let next = { x: initial.slice(), fx: 0, fxprime: initial.slice() };
5833
+ const yk = initial.slice();
5834
+ let temp;
5835
+ let a = 1;
5836
+ params = params || {};
5837
+ const maxIterations = params.maxIterations || initial.length * 20;
5838
+ current.fx = f(current.x, current.fxprime);
5839
+ const pk = current.fxprime.slice();
5840
+ scale(pk, current.fxprime, -1);
5841
+ for (let i = 0; i < maxIterations; ++i) {
5842
+ a = wolfeLineSearch(f, pk, current, next, a);
5843
+ if (params.history) {
5844
+ params.history.push({ x: current.x.slice(), fx: current.fx, fxprime: current.fxprime.slice(), alpha: a });
5845
+ }
5846
+ if (!a) {
5847
+ scale(pk, current.fxprime, -1);
5848
+ }
5849
+ else {
5850
+ weightedSum(yk, 1, next.fxprime, -1, current.fxprime);
5851
+ const delta_k = dotProduct(current.fxprime, current.fxprime);
5852
+ const beta_k = Math.max(0, dotProduct(yk, next.fxprime) / delta_k);
5853
+ weightedSum(pk, beta_k, pk, -1, next.fxprime);
5854
+ temp = current;
5855
+ current = next;
5856
+ next = temp;
5857
+ }
5858
+ if (norm2(current.fxprime) <= 1e-5) {
5859
+ break;
5860
+ }
5861
+ }
5862
+ if (params.history) {
5863
+ params.history.push({ x: current.x.slice(), fx: current.fx, fxprime: current.fxprime.slice(), alpha: a });
5864
+ }
5865
+ return current;
5866
+ }
5867
+
5868
+ function findZeroOfFunction(f, a, b, parameters) {
5869
+ parameters = parameters || {};
5870
+ const maxIterations = parameters.maxIterations || 100;
5871
+ const tolerance = parameters.tolerance || 1e-10;
5872
+ const fA = f(a);
5873
+ const fB = f(b);
5874
+ let delta = b - a;
5875
+ if (fA * fB > 0) {
5876
+ const logger = Logger.getInstance();
5877
+ logger.error('Initial bisect points must have opposite signs');
5878
+ return NaN;
5879
+ }
5880
+ if (fA === 0) {
5881
+ return a;
5882
+ }
5883
+ if (fB === 0) {
5884
+ return b;
5885
+ }
5886
+ for (let i = 0; i < maxIterations; ++i) {
5887
+ delta /= 2;
5888
+ const mid = a + delta;
5889
+ const fMid = f(mid);
5890
+ if (fMid * fA >= 0) {
5891
+ a = mid;
5892
+ }
5893
+ if (Math.abs(delta) < tolerance || fMid === 0) {
5894
+ return mid;
5895
+ }
5896
+ }
5897
+ return a + delta;
5898
+ }
5899
+
5465
5900
  exports.AABBBounds = AABBBounds;
5466
5901
  exports.Bounds = Bounds;
5467
5902
  exports.Color = Color;
@@ -5488,6 +5923,7 @@
5488
5923
  exports.PolarPoint = PolarPoint;
5489
5924
  exports.RGB = RGB;
5490
5925
  exports.SECOND = SECOND;
5926
+ exports.SMALL = SMALL;
5491
5927
  exports.SUBDIVISION_MAX_ITERATIONS = SUBDIVISION_MAX_ITERATIONS;
5492
5928
  exports.SUBDIVISION_PRECISION = SUBDIVISION_PRECISION;
5493
5929
  exports.TextMeasure = TextMeasure;
@@ -5501,6 +5937,9 @@
5501
5937
  exports.asin = asin;
5502
5938
  exports.atan2 = atan2;
5503
5939
  exports.bisect = bisect;
5940
+ exports.circleArea = circleArea;
5941
+ exports.circleCircleIntersection = circleCircleIntersection;
5942
+ exports.circleOverlap = circleOverlap;
5504
5943
  exports.clamp = clamp;
5505
5944
  exports.clampAngleByDegree = clampAngleByDegree;
5506
5945
  exports.clampAngleByRadian = clampAngleByRadian;
@@ -5510,7 +5949,9 @@
5510
5949
  exports.clamper = clamper;
5511
5950
  exports.clone = clone;
5512
5951
  exports.cloneDeep = cloneDeep;
5952
+ exports.conjugateGradient = conjugateGradient;
5513
5953
  exports.constant = constant;
5954
+ exports.containedInCircles = containedInCircles;
5514
5955
  exports.cos = cos;
5515
5956
  exports.crossProduct = crossProduct;
5516
5957
  exports.crossProductPoint = crossProductPoint;
@@ -5525,9 +5966,11 @@
5525
5966
  exports.degreeToRadian = degreeToRadian;
5526
5967
  exports.destination = destination;
5527
5968
  exports.deviation = deviation;
5969
+ exports.dotProduct = dotProduct;
5528
5970
  exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
5529
5971
  exports.epsilon = epsilon;
5530
5972
  exports.exponent = exponent;
5973
+ exports.findZeroOfFunction = findZeroOfFunction;
5531
5974
  exports.fixPrecision = fixPrecision;
5532
5975
  exports.flattenArray = flattenArray;
5533
5976
  exports.formatNumerals = formatNumerals;
@@ -5537,12 +5980,14 @@
5537
5980
  exports.fullYearSetterName = fullYearSetterName;
5538
5981
  exports.fuzzyEqualNumber = fuzzyEqualNumber;
5539
5982
  exports.fuzzyEqualVec = fuzzyEqualVec;
5983
+ exports.gemv = gemv;
5540
5984
  exports.generateCeil = generateCeil;
5541
5985
  exports.generateCount = generateCount;
5542
5986
  exports.generateStepInterval = generateStepInterval;
5543
5987
  exports.get = get;
5544
5988
  exports.getAABBFromPoints = getAABBFromPoints;
5545
5989
  exports.getAngleByPoint = getAngleByPoint;
5990
+ exports.getCenter = getCenter;
5546
5991
  exports.getContainerSize = getContainerSize;
5547
5992
  exports.getContextFont = getContextFont;
5548
5993
  exports.getDecimalPlaces = getDecimalPlaces;
@@ -5575,6 +6020,7 @@
5575
6020
  exports.interpolateNumberRound = interpolateNumberRound;
5576
6021
  exports.interpolateRgb = interpolateRgb;
5577
6022
  exports.interpolateString = interpolateString;
6023
+ exports.intersectionArea = intersectionArea;
5578
6024
  exports.isArray = isArray;
5579
6025
  exports.isArrayLike = isArrayLike;
5580
6026
  exports.isBase64 = isBase64;
@@ -5637,6 +6083,8 @@
5637
6083
  exports.monthGetterName = monthGetterName;
5638
6084
  exports.monthOffset = monthOffset;
5639
6085
  exports.monthSetterName = monthSetterName;
6086
+ exports.nelderMead = nelderMead;
6087
+ exports.norm2 = norm2;
5640
6088
  exports.normalTransform = normalTransform;
5641
6089
  exports.normalizePadding = normalizePadding;
5642
6090
  exports.numberSpecifierReg = numberSpecifierReg;
@@ -5664,6 +6112,7 @@
5664
6112
  exports.rectInsideAnotherRect = rectInsideAnotherRect;
5665
6113
  exports.rgbToHex = rgbToHex;
5666
6114
  exports.rgbToHsl = rgbToHsl;
6115
+ exports.scale = scale;
5667
6116
  exports.secondCount = secondCount;
5668
6117
  exports.secondField = secondField;
5669
6118
  exports.secondFloor = secondFloor;
@@ -5711,9 +6160,12 @@
5711
6160
  exports.utcYearOffset = utcYearOffset;
5712
6161
  exports.uuid = uuid;
5713
6162
  exports.variance = variance;
6163
+ exports.weightedSum = weightedSum;
5714
6164
  exports.yearCount = yearCount;
5715
6165
  exports.yearField = yearField;
5716
6166
  exports.yearFloor = yearFloor;
5717
6167
  exports.yearOffset = yearOffset;
6168
+ exports.zeros = zeros;
6169
+ exports.zerosM = zerosM;
5718
6170
 
5719
6171
  }));