@antv/g 5.13.0 → 5.13.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.
- package/dist/index.umd.js +812 -72
- package/dist/index.umd.min.js +2 -2
- package/package.json +8 -8
package/dist/index.umd.js
CHANGED
|
@@ -5063,40 +5063,6 @@
|
|
|
5063
5063
|
};
|
|
5064
5064
|
}
|
|
5065
5065
|
|
|
5066
|
-
/**
|
|
5067
|
-
* Returns the bounding box of a shape.
|
|
5068
|
-
*/
|
|
5069
|
-
function getPathBBox(path, options) {
|
|
5070
|
-
if (!path) {
|
|
5071
|
-
return {
|
|
5072
|
-
x: 0,
|
|
5073
|
-
y: 0,
|
|
5074
|
-
width: 0,
|
|
5075
|
-
height: 0,
|
|
5076
|
-
x2: 0,
|
|
5077
|
-
y2: 0,
|
|
5078
|
-
cx: 0,
|
|
5079
|
-
cy: 0,
|
|
5080
|
-
cz: 0,
|
|
5081
|
-
};
|
|
5082
|
-
}
|
|
5083
|
-
var _a = pathLengthFactory(path, undefined, __assign(__assign({}, options), { length: false })), _b = _a.min, xMin = _b.x, yMin = _b.y, _c = _a.max, xMax = _c.x, yMax = _c.y;
|
|
5084
|
-
var width = xMax - xMin;
|
|
5085
|
-
var height = yMax - yMin;
|
|
5086
|
-
return {
|
|
5087
|
-
width: width,
|
|
5088
|
-
height: height,
|
|
5089
|
-
x: xMin,
|
|
5090
|
-
y: yMin,
|
|
5091
|
-
x2: xMax,
|
|
5092
|
-
y2: yMax,
|
|
5093
|
-
cx: xMin + width / 2,
|
|
5094
|
-
cy: yMin + height / 2,
|
|
5095
|
-
// an estimted guess
|
|
5096
|
-
cz: Math.max(width, height) + Math.min(width, height) / 2,
|
|
5097
|
-
};
|
|
5098
|
-
}
|
|
5099
|
-
|
|
5100
5066
|
/**
|
|
5101
5067
|
* Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
|
|
5102
5068
|
*
|
|
@@ -5317,6 +5283,10 @@
|
|
|
5317
5283
|
var toString = {}.toString;
|
|
5318
5284
|
var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
|
|
5319
5285
|
|
|
5286
|
+
var isArray = (function (value) {
|
|
5287
|
+
return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
|
|
5288
|
+
});
|
|
5289
|
+
|
|
5320
5290
|
var isObject = (function (value) {
|
|
5321
5291
|
/**
|
|
5322
5292
|
* isObject({}) => true
|
|
@@ -5328,6 +5298,58 @@
|
|
|
5328
5298
|
return (value !== null && type === 'object') || type === 'function';
|
|
5329
5299
|
});
|
|
5330
5300
|
|
|
5301
|
+
/**
|
|
5302
|
+
* @param {Array} arr The array to iterate over.
|
|
5303
|
+
* @return {*} Returns the maximum value.
|
|
5304
|
+
* @example
|
|
5305
|
+
*
|
|
5306
|
+
* max([1, 2]);
|
|
5307
|
+
* // => 2
|
|
5308
|
+
*
|
|
5309
|
+
* max([]);
|
|
5310
|
+
* // => undefined
|
|
5311
|
+
*
|
|
5312
|
+
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
5313
|
+
*
|
|
5314
|
+
* max(data);
|
|
5315
|
+
* // => 1250010
|
|
5316
|
+
* // Math.max(...data) will encounter "Maximum call stack size exceeded" error
|
|
5317
|
+
*/
|
|
5318
|
+
var max$1 = (function (arr) {
|
|
5319
|
+
if (!isArray(arr)) {
|
|
5320
|
+
return undefined;
|
|
5321
|
+
}
|
|
5322
|
+
return arr.reduce(function (prev, curr) {
|
|
5323
|
+
return Math.max(prev, curr);
|
|
5324
|
+
}, arr[0]);
|
|
5325
|
+
});
|
|
5326
|
+
|
|
5327
|
+
/**
|
|
5328
|
+
* @param {Array} arr The array to iterate over.
|
|
5329
|
+
* @return {*} Returns the minimum value.
|
|
5330
|
+
* @example
|
|
5331
|
+
*
|
|
5332
|
+
* min([1, 2]);
|
|
5333
|
+
* // => 1
|
|
5334
|
+
*
|
|
5335
|
+
* min([]);
|
|
5336
|
+
* // => undefined
|
|
5337
|
+
*
|
|
5338
|
+
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
5339
|
+
*
|
|
5340
|
+
* min(data);
|
|
5341
|
+
* // => 1250010
|
|
5342
|
+
* // Math.min(...data) will encounter "Maximum call stack size exceeded" error
|
|
5343
|
+
*/
|
|
5344
|
+
var min$1 = (function (arr) {
|
|
5345
|
+
if (!isArray(arr)) {
|
|
5346
|
+
return undefined;
|
|
5347
|
+
}
|
|
5348
|
+
return arr.reduce(function (prev, curr) {
|
|
5349
|
+
return Math.min(prev, curr);
|
|
5350
|
+
}, arr[0]);
|
|
5351
|
+
});
|
|
5352
|
+
|
|
5331
5353
|
var isString = (function (str) {
|
|
5332
5354
|
return isType(str, 'String');
|
|
5333
5355
|
});
|
|
@@ -5350,6 +5372,16 @@
|
|
|
5350
5372
|
return isType(value, 'Number');
|
|
5351
5373
|
};
|
|
5352
5374
|
|
|
5375
|
+
var PRECISION = 0.00001; // numbers less than this is considered as 0
|
|
5376
|
+
function isNumberEqual(a, b, precision) {
|
|
5377
|
+
if (precision === void 0) { precision = PRECISION; }
|
|
5378
|
+
return Math.abs(a - b) < precision;
|
|
5379
|
+
}
|
|
5380
|
+
|
|
5381
|
+
var mod = function (n, m) {
|
|
5382
|
+
return ((n % m) + m) % m;
|
|
5383
|
+
};
|
|
5384
|
+
|
|
5353
5385
|
/**
|
|
5354
5386
|
* 是否是布尔类型
|
|
5355
5387
|
*
|
|
@@ -5790,6 +5822,10 @@
|
|
|
5790
5822
|
return Math.sqrt(dx * dx + dy * dy);
|
|
5791
5823
|
}
|
|
5792
5824
|
|
|
5825
|
+
function isNumberEqual$1(v1, v2) {
|
|
5826
|
+
return Math.abs(v1 - v2) < 0.001;
|
|
5827
|
+
}
|
|
5828
|
+
|
|
5793
5829
|
function getBBoxByArray(xArr, yArr) {
|
|
5794
5830
|
var minX = Math.min.apply(Math, xArr);
|
|
5795
5831
|
var minY = Math.min.apply(Math, yArr);
|
|
@@ -5802,6 +5838,10 @@
|
|
|
5802
5838
|
height: maxY - minY
|
|
5803
5839
|
};
|
|
5804
5840
|
}
|
|
5841
|
+
|
|
5842
|
+
function piMod(angle) {
|
|
5843
|
+
return (angle + Math.PI * 2) % (Math.PI * 2);
|
|
5844
|
+
}
|
|
5805
5845
|
var line = {
|
|
5806
5846
|
/**
|
|
5807
5847
|
* 计算线段的包围盒
|
|
@@ -5906,6 +5946,687 @@
|
|
|
5906
5946
|
return Math.atan2(y2 - y1, x2 - x1);
|
|
5907
5947
|
}
|
|
5908
5948
|
};
|
|
5949
|
+
var EPSILON$1 = 0.0001;
|
|
5950
|
+
/**
|
|
5951
|
+
* 使用牛顿切割法求最近的点
|
|
5952
|
+
* @param {number[]} xArr 点的 x 数组
|
|
5953
|
+
* @param {number[]} yArr 点的 y 数组
|
|
5954
|
+
* @param {number} x 指定的点 x
|
|
5955
|
+
* @param {number} y 指定的点 y
|
|
5956
|
+
* @param {Function} tCallback 差值函数
|
|
5957
|
+
*/
|
|
5958
|
+
|
|
5959
|
+
function nearestPoint(xArr, yArr, x, y, tCallback, length) {
|
|
5960
|
+
var t = -1;
|
|
5961
|
+
var d = Infinity;
|
|
5962
|
+
var v0 = [x, y];
|
|
5963
|
+
var segNum = 20;
|
|
5964
|
+
|
|
5965
|
+
if (length && length > 200) {
|
|
5966
|
+
segNum = length / 10;
|
|
5967
|
+
}
|
|
5968
|
+
|
|
5969
|
+
var increaseRate = 1 / segNum;
|
|
5970
|
+
var interval = increaseRate / 10;
|
|
5971
|
+
|
|
5972
|
+
for (var i = 0; i <= segNum; i++) {
|
|
5973
|
+
var _t = i * increaseRate;
|
|
5974
|
+
|
|
5975
|
+
var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
|
|
5976
|
+
var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
|
|
5977
|
+
|
|
5978
|
+
if (d1 < d) {
|
|
5979
|
+
t = _t;
|
|
5980
|
+
d = d1;
|
|
5981
|
+
}
|
|
5982
|
+
} // 提前终止
|
|
5983
|
+
|
|
5984
|
+
|
|
5985
|
+
if (t === 0) {
|
|
5986
|
+
return {
|
|
5987
|
+
x: xArr[0],
|
|
5988
|
+
y: yArr[0]
|
|
5989
|
+
};
|
|
5990
|
+
}
|
|
5991
|
+
|
|
5992
|
+
if (t === 1) {
|
|
5993
|
+
var count = xArr.length;
|
|
5994
|
+
return {
|
|
5995
|
+
x: xArr[count - 1],
|
|
5996
|
+
y: yArr[count - 1]
|
|
5997
|
+
};
|
|
5998
|
+
}
|
|
5999
|
+
|
|
6000
|
+
d = Infinity;
|
|
6001
|
+
|
|
6002
|
+
for (var _i = 0; _i < 32; _i++) {
|
|
6003
|
+
if (interval < EPSILON$1) {
|
|
6004
|
+
break;
|
|
6005
|
+
}
|
|
6006
|
+
|
|
6007
|
+
var prev = t - interval;
|
|
6008
|
+
var next = t + interval;
|
|
6009
|
+
var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
|
|
6010
|
+
|
|
6011
|
+
var _d = distance(v0[0], v0[1], _v[0], _v[1]);
|
|
6012
|
+
|
|
6013
|
+
if (prev >= 0 && _d < d) {
|
|
6014
|
+
t = prev;
|
|
6015
|
+
d = _d;
|
|
6016
|
+
} else {
|
|
6017
|
+
var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
|
|
6018
|
+
var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
|
|
6019
|
+
|
|
6020
|
+
if (next <= 1 && d2 < d) {
|
|
6021
|
+
t = next;
|
|
6022
|
+
d = d2;
|
|
6023
|
+
} else {
|
|
6024
|
+
interval *= 0.5;
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
|
|
6029
|
+
return {
|
|
6030
|
+
x: tCallback.apply(void 0, xArr.concat([t])),
|
|
6031
|
+
y: tCallback.apply(void 0, yArr.concat([t]))
|
|
6032
|
+
};
|
|
6033
|
+
} // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
|
|
6034
|
+
|
|
6035
|
+
|
|
6036
|
+
function snapLength(xArr, yArr) {
|
|
6037
|
+
var totalLength = 0;
|
|
6038
|
+
var count = xArr.length;
|
|
6039
|
+
|
|
6040
|
+
for (var i = 0; i < count; i++) {
|
|
6041
|
+
var x = xArr[i];
|
|
6042
|
+
var y = yArr[i];
|
|
6043
|
+
var nextX = xArr[(i + 1) % count];
|
|
6044
|
+
var nextY = yArr[(i + 1) % count];
|
|
6045
|
+
totalLength += distance(x, y, nextX, nextY);
|
|
6046
|
+
}
|
|
6047
|
+
|
|
6048
|
+
return totalLength / 2;
|
|
6049
|
+
}
|
|
6050
|
+
|
|
6051
|
+
function quadraticAt(p0, p1, p2, t) {
|
|
6052
|
+
var onet = 1 - t;
|
|
6053
|
+
return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
|
|
6054
|
+
} // 求极值
|
|
6055
|
+
|
|
6056
|
+
|
|
6057
|
+
function extrema(p0, p1, p2) {
|
|
6058
|
+
var a = p0 + p2 - 2 * p1;
|
|
6059
|
+
|
|
6060
|
+
if (isNumberEqual$1(a, 0)) {
|
|
6061
|
+
return [0.5];
|
|
6062
|
+
}
|
|
6063
|
+
|
|
6064
|
+
var rst = (p0 - p1) / a;
|
|
6065
|
+
|
|
6066
|
+
if (rst <= 1 && rst >= 0) {
|
|
6067
|
+
return [rst];
|
|
6068
|
+
}
|
|
6069
|
+
|
|
6070
|
+
return [];
|
|
6071
|
+
}
|
|
6072
|
+
|
|
6073
|
+
function derivativeAt(p0, p1, p2, t) {
|
|
6074
|
+
return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
|
|
6075
|
+
} // 分割贝塞尔曲线
|
|
6076
|
+
|
|
6077
|
+
|
|
6078
|
+
function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
|
|
6079
|
+
// 划分点
|
|
6080
|
+
var xt = quadraticAt(x1, x2, x3, t);
|
|
6081
|
+
var yt = quadraticAt(y1, y2, y3, t); // 分割的第一条曲线的控制点
|
|
6082
|
+
|
|
6083
|
+
var controlPoint1 = line.pointAt(x1, y1, x2, y2, t); // 分割的第二条曲线的控制点
|
|
6084
|
+
|
|
6085
|
+
var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
|
|
6086
|
+
return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
|
|
6087
|
+
} // 使用迭代法取贝塞尔曲线的长度
|
|
6088
|
+
|
|
6089
|
+
|
|
6090
|
+
function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
|
|
6091
|
+
if (iterationCount === 0) {
|
|
6092
|
+
return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
|
|
6093
|
+
}
|
|
6094
|
+
|
|
6095
|
+
var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
|
|
6096
|
+
var left = quadratics[0];
|
|
6097
|
+
var right = quadratics[1];
|
|
6098
|
+
left.push(iterationCount - 1);
|
|
6099
|
+
right.push(iterationCount - 1);
|
|
6100
|
+
return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
|
|
6101
|
+
}
|
|
6102
|
+
|
|
6103
|
+
var quadratic = {
|
|
6104
|
+
box: function box(x1, y1, x2, y2, x3, y3) {
|
|
6105
|
+
var xExtrema = extrema(x1, x2, x3)[0];
|
|
6106
|
+
var yExtrema = extrema(y1, y2, y3)[0]; // 控制点不加入 box 的计算
|
|
6107
|
+
|
|
6108
|
+
var xArr = [x1, x3];
|
|
6109
|
+
var yArr = [y1, y3];
|
|
6110
|
+
|
|
6111
|
+
if (xExtrema !== undefined) {
|
|
6112
|
+
xArr.push(quadraticAt(x1, x2, x3, xExtrema));
|
|
6113
|
+
}
|
|
6114
|
+
|
|
6115
|
+
if (yExtrema !== undefined) {
|
|
6116
|
+
yArr.push(quadraticAt(y1, y2, y3, yExtrema));
|
|
6117
|
+
}
|
|
6118
|
+
|
|
6119
|
+
return getBBoxByArray(xArr, yArr);
|
|
6120
|
+
},
|
|
6121
|
+
length: function length(x1, y1, x2, y2, x3, y3) {
|
|
6122
|
+
return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
|
|
6123
|
+
},
|
|
6124
|
+
nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
6125
|
+
return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
|
|
6126
|
+
},
|
|
6127
|
+
pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
6128
|
+
var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
|
|
6129
|
+
return distance(point.x, point.y, x0, y0);
|
|
6130
|
+
},
|
|
6131
|
+
interpolationAt: quadraticAt,
|
|
6132
|
+
pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
|
|
6133
|
+
return {
|
|
6134
|
+
x: quadraticAt(x1, x2, x3, t),
|
|
6135
|
+
y: quadraticAt(y1, y2, y3, t)
|
|
6136
|
+
};
|
|
6137
|
+
},
|
|
6138
|
+
divide: function divide(x1, y1, x2, y2, x3, y3, t) {
|
|
6139
|
+
return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
|
|
6140
|
+
},
|
|
6141
|
+
tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
|
|
6142
|
+
var dx = derivativeAt(x1, x2, x3, t);
|
|
6143
|
+
var dy = derivativeAt(y1, y2, y3, t);
|
|
6144
|
+
var angle = Math.atan2(dy, dx);
|
|
6145
|
+
return piMod(angle);
|
|
6146
|
+
}
|
|
6147
|
+
};
|
|
6148
|
+
|
|
6149
|
+
function cubicAt(p0, p1, p2, p3, t) {
|
|
6150
|
+
var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
|
|
6151
|
+
|
|
6152
|
+
return onet * onet * onet * p0 + 3 * p1 * t * onet * onet + 3 * p2 * t * t * onet + p3 * t * t * t;
|
|
6153
|
+
}
|
|
6154
|
+
|
|
6155
|
+
function derivativeAt$1(p0, p1, p2, p3, t) {
|
|
6156
|
+
var onet = 1 - t;
|
|
6157
|
+
return 3 * (onet * onet * (p1 - p0) + 2 * onet * t * (p2 - p1) + t * t * (p3 - p2));
|
|
6158
|
+
}
|
|
6159
|
+
|
|
6160
|
+
function extrema$1(p0, p1, p2, p3) {
|
|
6161
|
+
var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
|
|
6162
|
+
var b = 6 * p0 - 12 * p1 + 6 * p2;
|
|
6163
|
+
var c = 3 * p1 - 3 * p0;
|
|
6164
|
+
var extremas = [];
|
|
6165
|
+
var t1;
|
|
6166
|
+
var t2;
|
|
6167
|
+
var discSqrt;
|
|
6168
|
+
|
|
6169
|
+
if (isNumberEqual$1(a, 0)) {
|
|
6170
|
+
if (!isNumberEqual$1(b, 0)) {
|
|
6171
|
+
t1 = -c / b;
|
|
6172
|
+
|
|
6173
|
+
if (t1 >= 0 && t1 <= 1) {
|
|
6174
|
+
extremas.push(t1);
|
|
6175
|
+
}
|
|
6176
|
+
}
|
|
6177
|
+
} else {
|
|
6178
|
+
var disc = b * b - 4 * a * c;
|
|
6179
|
+
|
|
6180
|
+
if (isNumberEqual$1(disc, 0)) {
|
|
6181
|
+
extremas.push(-b / (2 * a));
|
|
6182
|
+
} else if (disc > 0) {
|
|
6183
|
+
discSqrt = Math.sqrt(disc);
|
|
6184
|
+
t1 = (-b + discSqrt) / (2 * a);
|
|
6185
|
+
t2 = (-b - discSqrt) / (2 * a);
|
|
6186
|
+
|
|
6187
|
+
if (t1 >= 0 && t1 <= 1) {
|
|
6188
|
+
extremas.push(t1);
|
|
6189
|
+
}
|
|
6190
|
+
|
|
6191
|
+
if (t2 >= 0 && t2 <= 1) {
|
|
6192
|
+
extremas.push(t2);
|
|
6193
|
+
}
|
|
6194
|
+
}
|
|
6195
|
+
}
|
|
6196
|
+
|
|
6197
|
+
return extremas;
|
|
6198
|
+
} // 分割贝塞尔曲线
|
|
6199
|
+
|
|
6200
|
+
|
|
6201
|
+
function divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6202
|
+
// 划分点
|
|
6203
|
+
var xt = cubicAt(x1, x2, x3, x4, t);
|
|
6204
|
+
var yt = cubicAt(y1, y2, y3, y4, t); // 计算两点之间的差值点
|
|
6205
|
+
|
|
6206
|
+
var c1 = line.pointAt(x1, y1, x2, y2, t);
|
|
6207
|
+
var c2 = line.pointAt(x2, y2, x3, y3, t);
|
|
6208
|
+
var c3 = line.pointAt(x3, y3, x4, y4, t);
|
|
6209
|
+
var c12 = line.pointAt(c1.x, c1.y, c2.x, c2.y, t);
|
|
6210
|
+
var c23 = line.pointAt(c2.x, c2.y, c3.x, c3.y, t);
|
|
6211
|
+
return [[x1, y1, c1.x, c1.y, c12.x, c12.y, xt, yt], [xt, yt, c23.x, c23.y, c3.x, c3.y, x4, y4]];
|
|
6212
|
+
} // 使用迭代法取贝塞尔曲线的长度,二阶和三阶分开写,更清晰和便于调试
|
|
6213
|
+
|
|
6214
|
+
|
|
6215
|
+
function cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, iterationCount) {
|
|
6216
|
+
if (iterationCount === 0) {
|
|
6217
|
+
return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
|
|
6218
|
+
}
|
|
6219
|
+
|
|
6220
|
+
var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
|
|
6221
|
+
var left = [].concat(cubics[0], [iterationCount - 1]);
|
|
6222
|
+
var right = [].concat(cubics[1], [iterationCount - 1]);
|
|
6223
|
+
return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
|
|
6224
|
+
}
|
|
6225
|
+
|
|
6226
|
+
var cubic = {
|
|
6227
|
+
extrema: extrema$1,
|
|
6228
|
+
box: function box(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
6229
|
+
var xArr = [x1, x4];
|
|
6230
|
+
var yArr = [y1, y4];
|
|
6231
|
+
var xExtrema = extrema$1(x1, x2, x3, x4);
|
|
6232
|
+
var yExtrema = extrema$1(y1, y2, y3, y4);
|
|
6233
|
+
|
|
6234
|
+
for (var i = 0; i < xExtrema.length; i++) {
|
|
6235
|
+
xArr.push(cubicAt(x1, x2, x3, x4, xExtrema[i]));
|
|
6236
|
+
}
|
|
6237
|
+
|
|
6238
|
+
for (var _i = 0; _i < yExtrema.length; _i++) {
|
|
6239
|
+
yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i]));
|
|
6240
|
+
}
|
|
6241
|
+
|
|
6242
|
+
return getBBoxByArray(xArr, yArr);
|
|
6243
|
+
},
|
|
6244
|
+
length: function length(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
6245
|
+
// 迭代三次,划分成 8 段求长度
|
|
6246
|
+
return cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, 3);
|
|
6247
|
+
},
|
|
6248
|
+
nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
|
|
6249
|
+
return nearestPoint([x1, x2, x3, x4], [y1, y2, y3, y4], x0, y0, cubicAt, length);
|
|
6250
|
+
},
|
|
6251
|
+
pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
|
|
6252
|
+
var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length);
|
|
6253
|
+
return distance(point.x, point.y, x0, y0);
|
|
6254
|
+
},
|
|
6255
|
+
interpolationAt: cubicAt,
|
|
6256
|
+
pointAt: function pointAt(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6257
|
+
return {
|
|
6258
|
+
x: cubicAt(x1, x2, x3, x4, t),
|
|
6259
|
+
y: cubicAt(y1, y2, y3, y4, t)
|
|
6260
|
+
};
|
|
6261
|
+
},
|
|
6262
|
+
divide: function divide(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6263
|
+
return divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t);
|
|
6264
|
+
},
|
|
6265
|
+
tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
6266
|
+
var dx = derivativeAt$1(x1, x2, x3, x4, t);
|
|
6267
|
+
var dy = derivativeAt$1(y1, y2, y3, y4, t);
|
|
6268
|
+
return piMod(Math.atan2(dy, dx));
|
|
6269
|
+
}
|
|
6270
|
+
};
|
|
6271
|
+
/**
|
|
6272
|
+
* @fileoverview 椭圆的一些计算,
|
|
6273
|
+
* - 周长计算参考:https://www.mathsisfun.com/geometry/ellipse-perimeter.html
|
|
6274
|
+
* - 距离计算参考:https://wet-robots.ghost.io/simple-method-for-distance-to-ellipse/
|
|
6275
|
+
* @author dxq613@gmail.com
|
|
6276
|
+
*/
|
|
6277
|
+
|
|
6278
|
+
function copysign(v1, v2) {
|
|
6279
|
+
var absv = Math.abs(v1);
|
|
6280
|
+
return v2 > 0 ? absv : absv * -1;
|
|
6281
|
+
}
|
|
6282
|
+
|
|
6283
|
+
var ellipse = {
|
|
6284
|
+
/**
|
|
6285
|
+
* 包围盒计算
|
|
6286
|
+
* @param {number} x 椭圆中心 x
|
|
6287
|
+
* @param {number} y 椭圆中心 y
|
|
6288
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6289
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6290
|
+
* @return {object} 包围盒
|
|
6291
|
+
*/
|
|
6292
|
+
box: function box(x, y, rx, ry) {
|
|
6293
|
+
return {
|
|
6294
|
+
x: x - rx,
|
|
6295
|
+
y: y - ry,
|
|
6296
|
+
width: rx * 2,
|
|
6297
|
+
height: ry * 2
|
|
6298
|
+
};
|
|
6299
|
+
},
|
|
6300
|
+
|
|
6301
|
+
/**
|
|
6302
|
+
* 计算周长,使用近似法
|
|
6303
|
+
* @param {number} x 椭圆中心 x
|
|
6304
|
+
* @param {number} y 椭圆中心 y
|
|
6305
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6306
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6307
|
+
* @return {number} 椭圆周长
|
|
6308
|
+
*/
|
|
6309
|
+
length: function length(x, y, rx, ry) {
|
|
6310
|
+
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
6311
|
+
},
|
|
6312
|
+
|
|
6313
|
+
/**
|
|
6314
|
+
* 距离椭圆最近的点
|
|
6315
|
+
* @param {number} x 椭圆中心 x
|
|
6316
|
+
* @param {number} y 椭圆中心 y
|
|
6317
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6318
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6319
|
+
* @param {number} x0 指定的点 x
|
|
6320
|
+
* @param {number} y0 指定的点 y
|
|
6321
|
+
* @return {object} 椭圆上距离指定点最近的点
|
|
6322
|
+
*/
|
|
6323
|
+
nearestPoint: function nearestPoint(x, y, rx, ry, x0, y0) {
|
|
6324
|
+
var a = rx;
|
|
6325
|
+
var b = ry; // 假如椭圆半径为0则返回圆心
|
|
6326
|
+
|
|
6327
|
+
if (a === 0 || b === 0) {
|
|
6328
|
+
return {
|
|
6329
|
+
x: x,
|
|
6330
|
+
y: y
|
|
6331
|
+
};
|
|
6332
|
+
} // 转换成 0, 0 为中心的椭圆计算
|
|
6333
|
+
|
|
6334
|
+
|
|
6335
|
+
var relativeX = x0 - x;
|
|
6336
|
+
var relativeY = y0 - y;
|
|
6337
|
+
var px = Math.abs(relativeX);
|
|
6338
|
+
var py = Math.abs(relativeY);
|
|
6339
|
+
var squareA = a * a;
|
|
6340
|
+
var squareB = b * b; // const angle0 = Math.atan2(relativeY, relativeX);
|
|
6341
|
+
|
|
6342
|
+
var t = Math.PI / 4;
|
|
6343
|
+
var nearestX = 0; // 椭圆上的任一点
|
|
6344
|
+
|
|
6345
|
+
var nearestY = 0; // 迭代 4 次
|
|
6346
|
+
|
|
6347
|
+
for (var i = 0; i < 4; i++) {
|
|
6348
|
+
nearestX = a * Math.cos(t);
|
|
6349
|
+
nearestY = b * Math.sin(t);
|
|
6350
|
+
var ex = (squareA - squareB) * Math.pow(Math.cos(t), 3) / a;
|
|
6351
|
+
var ey = (squareB - squareA) * Math.pow(Math.sin(t), 3) / b;
|
|
6352
|
+
var rx1 = nearestX - ex;
|
|
6353
|
+
var ry1 = nearestY - ey;
|
|
6354
|
+
var qx = px - ex;
|
|
6355
|
+
var qy = py - ey;
|
|
6356
|
+
var r = Math.hypot(ry1, rx1);
|
|
6357
|
+
var q = Math.hypot(qy, qx);
|
|
6358
|
+
var delta_c = r * Math.asin((rx1 * qy - ry1 * qx) / (r * q));
|
|
6359
|
+
var delta_t = delta_c / Math.sqrt(squareA + squareB - nearestX * nearestX - nearestY * nearestY);
|
|
6360
|
+
t += delta_t;
|
|
6361
|
+
t = Math.min(Math.PI / 2, Math.max(0, t));
|
|
6362
|
+
}
|
|
6363
|
+
|
|
6364
|
+
return {
|
|
6365
|
+
x: x + copysign(nearestX, relativeX),
|
|
6366
|
+
y: y + copysign(nearestY, relativeY)
|
|
6367
|
+
};
|
|
6368
|
+
},
|
|
6369
|
+
|
|
6370
|
+
/**
|
|
6371
|
+
* 点到椭圆最近的距离
|
|
6372
|
+
* @param {number} x 椭圆中心 x
|
|
6373
|
+
* @param {number} y 椭圆中心 y
|
|
6374
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6375
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6376
|
+
* @param {number} x0 指定的点 x
|
|
6377
|
+
* @param {number} y0 指定的点 y
|
|
6378
|
+
* @return {number} 点到椭圆的距离
|
|
6379
|
+
*/
|
|
6380
|
+
pointDistance: function pointDistance(x, y, rx, ry, x0, y0) {
|
|
6381
|
+
var nearestPoint = this.nearestPoint(x, y, rx, ry, x0, y0);
|
|
6382
|
+
return distance(nearestPoint.x, nearestPoint.y, x0, y0);
|
|
6383
|
+
},
|
|
6384
|
+
|
|
6385
|
+
/**
|
|
6386
|
+
* 根据比例获取点
|
|
6387
|
+
* @param {number} x 椭圆中心 x
|
|
6388
|
+
* @param {number} y 椭圆中心 y
|
|
6389
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6390
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6391
|
+
* @param {number} t 指定比例,x轴方向为 0
|
|
6392
|
+
* @return {object} 点
|
|
6393
|
+
*/
|
|
6394
|
+
pointAt: function pointAt(x, y, rx, ry, t) {
|
|
6395
|
+
var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
|
|
6396
|
+
|
|
6397
|
+
return {
|
|
6398
|
+
x: x + rx * Math.cos(angle),
|
|
6399
|
+
y: y + ry * Math.sin(angle)
|
|
6400
|
+
};
|
|
6401
|
+
},
|
|
6402
|
+
|
|
6403
|
+
/**
|
|
6404
|
+
* 根据比例计算切线角度
|
|
6405
|
+
* @param {number} x 椭圆中心 x
|
|
6406
|
+
* @param {number} y 椭圆中心 y
|
|
6407
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
6408
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
6409
|
+
* @param {number} t 指定比例 0 - 1 之间,x轴方向为 0。在 0-1 范围之外是循环还是返回 null,还需要调整
|
|
6410
|
+
* @return {number} 角度,在 0 - 2PI 之间
|
|
6411
|
+
*/
|
|
6412
|
+
tangentAngle: function tangentAngle(x, y, rx, ry, t) {
|
|
6413
|
+
var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
|
|
6414
|
+
// 直接使用 x,y 的导数计算, x' = -rx * sin(t); y' = ry * cos(t);
|
|
6415
|
+
|
|
6416
|
+
var tangentAngle = Math.atan2(ry * Math.cos(angle), -rx * Math.sin(angle)); // 也可以使用指定点的切线方程计算,成本有些高
|
|
6417
|
+
// const point = this.pointAt(0, 0, rx, ry, t); // 椭圆的切线同椭圆的中心不相关
|
|
6418
|
+
// let tangentAngle = -1 * Math.atan((ry * ry * point.x) / (rx * rx * point.y));
|
|
6419
|
+
// if (angle >= 0 && angle <= Math.PI) {
|
|
6420
|
+
// tangentAngle += Math.PI;
|
|
6421
|
+
// }
|
|
6422
|
+
|
|
6423
|
+
return piMod(tangentAngle);
|
|
6424
|
+
}
|
|
6425
|
+
};
|
|
6426
|
+
|
|
6427
|
+
function derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
|
|
6428
|
+
return -1 * rx * Math.cos(xRotation) * Math.sin(angle) - ry * Math.sin(xRotation) * Math.cos(angle);
|
|
6429
|
+
} // 偏导数 y
|
|
6430
|
+
|
|
6431
|
+
|
|
6432
|
+
function derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
|
|
6433
|
+
return -1 * rx * Math.sin(xRotation) * Math.sin(angle) + ry * Math.cos(xRotation) * Math.cos(angle);
|
|
6434
|
+
} // x 的极值
|
|
6435
|
+
|
|
6436
|
+
|
|
6437
|
+
function xExtrema(rx, ry, xRotation) {
|
|
6438
|
+
return Math.atan(-ry / rx * Math.tan(xRotation));
|
|
6439
|
+
} // y 的极值
|
|
6440
|
+
|
|
6441
|
+
|
|
6442
|
+
function yExtrema(rx, ry, xRotation) {
|
|
6443
|
+
return Math.atan(ry / (rx * Math.tan(xRotation)));
|
|
6444
|
+
} // 根据角度求 x 坐标
|
|
6445
|
+
|
|
6446
|
+
|
|
6447
|
+
function xAt(cx, cy, rx, ry, xRotation, angle) {
|
|
6448
|
+
return rx * Math.cos(xRotation) * Math.cos(angle) - ry * Math.sin(xRotation) * Math.sin(angle) + cx;
|
|
6449
|
+
} // 根据角度求 y 坐标
|
|
6450
|
+
|
|
6451
|
+
|
|
6452
|
+
function yAt(cx, cy, rx, ry, xRotation, angle) {
|
|
6453
|
+
return rx * Math.sin(xRotation) * Math.cos(angle) + ry * Math.cos(xRotation) * Math.sin(angle) + cy;
|
|
6454
|
+
} // 获取点在椭圆上的角度
|
|
6455
|
+
|
|
6456
|
+
|
|
6457
|
+
function getAngle(rx, ry, x0, y0) {
|
|
6458
|
+
var angle = Math.atan2(y0 * rx, x0 * ry); // 转换到 0 - 2PI 内
|
|
6459
|
+
|
|
6460
|
+
return (angle + Math.PI * 2) % (Math.PI * 2);
|
|
6461
|
+
} // 根据角度获取,x,y
|
|
6462
|
+
|
|
6463
|
+
|
|
6464
|
+
function getPoint(rx, ry, angle) {
|
|
6465
|
+
return {
|
|
6466
|
+
x: rx * Math.cos(angle),
|
|
6467
|
+
y: ry * Math.sin(angle)
|
|
6468
|
+
};
|
|
6469
|
+
} // 旋转
|
|
6470
|
+
|
|
6471
|
+
|
|
6472
|
+
function rotate$1(x, y, angle) {
|
|
6473
|
+
var cos = Math.cos(angle);
|
|
6474
|
+
var sin = Math.sin(angle);
|
|
6475
|
+
return [x * cos - y * sin, x * sin + y * cos];
|
|
6476
|
+
}
|
|
6477
|
+
|
|
6478
|
+
var arc = {
|
|
6479
|
+
/**
|
|
6480
|
+
* 计算包围盒
|
|
6481
|
+
* @param {number} cx 圆心 x
|
|
6482
|
+
* @param {number} cy 圆心 y
|
|
6483
|
+
* @param {number} rx x 轴方向的半径
|
|
6484
|
+
* @param {number} ry y 轴方向的半径
|
|
6485
|
+
* @param {number} xRotation 旋转角度
|
|
6486
|
+
* @param {number} startAngle 起始角度
|
|
6487
|
+
* @param {number} endAngle 结束角度
|
|
6488
|
+
* @return {object} 包围盒对象
|
|
6489
|
+
*/
|
|
6490
|
+
box: function box(cx, cy, rx, ry, xRotation, startAngle, endAngle) {
|
|
6491
|
+
var xDim = xExtrema(rx, ry, xRotation);
|
|
6492
|
+
var minX = Infinity;
|
|
6493
|
+
var maxX = -Infinity;
|
|
6494
|
+
var xs = [startAngle, endAngle];
|
|
6495
|
+
|
|
6496
|
+
for (var i = -Math.PI * 2; i <= Math.PI * 2; i += Math.PI) {
|
|
6497
|
+
var xAngle = xDim + i;
|
|
6498
|
+
|
|
6499
|
+
if (startAngle < endAngle) {
|
|
6500
|
+
if (startAngle < xAngle && xAngle < endAngle) {
|
|
6501
|
+
xs.push(xAngle);
|
|
6502
|
+
}
|
|
6503
|
+
} else {
|
|
6504
|
+
if (endAngle < xAngle && xAngle < startAngle) {
|
|
6505
|
+
xs.push(xAngle);
|
|
6506
|
+
}
|
|
6507
|
+
}
|
|
6508
|
+
}
|
|
6509
|
+
|
|
6510
|
+
for (var _i = 0; _i < xs.length; _i++) {
|
|
6511
|
+
var x = xAt(cx, cy, rx, ry, xRotation, xs[_i]);
|
|
6512
|
+
|
|
6513
|
+
if (x < minX) {
|
|
6514
|
+
minX = x;
|
|
6515
|
+
}
|
|
6516
|
+
|
|
6517
|
+
if (x > maxX) {
|
|
6518
|
+
maxX = x;
|
|
6519
|
+
}
|
|
6520
|
+
}
|
|
6521
|
+
|
|
6522
|
+
var yDim = yExtrema(rx, ry, xRotation);
|
|
6523
|
+
var minY = Infinity;
|
|
6524
|
+
var maxY = -Infinity;
|
|
6525
|
+
var ys = [startAngle, endAngle];
|
|
6526
|
+
|
|
6527
|
+
for (var _i2 = -Math.PI * 2; _i2 <= Math.PI * 2; _i2 += Math.PI) {
|
|
6528
|
+
var yAngle = yDim + _i2;
|
|
6529
|
+
|
|
6530
|
+
if (startAngle < endAngle) {
|
|
6531
|
+
if (startAngle < yAngle && yAngle < endAngle) {
|
|
6532
|
+
ys.push(yAngle);
|
|
6533
|
+
}
|
|
6534
|
+
} else {
|
|
6535
|
+
if (endAngle < yAngle && yAngle < startAngle) {
|
|
6536
|
+
ys.push(yAngle);
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
|
|
6541
|
+
for (var _i3 = 0; _i3 < ys.length; _i3++) {
|
|
6542
|
+
var y = yAt(cx, cy, rx, ry, xRotation, ys[_i3]);
|
|
6543
|
+
|
|
6544
|
+
if (y < minY) {
|
|
6545
|
+
minY = y;
|
|
6546
|
+
}
|
|
6547
|
+
|
|
6548
|
+
if (y > maxY) {
|
|
6549
|
+
maxY = y;
|
|
6550
|
+
}
|
|
6551
|
+
}
|
|
6552
|
+
|
|
6553
|
+
return {
|
|
6554
|
+
x: minX,
|
|
6555
|
+
y: minY,
|
|
6556
|
+
width: maxX - minX,
|
|
6557
|
+
height: maxY - minY
|
|
6558
|
+
};
|
|
6559
|
+
},
|
|
6560
|
+
|
|
6561
|
+
/**
|
|
6562
|
+
* 获取圆弧的长度,计算圆弧长度时不考虑旋转角度,
|
|
6563
|
+
* 仅跟 rx, ry, startAngle, endAngle 相关
|
|
6564
|
+
* @param {number} cx 圆心 x
|
|
6565
|
+
* @param {number} cy 圆心 y
|
|
6566
|
+
* @param {number} rx x 轴方向的半径
|
|
6567
|
+
* @param {number} ry y 轴方向的半径
|
|
6568
|
+
* @param {number} xRotation 旋转角度
|
|
6569
|
+
* @param {number} startAngle 起始角度
|
|
6570
|
+
* @param {number} endAngle 结束角度
|
|
6571
|
+
*/
|
|
6572
|
+
length: function length(cx, cy, rx, ry, xRotation, startAngle, endAngle) {},
|
|
6573
|
+
|
|
6574
|
+
/**
|
|
6575
|
+
* 获取指定点到圆弧的最近距离的点
|
|
6576
|
+
* @param {number} cx 圆心 x
|
|
6577
|
+
* @param {number} cy 圆心 y
|
|
6578
|
+
* @param {number} rx x 轴方向的半径
|
|
6579
|
+
* @param {number} ry y 轴方向的半径
|
|
6580
|
+
* @param {number} xRotation 旋转角度
|
|
6581
|
+
* @param {number} startAngle 起始角度
|
|
6582
|
+
* @param {number} endAngle 结束角度
|
|
6583
|
+
* @param {number} x0 指定点的 x
|
|
6584
|
+
* @param {number} y0 指定点的 y
|
|
6585
|
+
* @return {object} 到指定点最近距离的点
|
|
6586
|
+
*/
|
|
6587
|
+
nearestPoint: function nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
|
|
6588
|
+
// 将最近距离问题转换成到椭圆中心 0,0 没有旋转的椭圆问题
|
|
6589
|
+
var relativeVector = rotate$1(x0 - cx, y0 - cy, -xRotation);
|
|
6590
|
+
var x1 = relativeVector[0],
|
|
6591
|
+
y1 = relativeVector[1]; // 计算点到椭圆的最近的点
|
|
6592
|
+
|
|
6593
|
+
var relativePoint = ellipse.nearestPoint(0, 0, rx, ry, x1, y1); // 获取点在椭圆上的角度
|
|
6594
|
+
|
|
6595
|
+
var angle = getAngle(rx, ry, relativePoint.x, relativePoint.y); // 点没有在圆弧上
|
|
6596
|
+
|
|
6597
|
+
if (angle < startAngle) {
|
|
6598
|
+
// 小于起始圆弧
|
|
6599
|
+
relativePoint = getPoint(rx, ry, startAngle);
|
|
6600
|
+
} else if (angle > endAngle) {
|
|
6601
|
+
// 大于结束圆弧
|
|
6602
|
+
relativePoint = getPoint(rx, ry, endAngle);
|
|
6603
|
+
} // 旋转到 xRotation 的角度
|
|
6604
|
+
|
|
6605
|
+
|
|
6606
|
+
var vector = rotate$1(relativePoint.x, relativePoint.y, xRotation);
|
|
6607
|
+
return {
|
|
6608
|
+
x: vector[0] + cx,
|
|
6609
|
+
y: vector[1] + cy
|
|
6610
|
+
};
|
|
6611
|
+
},
|
|
6612
|
+
pointDistance: function pointDistance(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
|
|
6613
|
+
var nearestPoint = this.nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0);
|
|
6614
|
+
return distance(nearestPoint.x, nearestPoint.y, x0, y0);
|
|
6615
|
+
},
|
|
6616
|
+
pointAt: function pointAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
|
|
6617
|
+
var angle = (endAngle - startAngle) * t + startAngle;
|
|
6618
|
+
return {
|
|
6619
|
+
x: xAt(cx, cy, rx, ry, xRotation, angle),
|
|
6620
|
+
y: yAt(cx, cy, rx, ry, xRotation, angle)
|
|
6621
|
+
};
|
|
6622
|
+
},
|
|
6623
|
+
tangentAngle: function tangentAngle(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
|
|
6624
|
+
var angle = (endAngle - startAngle) * t + startAngle;
|
|
6625
|
+
var dx = derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
|
|
6626
|
+
var dy = derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
|
|
6627
|
+
return piMod(Math.atan2(dy, dx));
|
|
6628
|
+
}
|
|
6629
|
+
};
|
|
5909
6630
|
|
|
5910
6631
|
function analyzePoints(points) {
|
|
5911
6632
|
// 计算每段的长度和总的长度
|
|
@@ -7241,17 +7962,9 @@
|
|
|
7241
7962
|
if(path===''||Array.isArray(path)&&path.length===0){return {absolutePath:[],hasArc:false,segments:[],polygons:[],polylines:[],curve:[],totalLength:0,zCommandIndexes:[],rect:{x:0,y:0,width:0,height:0}};}var absolutePath;try{absolutePath=normalizePath(path);}catch(e){absolutePath=normalizePath('');console.error("[g]: Invalid SVG Path definition: "+path);}var hasArc=hasArcOrBezier(absolutePath);var _extractPolygons=extractPolygons(absolutePath),polygons=_extractPolygons.polygons,polylines=_extractPolygons.polylines;// convert to curves to do morphing & picking later
|
|
7242
7963
|
// @see http://thednp.github.io/kute.js/svgCubicMorph.html
|
|
7243
7964
|
var _path2Curve=path2Curve(absolutePath,true),curve=_path2Curve[0],zCommandIndexes=_path2Curve[1];// for later use
|
|
7244
|
-
var segments=path2Segments(
|
|
7245
|
-
var _getPathBBox=getPathBBox(
|
|
7246
|
-
|
|
7247
|
-
// totalLength: length,
|
|
7248
|
-
totalLength:0,zCommandIndexes:zCommandIndexes,// rect: new Rectangle(
|
|
7249
|
-
// Number.isFinite(x) ? x : 0,
|
|
7250
|
-
// Number.isFinite(y) ? y : 0,
|
|
7251
|
-
// Number.isFinite(width) ? width : 0,
|
|
7252
|
-
// Number.isFinite(height) ? height : 0,
|
|
7253
|
-
// ),
|
|
7254
|
-
rect:{x:Number.isFinite(x)?x:0,y:Number.isFinite(y)?y:0,width:Number.isFinite(width)?width:0,height:Number.isFinite(height)?height:0}};};var memoizedParsePath=memoize(internalParsePath);function parsePath(path,object){var result=isString(path)?memoizedParsePath(path):internalParsePath(path);if(object){object.parsedStyle.defX=result.rect.x;object.parsedStyle.defY=result.rect.y;}return result;}function mergePaths(left,right,object){var curve1=left.curve;var curve2=right.curve;var curves=[curve1,curve2];if(curve1.length!==curve2.length){curves=equalizeSegments(curve1,curve2);}var curve0=getDrawDirection(curves[0])!==getDrawDirection(curves[1])?reverseCurve(curves[0]):clonePath(curves[0]);return [curve0,getRotatedCurve(curves[1],curve0),function(pathArray){// need converting to path string?
|
|
7965
|
+
var segments=path2Segments(absolutePath);// Only calculate bbox here since we don't need length now.
|
|
7966
|
+
var _getPathBBox=getPathBBox(segments,0),x=_getPathBBox.x,y=_getPathBBox.y,width=_getPathBBox.width,height=_getPathBBox.height;return {absolutePath:absolutePath,hasArc:hasArc,segments:segments,polygons:polygons,polylines:polylines,curve:curve,// Delay the calculation of length.
|
|
7967
|
+
totalLength:0,zCommandIndexes:zCommandIndexes,rect:{x:Number.isFinite(x)?x:0,y:Number.isFinite(y)?y:0,width:Number.isFinite(width)?width:0,height:Number.isFinite(height)?height:0}};};var memoizedParsePath=memoize(internalParsePath);function parsePath(path,object){var result=isString(path)?memoizedParsePath(path):internalParsePath(path);if(object){object.parsedStyle.defX=result.rect.x;object.parsedStyle.defY=result.rect.y;}return result;}function mergePaths(left,right,object){var curve1=left.curve;var curve2=right.curve;var curves=[curve1,curve2];if(curve1.length!==curve2.length){curves=equalizeSegments(curve1,curve2);}var curve0=getDrawDirection(curves[0])!==getDrawDirection(curves[1])?reverseCurve(curves[0]):clonePath(curves[0]);return [curve0,getRotatedCurve(curves[1],curve0),function(pathArray){// need converting to path string?
|
|
7255
7968
|
return pathArray;}];}/**
|
|
7256
7969
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/points
|
|
7257
7970
|
*
|
|
@@ -7399,7 +8112,7 @@
|
|
|
7399
8112
|
* @example
|
|
7400
8113
|
* [10px, 10px] [10%, 10%]
|
|
7401
8114
|
*/var CSSPropertyTransformOrigin=function CSSPropertyTransformOrigin(){this.parser=parseTransformOrigin;};var CSSPropertyZIndex=/*#__PURE__*/function(){function CSSPropertyZIndex(){this.parser=parseNumber;}var _proto=CSSPropertyZIndex.prototype;_proto.calculator=function calculator(name,oldParsed,computed,object){return computed.value;};_proto.postProcessor=function postProcessor(object){if(object.parentNode){var parentEntity=object.parentNode;var parentRenderable=parentEntity.renderable;var parentSortable=parentEntity.sortable;if(parentRenderable){parentRenderable.dirty=true;}// need re-sort on parent
|
|
7402
|
-
if(parentSortable){parentSortable.dirty=true;}}};return CSSPropertyZIndex;}();function getAngle(angle){if(angle===undefined){return 0;}else if(angle>360||angle<-360){return angle%360;}return angle;}function createVec3(x,y,z){if(y===void 0){y=0;}if(z===void 0){z=0;}if(isNumber(x)){return fromValues$2(x,y,z);}if(Array.isArray(x)&&x.length===3){return clone$1(x);}return fromValues$2(x[0],x[1]||y,x[2]||z);}function deg2rad(deg){return deg*(Math.PI/180);}function rad2deg(rad){return rad*(180/Math.PI);}function grad2deg(grads){grads=grads%400;if(grads<0){grads+=400;}return grads/400*360;}function deg2turn(deg){return deg/360;}function turn2deg(turn){return 360*turn;}function getEulerFromQuat(out,quat){var x=quat[0];var y=quat[1];var z=quat[2];var w=quat[3];var x2=x*x;var y2=y*y;var z2=z*z;var w2=w*w;var unit=x2+y2+z2+w2;var test=x*w-y*z;if(test>0.499995*unit){// TODO: Use glmatrix.EPSILON
|
|
8115
|
+
if(parentSortable){parentSortable.dirty=true;}}};return CSSPropertyZIndex;}();function getAngle$1(angle){if(angle===undefined){return 0;}else if(angle>360||angle<-360){return angle%360;}return angle;}function createVec3(x,y,z){if(y===void 0){y=0;}if(z===void 0){z=0;}if(isNumber(x)){return fromValues$2(x,y,z);}if(Array.isArray(x)&&x.length===3){return clone$1(x);}return fromValues$2(x[0],x[1]||y,x[2]||z);}function deg2rad(deg){return deg*(Math.PI/180);}function rad2deg(rad){return rad*(180/Math.PI);}function grad2deg(grads){grads=grads%400;if(grads<0){grads+=400;}return grads/400*360;}function deg2turn(deg){return deg/360;}function turn2deg(turn){return 360*turn;}function getEulerFromQuat(out,quat){var x=quat[0];var y=quat[1];var z=quat[2];var w=quat[3];var x2=x*x;var y2=y*y;var z2=z*z;var w2=w*w;var unit=x2+y2+z2+w2;var test=x*w-y*z;if(test>0.499995*unit){// TODO: Use glmatrix.EPSILON
|
|
7403
8116
|
// singularity at the north pole
|
|
7404
8117
|
out[0]=Math.PI/2;out[1]=2*Math.atan2(y,x);out[2]=0;}else if(test<-0.499995*unit){//TODO: Use glmatrix.EPSILON
|
|
7405
8118
|
// singularity at the south pole
|
|
@@ -7479,27 +8192,58 @@
|
|
|
7479
8192
|
}// 如果不存在点,同时 'Z',则说明是错误,不处理
|
|
7480
8193
|
}else {points.push([params[1],params[2]]);}}// 说明 points 未放入 polygons 或者 polyline
|
|
7481
8194
|
// 仅当只有一个 M,没有 Z 时会发生这种情况
|
|
7482
|
-
if(points.length>0){polylines.push(points);}return {polygons:polygons,polylines:polylines};}function isSamePoint(point1,point2){return point1[0]===point2[0]&&point1[1]===point2[1];}function
|
|
8195
|
+
if(points.length>0){polylines.push(points);}return {polygons:polygons,polylines:polylines};}function isSamePoint(point1,point2){return point1[0]===point2[0]&&point1[1]===point2[1];}function getPathBBox(segments,lineWidth){var xArr=[];var yArr=[];var segmentsWithAngle=[];for(var i=0;i<segments.length;i++){var segment=segments[i];var currentPoint=segment.currentPoint,params=segment.params,prePoint=segment.prePoint;var box=void 0;switch(segment.command){case'Q':box=quadratic.box(prePoint[0],prePoint[1],params[1],params[2],params[3],params[4]);break;case'C':box=cubic.box(prePoint[0],prePoint[1],params[1],params[2],params[3],params[4],params[5],params[6]);break;case'A':var arcParams=segment.arcParams;box=arc.box(arcParams.cx,arcParams.cy,arcParams.rx,arcParams.ry,arcParams.xRotation,arcParams.startAngle,arcParams.endAngle);break;default:xArr.push(currentPoint[0]);yArr.push(currentPoint[1]);break;}if(box){segment.box=box;xArr.push(box.x,box.x+box.width);yArr.push(box.y,box.y+box.height);}if(lineWidth&&(segment.command==='L'||segment.command==='M')&&segment.prePoint&&segment.nextPoint){segmentsWithAngle.push(segment);}}// bbox calculation should ignore NaN for path attribute
|
|
8196
|
+
// ref: https://github.com/antvis/g/issues/210
|
|
8197
|
+
// ref: https://github.com/antvis/G2/issues/3109
|
|
8198
|
+
xArr=xArr.filter(function(item){return !Number.isNaN(item)&&item!==Infinity&&item!==-Infinity;});yArr=yArr.filter(function(item){return !Number.isNaN(item)&&item!==Infinity&&item!==-Infinity;});var minX=min$1(xArr);var minY=min$1(yArr);var maxX=max$1(xArr);var maxY=max$1(yArr);if(segmentsWithAngle.length===0){return {x:minX,y:minY,width:maxX-minX,height:maxY-minY};}for(var _i=0;_i<segmentsWithAngle.length;_i++){var _segment=segmentsWithAngle[_i];var _currentPoint=_segment.currentPoint;var extra=void 0;if(_currentPoint[0]===minX){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);minX=minX-extra.xExtra;}else if(_currentPoint[0]===maxX){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);maxX=maxX+extra.xExtra;}if(_currentPoint[1]===minY){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);minY=minY-extra.yExtra;}else if(_currentPoint[1]===maxY){extra=getExtraFromSegmentWithAngle(_segment,lineWidth);maxY=maxY+extra.yExtra;}}return {x:minX,y:minY,width:maxX-minX,height:maxY-minY};}function getExtraFromSegmentWithAngle(segment,lineWidth){var prePoint=segment.prePoint,currentPoint=segment.currentPoint,nextPoint=segment.nextPoint;var currentAndPre=Math.pow(currentPoint[0]-prePoint[0],2)+Math.pow(currentPoint[1]-prePoint[1],2);var currentAndNext=Math.pow(currentPoint[0]-nextPoint[0],2)+Math.pow(currentPoint[1]-nextPoint[1],2);var preAndNext=Math.pow(prePoint[0]-nextPoint[0],2)+Math.pow(prePoint[1]-nextPoint[1],2);// 以 currentPoint 为顶点的夹角
|
|
8199
|
+
var currentAngle=Math.acos((currentAndPre+currentAndNext-preAndNext)/(2*Math.sqrt(currentAndPre)*Math.sqrt(currentAndNext)));// 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
|
|
8200
|
+
// 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
|
|
8201
|
+
if(!currentAngle||Math.sin(currentAngle)===0||isNumberEqual(currentAngle,0)){return {xExtra:0,yExtra:0};}var xAngle=Math.abs(Math.atan2(nextPoint[1]-currentPoint[1],nextPoint[0]-currentPoint[0]));var yAngle=Math.abs(Math.atan2(nextPoint[0]-currentPoint[0],nextPoint[1]-currentPoint[1]));// 将夹角转为锐角
|
|
8202
|
+
xAngle=xAngle>Math.PI/2?Math.PI-xAngle:xAngle;yAngle=yAngle>Math.PI/2?Math.PI-yAngle:yAngle;// 这里不考虑在水平和垂直方向的投影,直接使用最大差值
|
|
8203
|
+
// 由于上层统一加减了二分之一线宽,这里需要进行弥补
|
|
8204
|
+
var extra={// 水平方向投影
|
|
8205
|
+
xExtra:Math.cos(currentAngle/2-xAngle)*(lineWidth/2*(1/Math.sin(currentAngle/2)))-lineWidth/2||0,// 垂直方向投影
|
|
8206
|
+
yExtra:Math.cos(yAngle-currentAngle/2)*(lineWidth/2*(1/Math.sin(currentAngle/2)))-lineWidth/2||0};return extra;}// 点对称
|
|
8207
|
+
function toSymmetry(point,center){return [center[0]+(center[0]-point[0]),center[1]+(center[1]-point[1])];}function path2Segments(path){var segments=[];var currentPoint=null;// 当前图形
|
|
7483
8208
|
var nextParams=null;// 下一节点的 path 参数
|
|
7484
|
-
|
|
8209
|
+
var startMovePoint=null;// 开始 M 的点,可能会有多个
|
|
7485
8210
|
var lastStartMovePointIndex=0;// 最近一个开始点 M 的索引
|
|
7486
8211
|
var count=path.length;for(var i=0;i<count;i++){var params=path[i];nextParams=path[i+1];var command=params[0];// 数学定义上的参数,便于后面的计算
|
|
7487
|
-
var segment={command:command,prePoint:currentPoint,params:params,startTangent:null,endTangent:null};switch(command){case'M'
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
segment.
|
|
7492
|
-
|
|
8212
|
+
var segment={command:command,prePoint:currentPoint,params:params,startTangent:null,endTangent:null,currentPoint:null,nextPoint:null,arcParams:null};switch(command){case'M':startMovePoint=[params[1],params[2]];lastStartMovePointIndex=i;break;case'A':var arcParams=getArcParams(currentPoint,params);segment.arcParams=arcParams;break;}if(command==='Z'){// 有了 Z 后,当前节点从开始 M 的点开始
|
|
8213
|
+
currentPoint=startMovePoint;// 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
|
|
8214
|
+
nextParams=path[lastStartMovePointIndex+1];}else {var len=params.length;currentPoint=[params[len-2],params[len-1]];}if(nextParams&&nextParams[0]==='Z'){// 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
|
|
8215
|
+
nextParams=path[lastStartMovePointIndex];if(segments[lastStartMovePointIndex]){// 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
|
|
8216
|
+
segments[lastStartMovePointIndex].prePoint=currentPoint;}}segment.currentPoint=currentPoint;// 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
|
|
8217
|
+
if(segments[lastStartMovePointIndex]&&isSamePoint(currentPoint,segments[lastStartMovePointIndex].currentPoint)){segments[lastStartMovePointIndex].prePoint=segment.prePoint;}var nextPoint=nextParams?[nextParams[nextParams.length-2],nextParams[nextParams.length-1]]:null;segment.nextPoint=nextPoint;// Add startTangent and endTangent
|
|
8218
|
+
var prePoint=segment.prePoint;if(['L','H','V'].includes(command)){segment.startTangent=[prePoint[0]-currentPoint[0],prePoint[1]-currentPoint[1]];segment.endTangent=[currentPoint[0]-prePoint[0],currentPoint[1]-prePoint[1]];}else if(command==='Q'){// 二次贝塞尔曲线只有一个控制点
|
|
8219
|
+
var cp=[params[1],params[2]];// 二次贝塞尔曲线的终点为 currentPoint
|
|
8220
|
+
segment.startTangent=[prePoint[0]-cp[0],prePoint[1]-cp[1]];segment.endTangent=[currentPoint[0]-cp[0],currentPoint[1]-cp[1]];}else if(command==='T'){var preSegment=segments[i-1];var _cp=toSymmetry(preSegment.currentPoint,prePoint);if(preSegment.command==='Q'){segment.command='Q';segment.startTangent=[prePoint[0]-_cp[0],prePoint[1]-_cp[1]];segment.endTangent=[currentPoint[0]-_cp[0],currentPoint[1]-_cp[1]];}else {// @ts-ignore
|
|
8221
|
+
segment.command='TL';segment.startTangent=[prePoint[0]-currentPoint[0],prePoint[1]-currentPoint[1]];segment.endTangent=[currentPoint[0]-prePoint[0],currentPoint[1]-prePoint[1]];}}else if(command==='C'){// 三次贝塞尔曲线有两个控制点
|
|
7493
8222
|
var cp1=[params[1],params[2]];var cp2=[params[3],params[4]];segment.startTangent=[prePoint[0]-cp1[0],prePoint[1]-cp1[1]];segment.endTangent=[currentPoint[0]-cp2[0],currentPoint[1]-cp2[1]];// horizontal line, eg. ['C', 100, 100, 100, 100, 200, 200]
|
|
7494
|
-
if(segment.startTangent[0]===0&&segment.startTangent[1]===0){segment.startTangent=[cp1[0]-cp2[0],cp1[1]-cp2[1]];}if(segment.endTangent[0]===0&&segment.endTangent[1]===0){segment.endTangent=[cp2[0]-cp1[0],cp2[1]-cp1[1]];}}
|
|
8223
|
+
if(segment.startTangent[0]===0&&segment.startTangent[1]===0){segment.startTangent=[cp1[0]-cp2[0],cp1[1]-cp2[1]];}if(segment.endTangent[0]===0&&segment.endTangent[1]===0){segment.endTangent=[cp2[0]-cp1[0],cp2[1]-cp1[1]];}}else if(command==='S'){var _preSegment=segments[i-1];var _cp2=toSymmetry(_preSegment.currentPoint,prePoint);var _cp3=[params[1],params[2]];if(_preSegment.command==='C'){segment.command='C';// 将 S 命令变换为 C 命令
|
|
8224
|
+
segment.startTangent=[prePoint[0]-_cp2[0],prePoint[1]-_cp2[1]];segment.endTangent=[currentPoint[0]-_cp3[0],currentPoint[1]-_cp3[1]];}else {// @ts-ignore
|
|
8225
|
+
segment.command='SQ';// 将 S 命令变换为 SQ 命令
|
|
8226
|
+
segment.startTangent=[prePoint[0]-_cp3[0],prePoint[1]-_cp3[1]];segment.endTangent=[currentPoint[0]-_cp3[0],currentPoint[1]-_cp3[1]];}}else if(command==='A'){var d=0.001;var _ref=segment.arcParams||{},_ref$cx=_ref.cx,cx=_ref$cx===void 0?0:_ref$cx,_ref$cy=_ref.cy,cy=_ref$cy===void 0?0:_ref$cy,_ref$rx=_ref.rx,rx=_ref$rx===void 0?0:_ref$rx,_ref$ry=_ref.ry,ry=_ref$ry===void 0?0:_ref$ry,_ref$sweepFlag=_ref.sweepFlag,sweepFlag=_ref$sweepFlag===void 0?0:_ref$sweepFlag,_ref$startAngle=_ref.startAngle,startAngle=_ref$startAngle===void 0?0:_ref$startAngle,_ref$endAngle=_ref.endAngle,endAngle=_ref$endAngle===void 0?0:_ref$endAngle;if(sweepFlag===0){d*=-1;}var dx1=rx*Math.cos(startAngle-d)+cx;var dy1=ry*Math.sin(startAngle-d)+cy;segment.startTangent=[dx1-startMovePoint[0],dy1-startMovePoint[1]];var dx2=rx*Math.cos(startAngle+endAngle+d)+cx;var dy2=ry*Math.sin(startAngle+endAngle-d)+cy;segment.endTangent=[prePoint[0]-dx2,prePoint[1]-dy2];}segments.push(segment);}return segments;}// 向量长度
|
|
8227
|
+
function vMag(v){return Math.sqrt(v[0]*v[0]+v[1]*v[1]);}// u.v/|u||v|,计算夹角的余弦值
|
|
8228
|
+
function vRatio(u,v){// 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
|
|
8229
|
+
return vMag(u)*vMag(v)?(u[0]*v[0]+u[1]*v[1])/(vMag(u)*vMag(v)):1;}// 向量角度
|
|
8230
|
+
function vAngle(u,v){return (u[0]*v[1]<u[1]*v[0]?-1:1)*Math.acos(vRatio(u,v));}function getArcParams(startPoint,params){var rx=params[1];var ry=params[2];var xRotation=mod(deg2rad(params[3]),Math.PI*2);var arcFlag=params[4];var sweepFlag=params[5];// 弧形起点坐标
|
|
8231
|
+
var x1=startPoint[0];var y1=startPoint[1];// 弧形终点坐标
|
|
8232
|
+
var x2=params[6];var y2=params[7];var xp=Math.cos(xRotation)*(x1-x2)/2.0+Math.sin(xRotation)*(y1-y2)/2.0;var yp=-1*Math.sin(xRotation)*(x1-x2)/2.0+Math.cos(xRotation)*(y1-y2)/2.0;var lambda=xp*xp/(rx*rx)+yp*yp/(ry*ry);if(lambda>1){rx*=Math.sqrt(lambda);ry*=Math.sqrt(lambda);}var diff=rx*rx*(yp*yp)+ry*ry*(xp*xp);var f=diff?Math.sqrt((rx*rx*(ry*ry)-diff)/diff):1;if(arcFlag===sweepFlag){f*=-1;}if(isNaN(f)){f=0;}// 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
|
|
8233
|
+
var cxp=ry?f*rx*yp/ry:0;var cyp=rx?f*-ry*xp/rx:0;// 椭圆圆心坐标
|
|
8234
|
+
var cx=(x1+x2)/2.0+Math.cos(xRotation)*cxp-Math.sin(xRotation)*cyp;var cy=(y1+y2)/2.0+Math.sin(xRotation)*cxp+Math.cos(xRotation)*cyp;// 起始点的单位向量
|
|
8235
|
+
var u=[(xp-cxp)/rx,(yp-cyp)/ry];// 终止点的单位向量
|
|
8236
|
+
var v=[(-1*xp-cxp)/rx,(-1*yp-cyp)/ry];// 计算起始点和圆心的连线,与 x 轴正方向的夹角
|
|
8237
|
+
var theta=vAngle([1,0],u);// 计算圆弧起始点和终止点与椭圆圆心连线的夹角
|
|
8238
|
+
var dTheta=vAngle(u,v);if(vRatio(u,v)<=-1){dTheta=Math.PI;}if(vRatio(u,v)>=1){dTheta=0;}if(sweepFlag===0&&dTheta>0){dTheta=dTheta-2*Math.PI;}if(sweepFlag===1&&dTheta<0){dTheta=dTheta+2*Math.PI;}return {cx:cx,cy:cy,// 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
|
|
8239
|
+
rx:isSamePoint(startPoint,[x2,y2])?0:rx,ry:isSamePoint(startPoint,[x2,y2])?0:ry,startAngle:theta,endAngle:theta+dTheta,xRotation:xRotation,arcFlag:arcFlag,sweepFlag:sweepFlag};}function commandsToPathString(commands,object,transform){var _object$parsedStyle=object.parsedStyle,_object$parsedStyle$d=_object$parsedStyle.defX,defX=_object$parsedStyle$d===void 0?0:_object$parsedStyle$d,_object$parsedStyle$d2=_object$parsedStyle.defY,defY=_object$parsedStyle$d2===void 0?0:_object$parsedStyle$d2;return commands.reduce(function(prev,cur){var path='';if(cur[0]==='M'||cur[0]==='L'){var p=fromValues$2(cur[1]-defX,cur[2]-defY,0);if(transform){transformMat4(p,p,transform);}path=""+cur[0]+p[0]+","+p[1];}else if(cur[0]==='Z'){path=cur[0];}else if(cur[0]==='C'){var p1=fromValues$2(cur[1]-defX,cur[2]-defY,0);var p2=fromValues$2(cur[3]-defX,cur[4]-defY,0);var p3=fromValues$2(cur[5]-defX,cur[6]-defY,0);if(transform){transformMat4(p1,p1,transform);transformMat4(p2,p2,transform);transformMat4(p3,p3,transform);}path=""+cur[0]+p1[0]+","+p1[1]+","+p2[0]+","+p2[1]+","+p3[0]+","+p3[1];}else if(cur[0]==='A'){var c=fromValues$2(cur[6]-defX,cur[7]-defY,0);if(transform){transformMat4(c,c,transform);}path=""+cur[0]+cur[1]+","+cur[2]+","+cur[3]+","+cur[4]+","+cur[5]+","+c[0]+","+c[1];}return prev+=path;},'');}function lineToCommands(x1,y1,x2,y2){return [['M',x1,y1],['L',x2,y2]];}function ellipseToCommands(rx,ry,cx,cy){var factor=(-1+Math.sqrt(2))/3*4;var dx=rx*factor;var dy=ry*factor;var left=cx-rx;var right=cx+rx;var top=cy-ry;var bottom=cy+ry;return [['M',left,cy],['C',left,cy-dy,cx-dx,top,cx,top],['C',cx+dx,top,right,cy-dy,right,cy],['C',right,cy+dy,cx+dx,bottom,cx,bottom],['C',cx-dx,bottom,left,cy+dy,left,cy],['Z']];}function polygonToCommands(points,closed){var result=points.map(function(point,i){return [i===0?'M':'L',point[0],point[1]];});if(closed){result.push(['Z']);}return result;}function rectToCommands(width,height,x,y,radius){// @see https://gist.github.com/danielpquinn/dd966af424030d47e476
|
|
7495
8240
|
if(radius){var tlr=radius[0],trr=radius[1],brr=radius[2],blr=radius[3];var signX=width>0?1:-1;var signY=height>0?1:-1;// sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
|
|
7496
8241
|
var sweepFlag=signX+signY!==0?1:0;return [['M',signX*tlr+x,y],['L',width-signX*trr+x,y],trr?['A',trr,trr,0,0,sweepFlag,width+x,signY*trr+y]:null,['L',width+x,height-signY*brr+y],brr?['A',brr,brr,0,0,sweepFlag,width+x-signX*brr,height+y]:null,['L',x+signX*blr,height+y],blr?['A',blr,blr,0,0,sweepFlag,x,height+y-signY*blr]:null,['L',x,signY*tlr+y],tlr?['A',tlr,tlr,0,0,sweepFlag,signX*tlr+x,y]:null,['Z']].filter(function(command){return command;});}return [['M',x,y],['L',x+width,y],['L',x+width,y+height],['L',x,y+height],['Z']];}/**
|
|
7497
8242
|
* convert object to path, should account for:
|
|
7498
8243
|
* * transform & origin
|
|
7499
8244
|
* * anchor
|
|
7500
8245
|
* * lineWidth
|
|
7501
|
-
*/function convertToPath(object,
|
|
7502
|
-
var isClosed=pathArray[pathArray.length-1][0]==='Z';var offsetX=i===pathArray.length-(isClosed?2:1)?endOffsetX:0;var offsetY=i===pathArray.length-(isClosed?2:1)?endOffsetY:0;switch(command){case'M':return "M "+(params[1]-x+startOffsetX)+","+(params[2]-y+startOffsetY);case'L':return "L "+(params[1]-x+offsetX)+","+(params[2]-y+offsetY);case'Q':return "Q "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x+offsetX)+" "+(params[4]-y+offsetY);case'C':return "C "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x)+" "+(params[4]-y)+","+(params[5]-x+offsetX)+" "+(params[6]-y+offsetY);case'A':return "A "+params[1]+" "+params[2]+" "+params[3]+" "+params[4]+" "+params[5]+" "+(params[6]-x+offsetX)+" "+(params[7]-y+offsetY);case'Z':return 'Z';}}).join(' ');if(~newValue.indexOf('NaN')){return '';}return newValue;}function isFillOrStrokeAffected(pointerEvents,fill,stroke){// account for pointerEvents
|
|
8246
|
+
*/function convertToPath(object,transform){if(transform===void 0){transform=object.getLocalTransform();}var commands=[];switch(object.nodeName){case exports.Shape.LINE:var _object$parsedStyle2=object.parsedStyle,x1=_object$parsedStyle2.x1,y1=_object$parsedStyle2.y1,x2=_object$parsedStyle2.x2,y2=_object$parsedStyle2.y2;commands=lineToCommands(x1,y1,x2,y2);break;case exports.Shape.CIRCLE:{var _object$parsedStyle3=object.parsedStyle,r=_object$parsedStyle3.r,cx=_object$parsedStyle3.cx,cy=_object$parsedStyle3.cy;commands=ellipseToCommands(r,r,cx,cy);break;}case exports.Shape.ELLIPSE:{var _object$parsedStyle4=object.parsedStyle,rx=_object$parsedStyle4.rx,ry=_object$parsedStyle4.ry,_cx=_object$parsedStyle4.cx,_cy=_object$parsedStyle4.cy;commands=ellipseToCommands(rx,ry,_cx,_cy);break;}case exports.Shape.POLYLINE:case exports.Shape.POLYGON:var points=object.parsedStyle.points;commands=polygonToCommands(points.points,object.nodeName===exports.Shape.POLYGON);break;case exports.Shape.RECT:var _object$parsedStyle5=object.parsedStyle,width=_object$parsedStyle5.width,height=_object$parsedStyle5.height,x=_object$parsedStyle5.x,y=_object$parsedStyle5.y,radius=_object$parsedStyle5.radius;var hasRadius=radius&&radius.some(function(r){return r!==0;});commands=rectToCommands(width,height,x,y,hasRadius&&radius.map(function(r){return clamp(r,0,Math.min(Math.abs(width)/2,Math.abs(height)/2));}));break;case exports.Shape.PATH:var _object$parsedStyle$p=object.parsedStyle.path,curve=_object$parsedStyle$p.curve,zCommandIndexes=_object$parsedStyle$p.zCommandIndexes;commands=[].concat(curve);zCommandIndexes.forEach(function(zIndex,index){commands.splice(zIndex+index+1,0,['Z']);});break;}if(commands.length){return commandsToPathString(commands,object,transform);}}function translatePathToString(pathArray,x,y,startOffsetX,startOffsetY,endOffsetX,endOffsetY){if(startOffsetX===void 0){startOffsetX=0;}if(startOffsetY===void 0){startOffsetY=0;}if(endOffsetX===void 0){endOffsetX=0;}if(endOffsetY===void 0){endOffsetY=0;}var newValue=pathArray.map(function(params,i){var command=params[0];var isClosed=pathArray[pathArray.length-1][0]==='Z';var offsetX=i===pathArray.length-(isClosed?2:1)?endOffsetX:0;var offsetY=i===pathArray.length-(isClosed?2:1)?endOffsetY:0;switch(command){case'M':return "M "+(params[1]-x+startOffsetX)+","+(params[2]-y+startOffsetY);case'L':return "L "+(params[1]-x+offsetX)+","+(params[2]-y+offsetY);case'Q':return "Q "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x+offsetX)+" "+(params[4]-y+offsetY);case'C':return "C "+(params[1]-x)+" "+(params[2]-y)+","+(params[3]-x)+" "+(params[4]-y)+","+(params[5]-x+offsetX)+" "+(params[6]-y+offsetY);case'A':return "A "+params[1]+" "+params[2]+" "+params[3]+" "+params[4]+" "+params[5]+" "+(params[6]-x+offsetX)+" "+(params[7]-y+offsetY);case'Z':return 'Z';}}).join(' ');if(~newValue.indexOf('NaN')){return '';}return newValue;}function isFillOrStrokeAffected(pointerEvents,fill,stroke){// account for pointerEvents
|
|
7503
8247
|
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
|
|
7504
8248
|
var hasFill=false;var hasStroke=false;var isFillOtherThanNone=!!fill&&!fill.isNone;var isStrokeOtherThanNone=!!stroke&&!stroke.isNone;if(pointerEvents==='visiblepainted'||pointerEvents==='painted'||pointerEvents==='auto'){hasFill=isFillOtherThanNone;hasStroke=isStrokeOtherThanNone;}else if(pointerEvents==='visiblefill'||pointerEvents==='fill'){hasFill=true;}else if(pointerEvents==='visiblestroke'||pointerEvents==='stroke'){hasStroke=true;}else if(pointerEvents==='visible'||pointerEvents==='all'){// The values of the fill and stroke do not affect event processing.
|
|
7505
8249
|
hasFill=true;hasStroke=true;}return [hasFill,hasStroke];}// @ts-nocheck
|
|
@@ -8135,12 +8879,7 @@
|
|
|
8135
8879
|
*/;_proto.getAnimations=function getAnimations(){return this.activeAnimations;}/**
|
|
8136
8880
|
* create an animation with WAAPI
|
|
8137
8881
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate
|
|
8138
|
-
*/;_proto.animate=function animate(keyframes,options){var _this$ownerDocument;var timeline=(_this$ownerDocument=this.ownerDocument)===null||_this$ownerDocument===void 0?void 0:_this$ownerDocument.timeline
|
|
8139
|
-
// if (this.parsedStyle.clipPathTargets && this.parsedStyle.clipPathTargets.length) {
|
|
8140
|
-
// const target = this.parsedStyle.clipPathTargets[0];
|
|
8141
|
-
// timeline = target.ownerDocument?.timeline;
|
|
8142
|
-
// }
|
|
8143
|
-
if(timeline){return timeline.play(this,keyframes,options);}return null;}// #endregion animatable
|
|
8882
|
+
*/;_proto.animate=function animate(keyframes,options){var _this$ownerDocument;var timeline=(_this$ownerDocument=this.ownerDocument)===null||_this$ownerDocument===void 0?void 0:_this$ownerDocument.timeline;if(timeline){return timeline.play(this,keyframes,options);}return null;}// #endregion animatable
|
|
8144
8883
|
// #region visible
|
|
8145
8884
|
/**
|
|
8146
8885
|
* shortcut for Used value of `visibility`
|
|
@@ -8399,11 +9138,11 @@
|
|
|
8399
9138
|
*/;_proto.setDistance=function setDistance(d){if(this.distance===d||d<0){return this;}this.distance=d;if(this.distance<MIN_DISTANCE){this.distance=MIN_DISTANCE;}this.dollyingStep=this.distance/100;var pos=create$2();d=this.distance;var n=this.forward;var f=this.focalPoint;pos[0]=d*n[0]+f[0];pos[1]=d*n[1]+f[1];pos[2]=d*n[2]+f[2];this._setPosition(pos);this.triggerUpdate();return this;};_proto.setMaxDistance=function setMaxDistance(d){this.maxDistance=d;return this;};_proto.setMinDistance=function setMinDistance(d){this.minDistance=d;return this;}/**
|
|
8400
9139
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
8401
9140
|
* the azimuth in degrees
|
|
8402
|
-
*/;_proto.setAzimuth=function setAzimuth(az){this.azimuth=getAngle(az);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getAzimuth=function getAzimuth(){return this.azimuth;}/**
|
|
9141
|
+
*/;_proto.setAzimuth=function setAzimuth(az){this.azimuth=getAngle$1(az);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getAzimuth=function getAzimuth(){return this.azimuth;}/**
|
|
8403
9142
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
8404
|
-
*/;_proto.setElevation=function setElevation(el){this.elevation=getAngle(el);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getElevation=function getElevation(){return this.elevation;}/**
|
|
9143
|
+
*/;_proto.setElevation=function setElevation(el){this.elevation=getAngle$1(el);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getElevation=function getElevation(){return this.elevation;}/**
|
|
8405
9144
|
* 设置相机方位角,不同相机模式下需要重新计算相机位置或者是视点位置
|
|
8406
|
-
*/;_proto.setRoll=function setRoll(angle){this.roll=getAngle(angle);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getRoll=function getRoll(){return this.roll;}/**
|
|
9145
|
+
*/;_proto.setRoll=function setRoll(angle){this.roll=getAngle$1(angle);this.computeMatrix();this._getAxes();if(this.type===exports.CameraType.ORBITING||this.type===exports.CameraType.EXPLORING){this._getPosition();}else if(this.type===exports.CameraType.TRACKING){this._getFocalPoint();}this.triggerUpdate();return this;};_proto.getRoll=function getRoll(){return this.roll;}/**
|
|
8407
9146
|
* 根据相机矩阵重新计算各种相机参数
|
|
8408
9147
|
*/;_proto._update=function _update(){this._getAxes();this._getPosition();this._getDistance();this._getAngles();this._getOrthoMatrix();this.triggerUpdate();}/**
|
|
8409
9148
|
* 计算相机矩阵
|
|
@@ -8934,7 +9673,7 @@
|
|
|
8934
9673
|
// Configuration Constants
|
|
8935
9674
|
|
|
8936
9675
|
|
|
8937
|
-
var EPSILON$
|
|
9676
|
+
var EPSILON$2 = 0.000001;
|
|
8938
9677
|
var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
8939
9678
|
if (!Math.hypot) Math.hypot = function () {
|
|
8940
9679
|
var y = 0,
|
|
@@ -9699,7 +10438,7 @@
|
|
|
9699
10438
|
} // calculate coefficients
|
|
9700
10439
|
|
|
9701
10440
|
|
|
9702
|
-
if (1.0 - cosom > EPSILON$
|
|
10441
|
+
if (1.0 - cosom > EPSILON$2) {
|
|
9703
10442
|
// standard case (slerp)
|
|
9704
10443
|
omega = Math.acos(cosom);
|
|
9705
10444
|
sinom = Math.sin(omega);
|
|
@@ -9897,9 +10636,9 @@
|
|
|
9897
10636
|
*/
|
|
9898
10637
|
|
|
9899
10638
|
_proto.rotate = function rotate(azimuth, elevation, roll) {
|
|
9900
|
-
this.relElevation = getAngle(elevation);
|
|
9901
|
-
this.relAzimuth = getAngle(azimuth);
|
|
9902
|
-
this.relRoll = getAngle(roll);
|
|
10639
|
+
this.relElevation = getAngle$1(elevation);
|
|
10640
|
+
this.relAzimuth = getAngle$1(azimuth);
|
|
10641
|
+
this.relRoll = getAngle$1(roll);
|
|
9903
10642
|
this.elevation += this.relElevation;
|
|
9904
10643
|
this.azimuth += this.relAzimuth;
|
|
9905
10644
|
this.roll += this.relRoll;
|
|
@@ -14095,7 +14834,8 @@
|
|
|
14095
14834
|
exports.deg2rad = deg2rad;
|
|
14096
14835
|
exports.deg2turn = deg2turn;
|
|
14097
14836
|
exports.findClosestClipPathTarget = findClosestClipPathTarget;
|
|
14098
|
-
exports.
|
|
14837
|
+
exports.fromRotationTranslationScale = fromRotationTranslationScale$1;
|
|
14838
|
+
exports.getAngle = getAngle$1;
|
|
14099
14839
|
exports.getEuler = getEuler;
|
|
14100
14840
|
exports.getOrCalculatePathTotalLength = getOrCalculatePathTotalLength;
|
|
14101
14841
|
exports.grad2deg = grad2deg;
|