@willcgage/module-schematic 0.64.0 → 0.66.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
@@ -1285,6 +1285,18 @@ function leadInchesForSize(size, library = BUILT_IN_TRACK_PARTS) {
1285
1285
  const t = (size - lo.n) / (hi.n - lo.n);
1286
1286
  return lo.lead + t * (hi.lead - lo.lead);
1287
1287
  }
1288
+ function pastFrogInchesForSize(size, library = BUILT_IN_TRACK_PARTS) {
1289
+ const measured = library.filter((p) => p.kind === "turnout" && p.frogNumber != null).map((p) => ({ n: p.frogNumber, ext: partExtent(p) })).filter((p) => p.ext != null).map((p) => ({ n: p.n, past: p.ext.pastFrog })).sort((a, b) => a.n - b.n);
1290
+ if (!measured.length) return RAIL_GAUGE_INCHES * size;
1291
+ if (measured.length === 1) return measured[0].past;
1292
+ let i;
1293
+ if (size >= measured[measured.length - 1].n) i = measured.length - 2;
1294
+ else i = Math.max(0, measured.findIndex((p) => p.n >= size) - 1);
1295
+ const lo = measured[i];
1296
+ const hi = measured[i + 1];
1297
+ const t = (size - lo.n) / (hi.n - lo.n);
1298
+ return Math.max(0, lo.past + t * (hi.past - lo.past));
1299
+ }
1288
1300
  function parseXtpLibrary(text) {
1289
1301
  const parts = [];
1290
1302
  let cur = null;
@@ -1767,8 +1779,9 @@ function moduleFeatures(doc) {
1767
1779
  ...crossings.flatMap((x) => [x.laneA, x.laneB]),
1768
1780
  ...crossovers.flatMap((x) => [x.fromLane, x.toLane])
1769
1781
  ];
1770
- let upLane = Math.max(...baseLanes, 0);
1771
- let downLane = Math.min(...baseLanes, 0);
1782
+ const LANE_GAP_FROM_OTHERS = 2;
1783
+ let upLane = Math.max(...baseLanes, 0) + (LANE_GAP_FROM_OTHERS - 1);
1784
+ let downLane = Math.min(...baseLanes, 0) - (LANE_GAP_FROM_OTHERS - 1);
1772
1785
  const branchConnectors = doc.endplates.filter(
1773
1786
  (e) => e.id !== "A" && e.id !== "B" && e.at && !!e.trackId && (doc.tracks ?? []).some((t) => t.id === e.trackId)
1774
1787
  ).map((e) => {
@@ -1779,10 +1792,6 @@ function moduleFeatures(doc) {
1779
1792
  const lane = side === "down" ? --downLane : ++upLane;
1780
1793
  const runInches = pathLengthInches(trk.path) || Math.abs(e.at.pos - startPos) || FREEMO_ENDPLATE_WIDTH_MIN_INCHES;
1781
1794
  const toB = e.at.pos >= startPos;
1782
- const fits = (p) => p >= 0 && p <= len;
1783
- const ahead = startPos + runInches;
1784
- const behind = startPos - runInches;
1785
- const endPos = toB && fits(ahead) ? ahead : !toB && fits(behind) ? behind : fits(toB ? behind : ahead) ? toB ? behind : ahead : ahead;
1786
1795
  return {
1787
1796
  id: e.id,
1788
1797
  label: e.label ?? e.id,
@@ -1793,7 +1802,7 @@ function moduleFeatures(doc) {
1793
1802
  fromLane: sw ? trackLane.get(sw.onTrack) ?? 0 : 0,
1794
1803
  side,
1795
1804
  lane,
1796
- endFrac: clampFrac(endPos),
1805
+ endFrac: toB ? 1 : 0,
1797
1806
  lengthInches: runInches
1798
1807
  };
1799
1808
  });
@@ -2181,6 +2190,7 @@ exports.parseXtpLibrary = parseXtpLibrary;
2181
2190
  exports.partExtent = partExtent;
2182
2191
  exports.partExtentForSize = partExtentForSize;
2183
2192
  exports.partOutlineAtFrog = partOutlineAtFrog;
2193
+ exports.pastFrogInchesForSize = pastFrogInchesForSize;
2184
2194
  exports.pathLengthInches = pathLengthInches;
2185
2195
  exports.poseNeedsManual = poseNeedsManual;
2186
2196
  exports.poseOverridesFromDoc = poseOverridesFromDoc;