@visactor/vutils 0.18.2-alpha.0 → 0.18.3
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/dom.d.ts +2 -0
- package/cjs/dom.js +20 -1
- package/cjs/dom.js.map +1 -1
- package/cjs/fmin/bisect.js +11 -4
- package/cjs/fmin/bisect.js.map +1 -1
- package/cjs/fmin/blas1.d.ts +0 -1
- package/cjs/fmin/blas1.js +10 -13
- package/cjs/fmin/blas1.js.map +1 -1
- package/cjs/fmin/conjugate-gradient.js +3 -3
- package/cjs/fmin/conjugate-gradient.js.map +1 -1
- package/cjs/fmin/linesearch.js +4 -4
- package/cjs/fmin/linesearch.js.map +1 -1
- package/cjs/graphics/bounds-util.d.ts +7 -0
- package/cjs/graphics/bounds-util.js +53 -0
- package/cjs/graphics/bounds-util.js.map +1 -0
- package/cjs/graphics/index.d.ts +1 -0
- package/cjs/graphics/index.js +1 -1
- package/cjs/graphics/index.js.map +1 -1
- package/cjs/math.d.ts +1 -0
- package/cjs/math.js +8 -2
- package/cjs/math.js.map +1 -1
- package/dist/index.js +86 -16
- package/dist/index.min.js +1 -1
- package/es/dom.d.ts +2 -0
- package/es/dom.js +15 -0
- package/es/dom.js.map +1 -1
- package/es/fmin/bisect.js +6 -1
- package/es/fmin/bisect.js.map +1 -1
- package/es/fmin/blas1.d.ts +0 -1
- package/es/fmin/blas1.js +4 -8
- package/es/fmin/blas1.js.map +1 -1
- package/es/fmin/conjugate-gradient.js +4 -2
- package/es/fmin/conjugate-gradient.js.map +1 -1
- package/es/fmin/linesearch.js +6 -4
- package/es/fmin/linesearch.js.map +1 -1
- package/es/graphics/bounds-util.d.ts +7 -0
- package/es/graphics/bounds-util.js +45 -0
- package/es/graphics/bounds-util.js.map +1 -0
- package/es/graphics/index.d.ts +1 -0
- package/es/graphics/index.js +2 -0
- package/es/graphics/index.js.map +1 -1
- package/es/math.d.ts +1 -0
- package/es/math.js +6 -0
- package/es/math.js.map +1 -1
- package/package.json +2 -2
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
|
}
|
|
@@ -4080,6 +4087,52 @@
|
|
|
4080
4087
|
TextMeasure.NUMBERS_CHAR_SET = '0123456789';
|
|
4081
4088
|
TextMeasure.FULL_SIZE_CHAR = '字';
|
|
4082
4089
|
|
|
4090
|
+
const calculateAnchorOfBounds = (bounds, anchorType) => {
|
|
4091
|
+
const { x1, x2, y1, y2 } = bounds;
|
|
4092
|
+
const rectWidth = Math.abs(x2 - x1);
|
|
4093
|
+
const rectHeight = Math.abs(y2 - y1);
|
|
4094
|
+
let anchorX = (x1 + x2) / 2;
|
|
4095
|
+
let anchorY = (y1 + y2) / 2;
|
|
4096
|
+
let sx = 0;
|
|
4097
|
+
let sy = 0;
|
|
4098
|
+
switch (anchorType) {
|
|
4099
|
+
case 'top':
|
|
4100
|
+
case 'inside-top':
|
|
4101
|
+
sy = -0.5;
|
|
4102
|
+
break;
|
|
4103
|
+
case 'bottom':
|
|
4104
|
+
case 'inside-bottom':
|
|
4105
|
+
sy = 0.5;
|
|
4106
|
+
break;
|
|
4107
|
+
case 'left':
|
|
4108
|
+
case 'inside-left':
|
|
4109
|
+
sx = -0.5;
|
|
4110
|
+
break;
|
|
4111
|
+
case 'right':
|
|
4112
|
+
case 'inside-right':
|
|
4113
|
+
sx = 0.5;
|
|
4114
|
+
break;
|
|
4115
|
+
case 'top-right':
|
|
4116
|
+
sx = 0.5;
|
|
4117
|
+
sy = -0.5;
|
|
4118
|
+
break;
|
|
4119
|
+
case 'top-left':
|
|
4120
|
+
sx = -0.5;
|
|
4121
|
+
sy = -0.5;
|
|
4122
|
+
break;
|
|
4123
|
+
case 'bottom-right':
|
|
4124
|
+
sx = 0.5;
|
|
4125
|
+
sy = 0.5;
|
|
4126
|
+
break;
|
|
4127
|
+
case 'bottom-left':
|
|
4128
|
+
sx = -0.5;
|
|
4129
|
+
sy = 0.5;
|
|
4130
|
+
}
|
|
4131
|
+
anchorX += sx * rectWidth;
|
|
4132
|
+
anchorY += sy * rectHeight;
|
|
4133
|
+
return { x: anchorX, y: anchorY };
|
|
4134
|
+
};
|
|
4135
|
+
|
|
4083
4136
|
const hasConsole = typeof console !== 'undefined';
|
|
4084
4137
|
function log(method, level, input) {
|
|
4085
4138
|
const args = [level].concat([].slice.call(input));
|
|
@@ -4681,6 +4734,25 @@
|
|
|
4681
4734
|
}
|
|
4682
4735
|
return false;
|
|
4683
4736
|
}
|
|
4737
|
+
const styleStringToObject = (styleStr = '') => {
|
|
4738
|
+
const res = {};
|
|
4739
|
+
styleStr.split(';').forEach(item => {
|
|
4740
|
+
if (item) {
|
|
4741
|
+
const arr = item.split(':');
|
|
4742
|
+
if (arr.length === 2) {
|
|
4743
|
+
const key = arr[0].trim();
|
|
4744
|
+
const value = arr[1].trim();
|
|
4745
|
+
if (key && value) {
|
|
4746
|
+
res[key] = value;
|
|
4747
|
+
}
|
|
4748
|
+
}
|
|
4749
|
+
}
|
|
4750
|
+
});
|
|
4751
|
+
return res;
|
|
4752
|
+
};
|
|
4753
|
+
const lowerCamelCaseToMiddle = (str) => {
|
|
4754
|
+
return str.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
4755
|
+
};
|
|
4684
4756
|
|
|
4685
4757
|
/**
|
|
4686
4758
|
* @module helpers
|
|
@@ -5631,15 +5703,8 @@
|
|
|
5631
5703
|
return zeros(y);
|
|
5632
5704
|
});
|
|
5633
5705
|
}
|
|
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
5706
|
function norm2(a) {
|
|
5642
|
-
return Math.sqrt(
|
|
5707
|
+
return Math.sqrt(dotProduct(a, a));
|
|
5643
5708
|
}
|
|
5644
5709
|
function scale(ret, value, c) {
|
|
5645
5710
|
for (let i = 0; i < value.length; ++i) {
|
|
@@ -5653,7 +5718,7 @@
|
|
|
5653
5718
|
}
|
|
5654
5719
|
function gemv(output, A, x) {
|
|
5655
5720
|
for (let i = 0; i < output.length; ++i) {
|
|
5656
|
-
output[i] =
|
|
5721
|
+
output[i] = dotProduct(A[i], x);
|
|
5657
5722
|
}
|
|
5658
5723
|
}
|
|
5659
5724
|
|
|
@@ -5777,7 +5842,7 @@
|
|
|
5777
5842
|
|
|
5778
5843
|
function wolfeLineSearch(f, pk, current, next, a, c1, c2) {
|
|
5779
5844
|
const phi0 = current.fx;
|
|
5780
|
-
const phiPrime0 =
|
|
5845
|
+
const phiPrime0 = dotProduct(current.fxprime, pk);
|
|
5781
5846
|
let phi = phi0;
|
|
5782
5847
|
let phi_old = phi0;
|
|
5783
5848
|
let phiPrime = phiPrime0;
|
|
@@ -5790,7 +5855,7 @@
|
|
|
5790
5855
|
a = (a_lo + a_high) / 2;
|
|
5791
5856
|
weightedSum(next.x, 1.0, current.x, a, pk);
|
|
5792
5857
|
phi = next.fx = f(next.x, next.fxprime);
|
|
5793
|
-
phiPrime =
|
|
5858
|
+
phiPrime = dotProduct(next.fxprime, pk);
|
|
5794
5859
|
if (phi > phi0 + c1 * a * phiPrime0 || phi >= phi_lo) {
|
|
5795
5860
|
a_high = a;
|
|
5796
5861
|
}
|
|
@@ -5810,7 +5875,7 @@
|
|
|
5810
5875
|
for (let iteration = 0; iteration < 10; ++iteration) {
|
|
5811
5876
|
weightedSum(next.x, 1.0, current.x, a, pk);
|
|
5812
5877
|
phi = next.fx = f(next.x, next.fxprime);
|
|
5813
|
-
phiPrime =
|
|
5878
|
+
phiPrime = dotProduct(next.fxprime, pk);
|
|
5814
5879
|
if (phi > phi0 + c1 * a * phiPrime0 || (iteration && phi >= phi_old)) {
|
|
5815
5880
|
return zoom(a0, a, phi_old);
|
|
5816
5881
|
}
|
|
@@ -5848,8 +5913,8 @@
|
|
|
5848
5913
|
}
|
|
5849
5914
|
else {
|
|
5850
5915
|
weightedSum(yk, 1, next.fxprime, -1, current.fxprime);
|
|
5851
|
-
const delta_k =
|
|
5852
|
-
const beta_k = Math.max(0,
|
|
5916
|
+
const delta_k = dotProduct(current.fxprime, current.fxprime);
|
|
5917
|
+
const beta_k = Math.max(0, dotProduct(yk, next.fxprime) / delta_k);
|
|
5853
5918
|
weightedSum(pk, beta_k, pk, -1, next.fxprime);
|
|
5854
5919
|
temp = current;
|
|
5855
5920
|
current = next;
|
|
@@ -5873,7 +5938,9 @@
|
|
|
5873
5938
|
const fB = f(b);
|
|
5874
5939
|
let delta = b - a;
|
|
5875
5940
|
if (fA * fB > 0) {
|
|
5876
|
-
|
|
5941
|
+
const logger = Logger.getInstance();
|
|
5942
|
+
logger.error('Initial bisect points must have opposite signs');
|
|
5943
|
+
return NaN;
|
|
5877
5944
|
}
|
|
5878
5945
|
if (fA === 0) {
|
|
5879
5946
|
return a;
|
|
@@ -5935,6 +6002,7 @@
|
|
|
5935
6002
|
exports.asin = asin;
|
|
5936
6003
|
exports.atan2 = atan2;
|
|
5937
6004
|
exports.bisect = bisect;
|
|
6005
|
+
exports.calculateAnchorOfBounds = calculateAnchorOfBounds;
|
|
5938
6006
|
exports.circleArea = circleArea;
|
|
5939
6007
|
exports.circleCircleIntersection = circleCircleIntersection;
|
|
5940
6008
|
exports.circleOverlap = circleOverlap;
|
|
@@ -5964,7 +6032,7 @@
|
|
|
5964
6032
|
exports.degreeToRadian = degreeToRadian;
|
|
5965
6033
|
exports.destination = destination;
|
|
5966
6034
|
exports.deviation = deviation;
|
|
5967
|
-
exports.
|
|
6035
|
+
exports.dotProduct = dotProduct;
|
|
5968
6036
|
exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
|
|
5969
6037
|
exports.epsilon = epsilon;
|
|
5970
6038
|
exports.exponent = exponent;
|
|
@@ -6054,6 +6122,7 @@
|
|
|
6054
6122
|
exports.last = last;
|
|
6055
6123
|
exports.lengthFromPointToLine = lengthFromPointToLine;
|
|
6056
6124
|
exports.lineIntersectPolygon = lineIntersectPolygon;
|
|
6125
|
+
exports.lowerCamelCaseToMiddle = lowerCamelCaseToMiddle;
|
|
6057
6126
|
exports.lowerFirst = lowerFirst;
|
|
6058
6127
|
exports.max = max;
|
|
6059
6128
|
exports.maxInArray = maxInArray;
|
|
@@ -6122,6 +6191,7 @@
|
|
|
6122
6191
|
exports.span = span;
|
|
6123
6192
|
exports.sqrt = sqrt;
|
|
6124
6193
|
exports.stringWidth = stringWidth;
|
|
6194
|
+
exports.styleStringToObject = styleStringToObject;
|
|
6125
6195
|
exports.substitute = substitute;
|
|
6126
6196
|
exports.tau = tau;
|
|
6127
6197
|
exports.throttle = throttle;
|