@euphrasiologist/lwphylo 1.2.19 → 1.2.20

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.js CHANGED
@@ -565,6 +565,9 @@ function getChildArcsFan(pd) {
565
565
  const TAU = Math.PI * 2;
566
566
  const norm = (t) => ((t % TAU) + TAU) % TAU;
567
567
 
568
+ const ccwDelta = (a0, a1) => (a1 - a0 + TAU) % TAU;
569
+ const cwDelta = (a0, a1) => (a0 - a1 + TAU) % TAU;
570
+
568
571
  // Circular midpoint that travels CCW from a -> b by half the CCW span
569
572
  function midCCW(a, b) {
570
573
  const d = (b - a + TAU) % TAU; // CCW delta in [0, 2π)
@@ -610,20 +613,25 @@ function getChildArcsFan(pd) {
610
613
 
611
614
  for (let i = 0; i < N; i++) {
612
615
  const prev = A[(i - 1 + N) % N];
613
- const cur = A[i];
616
+ const cur = A[i];
614
617
  const next = A[(i + 1) % N];
615
618
 
616
619
  // “fan” wedge around the child: midpoint(prev→cur) .. midpoint(cur→next), CCW
617
620
  const start = midCCW(prev.a, cur.a);
618
- const end = midCCW(cur.a, next.a);
621
+ const end = midCCW(cur.a, next.a);
622
+
623
+ // Choose the **shorter** sweep (0 = CCW, 1 = CW in our math-angle convention)
624
+ const ccw = ccwDelta(start, end);
625
+ const cw = cwDelta(start, end);
626
+ const sweep = ccw <= cw ? 0 : 1;
619
627
 
620
628
  child_arcs.push({
621
629
  parentId: pid,
622
- childId: cur.id,
630
+ childId: cur.id,
623
631
  radius,
624
632
  start,
625
633
  end,
626
- sweep: 0 // CCW (consistent with describeArcSweep and your y-flip)
634
+ sweep
627
635
  });
628
636
  }
629
637
  }