poly-extrude 0.20.4 → 0.20.6

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * poly-extrude v0.20.4
2
+ * poly-extrude v0.20.6
3
3
  */
4
4
  (function (global, factory) {
5
5
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
@@ -2443,15 +2443,18 @@
2443
2443
  points.push(points[len2 - 2], points[len2 - 1]);
2444
2444
  }
2445
2445
  };
2446
- const equal = (p1, p2) => {
2447
- return p1[0] === p2[0] && p1[1] === p2[1];
2448
- };
2449
2446
  let i = 0;
2450
- let preleftline, prerightline;
2447
+ let pre, preleftline, prerightline;
2451
2448
  while (i < len) {
2452
2449
  let p0;
2453
2450
  let p1 = line[i], p2 = line[i + 1];
2454
2451
  const current = p1;
2452
+ if (pre && equal(pre, current)) {
2453
+ repeatVertex();
2454
+ i++;
2455
+ continue;
2456
+ }
2457
+ let lastRepeat = false;
2455
2458
  // last vertex
2456
2459
  if (i === len - 1) {
2457
2460
  p1 = line[len - 2];
@@ -2476,18 +2479,29 @@
2476
2479
  }
2477
2480
  }
2478
2481
  }
2482
+ if (equal(p1, p2)) {
2483
+ lastRepeat = true;
2484
+ for (let j = line.indexOf(p1); j >= 0; j--) {
2485
+ const p = line[j];
2486
+ if (!equal(p, current)) {
2487
+ p1 = p;
2488
+ break;
2489
+ }
2490
+ }
2491
+ }
2479
2492
  }
2480
2493
  if (equal(p1, p2)) {
2494
+ console.error('not find next vertex:index:', i, line);
2481
2495
  repeatVertex();
2482
2496
  i++;
2483
2497
  continue;
2484
2498
  }
2485
2499
  let dy = p2[1] - p1[1], dx = p2[0] - p1[0];
2486
- let rAngle = 0;
2500
+ let rangle = 0;
2487
2501
  const rad = Math.atan2(dy, dx);
2488
2502
  const angle = radToDeg(rad);
2489
- if (i === 0 || i === len - 1) {
2490
- rAngle = angle - 90;
2503
+ if (i === 0 || i === len - 1 || lastRepeat) {
2504
+ rangle = angle - 90;
2491
2505
  }
2492
2506
  else {
2493
2507
  // 至少3个顶点才会触发
@@ -2502,6 +2516,7 @@
2502
2516
  }
2503
2517
  }
2504
2518
  if (equal(p0, p2) || equal(p0, p1) || equal(p1, p2)) {
2519
+ console.error('not find pre vertex:index:', i, line);
2505
2520
  repeatVertex();
2506
2521
  i++;
2507
2522
  continue;
@@ -2511,7 +2526,7 @@
2511
2526
  const angle1 = radToDeg(rad1);
2512
2527
  // 平行,回头路
2513
2528
  if (Math.abs(Math.abs(angle1 - angle) - 180) <= 0.0001) {
2514
- rAngle = angle - 90;
2529
+ rangle = angle - 90;
2515
2530
  }
2516
2531
  else {
2517
2532
  TEMPV1.x = p0[0] - p1[0];
@@ -2522,10 +2537,15 @@
2522
2537
  console.error('has repeat vertex,the index:', i);
2523
2538
  }
2524
2539
  const vAngle = getAngle$1(TEMPV1, TEMPV2);
2525
- rAngle = angle - vAngle / 2;
2540
+ if (Math.abs(vAngle) <= 1) {
2541
+ rangle = angle - 90;
2542
+ }
2543
+ else {
2544
+ rangle = angle - vAngle / 2;
2545
+ }
2526
2546
  }
2527
2547
  }
2528
- const rRad = degToRad(rAngle);
2548
+ const rRad = degToRad(rangle);
2529
2549
  const p3 = current;
2530
2550
  const x = Math.cos(rRad) + p3[0], y = Math.sin(rRad) + p3[1];
2531
2551
  const p4 = [x, y];
@@ -2608,10 +2628,14 @@
2608
2628
  }
2609
2629
  preleftline = leftline;
2610
2630
  prerightline = rightline;
2631
+ pre = current;
2611
2632
  i++;
2612
2633
  }
2613
2634
  return { offsetPoints: points, leftPoints, rightPoints, line };
2614
2635
  }
2636
+ function equal(p1, p2) {
2637
+ return p1[0] === p2[0] && p1[1] === p2[1];
2638
+ }
2615
2639
  const getAngle$1 = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {
2616
2640
  const dot = x1 * x2 + y1 * y2;
2617
2641
  const det = x1 * y2 - y1 * x2;