@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.
@@ -473,6 +473,9 @@ function getChildArcsFan(pd) {
473
473
  const TAU = Math.PI * 2;
474
474
  const norm = (t) => ((t % TAU) + TAU) % TAU;
475
475
 
476
+ const ccwDelta = (a0, a1) => (a1 - a0 + TAU) % TAU;
477
+ const cwDelta = (a0, a1) => (a0 - a1 + TAU) % TAU;
478
+
476
479
  // Circular midpoint that travels CCW from a -> b by half the CCW span
477
480
  function midCCW(a, b) {
478
481
  const d = (b - a + TAU) % TAU; // CCW delta in [0, 2π)
@@ -518,20 +521,25 @@ function getChildArcsFan(pd) {
518
521
 
519
522
  for (let i = 0; i < N; i++) {
520
523
  const prev = A[(i - 1 + N) % N];
521
- const cur = A[i];
524
+ const cur = A[i];
522
525
  const next = A[(i + 1) % N];
523
526
 
524
527
  // “fan” wedge around the child: midpoint(prev→cur) .. midpoint(cur→next), CCW
525
528
  const start = midCCW(prev.a, cur.a);
526
- const end = midCCW(cur.a, next.a);
529
+ const end = midCCW(cur.a, next.a);
530
+
531
+ // Choose the **shorter** sweep (0 = CCW, 1 = CW in our math-angle convention)
532
+ const ccw = ccwDelta(start, end);
533
+ const cw = cwDelta(start, end);
534
+ const sweep = ccw <= cw ? 0 : 1;
527
535
 
528
536
  child_arcs.push({
529
537
  parentId: pid,
530
- childId: cur.id,
538
+ childId: cur.id,
531
539
  radius,
532
540
  start,
533
541
  end,
534
- sweep: 0 // CCW (consistent with describeArcSweep and your y-flip)
542
+ sweep
535
543
  });
536
544
  }
537
545
  }