poly-extrude 0.20.4 → 0.20.5

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.5
3
3
  */
4
4
  (function (global, factory) {
5
5
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
@@ -2443,15 +2443,17 @@
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
+ }
2455
2457
  // last vertex
2456
2458
  if (i === len - 1) {
2457
2459
  p1 = line[len - 2];
@@ -2478,16 +2480,17 @@
2478
2480
  }
2479
2481
  }
2480
2482
  if (equal(p1, p2)) {
2483
+ console.error('not find next vertex:index:', i, line);
2481
2484
  repeatVertex();
2482
2485
  i++;
2483
2486
  continue;
2484
2487
  }
2485
2488
  let dy = p2[1] - p1[1], dx = p2[0] - p1[0];
2486
- let rAngle = 0;
2489
+ let rangle = 0;
2487
2490
  const rad = Math.atan2(dy, dx);
2488
2491
  const angle = radToDeg(rad);
2489
2492
  if (i === 0 || i === len - 1) {
2490
- rAngle = angle - 90;
2493
+ rangle = angle - 90;
2491
2494
  }
2492
2495
  else {
2493
2496
  // 至少3个顶点才会触发
@@ -2502,6 +2505,7 @@
2502
2505
  }
2503
2506
  }
2504
2507
  if (equal(p0, p2) || equal(p0, p1) || equal(p1, p2)) {
2508
+ console.error('not find pre vertex:index:', i, line);
2505
2509
  repeatVertex();
2506
2510
  i++;
2507
2511
  continue;
@@ -2511,7 +2515,7 @@
2511
2515
  const angle1 = radToDeg(rad1);
2512
2516
  // 平行,回头路
2513
2517
  if (Math.abs(Math.abs(angle1 - angle) - 180) <= 0.0001) {
2514
- rAngle = angle - 90;
2518
+ rangle = angle - 90;
2515
2519
  }
2516
2520
  else {
2517
2521
  TEMPV1.x = p0[0] - p1[0];
@@ -2522,10 +2526,15 @@
2522
2526
  console.error('has repeat vertex,the index:', i);
2523
2527
  }
2524
2528
  const vAngle = getAngle$1(TEMPV1, TEMPV2);
2525
- rAngle = angle - vAngle / 2;
2529
+ if (Math.abs(vAngle) <= 1) {
2530
+ rangle = angle - 90;
2531
+ }
2532
+ else {
2533
+ rangle = angle - vAngle / 2;
2534
+ }
2526
2535
  }
2527
2536
  }
2528
- const rRad = degToRad(rAngle);
2537
+ const rRad = degToRad(rangle);
2529
2538
  const p3 = current;
2530
2539
  const x = Math.cos(rRad) + p3[0], y = Math.sin(rRad) + p3[1];
2531
2540
  const p4 = [x, y];
@@ -2608,10 +2617,14 @@
2608
2617
  }
2609
2618
  preleftline = leftline;
2610
2619
  prerightline = rightline;
2620
+ pre = current;
2611
2621
  i++;
2612
2622
  }
2613
2623
  return { offsetPoints: points, leftPoints, rightPoints, line };
2614
2624
  }
2625
+ function equal(p1, p2) {
2626
+ return p1[0] === p2[0] && p1[1] === p2[1];
2627
+ }
2615
2628
  const getAngle$1 = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {
2616
2629
  const dot = x1 * x2 + y1 * y2;
2617
2630
  const det = x1 * y2 - y1 * x2;