@visactor/vutils 0.18.0 → 0.18.2-alpha.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/cjs/fmin/bisect.d.ts +1 -0
- package/cjs/fmin/bisect.js +20 -0
- package/cjs/fmin/bisect.js.map +1 -0
- package/cjs/fmin/blas1.d.ts +7 -0
- package/cjs/fmin/blas1.js +42 -0
- package/cjs/fmin/blas1.js.map +1 -0
- package/cjs/fmin/conjugate-gradient.d.ts +5 -0
- package/cjs/fmin/conjugate-gradient.js +49 -0
- package/cjs/fmin/conjugate-gradient.js.map +1 -0
- package/cjs/fmin/index.d.ts +4 -0
- package/cjs/fmin/index.js +22 -0
- package/cjs/fmin/index.js.map +1 -0
- package/cjs/fmin/linesearch.d.ts +1 -0
- package/cjs/fmin/linesearch.js +33 -0
- package/cjs/fmin/linesearch.js.map +1 -0
- package/cjs/fmin/nelder-mead.d.ts +4 -0
- package/cjs/fmin/nelder-mead.js +70 -0
- package/cjs/fmin/nelder-mead.js.map +1 -0
- package/cjs/geo/circle-intersection.d.ts +11 -0
- package/cjs/geo/circle-intersection.js +132 -0
- package/cjs/geo/circle-intersection.js.map +1 -0
- package/cjs/geo/constant.d.ts +1 -0
- package/cjs/geo/constant.js +6 -0
- package/cjs/geo/constant.js.map +1 -0
- package/cjs/geo/index.d.ts +2 -0
- package/cjs/geo/index.js +2 -1
- package/cjs/geo/index.js.map +1 -1
- package/cjs/geo/interface.d.ts +24 -0
- package/cjs/geo/interface.js.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/dist/index.js +450 -0
- package/dist/index.min.js +1 -1
- package/es/fmin/bisect.d.ts +1 -0
- package/es/fmin/bisect.js +14 -0
- package/es/fmin/bisect.js.map +1 -0
- package/es/fmin/blas1.d.ts +7 -0
- package/es/fmin/blas1.js +34 -0
- package/es/fmin/blas1.js.map +1 -0
- package/es/fmin/conjugate-gradient.d.ts +5 -0
- package/es/fmin/conjugate-gradient.js +41 -0
- package/es/fmin/conjugate-gradient.js.map +1 -0
- package/es/fmin/index.d.ts +4 -0
- package/es/fmin/index.js +8 -0
- package/es/fmin/index.js.map +1 -0
- package/es/fmin/linesearch.d.ts +1 -0
- package/es/fmin/linesearch.js +25 -0
- package/es/fmin/linesearch.js.map +1 -0
- package/es/fmin/nelder-mead.d.ts +4 -0
- package/es/fmin/nelder-mead.js +62 -0
- package/es/fmin/nelder-mead.js.map +1 -0
- package/es/geo/circle-intersection.d.ts +11 -0
- package/es/geo/circle-intersection.js +124 -0
- package/es/geo/circle-intersection.js.map +1 -0
- package/es/geo/constant.d.ts +1 -0
- package/es/geo/constant.js +2 -0
- package/es/geo/constant.js.map +1 -0
- package/es/geo/index.d.ts +2 -0
- package/es/geo/index.js +4 -0
- package/es/geo/index.js.map +1 -1
- package/es/geo/interface.d.ts +24 -0
- package/es/geo/interface.js.map +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -0
- package/es/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findZeroOfFunction(f: any, a: any, b: any, parameters?: any): any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function findZeroOfFunction(f, a, b, parameters) {
|
|
4
|
+
const maxIterations = (parameters = parameters || {}).maxIterations || 100, tolerance = parameters.tolerance || 1e-10, fA = f(a), fB = f(b);
|
|
5
|
+
let delta = b - a;
|
|
6
|
+
if (fA * fB > 0) throw "Initial bisect points must have opposite signs";
|
|
7
|
+
if (0 === fA) return a;
|
|
8
|
+
if (0 === fB) return b;
|
|
9
|
+
for (let i = 0; i < maxIterations; ++i) {
|
|
10
|
+
delta /= 2;
|
|
11
|
+
const mid = a + delta, fMid = f(mid);
|
|
12
|
+
if (fMid * fA >= 0 && (a = mid), Math.abs(delta) < tolerance || 0 === fMid) return mid;
|
|
13
|
+
}
|
|
14
|
+
return a + delta;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, "__esModule", {
|
|
18
|
+
value: !0
|
|
19
|
+
}), exports.findZeroOfFunction = void 0, exports.findZeroOfFunction = findZeroOfFunction;
|
|
20
|
+
//# sourceMappingURL=bisect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fmin/bisect.ts"],"names":[],"mappings":";;;AAWA,SAAgB,kBAAkB,CAAC,CAAM,EAAE,CAAM,EAAE,CAAM,EAAE,UAAgB;IACzE,UAAU,GAAG,UAAU,IAAI,EAAE,CAAC;IAC9B,MAAM,aAAa,GAAG,UAAU,CAAC,aAAa,IAAI,GAAG,CAAC;IACtD,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,IAAI,KAAK,CAAC;IAChD,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChB,IAAI,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;IAElB,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE;QACf,MAAM,gDAAgD,CAAC;KACxD;IAED,IAAI,EAAE,KAAK,CAAC,EAAE;QACZ,OAAO,CAAC,CAAC;KACV;IACD,IAAI,EAAE,KAAK,CAAC,EAAE;QACZ,OAAO,CAAC,CAAC;KACV;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,EAAE,EAAE,CAAC,EAAE;QACtC,KAAK,IAAI,CAAC,CAAC;QACX,MAAM,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAEpB,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,EAAE;YAClB,CAAC,GAAG,GAAG,CAAC;SACT;QAED,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,SAAS,IAAI,IAAI,KAAK,CAAC,EAAE;YAC7C,OAAO,GAAG,CAAC;SACZ;KACF;IACD,OAAO,CAAC,GAAG,KAAK,CAAC;AACnB,CAAC;AAjCD,gDAiCC","file":"bisect.js","sourcesContent":["/* Adapted from fmin by Ben Frederickson\n * https://github.com/benfred/fmin\n * Licensed under the BSD-3-Clause\n\n * url: https://github.com/benfred/fmin/blob/master/src/bisect.js\n * License: https://github.com/benfred/fmin/blob/master/LICENSE\n * @license\n */\n\n/** finds the zeros of a function, given two starting points (which must\n * have opposite signs */\nexport function findZeroOfFunction(f: any, a: any, b: any, parameters?: any) {\n parameters = parameters || {};\n const maxIterations = parameters.maxIterations || 100;\n const tolerance = parameters.tolerance || 1e-10;\n const fA = f(a);\n const fB = f(b);\n let delta = b - a;\n\n if (fA * fB > 0) {\n throw 'Initial bisect points must have opposite signs';\n }\n\n if (fA === 0) {\n return a;\n }\n if (fB === 0) {\n return b;\n }\n\n for (let i = 0; i < maxIterations; ++i) {\n delta /= 2;\n const mid = a + delta;\n const fMid = f(mid);\n\n if (fMid * fA >= 0) {\n a = mid;\n }\n\n if (Math.abs(delta) < tolerance || fMid === 0) {\n return mid;\n }\n }\n return a + delta;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function zeros(x: number): number[];
|
|
2
|
+
export declare function zerosM(x: number, y: number): number[][];
|
|
3
|
+
export declare function dot(a: number[], b: number[]): number;
|
|
4
|
+
export declare function norm2(a: number[]): number;
|
|
5
|
+
export declare function scale(ret: number[], value: number[], c: number): void;
|
|
6
|
+
export declare function weightedSum(ret: number[], w1: number, v1: number[], w2: number, v2: number[]): void;
|
|
7
|
+
export declare function gemv(output: number[], A: number[][], x: number[]): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function zeros(x) {
|
|
4
|
+
const r = new Array(x);
|
|
5
|
+
for (let i = 0; i < x; ++i) r[i] = 0;
|
|
6
|
+
return r;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function zerosM(x, y) {
|
|
10
|
+
return zeros(x).map((function() {
|
|
11
|
+
return zeros(y);
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function dot(a, b) {
|
|
16
|
+
let ret = 0;
|
|
17
|
+
for (let i = 0; i < a.length; ++i) ret += a[i] * b[i];
|
|
18
|
+
return ret;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function norm2(a) {
|
|
22
|
+
return Math.sqrt(dot(a, a));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function scale(ret, value, c) {
|
|
26
|
+
for (let i = 0; i < value.length; ++i) ret[i] = value[i] * c;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function weightedSum(ret, w1, v1, w2, v2) {
|
|
30
|
+
for (let j = 0; j < ret.length; ++j) ret[j] = w1 * v1[j] + w2 * v2[j];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function gemv(output, A, x) {
|
|
34
|
+
for (let i = 0; i < output.length; ++i) output[i] = dot(A[i], x);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Object.defineProperty(exports, "__esModule", {
|
|
38
|
+
value: !0
|
|
39
|
+
}), exports.gemv = exports.weightedSum = exports.scale = exports.norm2 = exports.dot = exports.zerosM = exports.zeros = void 0,
|
|
40
|
+
exports.zeros = zeros, exports.zerosM = zerosM, exports.dot = dot, exports.norm2 = norm2,
|
|
41
|
+
exports.scale = scale, exports.weightedSum = weightedSum, exports.gemv = gemv;
|
|
42
|
+
//# sourceMappingURL=blas1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fmin/blas1.ts"],"names":[],"mappings":";;;AAWA,SAAgB,KAAK,CAAC,CAAS;IAC7B,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,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AC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;KAClC;AACH,CAAC;AAJD,kCAIC;AAED,SAAgB,IAAI,CAAC,MAAgB,EAAE,CAAa,EAAE,CAAW;IAC/D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACtC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KAC1B;AACH,CAAC;AAJD,oBAIC","file":"blas1.js","sourcesContent":["/* Adapted from fmin by Ben Frederickson\n * https://github.com/benfred/fmin\n * Licensed under the BSD-3-Clause\n\n * url: https://github.com/benfred/fmin/blob/master/src/blas1.js\n * License: https://github.com/benfred/fmin/blob/master/LICENSE\n * @license\n */\n\n// need some basic operations on vectors, rather than adding a dependency,\n// just define here\nexport function zeros(x: number): number[] {\n const r = new Array(x);\n for (let i = 0; i < x; ++i) {\n r[i] = 0;\n }\n return r;\n}\nexport function zerosM(x: number, y: number) {\n return zeros(x).map(function () {\n return zeros(y);\n });\n}\n\nexport function dot(a: number[], b: 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 norm2(a: number[]) {\n return Math.sqrt(dot(a, a));\n}\n\nexport function scale(ret: number[], value: number[], c: number) {\n for (let i = 0; i < value.length; ++i) {\n ret[i] = value[i] * c;\n }\n}\n\nexport function weightedSum(ret: number[], w1: number, v1: number[], w2: number, v2: number[]) {\n for (let j = 0; j < ret.length; ++j) {\n ret[j] = w1 * v1[j] + w2 * v2[j];\n }\n}\n\nexport function gemv(output: number[], A: number[][], x: number[]) {\n for (let i = 0; i < output.length; ++i) {\n output[i] = dot(A[i], x);\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.conjugateGradient = void 0;
|
|
6
|
+
|
|
7
|
+
const blas1_1 = require("./blas1"), linesearch_1 = require("./linesearch");
|
|
8
|
+
|
|
9
|
+
function conjugateGradient(f, initial, params) {
|
|
10
|
+
let current = {
|
|
11
|
+
x: initial.slice(),
|
|
12
|
+
fx: 0,
|
|
13
|
+
fxprime: initial.slice()
|
|
14
|
+
}, next = {
|
|
15
|
+
x: initial.slice(),
|
|
16
|
+
fx: 0,
|
|
17
|
+
fxprime: initial.slice()
|
|
18
|
+
};
|
|
19
|
+
const yk = initial.slice();
|
|
20
|
+
let temp, a = 1;
|
|
21
|
+
const maxIterations = (params = params || {}).maxIterations || 20 * initial.length;
|
|
22
|
+
current.fx = f(current.x, current.fxprime);
|
|
23
|
+
const pk = current.fxprime.slice();
|
|
24
|
+
(0, blas1_1.scale)(pk, current.fxprime, -1);
|
|
25
|
+
for (let i = 0; i < maxIterations; ++i) {
|
|
26
|
+
if (a = (0, linesearch_1.wolfeLineSearch)(f, pk, current, next, a), params.history && params.history.push({
|
|
27
|
+
x: current.x.slice(),
|
|
28
|
+
fx: current.fx,
|
|
29
|
+
fxprime: current.fxprime.slice(),
|
|
30
|
+
alpha: a
|
|
31
|
+
}), a) {
|
|
32
|
+
(0, blas1_1.weightedSum)(yk, 1, next.fxprime, -1, current.fxprime);
|
|
33
|
+
const delta_k = (0, blas1_1.dot)(current.fxprime, current.fxprime), beta_k = Math.max(0, (0,
|
|
34
|
+
blas1_1.dot)(yk, next.fxprime) / delta_k);
|
|
35
|
+
(0, blas1_1.weightedSum)(pk, beta_k, pk, -1, next.fxprime), temp = current, current = next,
|
|
36
|
+
next = temp;
|
|
37
|
+
} else (0, blas1_1.scale)(pk, current.fxprime, -1);
|
|
38
|
+
if ((0, blas1_1.norm2)(current.fxprime) <= 1e-5) break;
|
|
39
|
+
}
|
|
40
|
+
return params.history && params.history.push({
|
|
41
|
+
x: current.x.slice(),
|
|
42
|
+
fx: current.fx,
|
|
43
|
+
fxprime: current.fxprime.slice(),
|
|
44
|
+
alpha: a
|
|
45
|
+
}), current;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.conjugateGradient = conjugateGradient;
|
|
49
|
+
//# sourceMappingURL=conjugate-gradient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fmin/conjugate-gradient.ts"],"names":[],"mappings":";;;AASA,mCAA+D;AAC/D,6CAA+C;AAE/C,SAAgB,iBAAiB,CAAC,CAAM,EAAE,OAAY,EAAE,MAAW;IAGjE,IAAI,OAAO,GAAG,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IACtE,IAAI,IAAI,GAAG,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IACnE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAC3B,IAAI,IAAI,CAAC;IACT,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;IACtB,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC;IAElE,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACnC,IAAA,aAAK,EAAC,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAE/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAA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ClB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;KAC3G;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AApDD,8CAoDC","file":"conjugate-gradient.js","sourcesContent":["/* Adapted from fmin by Ben Frederickson\n * https://github.com/benfred/fmin\n * Licensed under the BSD-3-Clause\n\n * url: https://github.com/benfred/fmin/blob/master/src/conjugateGradient.js\n * License: https://github.com/benfred/fmin/blob/master/LICENSE\n * @license\n */\n\nimport { dot, norm2, scale, weightedSum, gemv } from './blas1';\nimport { wolfeLineSearch } from './linesearch';\n\nexport function conjugateGradient(f: any, initial: any, params: any) {\n // allocate all memory up front here, keep out of the loop for perfomance\n // reasons\n let current = { x: initial.slice(), fx: 0, fxprime: initial.slice() };\n let next = { x: initial.slice(), fx: 0, fxprime: initial.slice() };\n const yk = initial.slice();\n let temp;\n let a = 1;\n\n params = params || {};\n const maxIterations = params.maxIterations || initial.length * 20;\n\n current.fx = f(current.x, current.fxprime);\n const pk = current.fxprime.slice();\n scale(pk, current.fxprime, -1);\n\n for (let i = 0; i < maxIterations; ++i) {\n a = wolfeLineSearch(f, pk, current, next, a);\n\n // todo: history in wrong spot?\n if (params.history) {\n params.history.push({ x: current.x.slice(), fx: current.fx, fxprime: current.fxprime.slice(), alpha: a });\n }\n\n if (!a) {\n // faiiled to find point that satifies wolfe conditions.\n // reset direction for next iteration\n scale(pk, current.fxprime, -1);\n } else {\n // update direction using Polak–Ribiere CG method\n weightedSum(yk, 1, next.fxprime, -1, current.fxprime);\n\n const delta_k = dot(current.fxprime, current.fxprime);\n const beta_k = Math.max(0, dot(yk, next.fxprime) / delta_k);\n\n weightedSum(pk, beta_k, pk, -1, next.fxprime);\n\n temp = current;\n current = next;\n next = temp;\n }\n\n if (norm2(current.fxprime) <= 1e-5) {\n break;\n }\n }\n\n if (params.history) {\n params.history.push({ x: current.x.slice(), fx: current.fx, fxprime: current.fxprime.slice(), alpha: a });\n }\n\n return current;\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4
|
+
void 0 === k2 && (k2 = k);
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
get: function() {
|
|
9
|
+
return m[k];
|
|
10
|
+
}
|
|
11
|
+
}), Object.defineProperty(o, k2, desc);
|
|
12
|
+
} : function(o, m, k, k2) {
|
|
13
|
+
void 0 === k2 && (k2 = k), o[k2] = m[k];
|
|
14
|
+
}), __exportStar = this && this.__exportStar || function(m, exports) {
|
|
15
|
+
for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(exports, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), __exportStar(require("./blas1"), exports), __exportStar(require("./nelder-mead"), exports),
|
|
21
|
+
__exportStar(require("./conjugate-gradient"), exports), __exportStar(require("./bisect"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fmin/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B;AAC9B,uDAAqC;AACrC,2CAAyB","file":"index.js","sourcesContent":["export * from './blas1';\nexport * from './nelder-mead';\nexport * from './conjugate-gradient';\nexport * from './bisect';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wolfeLineSearch(f: any, pk: number[], current: any, next: any, a: number, c1?: number, c2?: number): number;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.wolfeLineSearch = void 0;
|
|
6
|
+
|
|
7
|
+
const blas1_1 = require("./blas1");
|
|
8
|
+
|
|
9
|
+
function wolfeLineSearch(f, pk, current, next, a, c1, c2) {
|
|
10
|
+
const phi0 = current.fx, phiPrime0 = (0, blas1_1.dot)(current.fxprime, pk);
|
|
11
|
+
let phi = phi0, phi_old = phi0, phiPrime = phiPrime0, a0 = 0;
|
|
12
|
+
function zoom(a_lo, a_high, phi_lo) {
|
|
13
|
+
for (let iteration = 0; iteration < 16; ++iteration) if (a = (a_lo + a_high) / 2,
|
|
14
|
+
(0, blas1_1.weightedSum)(next.x, 1, current.x, a, pk), phi = next.fx = f(next.x, next.fxprime),
|
|
15
|
+
phiPrime = (0, blas1_1.dot)(next.fxprime, pk), phi > phi0 + c1 * a * phiPrime0 || phi >= phi_lo) a_high = a; else {
|
|
16
|
+
if (Math.abs(phiPrime) <= -c2 * phiPrime0) return a;
|
|
17
|
+
phiPrime * (a_high - a_lo) >= 0 && (a_high = a_lo), a_lo = a, phi_lo = phi;
|
|
18
|
+
}
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
a = a || 1, c1 = c1 || 1e-6, c2 = c2 || .1;
|
|
22
|
+
for (let iteration = 0; iteration < 10; ++iteration) {
|
|
23
|
+
if ((0, blas1_1.weightedSum)(next.x, 1, current.x, a, pk), phi = next.fx = f(next.x, next.fxprime),
|
|
24
|
+
phiPrime = (0, blas1_1.dot)(next.fxprime, pk), phi > phi0 + c1 * a * phiPrime0 || iteration && phi >= phi_old) return zoom(a0, a, phi_old);
|
|
25
|
+
if (Math.abs(phiPrime) <= -c2 * phiPrime0) return a;
|
|
26
|
+
if (phiPrime >= 0) return zoom(a, a0, phi);
|
|
27
|
+
phi_old = phi, a0 = a, a *= 2;
|
|
28
|
+
}
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.wolfeLineSearch = wolfeLineSearch;
|
|
33
|
+
//# sourceMappingURL=linesearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fmin/linesearch.ts"],"names":[],"mappings":";;;AASA,mCAA2C;AAS3C,SAAgB,eAAe,CAAC,CAAM,EAAE,EAAY,EAAE,OAAY,EAAE,IAAS,EAAE,CAAS,EAAE,EAAW,EAAE,EAAW;IAChH,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC;IACxB,MAAM,SAAS,GAAG,IAAA,WAAG,EAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC3C,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,QAAQ,GAAG,SAAS,CAAC;IACzB,IAAI,EAAE,GAAG,CAAC,CAAC;IAEX,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACX,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC;IAChB,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC;IAEf,SAAS,IAAI,CAAC,IAAY,EAAE,MAAc,EAAE,MAAc;QACxD,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE;YACnD,CAAC,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YACxB,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3C,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACxC,QAAQ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V;QAED,IAAI,QAAQ,IAAI,CAAC,EAAE;YACjB,OAAO,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;SACzB;QAED,OAAO,GAAG,GAAG,CAAC;QACd,EAAE,GAAG,CAAC,CAAC;QACP,CAAC,IAAI,CAAC,CAAC;KACR;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AA5DD,0CA4DC","file":"linesearch.js","sourcesContent":["/* Adapted from fmin by Ben Frederickson\n * https://github.com/benfred/fmin\n * Licensed under the BSD-3-Clause\n\n * url: https://github.com/benfred/fmin/blob/master/src/linesearch.js\n * License: https://github.com/benfred/fmin/blob/master/LICENSE\n * @license\n */\n\nimport { dot, weightedSum } from './blas1';\n\n/// searches along line 'pk' for a point that satifies the wolfe conditions\n/// See 'Numerical Optimization' by Nocedal and Wright p59-60\n/// f : objective function\n/// pk : search direction\n/// current: object containing current gradient/loss\n/// next: output: contains next gradient/loss\n/// returns a: step size taken\nexport function wolfeLineSearch(f: any, pk: number[], current: any, next: any, a: number, c1?: number, c2?: number) {\n const phi0 = current.fx;\n const phiPrime0 = dot(current.fxprime, pk);\n let phi = phi0;\n let phi_old = phi0;\n let phiPrime = phiPrime0;\n let a0 = 0;\n\n a = a || 1;\n c1 = c1 || 1e-6;\n c2 = c2 || 0.1;\n\n function zoom(a_lo: number, a_high: number, phi_lo: number) {\n for (let iteration = 0; iteration < 16; ++iteration) {\n a = (a_lo + a_high) / 2;\n weightedSum(next.x, 1.0, current.x, a, pk);\n phi = next.fx = f(next.x, next.fxprime);\n phiPrime = dot(next.fxprime, pk);\n\n if (phi > phi0 + c1 * a * phiPrime0 || phi >= phi_lo) {\n a_high = a;\n } else {\n if (Math.abs(phiPrime) <= -c2 * phiPrime0) {\n return a;\n }\n\n if (phiPrime * (a_high - a_lo) >= 0) {\n a_high = a_lo;\n }\n\n a_lo = a;\n phi_lo = phi;\n }\n }\n\n return 0;\n }\n\n for (let iteration = 0; iteration < 10; ++iteration) {\n weightedSum(next.x, 1.0, current.x, a, pk);\n phi = next.fx = f(next.x, next.fxprime);\n phiPrime = dot(next.fxprime, pk);\n if (phi > phi0 + c1 * a * phiPrime0 || (iteration && phi >= phi_old)) {\n return zoom(a0, a, phi_old);\n }\n\n if (Math.abs(phiPrime) <= -c2 * phiPrime0) {\n return a;\n }\n\n if (phiPrime >= 0) {\n return zoom(a, a0, phi);\n }\n\n phi_old = phi;\n a0 = a;\n a *= 2;\n }\n\n return a;\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.nelderMead = void 0;
|
|
6
|
+
|
|
7
|
+
const blas1_1 = require("./blas1");
|
|
8
|
+
|
|
9
|
+
function nelderMead(f, x0, parameters) {
|
|
10
|
+
const maxIterations = (parameters = parameters || {}).maxIterations || 200 * x0.length, nonZeroDelta = parameters.nonZeroDelta || 1.05, zeroDelta = parameters.zeroDelta || .001, minErrorDelta = parameters.minErrorDelta || 1e-6, minTolerance = parameters.minErrorDelta || 1e-5, rho = void 0 !== parameters.rho ? parameters.rho : 1, chi = void 0 !== parameters.chi ? parameters.chi : 2, psi = void 0 !== parameters.psi ? parameters.psi : -.5, sigma = void 0 !== parameters.sigma ? parameters.sigma : .5;
|
|
11
|
+
let maxDiff;
|
|
12
|
+
const N = x0.length, simplex = new Array(N + 1);
|
|
13
|
+
simplex[0] = x0, simplex[0].fx = f(x0), simplex[0].id = 0;
|
|
14
|
+
for (let i = 0; i < N; ++i) {
|
|
15
|
+
const point = x0.slice();
|
|
16
|
+
point[i] = point[i] ? point[i] * nonZeroDelta : zeroDelta, simplex[i + 1] = point,
|
|
17
|
+
simplex[i + 1].fx = f(point), simplex[i + 1].id = i + 1;
|
|
18
|
+
}
|
|
19
|
+
function updateSimplex(value) {
|
|
20
|
+
for (let i = 0; i < value.length; i++) simplex[N][i] = value[i];
|
|
21
|
+
simplex[N].fx = value.fx;
|
|
22
|
+
}
|
|
23
|
+
const sortOrder = function(a, b) {
|
|
24
|
+
return a.fx - b.fx;
|
|
25
|
+
}, centroid = x0.slice(), reflected = x0.slice(), contracted = x0.slice(), expanded = x0.slice();
|
|
26
|
+
for (let iteration = 0; iteration < maxIterations; ++iteration) {
|
|
27
|
+
if (simplex.sort(sortOrder), parameters.history) {
|
|
28
|
+
const sortedSimplex = simplex.map((function(x) {
|
|
29
|
+
const state = x.slice();
|
|
30
|
+
return state.fx = x.fx, state.id = x.id, state;
|
|
31
|
+
}));
|
|
32
|
+
sortedSimplex.sort((function(a, b) {
|
|
33
|
+
return a.id - b.id;
|
|
34
|
+
})), parameters.history.push({
|
|
35
|
+
x: simplex[0].slice(),
|
|
36
|
+
fx: simplex[0].fx,
|
|
37
|
+
simplex: sortedSimplex
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
maxDiff = 0;
|
|
41
|
+
for (let i = 0; i < N; ++i) maxDiff = Math.max(maxDiff, Math.abs(simplex[0][i] - simplex[1][i]));
|
|
42
|
+
if (Math.abs(simplex[0].fx - simplex[N].fx) < minErrorDelta && maxDiff < minTolerance) break;
|
|
43
|
+
for (let i = 0; i < N; ++i) {
|
|
44
|
+
centroid[i] = 0;
|
|
45
|
+
for (let j = 0; j < N; ++j) centroid[i] += simplex[j][i];
|
|
46
|
+
centroid[i] /= N;
|
|
47
|
+
}
|
|
48
|
+
const worst = simplex[N];
|
|
49
|
+
if ((0, blas1_1.weightedSum)(reflected, 1 + rho, centroid, -rho, worst), reflected.fx = f(reflected),
|
|
50
|
+
reflected.fx < simplex[0].fx) (0, blas1_1.weightedSum)(expanded, 1 + chi, centroid, -chi, worst),
|
|
51
|
+
expanded.fx = f(expanded), expanded.fx < reflected.fx ? updateSimplex(expanded) : updateSimplex(reflected); else if (reflected.fx >= simplex[N - 1].fx) {
|
|
52
|
+
let shouldReduce = !1;
|
|
53
|
+
if (reflected.fx > worst.fx ? ((0, blas1_1.weightedSum)(contracted, 1 + psi, centroid, -psi, worst),
|
|
54
|
+
contracted.fx = f(contracted), contracted.fx < worst.fx ? updateSimplex(contracted) : shouldReduce = !0) : ((0,
|
|
55
|
+
blas1_1.weightedSum)(contracted, 1 - psi * rho, centroid, psi * rho, worst), contracted.fx = f(contracted),
|
|
56
|
+
contracted.fx < reflected.fx ? updateSimplex(contracted) : shouldReduce = !0), shouldReduce) {
|
|
57
|
+
if (sigma >= 1) break;
|
|
58
|
+
for (let i = 1; i < simplex.length; ++i) (0, blas1_1.weightedSum)(simplex[i], 1 - sigma, simplex[0], sigma, simplex[i]),
|
|
59
|
+
simplex[i].fx = f(simplex[i]);
|
|
60
|
+
}
|
|
61
|
+
} else updateSimplex(reflected);
|
|
62
|
+
}
|
|
63
|
+
return simplex.sort(sortOrder), {
|
|
64
|
+
fx: simplex[0].fx,
|
|
65
|
+
x: simplex[0]
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.nelderMead = nelderMead;
|
|
70
|
+
//# sourceMappingURL=nelder-mead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fmin/nelder-mead.ts"],"names":[],"mappings":";;;AASA,mCAAsC;AAGtC,SAAgB,UAAU,CAAC,CAAM,EAAE,EAAO,EAAE,UAAe;IACzD,UAAU,GAAG,UAAU,IAAI,EAAE,CAAC;IAE9B,MAAM,aAAa,GAAG,UAAU,CAAC,aAAa,IAAI,EAAE,CAAC,MAAM,GAAG,GAAG,CAAC;IAClE,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,IAAI,IAAI,CAAC;IACrD,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,IAAI,KAAK,CAAC;IAChD,MAAM,aAAa,GAAG,UAAU,CAAC,aAAa,IAAI,IAAI,CAAC;IACvD,MAAM,YAAY,GAAG,UAAU,CAAC,aAAa,IAAI,IAAI,CAAC;IACtD,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG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,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;gBAC9B,IAAI,UAAU,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,EAAE;oBAChC,aAAa,CAAC,UAAU,CAAC,CAAC;iBAC3B;qBAAM;oBACL,YAAY,GAAG,IAAI,CAAC;iBACrB;aACF;YAED,IAAI,YAAY,EAAE;gBAEhB,IAAI,KAAK,IAAI,CAAC,EAAE;oBACd,MAAM;iBACP;gBAGD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;oBACvC,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;oBAClE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;iBAC/B;aACF;SACF;aAAM;YACL,aAAa,CAAC,SAAS,CAAC,CAAC;SAC1B;KACF;IAED,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxB,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9C,CAAC;AA9ID,gCA8IC","file":"nelder-mead.js","sourcesContent":["/* Adapted from fmin by Ben Frederickson\n * https://github.com/benfred/fmin\n * Licensed under the BSD-3-Clause\n\n * url: https://github.com/benfred/fmin/blob/master/src/nelderMead.js\n * License: https://github.com/benfred/fmin/blob/master/LICENSE\n * @license\n */\n\nimport { weightedSum } from './blas1';\n\n/** minimizes a function using the downhill simplex method */\nexport function nelderMead(f: any, x0: any, parameters: any) {\n parameters = parameters || {};\n\n const maxIterations = parameters.maxIterations || x0.length * 200;\n const nonZeroDelta = parameters.nonZeroDelta || 1.05;\n const zeroDelta = parameters.zeroDelta || 0.001;\n const minErrorDelta = parameters.minErrorDelta || 1e-6;\n const minTolerance = parameters.minErrorDelta || 1e-5;\n const rho = parameters.rho !== undefined ? parameters.rho : 1;\n const chi = parameters.chi !== undefined ? parameters.chi : 2;\n const psi = parameters.psi !== undefined ? parameters.psi : -0.5;\n const sigma = parameters.sigma !== undefined ? parameters.sigma : 0.5;\n let maxDiff;\n\n // initialize simplex.\n const N = x0.length;\n const simplex = new Array(N + 1);\n simplex[0] = x0;\n simplex[0].fx = f(x0);\n simplex[0].id = 0;\n for (let i = 0; i < N; ++i) {\n const point = x0.slice();\n point[i] = point[i] ? point[i] * nonZeroDelta : zeroDelta;\n simplex[i + 1] = point;\n simplex[i + 1].fx = f(point);\n simplex[i + 1].id = i + 1;\n }\n\n function updateSimplex(value: any) {\n for (let i = 0; i < value.length; i++) {\n simplex[N][i] = value[i];\n }\n simplex[N].fx = value.fx;\n }\n\n const sortOrder = function (a: any, b: any) {\n return a.fx - b.fx;\n };\n\n const centroid = x0.slice();\n const reflected = x0.slice();\n const contracted = x0.slice();\n const expanded = x0.slice();\n\n for (let iteration = 0; iteration < maxIterations; ++iteration) {\n simplex.sort(sortOrder);\n\n if (parameters.history) {\n // copy the simplex (since later iterations will mutate) and\n // sort it to have a consistent order between iterations\n const sortedSimplex = simplex.map(function (x) {\n const state = x.slice();\n state.fx = x.fx;\n state.id = x.id;\n return state;\n });\n sortedSimplex.sort(function (a, b) {\n return a.id - b.id;\n });\n\n parameters.history.push({ x: simplex[0].slice(), fx: simplex[0].fx, simplex: sortedSimplex });\n }\n\n maxDiff = 0;\n for (let i = 0; i < N; ++i) {\n maxDiff = Math.max(maxDiff, Math.abs(simplex[0][i] - simplex[1][i]));\n }\n\n if (Math.abs(simplex[0].fx - simplex[N].fx) < minErrorDelta && maxDiff < minTolerance) {\n break;\n }\n\n // compute the centroid of all but the worst point in the simplex\n for (let i = 0; i < N; ++i) {\n centroid[i] = 0;\n for (let j = 0; j < N; ++j) {\n centroid[i] += simplex[j][i];\n }\n centroid[i] /= N;\n }\n\n // reflect the worst point past the centroid and compute loss at reflected\n // point\n const worst = simplex[N];\n weightedSum(reflected, 1 + rho, centroid, -rho, worst);\n reflected.fx = f(reflected);\n\n // if the reflected point is the best seen, then possibly expand\n if (reflected.fx < simplex[0].fx) {\n weightedSum(expanded, 1 + chi, centroid, -chi, worst);\n expanded.fx = f(expanded);\n if (expanded.fx < reflected.fx) {\n updateSimplex(expanded);\n } else {\n updateSimplex(reflected);\n }\n }\n\n // if the reflected point is worse than the second worst, we need to\n // contract\n else if (reflected.fx >= simplex[N - 1].fx) {\n let shouldReduce = false;\n\n if (reflected.fx > worst.fx) {\n // do an inside contraction\n weightedSum(contracted, 1 + psi, centroid, -psi, worst);\n contracted.fx = f(contracted);\n if (contracted.fx < worst.fx) {\n updateSimplex(contracted);\n } else {\n shouldReduce = true;\n }\n } else {\n // do an outside contraction\n weightedSum(contracted, 1 - psi * rho, centroid, psi * rho, worst);\n contracted.fx = f(contracted);\n if (contracted.fx < reflected.fx) {\n updateSimplex(contracted);\n } else {\n shouldReduce = true;\n }\n }\n\n if (shouldReduce) {\n // if we don't contract here, we're done\n if (sigma >= 1) {\n break;\n }\n\n // do a reduction\n for (let i = 1; i < simplex.length; ++i) {\n weightedSum(simplex[i], 1 - sigma, simplex[0], sigma, simplex[i]);\n simplex[i].fx = f(simplex[i]);\n }\n }\n } else {\n updateSimplex(reflected);\n }\n }\n\n simplex.sort(sortOrder);\n return { fx: simplex[0].fx, x: simplex[0] };\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IPointLike } from '../data-structure';
|
|
2
|
+
import type { ICircle, IIntersectPoint, IOverlapAreaStats } from './interface';
|
|
3
|
+
export declare function intersectionArea(circles: ICircle[], stats?: IOverlapAreaStats): number;
|
|
4
|
+
export declare function containedInCircles(point: IPointLike, circles: ICircle[]): boolean;
|
|
5
|
+
export declare function circleArea(r: number, width: number): number;
|
|
6
|
+
export declare function circleOverlap(r1: number, r2: number, d: number): number;
|
|
7
|
+
export declare function circleCircleIntersection(p1: ICircle, p2: ICircle): IIntersectPoint[];
|
|
8
|
+
export declare function getCenter(points: IPointLike[]): {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.getCenter = exports.circleCircleIntersection = exports.circleOverlap = exports.circleArea = exports.containedInCircles = exports.intersectionArea = void 0;
|
|
6
|
+
|
|
7
|
+
const data_structure_1 = require("../data-structure"), constant_1 = require("./constant");
|
|
8
|
+
|
|
9
|
+
function intersectionArea(circles, stats) {
|
|
10
|
+
const intersectionPoints = getIntersectionPoints(circles), innerPoints = intersectionPoints.filter((function(p) {
|
|
11
|
+
return containedInCircles(p, circles);
|
|
12
|
+
}));
|
|
13
|
+
let arcArea = 0, polygonArea = 0;
|
|
14
|
+
const arcs = [];
|
|
15
|
+
if (innerPoints.length > 1) {
|
|
16
|
+
const center = getCenter(innerPoints);
|
|
17
|
+
for (let i = 0; i < innerPoints.length; ++i) {
|
|
18
|
+
const p = innerPoints[i];
|
|
19
|
+
p.angle = Math.atan2(p.x - center.x, p.y - center.y);
|
|
20
|
+
}
|
|
21
|
+
innerPoints.sort((function(a, b) {
|
|
22
|
+
return b.angle - a.angle;
|
|
23
|
+
}));
|
|
24
|
+
let p2 = innerPoints[innerPoints.length - 1];
|
|
25
|
+
for (let i = 0; i < innerPoints.length; ++i) {
|
|
26
|
+
const p1 = innerPoints[i];
|
|
27
|
+
polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
|
|
28
|
+
const midPoint = {
|
|
29
|
+
x: (p1.x + p2.x) / 2,
|
|
30
|
+
y: (p1.y + p2.y) / 2
|
|
31
|
+
};
|
|
32
|
+
let arc = null;
|
|
33
|
+
for (let j = 0; j < p1.parentIndex.length; ++j) if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {
|
|
34
|
+
const circle = circles[p1.parentIndex[j]], a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y), a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);
|
|
35
|
+
let angleDiff = a2 - a1;
|
|
36
|
+
angleDiff < 0 && (angleDiff += 2 * Math.PI);
|
|
37
|
+
const a = a2 - angleDiff / 2;
|
|
38
|
+
let width = data_structure_1.PointService.distancePP(midPoint, {
|
|
39
|
+
x: circle.x + circle.radius * Math.sin(a),
|
|
40
|
+
y: circle.y + circle.radius * Math.cos(a)
|
|
41
|
+
});
|
|
42
|
+
width > 2 * circle.radius && (width = 2 * circle.radius), (null === arc || arc.width > width) && (arc = {
|
|
43
|
+
circle: circle,
|
|
44
|
+
width: width,
|
|
45
|
+
p1: p1,
|
|
46
|
+
p2: p2
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
null !== arc && (arcs.push(arc), arcArea += circleArea(arc.circle.radius, arc.width),
|
|
50
|
+
p2 = p1);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
let smallest = circles[0];
|
|
54
|
+
for (let i = 1; i < circles.length; ++i) circles[i].radius < smallest.radius && (smallest = circles[i]);
|
|
55
|
+
let disjoint = !1;
|
|
56
|
+
for (let i = 0; i < circles.length; ++i) if (data_structure_1.PointService.distancePP(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {
|
|
57
|
+
disjoint = !0;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
disjoint ? arcArea = polygonArea = 0 : (arcArea = smallest.radius * smallest.radius * Math.PI,
|
|
61
|
+
arcs.push({
|
|
62
|
+
circle: smallest,
|
|
63
|
+
p1: {
|
|
64
|
+
x: smallest.x,
|
|
65
|
+
y: smallest.y + smallest.radius
|
|
66
|
+
},
|
|
67
|
+
p2: {
|
|
68
|
+
x: smallest.x - constant_1.SMALL,
|
|
69
|
+
y: smallest.y + smallest.radius
|
|
70
|
+
},
|
|
71
|
+
width: 2 * smallest.radius
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
return polygonArea /= 2, stats && (stats.area = arcArea + polygonArea, stats.arcArea = arcArea,
|
|
75
|
+
stats.polygonArea = polygonArea, stats.arcs = arcs, stats.innerPoints = innerPoints,
|
|
76
|
+
stats.intersectionPoints = intersectionPoints), arcArea + polygonArea;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function containedInCircles(point, circles) {
|
|
80
|
+
for (let i = 0; i < circles.length; ++i) if (data_structure_1.PointService.distancePP(point, circles[i]) > circles[i].radius + constant_1.SMALL) return !1;
|
|
81
|
+
return !0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getIntersectionPoints(circles) {
|
|
85
|
+
const ret = [];
|
|
86
|
+
for (let i = 0; i < circles.length; ++i) for (let j = i + 1; j < circles.length; ++j) {
|
|
87
|
+
const intersect = circleCircleIntersection(circles[i], circles[j]);
|
|
88
|
+
for (let k = 0; k < intersect.length; ++k) {
|
|
89
|
+
const p = intersect[k];
|
|
90
|
+
p.parentIndex = [ i, j ], ret.push(p);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return ret;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function circleArea(r, width) {
|
|
97
|
+
return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function circleOverlap(r1, r2, d) {
|
|
101
|
+
if (d >= r1 + r2) return 0;
|
|
102
|
+
if (d <= Math.abs(r1 - r2)) return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
|
|
103
|
+
const w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
|
|
104
|
+
return circleArea(r1, r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d)) + circleArea(r2, w2);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function circleCircleIntersection(p1, p2) {
|
|
108
|
+
const d = data_structure_1.PointService.distancePP(p1, p2), r1 = p1.radius, r2 = p2.radius;
|
|
109
|
+
if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) return [];
|
|
110
|
+
const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d), h = Math.sqrt(r1 * r1 - a * a), x0 = p1.x + a * (p2.x - p1.x) / d, y0 = p1.y + a * (p2.y - p1.y) / d, rx = -(p2.y - p1.y) * (h / d), ry = -(p2.x - p1.x) * (h / d);
|
|
111
|
+
return [ {
|
|
112
|
+
x: x0 + rx,
|
|
113
|
+
y: y0 - ry
|
|
114
|
+
}, {
|
|
115
|
+
x: x0 - rx,
|
|
116
|
+
y: y0 + ry
|
|
117
|
+
} ];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function getCenter(points) {
|
|
121
|
+
const center = {
|
|
122
|
+
x: 0,
|
|
123
|
+
y: 0
|
|
124
|
+
};
|
|
125
|
+
for (let i = 0; i < points.length; ++i) center.x += points[i].x, center.y += points[i].y;
|
|
126
|
+
return center.x /= points.length, center.y /= points.length, center;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
exports.intersectionArea = intersectionArea, exports.containedInCircles = containedInCircles,
|
|
130
|
+
exports.circleArea = circleArea, exports.circleOverlap = circleOverlap, exports.circleCircleIntersection = circleCircleIntersection,
|
|
131
|
+
exports.getCenter = getCenter;
|
|
132
|
+
//# sourceMappingURL=circle-intersection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/geo/circle-intersection.ts"],"names":[],"mappings":";;;AAWA,sDAAiD;AACjD,yCAAmC;AAKnC,SAAgB,gBAAgB,CAAC,OAAkB,EAAE,KAAyB;IAE5E,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAG1D,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC;QACvD,OAAO,kBAAkB,CAAC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1B,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC;AATD,8BASC","file":"circle-intersection.js","sourcesContent":["/* Adapted from venn.js by Ben Frederickson\n * https://github.com/benfred/venn.js\n * Licensed under the MIT\n\n * url: https://github.com/benfred/venn.js/blob/master/src/circleintersection.js\n * License: https://github.com/benfred/venn.js/blob/master/LICENSE\n * @license\n */\n\nimport type { IPointLike } from '../data-structure';\n// eslint-disable-next-line no-duplicate-imports\nimport { PointService } from '../data-structure';\nimport { SMALL } from './constant';\nimport type { ICircleArc, ICircle, IIntersectPoint, IOverlapAreaStats } from './interface';\n\n/** Returns the intersection area of a bunch of circles (where each circle\n is an object having an x,y and radius property) */\nexport function intersectionArea(circles: ICircle[], stats?: IOverlapAreaStats) {\n // get all the intersection points of the circles\n const intersectionPoints = getIntersectionPoints(circles);\n\n // filter out points that aren't included in all the circles\n const innerPoints = intersectionPoints.filter(function (p) {\n return containedInCircles(p, circles);\n });\n\n let arcArea = 0;\n let polygonArea = 0;\n const arcs: ICircleArc[] = [];\n\n // if we have intersection points that are within all the circles,\n // then figure out the area contained by them\n if (innerPoints.length > 1) {\n // sort the points by angle from the center of the polygon, which lets\n // us just iterate over points to get the edges\n const center = getCenter(innerPoints);\n for (let i = 0; i < innerPoints.length; ++i) {\n const p = innerPoints[i];\n p.angle = Math.atan2(p.x - center.x, p.y - center.y);\n }\n innerPoints.sort(function (a, b) {\n return b.angle - a.angle;\n });\n\n // iterate over all points, get arc between the points\n // and update the areas\n let p2 = innerPoints[innerPoints.length - 1];\n for (let i = 0; i < innerPoints.length; ++i) {\n const p1 = innerPoints[i];\n\n // polygon area updates easily ...\n polygonArea += (p2.x + p1.x) * (p1.y - p2.y);\n\n // updating the arc area is a little more involved\n const midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };\n let arc = null;\n\n for (let j = 0; j < p1.parentIndex.length; ++j) {\n if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {\n // figure out the angle halfway between the two points\n // on the current circle\n const circle = circles[p1.parentIndex[j]];\n const a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y);\n const a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);\n\n let angleDiff = a2 - a1;\n if (angleDiff < 0) {\n angleDiff += 2 * Math.PI;\n }\n\n // and use that angle to figure out the width of the\n // arc\n const a = a2 - angleDiff / 2;\n let width = PointService.distancePP(midPoint, {\n x: circle.x + circle.radius * Math.sin(a),\n y: circle.y + circle.radius * Math.cos(a)\n });\n\n // clamp the width to the largest is can actually be\n // (sometimes slightly overflows because of FP errors)\n if (width > circle.radius * 2) {\n width = circle.radius * 2;\n }\n\n // pick the circle whose arc has the smallest width\n if (arc === null || arc.width > width) {\n arc = { circle: circle, width: width, p1: p1, p2: p2 };\n }\n }\n }\n\n if (arc !== null) {\n arcs.push(arc);\n arcArea += circleArea(arc.circle.radius, arc.width);\n p2 = p1;\n }\n }\n } else {\n // no intersection points, is either disjoint - or is completely\n // overlapped. figure out which by examining the smallest circle\n let smallest = circles[0];\n for (let i = 1; i < circles.length; ++i) {\n if (circles[i].radius < smallest.radius) {\n smallest = circles[i];\n }\n }\n\n // make sure the smallest circle is completely contained in all\n // the other circles\n let disjoint = false;\n for (let i = 0; i < circles.length; ++i) {\n if (PointService.distancePP(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {\n disjoint = true;\n break;\n }\n }\n\n if (disjoint) {\n arcArea = polygonArea = 0;\n } else {\n arcArea = smallest.radius * smallest.radius * Math.PI;\n arcs.push({\n circle: smallest,\n p1: { x: smallest.x, y: smallest.y + smallest.radius },\n p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius },\n width: smallest.radius * 2\n });\n }\n }\n\n polygonArea /= 2;\n if (stats) {\n stats.area = arcArea + polygonArea;\n stats.arcArea = arcArea;\n stats.polygonArea = polygonArea;\n stats.arcs = arcs;\n stats.innerPoints = innerPoints;\n stats.intersectionPoints = intersectionPoints;\n }\n\n return arcArea + polygonArea;\n}\n\n/** returns whether a point is contained by all of a list of circles */\nexport function containedInCircles(point: IPointLike, circles: ICircle[]) {\n for (let i = 0; i < circles.length; ++i) {\n if (PointService.distancePP(point, circles[i]) > circles[i].radius + SMALL) {\n return false;\n }\n }\n return true;\n}\n\n/** Gets all intersection points between a bunch of circles */\nfunction getIntersectionPoints(circles: ICircle[]) {\n const ret = [];\n for (let i = 0; i < circles.length; ++i) {\n for (let j = i + 1; j < circles.length; ++j) {\n const intersect = circleCircleIntersection(circles[i], circles[j]);\n for (let k = 0; k < intersect.length; ++k) {\n const p = intersect[k];\n p.parentIndex = [i, j];\n ret.push(p);\n }\n }\n }\n return ret;\n}\n\n/** Circular segment area calculation. See http://mathworld.wolfram.com/CircularSegment.html */\nexport function circleArea(r: number, width: number) {\n return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));\n}\n\n/** Returns the overlap area of two circles of radius r1 and r2 - that\nhave their centers separated by distance d. Simpler faster\ncircle intersection for only two circles */\nexport function circleOverlap(r1: number, r2: number, d: number) {\n // no overlap\n if (d >= r1 + r2) {\n return 0;\n }\n\n // completely overlapped\n if (d <= Math.abs(r1 - r2)) {\n return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);\n }\n\n const w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d);\n const w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);\n return circleArea(r1, w1) + circleArea(r2, w2);\n}\n\n/** Given two circles (containing a x/y/radius attributes),\nreturns the intersecting points if possible.\nnote: doesn't handle cases where there are infinitely many\nintersection points (circles are equivalent):, or only one intersection point*/\nexport function circleCircleIntersection(p1: ICircle, p2: ICircle): IIntersectPoint[] {\n const d = PointService.distancePP(p1, p2);\n const r1 = p1.radius;\n const r2 = p2.radius;\n\n // if to far away, or self contained - can't be done\n if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {\n return [];\n }\n\n const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d);\n const h = Math.sqrt(r1 * r1 - a * a);\n const x0 = p1.x + (a * (p2.x - p1.x)) / d;\n const y0 = p1.y + (a * (p2.y - p1.y)) / d;\n const rx = -(p2.y - p1.y) * (h / d);\n const ry = -(p2.x - p1.x) * (h / d);\n\n return [\n { x: x0 + rx, y: y0 - ry },\n { x: x0 - rx, y: y0 + ry }\n ];\n}\n\n/** Returns the center of a bunch of points */\nexport function getCenter(points: IPointLike[]) {\n const center = { x: 0, y: 0 };\n for (let i = 0; i < points.length; ++i) {\n center.x += points[i].x;\n center.y += points[i].y;\n }\n center.x /= points.length;\n center.y /= points.length;\n return center;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SMALL = 1e-10;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/geo/constant.ts"],"names":[],"mappings":";;;AASa,QAAA,KAAK,GAAG,KAAK,CAAC","file":"constant.js","sourcesContent":["/* Adapted from venn.js by Ben Frederickson\n * https://github.com/benfred/venn.js\n * Licensed under the MIT\n\n * url: https://github.com/benfred/venn.js/blob/master/src/circleintersection.js\n * License: https://github.com/benfred/venn.js/blob/master/LICENSE\n * @license\n */\n\nexport const SMALL = 1e-10;\n"]}
|
package/cjs/geo/index.d.ts
CHANGED
package/cjs/geo/index.js
CHANGED
|
@@ -17,5 +17,6 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
|
|
|
17
17
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", {
|
|
19
19
|
value: !0
|
|
20
|
-
}), __exportStar(require("./invariant"), exports), __exportStar(require("./interface"), exports)
|
|
20
|
+
}), __exportStar(require("./invariant"), exports), __exportStar(require("./interface"), exports),
|
|
21
|
+
__exportStar(require("./circle-intersection"), exports), __exportStar(require("./constant"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/cjs/geo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/geo/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B","file":"index.js","sourcesContent":["export * from './invariant';\nexport * from './interface';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/geo/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B;AAC5B,wDAAsC;AACtC,6CAA2B","file":"index.js","sourcesContent":["export * from './invariant';\nexport * from './interface';\nexport * from './circle-intersection';\nexport * from './constant';\n"]}
|
package/cjs/geo/interface.d.ts
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
+
import type { IPointLike } from '../data-structure';
|
|
1
2
|
export type { Feature, MultiPolygon, Polygon, Units } from '@turf/helpers';
|
|
3
|
+
export interface ICircle extends IPointLike {
|
|
4
|
+
radius: number;
|
|
5
|
+
size?: number;
|
|
6
|
+
parent?: ICircle;
|
|
7
|
+
}
|
|
8
|
+
export interface IIntersectPoint extends IPointLike {
|
|
9
|
+
parentIndex?: number[];
|
|
10
|
+
angle?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ICircleArc {
|
|
13
|
+
circle: ICircle;
|
|
14
|
+
width: number;
|
|
15
|
+
p1: IIntersectPoint;
|
|
16
|
+
p2: IIntersectPoint;
|
|
17
|
+
}
|
|
18
|
+
export interface IOverlapAreaStats {
|
|
19
|
+
area?: number;
|
|
20
|
+
arcArea?: number;
|
|
21
|
+
polygonArea?: number;
|
|
22
|
+
arcs?: ICircleArc[];
|
|
23
|
+
innerPoints?: IPointLike[];
|
|
24
|
+
intersectionPoints?: IIntersectPoint[];
|
|
25
|
+
}
|
package/cjs/geo/interface.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/geo/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/geo/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { IPointLike } from '../data-structure';\n\nexport type { Feature, MultiPolygon, Polygon, Units } from '@turf/helpers';\n\nexport interface ICircle extends IPointLike {\n radius: number;\n size?: number;\n parent?: ICircle;\n}\n\nexport interface IIntersectPoint extends IPointLike {\n parentIndex?: number[];\n angle?: number;\n}\n\nexport interface ICircleArc {\n circle: ICircle;\n width: number;\n p1: IIntersectPoint;\n p2: IIntersectPoint;\n}\n\nexport interface IOverlapAreaStats {\n area?: number;\n arcArea?: number;\n polygonArea?: number;\n arcs?: ICircleArc[];\n innerPoints?: IPointLike[];\n intersectionPoints?: IIntersectPoint[];\n}\n"]}
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -45,5 +45,5 @@ __exportStar(require("./type"), exports), __exportStar(require("./logger"), expo
|
|
|
45
45
|
__exportStar(require("./padding"), exports), __exportStar(require("./time"), exports),
|
|
46
46
|
__exportStar(require("./dom"), exports), __exportStar(require("./geo"), exports),
|
|
47
47
|
__exportStar(require("./color"), exports), __exportStar(require("./format/time"), exports),
|
|
48
|
-
__exportStar(require("./format/number"), exports);
|
|
48
|
+
__exportStar(require("./format/number"), exports), __exportStar(require("./fmin"), exports);
|
|
49
49
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAyC;AAQhC,uBARF,uBAAY,CAQE;AAErB,2CAAyB;AAGzB,mDAAiC;AAGjC,wCAAsB;AAGtB,yCAAuB;AAGvB,0CAAwB;AAIxB,qDAAqC;AAGrC,6CAA2B;AAG3B,yCAAuB;AAGvB,2CAAyB;AAGzB,4CAA0B;AAE1B,yCAAuB;AAGvB,wCAAsB;AAEtB,wCAAsB;AAEtB,0CAAwB;AAExB,gDAA8B;AAC9B,kDAAgC","file":"index.js","sourcesContent":["import EventEmitter from 'eventemitter3';\n\n/**\n * A high performance event emitter\n * @see {@link https://github.com/primus/eventemitter3}\n * @memberof PIXI.utils\n * @class EventEmitter\n */\nexport { EventEmitter };\n\nexport * from './common';\n\n// data structure\nexport * from './data-structure';\n\n// algorithm\nexport * from './lru';\n\n// math\nexport * from './math';\n\n// angle\nexport * from './angle';\n\n// color\n// TODO: 后续删除这个导出,避免引入不需要的内容\nexport * as ColorUtil from './color';\n\n// methods about graphics\nexport * from './graphics';\n\n// type\nexport * from './type';\n\n// log\nexport * from './logger';\n\n// padding\nexport * from './padding';\n\nexport * from './time';\n\n// dom\nexport * from './dom';\n\nexport * from './geo';\n\nexport * from './color';\n\nexport * from './format/time';\nexport * from './format/number';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAyC;AAQhC,uBARF,uBAAY,CAQE;AAErB,2CAAyB;AAGzB,mDAAiC;AAGjC,wCAAsB;AAGtB,yCAAuB;AAGvB,0CAAwB;AAIxB,qDAAqC;AAGrC,6CAA2B;AAG3B,yCAAuB;AAGvB,2CAAyB;AAGzB,4CAA0B;AAE1B,yCAAuB;AAGvB,wCAAsB;AAEtB,wCAAsB;AAEtB,0CAAwB;AAExB,gDAA8B;AAC9B,kDAAgC;AAEhC,yCAAuB","file":"index.js","sourcesContent":["import EventEmitter from 'eventemitter3';\n\n/**\n * A high performance event emitter\n * @see {@link https://github.com/primus/eventemitter3}\n * @memberof PIXI.utils\n * @class EventEmitter\n */\nexport { EventEmitter };\n\nexport * from './common';\n\n// data structure\nexport * from './data-structure';\n\n// algorithm\nexport * from './lru';\n\n// math\nexport * from './math';\n\n// angle\nexport * from './angle';\n\n// color\n// TODO: 后续删除这个导出,避免引入不需要的内容\nexport * as ColorUtil from './color';\n\n// methods about graphics\nexport * from './graphics';\n\n// type\nexport * from './type';\n\n// log\nexport * from './logger';\n\n// padding\nexport * from './padding';\n\nexport * from './time';\n\n// dom\nexport * from './dom';\n\nexport * from './geo';\n\nexport * from './color';\n\nexport * from './format/time';\nexport * from './format/number';\n\nexport * from './fmin';\n"]}
|