@antv/g-lite 1.0.13 → 1.0.14
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/css/parser/path.d.ts.map +1 -1
- package/dist/display-objects/Path.d.ts +26 -7
- package/dist/display-objects/Path.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +343 -38
- package/dist/index.js +340 -34
- package/dist/index.umd.js +1100 -73
- package/dist/index.umd.min.js +2 -2
- package/dist/utils/path.d.ts +11 -4
- package/dist/utils/path.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -5141,40 +5141,6 @@
|
|
|
5141
5141
|
};
|
|
5142
5142
|
}
|
|
5143
5143
|
|
|
5144
|
-
/**
|
|
5145
|
-
* Returns the bounding box of a shape.
|
|
5146
|
-
*/
|
|
5147
|
-
function getPathBBox(path, options) {
|
|
5148
|
-
if (!path) {
|
|
5149
|
-
return {
|
|
5150
|
-
x: 0,
|
|
5151
|
-
y: 0,
|
|
5152
|
-
width: 0,
|
|
5153
|
-
height: 0,
|
|
5154
|
-
x2: 0,
|
|
5155
|
-
y2: 0,
|
|
5156
|
-
cx: 0,
|
|
5157
|
-
cy: 0,
|
|
5158
|
-
cz: 0,
|
|
5159
|
-
};
|
|
5160
|
-
}
|
|
5161
|
-
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;
|
|
5162
|
-
var width = xMax - xMin;
|
|
5163
|
-
var height = yMax - yMin;
|
|
5164
|
-
return {
|
|
5165
|
-
width: width,
|
|
5166
|
-
height: height,
|
|
5167
|
-
x: xMin,
|
|
5168
|
-
y: yMin,
|
|
5169
|
-
x2: xMax,
|
|
5170
|
-
y2: yMax,
|
|
5171
|
-
cx: xMin + width / 2,
|
|
5172
|
-
cy: yMin + height / 2,
|
|
5173
|
-
// an estimted guess
|
|
5174
|
-
cz: Math.max(width, height) + Math.min(width, height) / 2,
|
|
5175
|
-
};
|
|
5176
|
-
}
|
|
5177
|
-
|
|
5178
5144
|
/**
|
|
5179
5145
|
* Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
|
|
5180
5146
|
*
|
|
@@ -5395,6 +5361,10 @@
|
|
|
5395
5361
|
var toString = {}.toString;
|
|
5396
5362
|
var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
|
|
5397
5363
|
|
|
5364
|
+
var isArray = (function (value) {
|
|
5365
|
+
return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
|
|
5366
|
+
});
|
|
5367
|
+
|
|
5398
5368
|
var isObject = (function (value) {
|
|
5399
5369
|
/**
|
|
5400
5370
|
* isObject({}) => true
|
|
@@ -5406,6 +5376,58 @@
|
|
|
5406
5376
|
return (value !== null && type === 'object') || type === 'function';
|
|
5407
5377
|
});
|
|
5408
5378
|
|
|
5379
|
+
/**
|
|
5380
|
+
* @param {Array} arr The array to iterate over.
|
|
5381
|
+
* @return {*} Returns the maximum value.
|
|
5382
|
+
* @example
|
|
5383
|
+
*
|
|
5384
|
+
* max([1, 2]);
|
|
5385
|
+
* // => 2
|
|
5386
|
+
*
|
|
5387
|
+
* max([]);
|
|
5388
|
+
* // => undefined
|
|
5389
|
+
*
|
|
5390
|
+
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
5391
|
+
*
|
|
5392
|
+
* max(data);
|
|
5393
|
+
* // => 1250010
|
|
5394
|
+
* // Math.max(...data) will encounter "Maximum call stack size exceeded" error
|
|
5395
|
+
*/
|
|
5396
|
+
var max$1 = (function (arr) {
|
|
5397
|
+
if (!isArray(arr)) {
|
|
5398
|
+
return undefined;
|
|
5399
|
+
}
|
|
5400
|
+
return arr.reduce(function (prev, curr) {
|
|
5401
|
+
return Math.max(prev, curr);
|
|
5402
|
+
}, arr[0]);
|
|
5403
|
+
});
|
|
5404
|
+
|
|
5405
|
+
/**
|
|
5406
|
+
* @param {Array} arr The array to iterate over.
|
|
5407
|
+
* @return {*} Returns the minimum value.
|
|
5408
|
+
* @example
|
|
5409
|
+
*
|
|
5410
|
+
* min([1, 2]);
|
|
5411
|
+
* // => 1
|
|
5412
|
+
*
|
|
5413
|
+
* min([]);
|
|
5414
|
+
* // => undefined
|
|
5415
|
+
*
|
|
5416
|
+
* const data = new Array(1250010).fill(1).map((d,idx) => idx);
|
|
5417
|
+
*
|
|
5418
|
+
* min(data);
|
|
5419
|
+
* // => 1250010
|
|
5420
|
+
* // Math.min(...data) will encounter "Maximum call stack size exceeded" error
|
|
5421
|
+
*/
|
|
5422
|
+
var min$1 = (function (arr) {
|
|
5423
|
+
if (!isArray(arr)) {
|
|
5424
|
+
return undefined;
|
|
5425
|
+
}
|
|
5426
|
+
return arr.reduce(function (prev, curr) {
|
|
5427
|
+
return Math.min(prev, curr);
|
|
5428
|
+
}, arr[0]);
|
|
5429
|
+
});
|
|
5430
|
+
|
|
5409
5431
|
var isString = (function (str) {
|
|
5410
5432
|
return isType(str, 'String');
|
|
5411
5433
|
});
|
|
@@ -5428,6 +5450,16 @@
|
|
|
5428
5450
|
return isType(value, 'Number');
|
|
5429
5451
|
};
|
|
5430
5452
|
|
|
5453
|
+
var PRECISION = 0.00001; // numbers less than this is considered as 0
|
|
5454
|
+
function isNumberEqual(a, b, precision) {
|
|
5455
|
+
if (precision === void 0) { precision = PRECISION; }
|
|
5456
|
+
return Math.abs(a - b) < precision;
|
|
5457
|
+
}
|
|
5458
|
+
|
|
5459
|
+
var mod = function (n, m) {
|
|
5460
|
+
return ((n % m) + m) % m;
|
|
5461
|
+
};
|
|
5462
|
+
|
|
5431
5463
|
/**
|
|
5432
5464
|
* 是否是布尔类型
|
|
5433
5465
|
*
|
|
@@ -10084,14 +10116,13 @@
|
|
|
10084
10116
|
zCommandIndexes = _path2Curve[1]; // for later use
|
|
10085
10117
|
|
|
10086
10118
|
|
|
10087
|
-
var segments = path2Segments(
|
|
10119
|
+
var segments = path2Segments(absolutePath); // Only calculate bbox here since we don't need length now.
|
|
10088
10120
|
|
|
10089
|
-
var _getPathBBox = getPathBBox(
|
|
10121
|
+
var _getPathBBox = getPathBBox(segments, 0),
|
|
10090
10122
|
x = _getPathBBox.x,
|
|
10091
10123
|
y = _getPathBBox.y,
|
|
10092
10124
|
width = _getPathBBox.width,
|
|
10093
|
-
height = _getPathBBox.height;
|
|
10094
|
-
|
|
10125
|
+
height = _getPathBBox.height;
|
|
10095
10126
|
|
|
10096
10127
|
return {
|
|
10097
10128
|
absolutePath: absolutePath,
|
|
@@ -10101,15 +10132,8 @@
|
|
|
10101
10132
|
polylines: polylines,
|
|
10102
10133
|
curve: curve,
|
|
10103
10134
|
// Delay the calculation of length.
|
|
10104
|
-
// totalLength: length,
|
|
10105
10135
|
totalLength: 0,
|
|
10106
10136
|
zCommandIndexes: zCommandIndexes,
|
|
10107
|
-
// rect: new Rectangle(
|
|
10108
|
-
// Number.isFinite(x) ? x : 0,
|
|
10109
|
-
// Number.isFinite(y) ? y : 0,
|
|
10110
|
-
// Number.isFinite(width) ? width : 0,
|
|
10111
|
-
// Number.isFinite(height) ? height : 0,
|
|
10112
|
-
// ),
|
|
10113
10137
|
rect: {
|
|
10114
10138
|
x: Number.isFinite(x) ? x : 0,
|
|
10115
10139
|
y: Number.isFinite(y) ? y : 0,
|
|
@@ -10161,6 +10185,10 @@
|
|
|
10161
10185
|
return Math.sqrt(dx * dx + dy * dy);
|
|
10162
10186
|
}
|
|
10163
10187
|
|
|
10188
|
+
function isNumberEqual$1(v1, v2) {
|
|
10189
|
+
return Math.abs(v1 - v2) < 0.001;
|
|
10190
|
+
}
|
|
10191
|
+
|
|
10164
10192
|
function getBBoxByArray(xArr, yArr) {
|
|
10165
10193
|
var minX = Math.min.apply(Math, xArr);
|
|
10166
10194
|
var minY = Math.min.apply(Math, yArr);
|
|
@@ -10173,6 +10201,10 @@
|
|
|
10173
10201
|
height: maxY - minY
|
|
10174
10202
|
};
|
|
10175
10203
|
}
|
|
10204
|
+
|
|
10205
|
+
function piMod(angle) {
|
|
10206
|
+
return (angle + Math.PI * 2) % (Math.PI * 2);
|
|
10207
|
+
}
|
|
10176
10208
|
var line = {
|
|
10177
10209
|
/**
|
|
10178
10210
|
* 计算线段的包围盒
|
|
@@ -10277,6 +10309,687 @@
|
|
|
10277
10309
|
return Math.atan2(y2 - y1, x2 - x1);
|
|
10278
10310
|
}
|
|
10279
10311
|
};
|
|
10312
|
+
var EPSILON$1 = 0.0001;
|
|
10313
|
+
/**
|
|
10314
|
+
* 使用牛顿切割法求最近的点
|
|
10315
|
+
* @param {number[]} xArr 点的 x 数组
|
|
10316
|
+
* @param {number[]} yArr 点的 y 数组
|
|
10317
|
+
* @param {number} x 指定的点 x
|
|
10318
|
+
* @param {number} y 指定的点 y
|
|
10319
|
+
* @param {Function} tCallback 差值函数
|
|
10320
|
+
*/
|
|
10321
|
+
|
|
10322
|
+
function nearestPoint(xArr, yArr, x, y, tCallback, length) {
|
|
10323
|
+
var t = -1;
|
|
10324
|
+
var d = Infinity;
|
|
10325
|
+
var v0 = [x, y];
|
|
10326
|
+
var segNum = 20;
|
|
10327
|
+
|
|
10328
|
+
if (length && length > 200) {
|
|
10329
|
+
segNum = length / 10;
|
|
10330
|
+
}
|
|
10331
|
+
|
|
10332
|
+
var increaseRate = 1 / segNum;
|
|
10333
|
+
var interval = increaseRate / 10;
|
|
10334
|
+
|
|
10335
|
+
for (var i = 0; i <= segNum; i++) {
|
|
10336
|
+
var _t = i * increaseRate;
|
|
10337
|
+
|
|
10338
|
+
var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
|
|
10339
|
+
var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
|
|
10340
|
+
|
|
10341
|
+
if (d1 < d) {
|
|
10342
|
+
t = _t;
|
|
10343
|
+
d = d1;
|
|
10344
|
+
}
|
|
10345
|
+
} // 提前终止
|
|
10346
|
+
|
|
10347
|
+
|
|
10348
|
+
if (t === 0) {
|
|
10349
|
+
return {
|
|
10350
|
+
x: xArr[0],
|
|
10351
|
+
y: yArr[0]
|
|
10352
|
+
};
|
|
10353
|
+
}
|
|
10354
|
+
|
|
10355
|
+
if (t === 1) {
|
|
10356
|
+
var count = xArr.length;
|
|
10357
|
+
return {
|
|
10358
|
+
x: xArr[count - 1],
|
|
10359
|
+
y: yArr[count - 1]
|
|
10360
|
+
};
|
|
10361
|
+
}
|
|
10362
|
+
|
|
10363
|
+
d = Infinity;
|
|
10364
|
+
|
|
10365
|
+
for (var _i = 0; _i < 32; _i++) {
|
|
10366
|
+
if (interval < EPSILON$1) {
|
|
10367
|
+
break;
|
|
10368
|
+
}
|
|
10369
|
+
|
|
10370
|
+
var prev = t - interval;
|
|
10371
|
+
var next = t + interval;
|
|
10372
|
+
var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
|
|
10373
|
+
|
|
10374
|
+
var _d = distance(v0[0], v0[1], _v[0], _v[1]);
|
|
10375
|
+
|
|
10376
|
+
if (prev >= 0 && _d < d) {
|
|
10377
|
+
t = prev;
|
|
10378
|
+
d = _d;
|
|
10379
|
+
} else {
|
|
10380
|
+
var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
|
|
10381
|
+
var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
|
|
10382
|
+
|
|
10383
|
+
if (next <= 1 && d2 < d) {
|
|
10384
|
+
t = next;
|
|
10385
|
+
d = d2;
|
|
10386
|
+
} else {
|
|
10387
|
+
interval *= 0.5;
|
|
10388
|
+
}
|
|
10389
|
+
}
|
|
10390
|
+
}
|
|
10391
|
+
|
|
10392
|
+
return {
|
|
10393
|
+
x: tCallback.apply(void 0, xArr.concat([t])),
|
|
10394
|
+
y: tCallback.apply(void 0, yArr.concat([t]))
|
|
10395
|
+
};
|
|
10396
|
+
} // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
|
|
10397
|
+
|
|
10398
|
+
|
|
10399
|
+
function snapLength(xArr, yArr) {
|
|
10400
|
+
var totalLength = 0;
|
|
10401
|
+
var count = xArr.length;
|
|
10402
|
+
|
|
10403
|
+
for (var i = 0; i < count; i++) {
|
|
10404
|
+
var x = xArr[i];
|
|
10405
|
+
var y = yArr[i];
|
|
10406
|
+
var nextX = xArr[(i + 1) % count];
|
|
10407
|
+
var nextY = yArr[(i + 1) % count];
|
|
10408
|
+
totalLength += distance(x, y, nextX, nextY);
|
|
10409
|
+
}
|
|
10410
|
+
|
|
10411
|
+
return totalLength / 2;
|
|
10412
|
+
}
|
|
10413
|
+
|
|
10414
|
+
function quadraticAt(p0, p1, p2, t) {
|
|
10415
|
+
var onet = 1 - t;
|
|
10416
|
+
return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
|
|
10417
|
+
} // 求极值
|
|
10418
|
+
|
|
10419
|
+
|
|
10420
|
+
function extrema(p0, p1, p2) {
|
|
10421
|
+
var a = p0 + p2 - 2 * p1;
|
|
10422
|
+
|
|
10423
|
+
if (isNumberEqual$1(a, 0)) {
|
|
10424
|
+
return [0.5];
|
|
10425
|
+
}
|
|
10426
|
+
|
|
10427
|
+
var rst = (p0 - p1) / a;
|
|
10428
|
+
|
|
10429
|
+
if (rst <= 1 && rst >= 0) {
|
|
10430
|
+
return [rst];
|
|
10431
|
+
}
|
|
10432
|
+
|
|
10433
|
+
return [];
|
|
10434
|
+
}
|
|
10435
|
+
|
|
10436
|
+
function derivativeAt(p0, p1, p2, t) {
|
|
10437
|
+
return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
|
|
10438
|
+
} // 分割贝塞尔曲线
|
|
10439
|
+
|
|
10440
|
+
|
|
10441
|
+
function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
|
|
10442
|
+
// 划分点
|
|
10443
|
+
var xt = quadraticAt(x1, x2, x3, t);
|
|
10444
|
+
var yt = quadraticAt(y1, y2, y3, t); // 分割的第一条曲线的控制点
|
|
10445
|
+
|
|
10446
|
+
var controlPoint1 = line.pointAt(x1, y1, x2, y2, t); // 分割的第二条曲线的控制点
|
|
10447
|
+
|
|
10448
|
+
var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
|
|
10449
|
+
return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
|
|
10450
|
+
} // 使用迭代法取贝塞尔曲线的长度
|
|
10451
|
+
|
|
10452
|
+
|
|
10453
|
+
function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
|
|
10454
|
+
if (iterationCount === 0) {
|
|
10455
|
+
return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
|
|
10456
|
+
}
|
|
10457
|
+
|
|
10458
|
+
var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
|
|
10459
|
+
var left = quadratics[0];
|
|
10460
|
+
var right = quadratics[1];
|
|
10461
|
+
left.push(iterationCount - 1);
|
|
10462
|
+
right.push(iterationCount - 1);
|
|
10463
|
+
return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
|
|
10464
|
+
}
|
|
10465
|
+
|
|
10466
|
+
var quadratic = {
|
|
10467
|
+
box: function box(x1, y1, x2, y2, x3, y3) {
|
|
10468
|
+
var xExtrema = extrema(x1, x2, x3)[0];
|
|
10469
|
+
var yExtrema = extrema(y1, y2, y3)[0]; // 控制点不加入 box 的计算
|
|
10470
|
+
|
|
10471
|
+
var xArr = [x1, x3];
|
|
10472
|
+
var yArr = [y1, y3];
|
|
10473
|
+
|
|
10474
|
+
if (xExtrema !== undefined) {
|
|
10475
|
+
xArr.push(quadraticAt(x1, x2, x3, xExtrema));
|
|
10476
|
+
}
|
|
10477
|
+
|
|
10478
|
+
if (yExtrema !== undefined) {
|
|
10479
|
+
yArr.push(quadraticAt(y1, y2, y3, yExtrema));
|
|
10480
|
+
}
|
|
10481
|
+
|
|
10482
|
+
return getBBoxByArray(xArr, yArr);
|
|
10483
|
+
},
|
|
10484
|
+
length: function length(x1, y1, x2, y2, x3, y3) {
|
|
10485
|
+
return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
|
|
10486
|
+
},
|
|
10487
|
+
nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
10488
|
+
return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
|
|
10489
|
+
},
|
|
10490
|
+
pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
10491
|
+
var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
|
|
10492
|
+
return distance(point.x, point.y, x0, y0);
|
|
10493
|
+
},
|
|
10494
|
+
interpolationAt: quadraticAt,
|
|
10495
|
+
pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
|
|
10496
|
+
return {
|
|
10497
|
+
x: quadraticAt(x1, x2, x3, t),
|
|
10498
|
+
y: quadraticAt(y1, y2, y3, t)
|
|
10499
|
+
};
|
|
10500
|
+
},
|
|
10501
|
+
divide: function divide(x1, y1, x2, y2, x3, y3, t) {
|
|
10502
|
+
return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
|
|
10503
|
+
},
|
|
10504
|
+
tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
|
|
10505
|
+
var dx = derivativeAt(x1, x2, x3, t);
|
|
10506
|
+
var dy = derivativeAt(y1, y2, y3, t);
|
|
10507
|
+
var angle = Math.atan2(dy, dx);
|
|
10508
|
+
return piMod(angle);
|
|
10509
|
+
}
|
|
10510
|
+
};
|
|
10511
|
+
|
|
10512
|
+
function cubicAt(p0, p1, p2, p3, t) {
|
|
10513
|
+
var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
|
|
10514
|
+
|
|
10515
|
+
return onet * onet * onet * p0 + 3 * p1 * t * onet * onet + 3 * p2 * t * t * onet + p3 * t * t * t;
|
|
10516
|
+
}
|
|
10517
|
+
|
|
10518
|
+
function derivativeAt$1(p0, p1, p2, p3, t) {
|
|
10519
|
+
var onet = 1 - t;
|
|
10520
|
+
return 3 * (onet * onet * (p1 - p0) + 2 * onet * t * (p2 - p1) + t * t * (p3 - p2));
|
|
10521
|
+
}
|
|
10522
|
+
|
|
10523
|
+
function extrema$1(p0, p1, p2, p3) {
|
|
10524
|
+
var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
|
|
10525
|
+
var b = 6 * p0 - 12 * p1 + 6 * p2;
|
|
10526
|
+
var c = 3 * p1 - 3 * p0;
|
|
10527
|
+
var extremas = [];
|
|
10528
|
+
var t1;
|
|
10529
|
+
var t2;
|
|
10530
|
+
var discSqrt;
|
|
10531
|
+
|
|
10532
|
+
if (isNumberEqual$1(a, 0)) {
|
|
10533
|
+
if (!isNumberEqual$1(b, 0)) {
|
|
10534
|
+
t1 = -c / b;
|
|
10535
|
+
|
|
10536
|
+
if (t1 >= 0 && t1 <= 1) {
|
|
10537
|
+
extremas.push(t1);
|
|
10538
|
+
}
|
|
10539
|
+
}
|
|
10540
|
+
} else {
|
|
10541
|
+
var disc = b * b - 4 * a * c;
|
|
10542
|
+
|
|
10543
|
+
if (isNumberEqual$1(disc, 0)) {
|
|
10544
|
+
extremas.push(-b / (2 * a));
|
|
10545
|
+
} else if (disc > 0) {
|
|
10546
|
+
discSqrt = Math.sqrt(disc);
|
|
10547
|
+
t1 = (-b + discSqrt) / (2 * a);
|
|
10548
|
+
t2 = (-b - discSqrt) / (2 * a);
|
|
10549
|
+
|
|
10550
|
+
if (t1 >= 0 && t1 <= 1) {
|
|
10551
|
+
extremas.push(t1);
|
|
10552
|
+
}
|
|
10553
|
+
|
|
10554
|
+
if (t2 >= 0 && t2 <= 1) {
|
|
10555
|
+
extremas.push(t2);
|
|
10556
|
+
}
|
|
10557
|
+
}
|
|
10558
|
+
}
|
|
10559
|
+
|
|
10560
|
+
return extremas;
|
|
10561
|
+
} // 分割贝塞尔曲线
|
|
10562
|
+
|
|
10563
|
+
|
|
10564
|
+
function divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
10565
|
+
// 划分点
|
|
10566
|
+
var xt = cubicAt(x1, x2, x3, x4, t);
|
|
10567
|
+
var yt = cubicAt(y1, y2, y3, y4, t); // 计算两点之间的差值点
|
|
10568
|
+
|
|
10569
|
+
var c1 = line.pointAt(x1, y1, x2, y2, t);
|
|
10570
|
+
var c2 = line.pointAt(x2, y2, x3, y3, t);
|
|
10571
|
+
var c3 = line.pointAt(x3, y3, x4, y4, t);
|
|
10572
|
+
var c12 = line.pointAt(c1.x, c1.y, c2.x, c2.y, t);
|
|
10573
|
+
var c23 = line.pointAt(c2.x, c2.y, c3.x, c3.y, t);
|
|
10574
|
+
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]];
|
|
10575
|
+
} // 使用迭代法取贝塞尔曲线的长度,二阶和三阶分开写,更清晰和便于调试
|
|
10576
|
+
|
|
10577
|
+
|
|
10578
|
+
function cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, iterationCount) {
|
|
10579
|
+
if (iterationCount === 0) {
|
|
10580
|
+
return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
|
|
10581
|
+
}
|
|
10582
|
+
|
|
10583
|
+
var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
|
|
10584
|
+
var left = [].concat(cubics[0], [iterationCount - 1]);
|
|
10585
|
+
var right = [].concat(cubics[1], [iterationCount - 1]);
|
|
10586
|
+
return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
|
|
10587
|
+
}
|
|
10588
|
+
|
|
10589
|
+
var cubic = {
|
|
10590
|
+
extrema: extrema$1,
|
|
10591
|
+
box: function box(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
10592
|
+
var xArr = [x1, x4];
|
|
10593
|
+
var yArr = [y1, y4];
|
|
10594
|
+
var xExtrema = extrema$1(x1, x2, x3, x4);
|
|
10595
|
+
var yExtrema = extrema$1(y1, y2, y3, y4);
|
|
10596
|
+
|
|
10597
|
+
for (var i = 0; i < xExtrema.length; i++) {
|
|
10598
|
+
xArr.push(cubicAt(x1, x2, x3, x4, xExtrema[i]));
|
|
10599
|
+
}
|
|
10600
|
+
|
|
10601
|
+
for (var _i = 0; _i < yExtrema.length; _i++) {
|
|
10602
|
+
yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i]));
|
|
10603
|
+
}
|
|
10604
|
+
|
|
10605
|
+
return getBBoxByArray(xArr, yArr);
|
|
10606
|
+
},
|
|
10607
|
+
length: function length(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
10608
|
+
// 迭代三次,划分成 8 段求长度
|
|
10609
|
+
return cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, 3);
|
|
10610
|
+
},
|
|
10611
|
+
nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
|
|
10612
|
+
return nearestPoint([x1, x2, x3, x4], [y1, y2, y3, y4], x0, y0, cubicAt, length);
|
|
10613
|
+
},
|
|
10614
|
+
pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
|
|
10615
|
+
var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length);
|
|
10616
|
+
return distance(point.x, point.y, x0, y0);
|
|
10617
|
+
},
|
|
10618
|
+
interpolationAt: cubicAt,
|
|
10619
|
+
pointAt: function pointAt(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
10620
|
+
return {
|
|
10621
|
+
x: cubicAt(x1, x2, x3, x4, t),
|
|
10622
|
+
y: cubicAt(y1, y2, y3, y4, t)
|
|
10623
|
+
};
|
|
10624
|
+
},
|
|
10625
|
+
divide: function divide(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
10626
|
+
return divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t);
|
|
10627
|
+
},
|
|
10628
|
+
tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
10629
|
+
var dx = derivativeAt$1(x1, x2, x3, x4, t);
|
|
10630
|
+
var dy = derivativeAt$1(y1, y2, y3, y4, t);
|
|
10631
|
+
return piMod(Math.atan2(dy, dx));
|
|
10632
|
+
}
|
|
10633
|
+
};
|
|
10634
|
+
/**
|
|
10635
|
+
* @fileoverview 椭圆的一些计算,
|
|
10636
|
+
* - 周长计算参考:https://www.mathsisfun.com/geometry/ellipse-perimeter.html
|
|
10637
|
+
* - 距离计算参考:https://wet-robots.ghost.io/simple-method-for-distance-to-ellipse/
|
|
10638
|
+
* @author dxq613@gmail.com
|
|
10639
|
+
*/
|
|
10640
|
+
|
|
10641
|
+
function copysign(v1, v2) {
|
|
10642
|
+
var absv = Math.abs(v1);
|
|
10643
|
+
return v2 > 0 ? absv : absv * -1;
|
|
10644
|
+
}
|
|
10645
|
+
|
|
10646
|
+
var ellipse = {
|
|
10647
|
+
/**
|
|
10648
|
+
* 包围盒计算
|
|
10649
|
+
* @param {number} x 椭圆中心 x
|
|
10650
|
+
* @param {number} y 椭圆中心 y
|
|
10651
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
10652
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
10653
|
+
* @return {object} 包围盒
|
|
10654
|
+
*/
|
|
10655
|
+
box: function box(x, y, rx, ry) {
|
|
10656
|
+
return {
|
|
10657
|
+
x: x - rx,
|
|
10658
|
+
y: y - ry,
|
|
10659
|
+
width: rx * 2,
|
|
10660
|
+
height: ry * 2
|
|
10661
|
+
};
|
|
10662
|
+
},
|
|
10663
|
+
|
|
10664
|
+
/**
|
|
10665
|
+
* 计算周长,使用近似法
|
|
10666
|
+
* @param {number} x 椭圆中心 x
|
|
10667
|
+
* @param {number} y 椭圆中心 y
|
|
10668
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
10669
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
10670
|
+
* @return {number} 椭圆周长
|
|
10671
|
+
*/
|
|
10672
|
+
length: function length(x, y, rx, ry) {
|
|
10673
|
+
return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
|
|
10674
|
+
},
|
|
10675
|
+
|
|
10676
|
+
/**
|
|
10677
|
+
* 距离椭圆最近的点
|
|
10678
|
+
* @param {number} x 椭圆中心 x
|
|
10679
|
+
* @param {number} y 椭圆中心 y
|
|
10680
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
10681
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
10682
|
+
* @param {number} x0 指定的点 x
|
|
10683
|
+
* @param {number} y0 指定的点 y
|
|
10684
|
+
* @return {object} 椭圆上距离指定点最近的点
|
|
10685
|
+
*/
|
|
10686
|
+
nearestPoint: function nearestPoint(x, y, rx, ry, x0, y0) {
|
|
10687
|
+
var a = rx;
|
|
10688
|
+
var b = ry; // 假如椭圆半径为0则返回圆心
|
|
10689
|
+
|
|
10690
|
+
if (a === 0 || b === 0) {
|
|
10691
|
+
return {
|
|
10692
|
+
x: x,
|
|
10693
|
+
y: y
|
|
10694
|
+
};
|
|
10695
|
+
} // 转换成 0, 0 为中心的椭圆计算
|
|
10696
|
+
|
|
10697
|
+
|
|
10698
|
+
var relativeX = x0 - x;
|
|
10699
|
+
var relativeY = y0 - y;
|
|
10700
|
+
var px = Math.abs(relativeX);
|
|
10701
|
+
var py = Math.abs(relativeY);
|
|
10702
|
+
var squareA = a * a;
|
|
10703
|
+
var squareB = b * b; // const angle0 = Math.atan2(relativeY, relativeX);
|
|
10704
|
+
|
|
10705
|
+
var t = Math.PI / 4;
|
|
10706
|
+
var nearestX = 0; // 椭圆上的任一点
|
|
10707
|
+
|
|
10708
|
+
var nearestY = 0; // 迭代 4 次
|
|
10709
|
+
|
|
10710
|
+
for (var i = 0; i < 4; i++) {
|
|
10711
|
+
nearestX = a * Math.cos(t);
|
|
10712
|
+
nearestY = b * Math.sin(t);
|
|
10713
|
+
var ex = (squareA - squareB) * Math.pow(Math.cos(t), 3) / a;
|
|
10714
|
+
var ey = (squareB - squareA) * Math.pow(Math.sin(t), 3) / b;
|
|
10715
|
+
var rx1 = nearestX - ex;
|
|
10716
|
+
var ry1 = nearestY - ey;
|
|
10717
|
+
var qx = px - ex;
|
|
10718
|
+
var qy = py - ey;
|
|
10719
|
+
var r = Math.hypot(ry1, rx1);
|
|
10720
|
+
var q = Math.hypot(qy, qx);
|
|
10721
|
+
var delta_c = r * Math.asin((rx1 * qy - ry1 * qx) / (r * q));
|
|
10722
|
+
var delta_t = delta_c / Math.sqrt(squareA + squareB - nearestX * nearestX - nearestY * nearestY);
|
|
10723
|
+
t += delta_t;
|
|
10724
|
+
t = Math.min(Math.PI / 2, Math.max(0, t));
|
|
10725
|
+
}
|
|
10726
|
+
|
|
10727
|
+
return {
|
|
10728
|
+
x: x + copysign(nearestX, relativeX),
|
|
10729
|
+
y: y + copysign(nearestY, relativeY)
|
|
10730
|
+
};
|
|
10731
|
+
},
|
|
10732
|
+
|
|
10733
|
+
/**
|
|
10734
|
+
* 点到椭圆最近的距离
|
|
10735
|
+
* @param {number} x 椭圆中心 x
|
|
10736
|
+
* @param {number} y 椭圆中心 y
|
|
10737
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
10738
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
10739
|
+
* @param {number} x0 指定的点 x
|
|
10740
|
+
* @param {number} y0 指定的点 y
|
|
10741
|
+
* @return {number} 点到椭圆的距离
|
|
10742
|
+
*/
|
|
10743
|
+
pointDistance: function pointDistance(x, y, rx, ry, x0, y0) {
|
|
10744
|
+
var nearestPoint = this.nearestPoint(x, y, rx, ry, x0, y0);
|
|
10745
|
+
return distance(nearestPoint.x, nearestPoint.y, x0, y0);
|
|
10746
|
+
},
|
|
10747
|
+
|
|
10748
|
+
/**
|
|
10749
|
+
* 根据比例获取点
|
|
10750
|
+
* @param {number} x 椭圆中心 x
|
|
10751
|
+
* @param {number} y 椭圆中心 y
|
|
10752
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
10753
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
10754
|
+
* @param {number} t 指定比例,x轴方向为 0
|
|
10755
|
+
* @return {object} 点
|
|
10756
|
+
*/
|
|
10757
|
+
pointAt: function pointAt(x, y, rx, ry, t) {
|
|
10758
|
+
var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
|
|
10759
|
+
|
|
10760
|
+
return {
|
|
10761
|
+
x: x + rx * Math.cos(angle),
|
|
10762
|
+
y: y + ry * Math.sin(angle)
|
|
10763
|
+
};
|
|
10764
|
+
},
|
|
10765
|
+
|
|
10766
|
+
/**
|
|
10767
|
+
* 根据比例计算切线角度
|
|
10768
|
+
* @param {number} x 椭圆中心 x
|
|
10769
|
+
* @param {number} y 椭圆中心 y
|
|
10770
|
+
* @param {number} rx 椭圆 x 方向半径
|
|
10771
|
+
* @param {number} ry 椭圆 y 方向半径
|
|
10772
|
+
* @param {number} t 指定比例 0 - 1 之间,x轴方向为 0。在 0-1 范围之外是循环还是返回 null,还需要调整
|
|
10773
|
+
* @return {number} 角度,在 0 - 2PI 之间
|
|
10774
|
+
*/
|
|
10775
|
+
tangentAngle: function tangentAngle(x, y, rx, ry, t) {
|
|
10776
|
+
var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
|
|
10777
|
+
// 直接使用 x,y 的导数计算, x' = -rx * sin(t); y' = ry * cos(t);
|
|
10778
|
+
|
|
10779
|
+
var tangentAngle = Math.atan2(ry * Math.cos(angle), -rx * Math.sin(angle)); // 也可以使用指定点的切线方程计算,成本有些高
|
|
10780
|
+
// const point = this.pointAt(0, 0, rx, ry, t); // 椭圆的切线同椭圆的中心不相关
|
|
10781
|
+
// let tangentAngle = -1 * Math.atan((ry * ry * point.x) / (rx * rx * point.y));
|
|
10782
|
+
// if (angle >= 0 && angle <= Math.PI) {
|
|
10783
|
+
// tangentAngle += Math.PI;
|
|
10784
|
+
// }
|
|
10785
|
+
|
|
10786
|
+
return piMod(tangentAngle);
|
|
10787
|
+
}
|
|
10788
|
+
};
|
|
10789
|
+
|
|
10790
|
+
function derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
|
|
10791
|
+
return -1 * rx * Math.cos(xRotation) * Math.sin(angle) - ry * Math.sin(xRotation) * Math.cos(angle);
|
|
10792
|
+
} // 偏导数 y
|
|
10793
|
+
|
|
10794
|
+
|
|
10795
|
+
function derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
|
|
10796
|
+
return -1 * rx * Math.sin(xRotation) * Math.sin(angle) + ry * Math.cos(xRotation) * Math.cos(angle);
|
|
10797
|
+
} // x 的极值
|
|
10798
|
+
|
|
10799
|
+
|
|
10800
|
+
function xExtrema(rx, ry, xRotation) {
|
|
10801
|
+
return Math.atan(-ry / rx * Math.tan(xRotation));
|
|
10802
|
+
} // y 的极值
|
|
10803
|
+
|
|
10804
|
+
|
|
10805
|
+
function yExtrema(rx, ry, xRotation) {
|
|
10806
|
+
return Math.atan(ry / (rx * Math.tan(xRotation)));
|
|
10807
|
+
} // 根据角度求 x 坐标
|
|
10808
|
+
|
|
10809
|
+
|
|
10810
|
+
function xAt(cx, cy, rx, ry, xRotation, angle) {
|
|
10811
|
+
return rx * Math.cos(xRotation) * Math.cos(angle) - ry * Math.sin(xRotation) * Math.sin(angle) + cx;
|
|
10812
|
+
} // 根据角度求 y 坐标
|
|
10813
|
+
|
|
10814
|
+
|
|
10815
|
+
function yAt(cx, cy, rx, ry, xRotation, angle) {
|
|
10816
|
+
return rx * Math.sin(xRotation) * Math.cos(angle) + ry * Math.cos(xRotation) * Math.sin(angle) + cy;
|
|
10817
|
+
} // 获取点在椭圆上的角度
|
|
10818
|
+
|
|
10819
|
+
|
|
10820
|
+
function getAngle(rx, ry, x0, y0) {
|
|
10821
|
+
var angle = Math.atan2(y0 * rx, x0 * ry); // 转换到 0 - 2PI 内
|
|
10822
|
+
|
|
10823
|
+
return (angle + Math.PI * 2) % (Math.PI * 2);
|
|
10824
|
+
} // 根据角度获取,x,y
|
|
10825
|
+
|
|
10826
|
+
|
|
10827
|
+
function getPoint(rx, ry, angle) {
|
|
10828
|
+
return {
|
|
10829
|
+
x: rx * Math.cos(angle),
|
|
10830
|
+
y: ry * Math.sin(angle)
|
|
10831
|
+
};
|
|
10832
|
+
} // 旋转
|
|
10833
|
+
|
|
10834
|
+
|
|
10835
|
+
function rotate$1(x, y, angle) {
|
|
10836
|
+
var cos = Math.cos(angle);
|
|
10837
|
+
var sin = Math.sin(angle);
|
|
10838
|
+
return [x * cos - y * sin, x * sin + y * cos];
|
|
10839
|
+
}
|
|
10840
|
+
|
|
10841
|
+
var arc = {
|
|
10842
|
+
/**
|
|
10843
|
+
* 计算包围盒
|
|
10844
|
+
* @param {number} cx 圆心 x
|
|
10845
|
+
* @param {number} cy 圆心 y
|
|
10846
|
+
* @param {number} rx x 轴方向的半径
|
|
10847
|
+
* @param {number} ry y 轴方向的半径
|
|
10848
|
+
* @param {number} xRotation 旋转角度
|
|
10849
|
+
* @param {number} startAngle 起始角度
|
|
10850
|
+
* @param {number} endAngle 结束角度
|
|
10851
|
+
* @return {object} 包围盒对象
|
|
10852
|
+
*/
|
|
10853
|
+
box: function box(cx, cy, rx, ry, xRotation, startAngle, endAngle) {
|
|
10854
|
+
var xDim = xExtrema(rx, ry, xRotation);
|
|
10855
|
+
var minX = Infinity;
|
|
10856
|
+
var maxX = -Infinity;
|
|
10857
|
+
var xs = [startAngle, endAngle];
|
|
10858
|
+
|
|
10859
|
+
for (var i = -Math.PI * 2; i <= Math.PI * 2; i += Math.PI) {
|
|
10860
|
+
var xAngle = xDim + i;
|
|
10861
|
+
|
|
10862
|
+
if (startAngle < endAngle) {
|
|
10863
|
+
if (startAngle < xAngle && xAngle < endAngle) {
|
|
10864
|
+
xs.push(xAngle);
|
|
10865
|
+
}
|
|
10866
|
+
} else {
|
|
10867
|
+
if (endAngle < xAngle && xAngle < startAngle) {
|
|
10868
|
+
xs.push(xAngle);
|
|
10869
|
+
}
|
|
10870
|
+
}
|
|
10871
|
+
}
|
|
10872
|
+
|
|
10873
|
+
for (var _i = 0; _i < xs.length; _i++) {
|
|
10874
|
+
var x = xAt(cx, cy, rx, ry, xRotation, xs[_i]);
|
|
10875
|
+
|
|
10876
|
+
if (x < minX) {
|
|
10877
|
+
minX = x;
|
|
10878
|
+
}
|
|
10879
|
+
|
|
10880
|
+
if (x > maxX) {
|
|
10881
|
+
maxX = x;
|
|
10882
|
+
}
|
|
10883
|
+
}
|
|
10884
|
+
|
|
10885
|
+
var yDim = yExtrema(rx, ry, xRotation);
|
|
10886
|
+
var minY = Infinity;
|
|
10887
|
+
var maxY = -Infinity;
|
|
10888
|
+
var ys = [startAngle, endAngle];
|
|
10889
|
+
|
|
10890
|
+
for (var _i2 = -Math.PI * 2; _i2 <= Math.PI * 2; _i2 += Math.PI) {
|
|
10891
|
+
var yAngle = yDim + _i2;
|
|
10892
|
+
|
|
10893
|
+
if (startAngle < endAngle) {
|
|
10894
|
+
if (startAngle < yAngle && yAngle < endAngle) {
|
|
10895
|
+
ys.push(yAngle);
|
|
10896
|
+
}
|
|
10897
|
+
} else {
|
|
10898
|
+
if (endAngle < yAngle && yAngle < startAngle) {
|
|
10899
|
+
ys.push(yAngle);
|
|
10900
|
+
}
|
|
10901
|
+
}
|
|
10902
|
+
}
|
|
10903
|
+
|
|
10904
|
+
for (var _i3 = 0; _i3 < ys.length; _i3++) {
|
|
10905
|
+
var y = yAt(cx, cy, rx, ry, xRotation, ys[_i3]);
|
|
10906
|
+
|
|
10907
|
+
if (y < minY) {
|
|
10908
|
+
minY = y;
|
|
10909
|
+
}
|
|
10910
|
+
|
|
10911
|
+
if (y > maxY) {
|
|
10912
|
+
maxY = y;
|
|
10913
|
+
}
|
|
10914
|
+
}
|
|
10915
|
+
|
|
10916
|
+
return {
|
|
10917
|
+
x: minX,
|
|
10918
|
+
y: minY,
|
|
10919
|
+
width: maxX - minX,
|
|
10920
|
+
height: maxY - minY
|
|
10921
|
+
};
|
|
10922
|
+
},
|
|
10923
|
+
|
|
10924
|
+
/**
|
|
10925
|
+
* 获取圆弧的长度,计算圆弧长度时不考虑旋转角度,
|
|
10926
|
+
* 仅跟 rx, ry, startAngle, endAngle 相关
|
|
10927
|
+
* @param {number} cx 圆心 x
|
|
10928
|
+
* @param {number} cy 圆心 y
|
|
10929
|
+
* @param {number} rx x 轴方向的半径
|
|
10930
|
+
* @param {number} ry y 轴方向的半径
|
|
10931
|
+
* @param {number} xRotation 旋转角度
|
|
10932
|
+
* @param {number} startAngle 起始角度
|
|
10933
|
+
* @param {number} endAngle 结束角度
|
|
10934
|
+
*/
|
|
10935
|
+
length: function length(cx, cy, rx, ry, xRotation, startAngle, endAngle) {},
|
|
10936
|
+
|
|
10937
|
+
/**
|
|
10938
|
+
* 获取指定点到圆弧的最近距离的点
|
|
10939
|
+
* @param {number} cx 圆心 x
|
|
10940
|
+
* @param {number} cy 圆心 y
|
|
10941
|
+
* @param {number} rx x 轴方向的半径
|
|
10942
|
+
* @param {number} ry y 轴方向的半径
|
|
10943
|
+
* @param {number} xRotation 旋转角度
|
|
10944
|
+
* @param {number} startAngle 起始角度
|
|
10945
|
+
* @param {number} endAngle 结束角度
|
|
10946
|
+
* @param {number} x0 指定点的 x
|
|
10947
|
+
* @param {number} y0 指定点的 y
|
|
10948
|
+
* @return {object} 到指定点最近距离的点
|
|
10949
|
+
*/
|
|
10950
|
+
nearestPoint: function nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
|
|
10951
|
+
// 将最近距离问题转换成到椭圆中心 0,0 没有旋转的椭圆问题
|
|
10952
|
+
var relativeVector = rotate$1(x0 - cx, y0 - cy, -xRotation);
|
|
10953
|
+
var x1 = relativeVector[0],
|
|
10954
|
+
y1 = relativeVector[1]; // 计算点到椭圆的最近的点
|
|
10955
|
+
|
|
10956
|
+
var relativePoint = ellipse.nearestPoint(0, 0, rx, ry, x1, y1); // 获取点在椭圆上的角度
|
|
10957
|
+
|
|
10958
|
+
var angle = getAngle(rx, ry, relativePoint.x, relativePoint.y); // 点没有在圆弧上
|
|
10959
|
+
|
|
10960
|
+
if (angle < startAngle) {
|
|
10961
|
+
// 小于起始圆弧
|
|
10962
|
+
relativePoint = getPoint(rx, ry, startAngle);
|
|
10963
|
+
} else if (angle > endAngle) {
|
|
10964
|
+
// 大于结束圆弧
|
|
10965
|
+
relativePoint = getPoint(rx, ry, endAngle);
|
|
10966
|
+
} // 旋转到 xRotation 的角度
|
|
10967
|
+
|
|
10968
|
+
|
|
10969
|
+
var vector = rotate$1(relativePoint.x, relativePoint.y, xRotation);
|
|
10970
|
+
return {
|
|
10971
|
+
x: vector[0] + cx,
|
|
10972
|
+
y: vector[1] + cy
|
|
10973
|
+
};
|
|
10974
|
+
},
|
|
10975
|
+
pointDistance: function pointDistance(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
|
|
10976
|
+
var nearestPoint = this.nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0);
|
|
10977
|
+
return distance(nearestPoint.x, nearestPoint.y, x0, y0);
|
|
10978
|
+
},
|
|
10979
|
+
pointAt: function pointAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
|
|
10980
|
+
var angle = (endAngle - startAngle) * t + startAngle;
|
|
10981
|
+
return {
|
|
10982
|
+
x: xAt(cx, cy, rx, ry, xRotation, angle),
|
|
10983
|
+
y: yAt(cx, cy, rx, ry, xRotation, angle)
|
|
10984
|
+
};
|
|
10985
|
+
},
|
|
10986
|
+
tangentAngle: function tangentAngle(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
|
|
10987
|
+
var angle = (endAngle - startAngle) * t + startAngle;
|
|
10988
|
+
var dx = derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
|
|
10989
|
+
var dy = derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
|
|
10990
|
+
return piMod(Math.atan2(dy, dx));
|
|
10991
|
+
}
|
|
10992
|
+
};
|
|
10280
10993
|
|
|
10281
10994
|
function analyzePoints(points) {
|
|
10282
10995
|
// 计算每段的长度和总的长度
|
|
@@ -11923,7 +12636,7 @@
|
|
|
11923
12636
|
return CSSPropertyZIndex;
|
|
11924
12637
|
}();
|
|
11925
12638
|
|
|
11926
|
-
function getAngle(angle) {
|
|
12639
|
+
function getAngle$1(angle) {
|
|
11927
12640
|
if (angle === undefined) {
|
|
11928
12641
|
return 0;
|
|
11929
12642
|
} else if (angle > 360 || angle < -360) {
|
|
@@ -12735,12 +13448,148 @@
|
|
|
12735
13448
|
return point1[0] === point2[0] && point1[1] === point2[1];
|
|
12736
13449
|
}
|
|
12737
13450
|
|
|
13451
|
+
function getPathBBox(segments, lineWidth) {
|
|
13452
|
+
var xArr = [];
|
|
13453
|
+
var yArr = [];
|
|
13454
|
+
var segmentsWithAngle = [];
|
|
13455
|
+
|
|
13456
|
+
for (var i = 0; i < segments.length; i++) {
|
|
13457
|
+
var segment = segments[i];
|
|
13458
|
+
var currentPoint = segment.currentPoint,
|
|
13459
|
+
params = segment.params,
|
|
13460
|
+
prePoint = segment.prePoint;
|
|
13461
|
+
var box = void 0;
|
|
13462
|
+
|
|
13463
|
+
switch (segment.command) {
|
|
13464
|
+
case 'Q':
|
|
13465
|
+
box = quadratic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
|
|
13466
|
+
break;
|
|
13467
|
+
|
|
13468
|
+
case 'C':
|
|
13469
|
+
box = cubic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6]);
|
|
13470
|
+
break;
|
|
13471
|
+
|
|
13472
|
+
case 'A':
|
|
13473
|
+
var arcParams = segment.arcParams;
|
|
13474
|
+
box = arc.box(arcParams.cx, arcParams.cy, arcParams.rx, arcParams.ry, arcParams.xRotation, arcParams.startAngle, arcParams.endAngle);
|
|
13475
|
+
break;
|
|
13476
|
+
|
|
13477
|
+
default:
|
|
13478
|
+
xArr.push(currentPoint[0]);
|
|
13479
|
+
yArr.push(currentPoint[1]);
|
|
13480
|
+
break;
|
|
13481
|
+
}
|
|
13482
|
+
|
|
13483
|
+
if (box) {
|
|
13484
|
+
segment.box = box;
|
|
13485
|
+
xArr.push(box.x, box.x + box.width);
|
|
13486
|
+
yArr.push(box.y, box.y + box.height);
|
|
13487
|
+
}
|
|
13488
|
+
|
|
13489
|
+
if (lineWidth && (segment.command === 'L' || segment.command === 'M') && segment.prePoint && segment.nextPoint) {
|
|
13490
|
+
segmentsWithAngle.push(segment);
|
|
13491
|
+
}
|
|
13492
|
+
} // bbox calculation should ignore NaN for path attribute
|
|
13493
|
+
// ref: https://github.com/antvis/g/issues/210
|
|
13494
|
+
// ref: https://github.com/antvis/G2/issues/3109
|
|
13495
|
+
|
|
13496
|
+
|
|
13497
|
+
xArr = xArr.filter(function (item) {
|
|
13498
|
+
return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
|
|
13499
|
+
});
|
|
13500
|
+
yArr = yArr.filter(function (item) {
|
|
13501
|
+
return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
|
|
13502
|
+
});
|
|
13503
|
+
var minX = min$1(xArr);
|
|
13504
|
+
var minY = min$1(yArr);
|
|
13505
|
+
var maxX = max$1(xArr);
|
|
13506
|
+
var maxY = max$1(yArr);
|
|
13507
|
+
|
|
13508
|
+
if (segmentsWithAngle.length === 0) {
|
|
13509
|
+
return {
|
|
13510
|
+
x: minX,
|
|
13511
|
+
y: minY,
|
|
13512
|
+
width: maxX - minX,
|
|
13513
|
+
height: maxY - minY
|
|
13514
|
+
};
|
|
13515
|
+
}
|
|
13516
|
+
|
|
13517
|
+
for (var _i = 0; _i < segmentsWithAngle.length; _i++) {
|
|
13518
|
+
var _segment = segmentsWithAngle[_i];
|
|
13519
|
+
var _currentPoint = _segment.currentPoint;
|
|
13520
|
+
var extra = void 0;
|
|
13521
|
+
|
|
13522
|
+
if (_currentPoint[0] === minX) {
|
|
13523
|
+
extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
|
|
13524
|
+
minX = minX - extra.xExtra;
|
|
13525
|
+
} else if (_currentPoint[0] === maxX) {
|
|
13526
|
+
extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
|
|
13527
|
+
maxX = maxX + extra.xExtra;
|
|
13528
|
+
}
|
|
13529
|
+
|
|
13530
|
+
if (_currentPoint[1] === minY) {
|
|
13531
|
+
extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
|
|
13532
|
+
minY = minY - extra.yExtra;
|
|
13533
|
+
} else if (_currentPoint[1] === maxY) {
|
|
13534
|
+
extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
|
|
13535
|
+
maxY = maxY + extra.yExtra;
|
|
13536
|
+
}
|
|
13537
|
+
}
|
|
13538
|
+
|
|
13539
|
+
return {
|
|
13540
|
+
x: minX,
|
|
13541
|
+
y: minY,
|
|
13542
|
+
width: maxX - minX,
|
|
13543
|
+
height: maxY - minY
|
|
13544
|
+
};
|
|
13545
|
+
}
|
|
13546
|
+
|
|
13547
|
+
function getExtraFromSegmentWithAngle(segment, lineWidth) {
|
|
13548
|
+
var prePoint = segment.prePoint,
|
|
13549
|
+
currentPoint = segment.currentPoint,
|
|
13550
|
+
nextPoint = segment.nextPoint;
|
|
13551
|
+
var currentAndPre = Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
|
|
13552
|
+
var currentAndNext = Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
|
|
13553
|
+
var preAndNext = Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2); // 以 currentPoint 为顶点的夹角
|
|
13554
|
+
|
|
13555
|
+
var currentAngle = Math.acos((currentAndPre + currentAndNext - preAndNext) / (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext))); // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
|
|
13556
|
+
// 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
|
|
13557
|
+
|
|
13558
|
+
if (!currentAngle || Math.sin(currentAngle) === 0 || isNumberEqual(currentAngle, 0)) {
|
|
13559
|
+
return {
|
|
13560
|
+
xExtra: 0,
|
|
13561
|
+
yExtra: 0
|
|
13562
|
+
};
|
|
13563
|
+
}
|
|
13564
|
+
|
|
13565
|
+
var xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
|
|
13566
|
+
var yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1])); // 将夹角转为锐角
|
|
13567
|
+
|
|
13568
|
+
xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
|
|
13569
|
+
yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle; // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
|
|
13570
|
+
// 由于上层统一加减了二分之一线宽,这里需要进行弥补
|
|
13571
|
+
|
|
13572
|
+
var extra = {
|
|
13573
|
+
// 水平方向投影
|
|
13574
|
+
xExtra: Math.cos(currentAngle / 2 - xAngle) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0,
|
|
13575
|
+
// 垂直方向投影
|
|
13576
|
+
yExtra: Math.cos(yAngle - currentAngle / 2) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0
|
|
13577
|
+
};
|
|
13578
|
+
return extra;
|
|
13579
|
+
} // 点对称
|
|
13580
|
+
|
|
13581
|
+
|
|
13582
|
+
function toSymmetry(point, center) {
|
|
13583
|
+
return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
|
|
13584
|
+
}
|
|
13585
|
+
|
|
12738
13586
|
function path2Segments(path) {
|
|
12739
13587
|
var segments = [];
|
|
12740
13588
|
var currentPoint = null; // 当前图形
|
|
12741
13589
|
|
|
12742
13590
|
var nextParams = null; // 下一节点的 path 参数
|
|
12743
|
-
|
|
13591
|
+
|
|
13592
|
+
var startMovePoint = null; // 开始 M 的点,可能会有多个
|
|
12744
13593
|
|
|
12745
13594
|
var lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
|
|
12746
13595
|
|
|
@@ -12756,18 +13605,43 @@
|
|
|
12756
13605
|
prePoint: currentPoint,
|
|
12757
13606
|
params: params,
|
|
12758
13607
|
startTangent: null,
|
|
12759
|
-
endTangent: null
|
|
13608
|
+
endTangent: null,
|
|
13609
|
+
currentPoint: null,
|
|
13610
|
+
nextPoint: null,
|
|
13611
|
+
arcParams: null
|
|
12760
13612
|
};
|
|
12761
13613
|
|
|
12762
13614
|
switch (command) {
|
|
12763
13615
|
case 'M':
|
|
12764
|
-
|
|
13616
|
+
startMovePoint = [params[1], params[2]];
|
|
12765
13617
|
lastStartMovePointIndex = i;
|
|
12766
13618
|
break;
|
|
13619
|
+
|
|
13620
|
+
case 'A':
|
|
13621
|
+
var arcParams = getArcParams(currentPoint, params);
|
|
13622
|
+
segment.arcParams = arcParams;
|
|
13623
|
+
break;
|
|
13624
|
+
}
|
|
13625
|
+
|
|
13626
|
+
if (command === 'Z') {
|
|
13627
|
+
// 有了 Z 后,当前节点从开始 M 的点开始
|
|
13628
|
+
currentPoint = startMovePoint; // 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
|
|
13629
|
+
|
|
13630
|
+
nextParams = path[lastStartMovePointIndex + 1];
|
|
13631
|
+
} else {
|
|
13632
|
+
var len = params.length;
|
|
13633
|
+
currentPoint = [params[len - 2], params[len - 1]];
|
|
12767
13634
|
}
|
|
12768
13635
|
|
|
12769
|
-
|
|
12770
|
-
|
|
13636
|
+
if (nextParams && nextParams[0] === 'Z') {
|
|
13637
|
+
// 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
|
|
13638
|
+
nextParams = path[lastStartMovePointIndex];
|
|
13639
|
+
|
|
13640
|
+
if (segments[lastStartMovePointIndex]) {
|
|
13641
|
+
// 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
|
|
13642
|
+
segments[lastStartMovePointIndex].prePoint = currentPoint;
|
|
13643
|
+
}
|
|
13644
|
+
}
|
|
12771
13645
|
|
|
12772
13646
|
segment.currentPoint = currentPoint; // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
|
|
12773
13647
|
|
|
@@ -12775,13 +13649,36 @@
|
|
|
12775
13649
|
segments[lastStartMovePointIndex].prePoint = segment.prePoint;
|
|
12776
13650
|
}
|
|
12777
13651
|
|
|
12778
|
-
var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
|
|
12779
|
-
|
|
13652
|
+
var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
|
|
12780
13653
|
segment.nextPoint = nextPoint; // Add startTangent and endTangent
|
|
12781
13654
|
|
|
12782
13655
|
var prePoint = segment.prePoint;
|
|
12783
13656
|
|
|
12784
|
-
if (
|
|
13657
|
+
if (['L', 'H', 'V'].includes(command)) {
|
|
13658
|
+
segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
|
|
13659
|
+
segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
|
|
13660
|
+
} else if (command === 'Q') {
|
|
13661
|
+
// 二次贝塞尔曲线只有一个控制点
|
|
13662
|
+
var cp = [params[1], params[2]]; // 二次贝塞尔曲线的终点为 currentPoint
|
|
13663
|
+
|
|
13664
|
+
segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
|
|
13665
|
+
segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
|
|
13666
|
+
} else if (command === 'T') {
|
|
13667
|
+
var preSegment = segments[i - 1];
|
|
13668
|
+
|
|
13669
|
+
var _cp = toSymmetry(preSegment.currentPoint, prePoint);
|
|
13670
|
+
|
|
13671
|
+
if (preSegment.command === 'Q') {
|
|
13672
|
+
segment.command = 'Q';
|
|
13673
|
+
segment.startTangent = [prePoint[0] - _cp[0], prePoint[1] - _cp[1]];
|
|
13674
|
+
segment.endTangent = [currentPoint[0] - _cp[0], currentPoint[1] - _cp[1]];
|
|
13675
|
+
} else {
|
|
13676
|
+
// @ts-ignore
|
|
13677
|
+
segment.command = 'TL';
|
|
13678
|
+
segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
|
|
13679
|
+
segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
|
|
13680
|
+
}
|
|
13681
|
+
} else if (command === 'C') {
|
|
12785
13682
|
// 三次贝塞尔曲线有两个控制点
|
|
12786
13683
|
var cp1 = [params[1], params[2]];
|
|
12787
13684
|
var cp2 = [params[3], params[4]];
|
|
@@ -12795,25 +13692,155 @@
|
|
|
12795
13692
|
if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
|
|
12796
13693
|
segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
|
|
12797
13694
|
}
|
|
13695
|
+
} else if (command === 'S') {
|
|
13696
|
+
var _preSegment = segments[i - 1];
|
|
13697
|
+
|
|
13698
|
+
var _cp2 = toSymmetry(_preSegment.currentPoint, prePoint);
|
|
13699
|
+
|
|
13700
|
+
var _cp3 = [params[1], params[2]];
|
|
13701
|
+
|
|
13702
|
+
if (_preSegment.command === 'C') {
|
|
13703
|
+
segment.command = 'C'; // 将 S 命令变换为 C 命令
|
|
13704
|
+
|
|
13705
|
+
segment.startTangent = [prePoint[0] - _cp2[0], prePoint[1] - _cp2[1]];
|
|
13706
|
+
segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
|
|
13707
|
+
} else {
|
|
13708
|
+
// @ts-ignore
|
|
13709
|
+
segment.command = 'SQ'; // 将 S 命令变换为 SQ 命令
|
|
13710
|
+
|
|
13711
|
+
segment.startTangent = [prePoint[0] - _cp3[0], prePoint[1] - _cp3[1]];
|
|
13712
|
+
segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
|
|
13713
|
+
}
|
|
13714
|
+
} else if (command === 'A') {
|
|
13715
|
+
var d = 0.001;
|
|
13716
|
+
|
|
13717
|
+
var _ref = segment.arcParams || {},
|
|
13718
|
+
_ref$cx = _ref.cx,
|
|
13719
|
+
cx = _ref$cx === void 0 ? 0 : _ref$cx,
|
|
13720
|
+
_ref$cy = _ref.cy,
|
|
13721
|
+
cy = _ref$cy === void 0 ? 0 : _ref$cy,
|
|
13722
|
+
_ref$rx = _ref.rx,
|
|
13723
|
+
rx = _ref$rx === void 0 ? 0 : _ref$rx,
|
|
13724
|
+
_ref$ry = _ref.ry,
|
|
13725
|
+
ry = _ref$ry === void 0 ? 0 : _ref$ry,
|
|
13726
|
+
_ref$sweepFlag = _ref.sweepFlag,
|
|
13727
|
+
sweepFlag = _ref$sweepFlag === void 0 ? 0 : _ref$sweepFlag,
|
|
13728
|
+
_ref$startAngle = _ref.startAngle,
|
|
13729
|
+
startAngle = _ref$startAngle === void 0 ? 0 : _ref$startAngle,
|
|
13730
|
+
_ref$endAngle = _ref.endAngle,
|
|
13731
|
+
endAngle = _ref$endAngle === void 0 ? 0 : _ref$endAngle;
|
|
13732
|
+
|
|
13733
|
+
if (sweepFlag === 0) {
|
|
13734
|
+
d *= -1;
|
|
13735
|
+
}
|
|
13736
|
+
|
|
13737
|
+
var dx1 = rx * Math.cos(startAngle - d) + cx;
|
|
13738
|
+
var dy1 = ry * Math.sin(startAngle - d) + cy;
|
|
13739
|
+
segment.startTangent = [dx1 - startMovePoint[0], dy1 - startMovePoint[1]];
|
|
13740
|
+
var dx2 = rx * Math.cos(startAngle + endAngle + d) + cx;
|
|
13741
|
+
var dy2 = ry * Math.sin(startAngle + endAngle - d) + cy;
|
|
13742
|
+
segment.endTangent = [prePoint[0] - dx2, prePoint[1] - dy2];
|
|
12798
13743
|
}
|
|
12799
13744
|
|
|
12800
13745
|
segments.push(segment);
|
|
12801
13746
|
}
|
|
12802
13747
|
|
|
12803
13748
|
return segments;
|
|
13749
|
+
} // 向量长度
|
|
13750
|
+
|
|
13751
|
+
function vMag(v) {
|
|
13752
|
+
return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
|
13753
|
+
} // u.v/|u||v|,计算夹角的余弦值
|
|
13754
|
+
|
|
13755
|
+
|
|
13756
|
+
function vRatio(u, v) {
|
|
13757
|
+
// 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
|
|
13758
|
+
return vMag(u) * vMag(v) ? (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v)) : 1;
|
|
13759
|
+
} // 向量角度
|
|
13760
|
+
|
|
13761
|
+
|
|
13762
|
+
function vAngle(u, v) {
|
|
13763
|
+
return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
|
|
12804
13764
|
}
|
|
12805
13765
|
|
|
12806
|
-
function
|
|
12807
|
-
|
|
12808
|
-
|
|
13766
|
+
function getArcParams(startPoint, params) {
|
|
13767
|
+
var rx = params[1];
|
|
13768
|
+
var ry = params[2];
|
|
13769
|
+
var xRotation = mod(deg2rad(params[3]), Math.PI * 2);
|
|
13770
|
+
var arcFlag = params[4];
|
|
13771
|
+
var sweepFlag = params[5]; // 弧形起点坐标
|
|
13772
|
+
|
|
13773
|
+
var x1 = startPoint[0];
|
|
13774
|
+
var y1 = startPoint[1]; // 弧形终点坐标
|
|
13775
|
+
|
|
13776
|
+
var x2 = params[6];
|
|
13777
|
+
var y2 = params[7];
|
|
13778
|
+
var xp = Math.cos(xRotation) * (x1 - x2) / 2.0 + Math.sin(xRotation) * (y1 - y2) / 2.0;
|
|
13779
|
+
var yp = -1 * Math.sin(xRotation) * (x1 - x2) / 2.0 + Math.cos(xRotation) * (y1 - y2) / 2.0;
|
|
13780
|
+
var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
|
|
13781
|
+
|
|
13782
|
+
if (lambda > 1) {
|
|
13783
|
+
rx *= Math.sqrt(lambda);
|
|
13784
|
+
ry *= Math.sqrt(lambda);
|
|
12809
13785
|
}
|
|
12810
13786
|
|
|
12811
|
-
var
|
|
13787
|
+
var diff = rx * rx * (yp * yp) + ry * ry * (xp * xp);
|
|
13788
|
+
var f = diff ? Math.sqrt((rx * rx * (ry * ry) - diff) / diff) : 1;
|
|
12812
13789
|
|
|
12813
|
-
if (
|
|
12814
|
-
|
|
13790
|
+
if (arcFlag === sweepFlag) {
|
|
13791
|
+
f *= -1;
|
|
12815
13792
|
}
|
|
12816
13793
|
|
|
13794
|
+
if (isNaN(f)) {
|
|
13795
|
+
f = 0;
|
|
13796
|
+
} // 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
|
|
13797
|
+
|
|
13798
|
+
|
|
13799
|
+
var cxp = ry ? f * rx * yp / ry : 0;
|
|
13800
|
+
var cyp = rx ? f * -ry * xp / rx : 0; // 椭圆圆心坐标
|
|
13801
|
+
|
|
13802
|
+
var cx = (x1 + x2) / 2.0 + Math.cos(xRotation) * cxp - Math.sin(xRotation) * cyp;
|
|
13803
|
+
var cy = (y1 + y2) / 2.0 + Math.sin(xRotation) * cxp + Math.cos(xRotation) * cyp; // 起始点的单位向量
|
|
13804
|
+
|
|
13805
|
+
var u = [(xp - cxp) / rx, (yp - cyp) / ry]; // 终止点的单位向量
|
|
13806
|
+
|
|
13807
|
+
var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; // 计算起始点和圆心的连线,与 x 轴正方向的夹角
|
|
13808
|
+
|
|
13809
|
+
var theta = vAngle([1, 0], u); // 计算圆弧起始点和终止点与椭圆圆心连线的夹角
|
|
13810
|
+
|
|
13811
|
+
var dTheta = vAngle(u, v);
|
|
13812
|
+
|
|
13813
|
+
if (vRatio(u, v) <= -1) {
|
|
13814
|
+
dTheta = Math.PI;
|
|
13815
|
+
}
|
|
13816
|
+
|
|
13817
|
+
if (vRatio(u, v) >= 1) {
|
|
13818
|
+
dTheta = 0;
|
|
13819
|
+
}
|
|
13820
|
+
|
|
13821
|
+
if (sweepFlag === 0 && dTheta > 0) {
|
|
13822
|
+
dTheta = dTheta - 2 * Math.PI;
|
|
13823
|
+
}
|
|
13824
|
+
|
|
13825
|
+
if (sweepFlag === 1 && dTheta < 0) {
|
|
13826
|
+
dTheta = dTheta + 2 * Math.PI;
|
|
13827
|
+
}
|
|
13828
|
+
|
|
13829
|
+
return {
|
|
13830
|
+
cx: cx,
|
|
13831
|
+
cy: cy,
|
|
13832
|
+
// 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
|
|
13833
|
+
rx: isSamePoint(startPoint, [x2, y2]) ? 0 : rx,
|
|
13834
|
+
ry: isSamePoint(startPoint, [x2, y2]) ? 0 : ry,
|
|
13835
|
+
startAngle: theta,
|
|
13836
|
+
endAngle: theta + dTheta,
|
|
13837
|
+
xRotation: xRotation,
|
|
13838
|
+
arcFlag: arcFlag,
|
|
13839
|
+
sweepFlag: sweepFlag
|
|
13840
|
+
};
|
|
13841
|
+
}
|
|
13842
|
+
|
|
13843
|
+
function commandsToPathString(commands, object, transform) {
|
|
12817
13844
|
var _object$parsedStyle = object.parsedStyle,
|
|
12818
13845
|
_object$parsedStyle$d = _object$parsedStyle.defX,
|
|
12819
13846
|
defX = _object$parsedStyle$d === void 0 ? 0 : _object$parsedStyle$d,
|
|
@@ -12825,7 +13852,7 @@
|
|
|
12825
13852
|
if (cur[0] === 'M' || cur[0] === 'L') {
|
|
12826
13853
|
var p = fromValues$2(cur[1] - defX, cur[2] - defY, 0);
|
|
12827
13854
|
|
|
12828
|
-
if (
|
|
13855
|
+
if (transform) {
|
|
12829
13856
|
transformMat4(p, p, transform);
|
|
12830
13857
|
}
|
|
12831
13858
|
|
|
@@ -12837,7 +13864,7 @@
|
|
|
12837
13864
|
var p2 = fromValues$2(cur[3] - defX, cur[4] - defY, 0);
|
|
12838
13865
|
var p3 = fromValues$2(cur[5] - defX, cur[6] - defY, 0);
|
|
12839
13866
|
|
|
12840
|
-
if (
|
|
13867
|
+
if (transform) {
|
|
12841
13868
|
transformMat4(p1, p1, transform);
|
|
12842
13869
|
transformMat4(p2, p2, transform);
|
|
12843
13870
|
transformMat4(p3, p3, transform);
|
|
@@ -12847,7 +13874,7 @@
|
|
|
12847
13874
|
} else if (cur[0] === 'A') {
|
|
12848
13875
|
var c = fromValues$2(cur[6] - defX, cur[7] - defY, 0);
|
|
12849
13876
|
|
|
12850
|
-
if (
|
|
13877
|
+
if (transform) {
|
|
12851
13878
|
transformMat4(c, c, transform);
|
|
12852
13879
|
}
|
|
12853
13880
|
|
|
@@ -12911,9 +13938,9 @@
|
|
|
12911
13938
|
*/
|
|
12912
13939
|
|
|
12913
13940
|
|
|
12914
|
-
function convertToPath(object,
|
|
12915
|
-
if (
|
|
12916
|
-
|
|
13941
|
+
function convertToPath(object, transform) {
|
|
13942
|
+
if (transform === void 0) {
|
|
13943
|
+
transform = object.getLocalTransform();
|
|
12917
13944
|
}
|
|
12918
13945
|
|
|
12919
13946
|
var commands = [];
|
|
@@ -12982,7 +14009,7 @@
|
|
|
12982
14009
|
}
|
|
12983
14010
|
|
|
12984
14011
|
if (commands.length) {
|
|
12985
|
-
return commandsToPathString(commands, object,
|
|
14012
|
+
return commandsToPathString(commands, object, transform);
|
|
12986
14013
|
}
|
|
12987
14014
|
}
|
|
12988
14015
|
function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
|
|
@@ -13003,8 +14030,7 @@
|
|
|
13003
14030
|
}
|
|
13004
14031
|
|
|
13005
14032
|
var newValue = pathArray.map(function (params, i) {
|
|
13006
|
-
var command = params[0];
|
|
13007
|
-
|
|
14033
|
+
var command = params[0];
|
|
13008
14034
|
var isClosed = pathArray[pathArray.length - 1][0] === 'Z';
|
|
13009
14035
|
var offsetX = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetX : 0;
|
|
13010
14036
|
var offsetY = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetY : 0;
|
|
@@ -20221,7 +21247,7 @@
|
|
|
20221
21247
|
;
|
|
20222
21248
|
|
|
20223
21249
|
_proto.setAzimuth = function setAzimuth(az) {
|
|
20224
|
-
this.azimuth = getAngle(az);
|
|
21250
|
+
this.azimuth = getAngle$1(az);
|
|
20225
21251
|
this.computeMatrix();
|
|
20226
21252
|
|
|
20227
21253
|
this._getAxes();
|
|
@@ -20245,7 +21271,7 @@
|
|
|
20245
21271
|
;
|
|
20246
21272
|
|
|
20247
21273
|
_proto.setElevation = function setElevation(el) {
|
|
20248
|
-
this.elevation = getAngle(el);
|
|
21274
|
+
this.elevation = getAngle$1(el);
|
|
20249
21275
|
this.computeMatrix();
|
|
20250
21276
|
|
|
20251
21277
|
this._getAxes();
|
|
@@ -20269,7 +21295,7 @@
|
|
|
20269
21295
|
;
|
|
20270
21296
|
|
|
20271
21297
|
_proto.setRoll = function setRoll(angle) {
|
|
20272
|
-
this.roll = getAngle(angle);
|
|
21298
|
+
this.roll = getAngle$1(angle);
|
|
20273
21299
|
this.computeMatrix();
|
|
20274
21300
|
|
|
20275
21301
|
this._getAxes();
|
|
@@ -25266,7 +26292,8 @@
|
|
|
25266
26292
|
exports.deg2rad = deg2rad;
|
|
25267
26293
|
exports.deg2turn = deg2turn;
|
|
25268
26294
|
exports.findClosestClipPathTarget = findClosestClipPathTarget;
|
|
25269
|
-
exports.
|
|
26295
|
+
exports.fromRotationTranslationScale = fromRotationTranslationScale$1;
|
|
26296
|
+
exports.getAngle = getAngle$1;
|
|
25270
26297
|
exports.getEuler = getEuler;
|
|
25271
26298
|
exports.getOrCalculatePathTotalLength = getOrCalculatePathTotalLength;
|
|
25272
26299
|
exports.grad2deg = grad2deg;
|