@willcgage/module-schematic 0.49.6 → 0.50.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
@@ -1090,6 +1090,24 @@ function buildCrossover(state) {
1090
1090
  ];
1091
1091
  return { track, turnouts };
1092
1092
  }
1093
+ var RAIL_GAUGE_INCHES = 0.354;
1094
+ var TURNOUT_LEAD_INCHES_PER_FROG = 0.482;
1095
+ function turnoutClosure(size, opts = {}) {
1096
+ const N = size > 0 ? size : 6;
1097
+ const g = opts.gaugeInches ?? RAIL_GAUGE_INCHES;
1098
+ const lead = Math.max(0.01, opts.leadInches ?? N * TURNOUT_LEAD_INCHES_PER_FROG);
1099
+ const frogSlope = 1 / N;
1100
+ const k = (lead / N - g) / (lead * lead);
1101
+ const switchSlope = Math.max(0, frogSlope - 2 * k * lead);
1102
+ return {
1103
+ lead,
1104
+ switchSlope,
1105
+ frogSlope,
1106
+ // Past the frog the route is straight at the frog angle — the closure curve
1107
+ // has done its work, so don't keep bending (that's the tangent Option 1).
1108
+ offsetAt: (s) => s <= lead ? switchSlope * s + k * s * s : g + frogSlope * (s - lead)
1109
+ };
1110
+ }
1093
1111
  function divergeSideForHand(kind, stubDir, flipped) {
1094
1112
  if (kind !== "left" && kind !== "right") return 0;
1095
1113
  const s = (stubDir >= 0 ? 1 : -1) * (flipped ? -1 : 1);
@@ -1613,6 +1631,8 @@ exports.MAIN2_TRACK_ID = MAIN2_TRACK_ID;
1613
1631
  exports.MAIN_TRACK_ID = MAIN_TRACK_ID;
1614
1632
  exports.N_CAR_LENGTH_INCHES = N_CAR_LENGTH_INCHES;
1615
1633
  exports.N_SCALE_RATIO = N_SCALE_RATIO;
1634
+ exports.RAIL_GAUGE_INCHES = RAIL_GAUGE_INCHES;
1635
+ exports.TURNOUT_LEAD_INCHES_PER_FROG = TURNOUT_LEAD_INCHES_PER_FROG;
1616
1636
  exports.WHOLE_MODULE_SECTION_ID = WHOLE_MODULE_SECTION_ID;
1617
1637
  exports.asModuleSchematic = asModuleSchematic;
1618
1638
  exports.benchworkBand = benchworkBand;
@@ -1664,5 +1684,6 @@ exports.stateToDoc = stateToDoc;
1664
1684
  exports.toSectionRelative = toSectionRelative;
1665
1685
  exports.trackMeetsEndplateIssues = trackMeetsEndplateIssues;
1666
1686
  exports.trackPath = trackPath;
1687
+ exports.turnoutClosure = turnoutClosure;
1667
1688
  //# sourceMappingURL=index.cjs.map
1668
1689
  //# sourceMappingURL=index.cjs.map