@willcgage/module-schematic 0.58.0 → 0.59.0

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.cjs CHANGED
@@ -1446,13 +1446,33 @@ function turnoutClosure(size, opts = {}) {
1446
1446
  const frogSlope = 1 / N;
1447
1447
  const k = (lead / N - g) / (lead * lead);
1448
1448
  const switchSlope = Math.max(0, frogSlope - 2 * k * lead);
1449
+ const target = opts.arriveAtInches;
1450
+ let a = Infinity;
1451
+ let b = 0;
1452
+ if (target != null && target > g) {
1453
+ b = Math.max(0.01, opts.easeInches ?? lead);
1454
+ a = (target - g) / frogSlope - b / 2;
1455
+ if (a < 0) {
1456
+ a = 0;
1457
+ b = 2 * (target - g) / frogSlope;
1458
+ }
1459
+ }
1460
+ const span = target != null && target > g ? lead + a + b : Infinity;
1449
1461
  return {
1450
1462
  lead,
1451
1463
  switchSlope,
1452
1464
  frogSlope,
1453
- // Past the frog the route is straight at the frog angle — the closure curve
1454
- // has done its work, so don't keep bending (that's the tangent Option 1).
1455
- offsetAt: (s) => s <= lead ? switchSlope * s + k * s * s : g + frogSlope * (s - lead)
1465
+ span,
1466
+ easeInches: b,
1467
+ offsetAt: (s) => {
1468
+ if (s <= lead) return switchSlope * s + k * s * s;
1469
+ const past = s - lead;
1470
+ if (past <= a) return g + frogSlope * past;
1471
+ if (target == null) return g + frogSlope * past;
1472
+ const u = Math.min(past - a, b);
1473
+ const eased = g + frogSlope * a + frogSlope * u - frogSlope * u * u / (2 * b);
1474
+ return past - a >= b ? target : eased;
1475
+ }
1456
1476
  };
1457
1477
  }
1458
1478
  function divergeSideForHand(kind, stubDir, flipped) {