poly-extrude 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/poly-extrude.js +65 -7
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -2
- package/dist/poly-extrude.mjs +65 -7
- package/dist/poly-extrude.mjs.map +1 -1
- package/dist/polyline.d.ts +8 -0
- package/dist/polyline.js +65 -7
- package/dist/polyline.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +1 -0
- package/src/polyline.ts +70 -8
package/dist/poly-extrude.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* poly-extrude v0.
|
2
|
+
* poly-extrude v0.19.0
|
3
3
|
*/
|
4
4
|
(function (global, factory) {
|
5
5
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
@@ -2419,38 +2419,90 @@
|
|
2419
2419
|
}
|
2420
2420
|
const TEMPV1 = { x: 0, y: 0 }, TEMPV2 = { x: 0, y: 0 };
|
2421
2421
|
function expandLine(line, options) {
|
2422
|
-
// let preAngle = 0;
|
2423
2422
|
let radius = options.lineWidth / 2;
|
2424
2423
|
if (options.isSlope) {
|
2425
2424
|
radius *= 2;
|
2426
2425
|
}
|
2427
2426
|
const points = [], leftPoints = [], rightPoints = [];
|
2428
2427
|
const len = line.length;
|
2428
|
+
const repeatVertex = () => {
|
2429
|
+
const len1 = leftPoints.length;
|
2430
|
+
if (len1) {
|
2431
|
+
leftPoints.push(leftPoints[len1 - 1]);
|
2432
|
+
rightPoints.push(rightPoints[len1 - 1]);
|
2433
|
+
const len2 = points.length;
|
2434
|
+
points.push(points[len2 - 2], points[len2 - 1]);
|
2435
|
+
}
|
2436
|
+
};
|
2437
|
+
const equal = (p1, p2) => {
|
2438
|
+
return p1[0] === p2[0] && p1[1] === p2[1];
|
2439
|
+
};
|
2429
2440
|
let i = 0;
|
2430
2441
|
while (i < len) {
|
2431
2442
|
let p1 = line[i], p2 = line[i + 1];
|
2432
|
-
const currentp =
|
2443
|
+
const currentp = p1;
|
2433
2444
|
// last vertex
|
2434
2445
|
if (i === len - 1) {
|
2435
2446
|
p1 = line[len - 2];
|
2436
2447
|
p2 = line[len - 1];
|
2448
|
+
if (equal(p1, p2)) {
|
2449
|
+
for (let j = line.indexOf(p1); j >= 0; j--) {
|
2450
|
+
const p = line[j];
|
2451
|
+
if (!equal(p, currentp)) {
|
2452
|
+
p1 = p;
|
2453
|
+
break;
|
2454
|
+
}
|
2455
|
+
}
|
2456
|
+
}
|
2437
2457
|
}
|
2438
|
-
|
2458
|
+
else {
|
2459
|
+
if (equal(p1, p2)) {
|
2460
|
+
for (let j = line.indexOf(p2); j < len; j++) {
|
2461
|
+
const p = line[j];
|
2462
|
+
if (!equal(p, currentp)) {
|
2463
|
+
p2 = p;
|
2464
|
+
break;
|
2465
|
+
}
|
2466
|
+
}
|
2467
|
+
}
|
2468
|
+
}
|
2469
|
+
if (equal(p1, p2)) {
|
2470
|
+
repeatVertex();
|
2471
|
+
i++;
|
2472
|
+
continue;
|
2473
|
+
}
|
2474
|
+
let dy = p2[1] - p1[1], dx = p2[0] - p1[0];
|
2439
2475
|
let rAngle = 0;
|
2440
|
-
const rad = Math.
|
2476
|
+
const rad = Math.atan2(dy, dx);
|
2441
2477
|
const angle = radToDeg(rad);
|
2442
|
-
// preAngle = angle;
|
2443
2478
|
if (i === 0 || i === len - 1) {
|
2444
2479
|
rAngle = angle;
|
2445
2480
|
rAngle -= 90;
|
2446
2481
|
}
|
2447
2482
|
else {
|
2448
2483
|
// 至少3个顶点才会触发
|
2449
|
-
|
2484
|
+
let p0 = line[i - 1];
|
2485
|
+
if (equal(p0, p2) || equal(p0, p1)) {
|
2486
|
+
for (let j = line.indexOf(p2); j >= 0; j--) {
|
2487
|
+
const p = line[j];
|
2488
|
+
if (!equal(p, p2) && (!equal(p, p1))) {
|
2489
|
+
p0 = p;
|
2490
|
+
break;
|
2491
|
+
}
|
2492
|
+
}
|
2493
|
+
}
|
2494
|
+
if (equal(p0, p2) || equal(p0, p1) || equal(p1, p2)) {
|
2495
|
+
repeatVertex();
|
2496
|
+
i++;
|
2497
|
+
continue;
|
2498
|
+
}
|
2450
2499
|
TEMPV1.x = p0[0] - p1[0];
|
2451
2500
|
TEMPV1.y = p0[1] - p1[1];
|
2452
2501
|
TEMPV2.x = p2[0] - p1[0];
|
2453
2502
|
TEMPV2.y = p2[1] - p1[1];
|
2503
|
+
if ((TEMPV1.x === 0 && TEMPV1.y === 0) || (TEMPV2.x === 0 && TEMPV2.y === 0)) {
|
2504
|
+
console.error('has repeat vertex,the index:', i);
|
2505
|
+
}
|
2454
2506
|
const vAngle = getAngle$1(TEMPV1, TEMPV2);
|
2455
2507
|
rAngle = angle - vAngle / 2;
|
2456
2508
|
}
|
@@ -2467,6 +2519,7 @@
|
|
2467
2519
|
const point1 = points[len1 - 2];
|
2468
2520
|
const point2 = points[len1 - 1];
|
2469
2521
|
if (!point1 || !point2) {
|
2522
|
+
i++;
|
2470
2523
|
continue;
|
2471
2524
|
}
|
2472
2525
|
op1 = [point1[0], point1[1]];
|
@@ -2509,6 +2562,9 @@
|
|
2509
2562
|
*/
|
2510
2563
|
function translateLine(p1, p2, distance) {
|
2511
2564
|
const dy = p2[1] - p1[1], dx = p2[0] - p1[0];
|
2565
|
+
if (dy === 0 && dx === 0) {
|
2566
|
+
return null;
|
2567
|
+
}
|
2512
2568
|
const rad = Math.atan2(dy, dx);
|
2513
2569
|
const rad1 = rad + Math.PI / 2;
|
2514
2570
|
let offsetX = Math.cos(rad1) * distance, offsetY = Math.sin(rad1) * distance;
|
@@ -2532,9 +2588,11 @@
|
|
2532
2588
|
function lineIntersection(p1, p2, p3, p4) {
|
2533
2589
|
const dx1 = p2[0] - p1[0], dy1 = p2[1] - p1[1];
|
2534
2590
|
const dx2 = p4[0] - p3[0], dy2 = p4[1] - p3[1];
|
2591
|
+
//vertical
|
2535
2592
|
if (dx1 === 0 && dx2 === 0) {
|
2536
2593
|
return null;
|
2537
2594
|
}
|
2595
|
+
//horizontal
|
2538
2596
|
if (dy1 === 0 && dy2 === 0) {
|
2539
2597
|
return null;
|
2540
2598
|
}
|