@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.
@@ -452,6 +452,9 @@ function getChildArcsFan(pd) {
452
452
  const TAU = Math.PI * 2;
453
453
  const norm = (t) => ((t % TAU) + TAU) % TAU;
454
454
 
455
+ const ccwDelta = (a0, a1) => (a1 - a0 + TAU) % TAU;
456
+ const cwDelta = (a0, a1) => (a0 - a1 + TAU) % TAU;
457
+
455
458
  // Circular midpoint that travels CCW from a -> b by half the CCW span
456
459
  function midCCW(a, b) {
457
460
  const d = (b - a + TAU) % TAU; // CCW delta in [0, 2π)
@@ -497,20 +500,25 @@ function getChildArcsFan(pd) {
497
500
 
498
501
  for (let i = 0; i < N; i++) {
499
502
  const prev = A[(i - 1 + N) % N];
500
- const cur = A[i];
503
+ const cur = A[i];
501
504
  const next = A[(i + 1) % N];
502
505
 
503
506
  // “fan” wedge around the child: midpoint(prev→cur) .. midpoint(cur→next), CCW
504
507
  const start = midCCW(prev.a, cur.a);
505
- const end = midCCW(cur.a, next.a);
508
+ const end = midCCW(cur.a, next.a);
509
+
510
+ // Choose the **shorter** sweep (0 = CCW, 1 = CW in our math-angle convention)
511
+ const ccw = ccwDelta(start, end);
512
+ const cw = cwDelta(start, end);
513
+ const sweep = ccw <= cw ? 0 : 1;
506
514
 
507
515
  child_arcs.push({
508
516
  parentId: pid,
509
- childId: cur.id,
517
+ childId: cur.id,
510
518
  radius,
511
519
  start,
512
520
  end,
513
- sweep: 0 // CCW (consistent with describeArcSweep and your y-flip)
521
+ sweep
514
522
  });
515
523
  }
516
524
  }