@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
package/dist/index.js
CHANGED
|
@@ -4784,6 +4784,163 @@
|
|
|
4784
4784
|
return { x: lng, y: lat };
|
|
4785
4785
|
}
|
|
4786
4786
|
|
|
4787
|
+
const SMALL = 1e-10;
|
|
4788
|
+
|
|
4789
|
+
function intersectionArea(circles, stats) {
|
|
4790
|
+
const intersectionPoints = getIntersectionPoints(circles);
|
|
4791
|
+
const innerPoints = intersectionPoints.filter(function (p) {
|
|
4792
|
+
return containedInCircles(p, circles);
|
|
4793
|
+
});
|
|
4794
|
+
let arcArea = 0;
|
|
4795
|
+
let polygonArea = 0;
|
|
4796
|
+
const arcs = [];
|
|
4797
|
+
if (innerPoints.length > 1) {
|
|
4798
|
+
const center = getCenter(innerPoints);
|
|
4799
|
+
for (let i = 0; i < innerPoints.length; ++i) {
|
|
4800
|
+
const p = innerPoints[i];
|
|
4801
|
+
p.angle = Math.atan2(p.x - center.x, p.y - center.y);
|
|
4802
|
+
}
|
|
4803
|
+
innerPoints.sort(function (a, b) {
|
|
4804
|
+
return b.angle - a.angle;
|
|
4805
|
+
});
|
|
4806
|
+
let p2 = innerPoints[innerPoints.length - 1];
|
|
4807
|
+
for (let i = 0; i < innerPoints.length; ++i) {
|
|
4808
|
+
const p1 = innerPoints[i];
|
|
4809
|
+
polygonArea += (p2.x + p1.x) * (p1.y - p2.y);
|
|
4810
|
+
const midPoint = { x: (p1.x + p2.x) / 2, y: (p1.y + p2.y) / 2 };
|
|
4811
|
+
let arc = null;
|
|
4812
|
+
for (let j = 0; j < p1.parentIndex.length; ++j) {
|
|
4813
|
+
if (p2.parentIndex.indexOf(p1.parentIndex[j]) > -1) {
|
|
4814
|
+
const circle = circles[p1.parentIndex[j]];
|
|
4815
|
+
const a1 = Math.atan2(p1.x - circle.x, p1.y - circle.y);
|
|
4816
|
+
const a2 = Math.atan2(p2.x - circle.x, p2.y - circle.y);
|
|
4817
|
+
let angleDiff = a2 - a1;
|
|
4818
|
+
if (angleDiff < 0) {
|
|
4819
|
+
angleDiff += 2 * Math.PI;
|
|
4820
|
+
}
|
|
4821
|
+
const a = a2 - angleDiff / 2;
|
|
4822
|
+
let width = PointService.distancePP(midPoint, {
|
|
4823
|
+
x: circle.x + circle.radius * Math.sin(a),
|
|
4824
|
+
y: circle.y + circle.radius * Math.cos(a)
|
|
4825
|
+
});
|
|
4826
|
+
if (width > circle.radius * 2) {
|
|
4827
|
+
width = circle.radius * 2;
|
|
4828
|
+
}
|
|
4829
|
+
if (arc === null || arc.width > width) {
|
|
4830
|
+
arc = { circle: circle, width: width, p1: p1, p2: p2 };
|
|
4831
|
+
}
|
|
4832
|
+
}
|
|
4833
|
+
}
|
|
4834
|
+
if (arc !== null) {
|
|
4835
|
+
arcs.push(arc);
|
|
4836
|
+
arcArea += circleArea(arc.circle.radius, arc.width);
|
|
4837
|
+
p2 = p1;
|
|
4838
|
+
}
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4841
|
+
else {
|
|
4842
|
+
let smallest = circles[0];
|
|
4843
|
+
for (let i = 1; i < circles.length; ++i) {
|
|
4844
|
+
if (circles[i].radius < smallest.radius) {
|
|
4845
|
+
smallest = circles[i];
|
|
4846
|
+
}
|
|
4847
|
+
}
|
|
4848
|
+
let disjoint = false;
|
|
4849
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
4850
|
+
if (PointService.distancePP(circles[i], smallest) > Math.abs(smallest.radius - circles[i].radius)) {
|
|
4851
|
+
disjoint = true;
|
|
4852
|
+
break;
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4855
|
+
if (disjoint) {
|
|
4856
|
+
arcArea = polygonArea = 0;
|
|
4857
|
+
}
|
|
4858
|
+
else {
|
|
4859
|
+
arcArea = smallest.radius * smallest.radius * Math.PI;
|
|
4860
|
+
arcs.push({
|
|
4861
|
+
circle: smallest,
|
|
4862
|
+
p1: { x: smallest.x, y: smallest.y + smallest.radius },
|
|
4863
|
+
p2: { x: smallest.x - SMALL, y: smallest.y + smallest.radius },
|
|
4864
|
+
width: smallest.radius * 2
|
|
4865
|
+
});
|
|
4866
|
+
}
|
|
4867
|
+
}
|
|
4868
|
+
polygonArea /= 2;
|
|
4869
|
+
if (stats) {
|
|
4870
|
+
stats.area = arcArea + polygonArea;
|
|
4871
|
+
stats.arcArea = arcArea;
|
|
4872
|
+
stats.polygonArea = polygonArea;
|
|
4873
|
+
stats.arcs = arcs;
|
|
4874
|
+
stats.innerPoints = innerPoints;
|
|
4875
|
+
stats.intersectionPoints = intersectionPoints;
|
|
4876
|
+
}
|
|
4877
|
+
return arcArea + polygonArea;
|
|
4878
|
+
}
|
|
4879
|
+
function containedInCircles(point, circles) {
|
|
4880
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
4881
|
+
if (PointService.distancePP(point, circles[i]) > circles[i].radius + SMALL) {
|
|
4882
|
+
return false;
|
|
4883
|
+
}
|
|
4884
|
+
}
|
|
4885
|
+
return true;
|
|
4886
|
+
}
|
|
4887
|
+
function getIntersectionPoints(circles) {
|
|
4888
|
+
const ret = [];
|
|
4889
|
+
for (let i = 0; i < circles.length; ++i) {
|
|
4890
|
+
for (let j = i + 1; j < circles.length; ++j) {
|
|
4891
|
+
const intersect = circleCircleIntersection(circles[i], circles[j]);
|
|
4892
|
+
for (let k = 0; k < intersect.length; ++k) {
|
|
4893
|
+
const p = intersect[k];
|
|
4894
|
+
p.parentIndex = [i, j];
|
|
4895
|
+
ret.push(p);
|
|
4896
|
+
}
|
|
4897
|
+
}
|
|
4898
|
+
}
|
|
4899
|
+
return ret;
|
|
4900
|
+
}
|
|
4901
|
+
function circleArea(r, width) {
|
|
4902
|
+
return r * r * Math.acos(1 - width / r) - (r - width) * Math.sqrt(width * (2 * r - width));
|
|
4903
|
+
}
|
|
4904
|
+
function circleOverlap(r1, r2, d) {
|
|
4905
|
+
if (d >= r1 + r2) {
|
|
4906
|
+
return 0;
|
|
4907
|
+
}
|
|
4908
|
+
if (d <= Math.abs(r1 - r2)) {
|
|
4909
|
+
return Math.PI * Math.min(r1, r2) * Math.min(r1, r2);
|
|
4910
|
+
}
|
|
4911
|
+
const w1 = r1 - (d * d - r2 * r2 + r1 * r1) / (2 * d);
|
|
4912
|
+
const w2 = r2 - (d * d - r1 * r1 + r2 * r2) / (2 * d);
|
|
4913
|
+
return circleArea(r1, w1) + circleArea(r2, w2);
|
|
4914
|
+
}
|
|
4915
|
+
function circleCircleIntersection(p1, p2) {
|
|
4916
|
+
const d = PointService.distancePP(p1, p2);
|
|
4917
|
+
const r1 = p1.radius;
|
|
4918
|
+
const r2 = p2.radius;
|
|
4919
|
+
if (d >= r1 + r2 || d <= Math.abs(r1 - r2)) {
|
|
4920
|
+
return [];
|
|
4921
|
+
}
|
|
4922
|
+
const a = (r1 * r1 - r2 * r2 + d * d) / (2 * d);
|
|
4923
|
+
const h = Math.sqrt(r1 * r1 - a * a);
|
|
4924
|
+
const x0 = p1.x + (a * (p2.x - p1.x)) / d;
|
|
4925
|
+
const y0 = p1.y + (a * (p2.y - p1.y)) / d;
|
|
4926
|
+
const rx = -(p2.y - p1.y) * (h / d);
|
|
4927
|
+
const ry = -(p2.x - p1.x) * (h / d);
|
|
4928
|
+
return [
|
|
4929
|
+
{ x: x0 + rx, y: y0 - ry },
|
|
4930
|
+
{ x: x0 - rx, y: y0 + ry }
|
|
4931
|
+
];
|
|
4932
|
+
}
|
|
4933
|
+
function getCenter(points) {
|
|
4934
|
+
const center = { x: 0, y: 0 };
|
|
4935
|
+
for (let i = 0; i < points.length; ++i) {
|
|
4936
|
+
center.x += points[i].x;
|
|
4937
|
+
center.y += points[i].y;
|
|
4938
|
+
}
|
|
4939
|
+
center.x /= points.length;
|
|
4940
|
+
center.y /= points.length;
|
|
4941
|
+
return center;
|
|
4942
|
+
}
|
|
4943
|
+
|
|
4787
4944
|
class TimeUtil {
|
|
4788
4945
|
static getInstance() {
|
|
4789
4946
|
if (!TimeUtil.instance) {
|
|
@@ -5462,6 +5619,282 @@
|
|
|
5462
5619
|
};
|
|
5463
5620
|
}
|
|
5464
5621
|
|
|
5622
|
+
function zeros(x) {
|
|
5623
|
+
const r = new Array(x);
|
|
5624
|
+
for (let i = 0; i < x; ++i) {
|
|
5625
|
+
r[i] = 0;
|
|
5626
|
+
}
|
|
5627
|
+
return r;
|
|
5628
|
+
}
|
|
5629
|
+
function zerosM(x, y) {
|
|
5630
|
+
return zeros(x).map(function () {
|
|
5631
|
+
return zeros(y);
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
function dot(a, b) {
|
|
5635
|
+
let ret = 0;
|
|
5636
|
+
for (let i = 0; i < a.length; ++i) {
|
|
5637
|
+
ret += a[i] * b[i];
|
|
5638
|
+
}
|
|
5639
|
+
return ret;
|
|
5640
|
+
}
|
|
5641
|
+
function norm2(a) {
|
|
5642
|
+
return Math.sqrt(dot(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] = dot(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 = dot(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 = dot(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 = dot(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 = dot(current.fxprime, current.fxprime);
|
|
5852
|
+
const beta_k = Math.max(0, dot(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
|
+
throw 'Initial bisect points must have opposite signs';
|
|
5877
|
+
}
|
|
5878
|
+
if (fA === 0) {
|
|
5879
|
+
return a;
|
|
5880
|
+
}
|
|
5881
|
+
if (fB === 0) {
|
|
5882
|
+
return b;
|
|
5883
|
+
}
|
|
5884
|
+
for (let i = 0; i < maxIterations; ++i) {
|
|
5885
|
+
delta /= 2;
|
|
5886
|
+
const mid = a + delta;
|
|
5887
|
+
const fMid = f(mid);
|
|
5888
|
+
if (fMid * fA >= 0) {
|
|
5889
|
+
a = mid;
|
|
5890
|
+
}
|
|
5891
|
+
if (Math.abs(delta) < tolerance || fMid === 0) {
|
|
5892
|
+
return mid;
|
|
5893
|
+
}
|
|
5894
|
+
}
|
|
5895
|
+
return a + delta;
|
|
5896
|
+
}
|
|
5897
|
+
|
|
5465
5898
|
exports.AABBBounds = AABBBounds;
|
|
5466
5899
|
exports.Bounds = Bounds;
|
|
5467
5900
|
exports.Color = Color;
|
|
@@ -5488,6 +5921,7 @@
|
|
|
5488
5921
|
exports.PolarPoint = PolarPoint;
|
|
5489
5922
|
exports.RGB = RGB;
|
|
5490
5923
|
exports.SECOND = SECOND;
|
|
5924
|
+
exports.SMALL = SMALL;
|
|
5491
5925
|
exports.SUBDIVISION_MAX_ITERATIONS = SUBDIVISION_MAX_ITERATIONS;
|
|
5492
5926
|
exports.SUBDIVISION_PRECISION = SUBDIVISION_PRECISION;
|
|
5493
5927
|
exports.TextMeasure = TextMeasure;
|
|
@@ -5501,6 +5935,9 @@
|
|
|
5501
5935
|
exports.asin = asin;
|
|
5502
5936
|
exports.atan2 = atan2;
|
|
5503
5937
|
exports.bisect = bisect;
|
|
5938
|
+
exports.circleArea = circleArea;
|
|
5939
|
+
exports.circleCircleIntersection = circleCircleIntersection;
|
|
5940
|
+
exports.circleOverlap = circleOverlap;
|
|
5504
5941
|
exports.clamp = clamp;
|
|
5505
5942
|
exports.clampAngleByDegree = clampAngleByDegree;
|
|
5506
5943
|
exports.clampAngleByRadian = clampAngleByRadian;
|
|
@@ -5510,7 +5947,9 @@
|
|
|
5510
5947
|
exports.clamper = clamper;
|
|
5511
5948
|
exports.clone = clone;
|
|
5512
5949
|
exports.cloneDeep = cloneDeep;
|
|
5950
|
+
exports.conjugateGradient = conjugateGradient;
|
|
5513
5951
|
exports.constant = constant;
|
|
5952
|
+
exports.containedInCircles = containedInCircles;
|
|
5514
5953
|
exports.cos = cos;
|
|
5515
5954
|
exports.crossProduct = crossProduct;
|
|
5516
5955
|
exports.crossProductPoint = crossProductPoint;
|
|
@@ -5525,9 +5964,11 @@
|
|
|
5525
5964
|
exports.degreeToRadian = degreeToRadian;
|
|
5526
5965
|
exports.destination = destination;
|
|
5527
5966
|
exports.deviation = deviation;
|
|
5967
|
+
exports.dot = dot;
|
|
5528
5968
|
exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
|
|
5529
5969
|
exports.epsilon = epsilon;
|
|
5530
5970
|
exports.exponent = exponent;
|
|
5971
|
+
exports.findZeroOfFunction = findZeroOfFunction;
|
|
5531
5972
|
exports.fixPrecision = fixPrecision;
|
|
5532
5973
|
exports.flattenArray = flattenArray;
|
|
5533
5974
|
exports.formatNumerals = formatNumerals;
|
|
@@ -5537,12 +5978,14 @@
|
|
|
5537
5978
|
exports.fullYearSetterName = fullYearSetterName;
|
|
5538
5979
|
exports.fuzzyEqualNumber = fuzzyEqualNumber;
|
|
5539
5980
|
exports.fuzzyEqualVec = fuzzyEqualVec;
|
|
5981
|
+
exports.gemv = gemv;
|
|
5540
5982
|
exports.generateCeil = generateCeil;
|
|
5541
5983
|
exports.generateCount = generateCount;
|
|
5542
5984
|
exports.generateStepInterval = generateStepInterval;
|
|
5543
5985
|
exports.get = get;
|
|
5544
5986
|
exports.getAABBFromPoints = getAABBFromPoints;
|
|
5545
5987
|
exports.getAngleByPoint = getAngleByPoint;
|
|
5988
|
+
exports.getCenter = getCenter;
|
|
5546
5989
|
exports.getContainerSize = getContainerSize;
|
|
5547
5990
|
exports.getContextFont = getContextFont;
|
|
5548
5991
|
exports.getDecimalPlaces = getDecimalPlaces;
|
|
@@ -5575,6 +6018,7 @@
|
|
|
5575
6018
|
exports.interpolateNumberRound = interpolateNumberRound;
|
|
5576
6019
|
exports.interpolateRgb = interpolateRgb;
|
|
5577
6020
|
exports.interpolateString = interpolateString;
|
|
6021
|
+
exports.intersectionArea = intersectionArea;
|
|
5578
6022
|
exports.isArray = isArray;
|
|
5579
6023
|
exports.isArrayLike = isArrayLike;
|
|
5580
6024
|
exports.isBase64 = isBase64;
|
|
@@ -5637,6 +6081,8 @@
|
|
|
5637
6081
|
exports.monthGetterName = monthGetterName;
|
|
5638
6082
|
exports.monthOffset = monthOffset;
|
|
5639
6083
|
exports.monthSetterName = monthSetterName;
|
|
6084
|
+
exports.nelderMead = nelderMead;
|
|
6085
|
+
exports.norm2 = norm2;
|
|
5640
6086
|
exports.normalTransform = normalTransform;
|
|
5641
6087
|
exports.normalizePadding = normalizePadding;
|
|
5642
6088
|
exports.numberSpecifierReg = numberSpecifierReg;
|
|
@@ -5664,6 +6110,7 @@
|
|
|
5664
6110
|
exports.rectInsideAnotherRect = rectInsideAnotherRect;
|
|
5665
6111
|
exports.rgbToHex = rgbToHex;
|
|
5666
6112
|
exports.rgbToHsl = rgbToHsl;
|
|
6113
|
+
exports.scale = scale;
|
|
5667
6114
|
exports.secondCount = secondCount;
|
|
5668
6115
|
exports.secondField = secondField;
|
|
5669
6116
|
exports.secondFloor = secondFloor;
|
|
@@ -5711,9 +6158,12 @@
|
|
|
5711
6158
|
exports.utcYearOffset = utcYearOffset;
|
|
5712
6159
|
exports.uuid = uuid;
|
|
5713
6160
|
exports.variance = variance;
|
|
6161
|
+
exports.weightedSum = weightedSum;
|
|
5714
6162
|
exports.yearCount = yearCount;
|
|
5715
6163
|
exports.yearField = yearField;
|
|
5716
6164
|
exports.yearFloor = yearFloor;
|
|
5717
6165
|
exports.yearOffset = yearOffset;
|
|
6166
|
+
exports.zeros = zeros;
|
|
6167
|
+
exports.zerosM = zerosM;
|
|
5718
6168
|
|
|
5719
6169
|
}));
|