@willcgage/module-schematic 0.34.0 → 0.36.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 +41 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -2
- package/dist/index.d.ts +76 -2
- package/dist/index.js +37 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -207,6 +207,35 @@ function sectionSpans(doc) {
|
|
|
207
207
|
}
|
|
208
208
|
return out;
|
|
209
209
|
}
|
|
210
|
+
function sectionSpansOrWhole(doc, lengthInches) {
|
|
211
|
+
const L = lengthInches > 0 ? lengthInches : 0;
|
|
212
|
+
const spans = sectionSpans(doc);
|
|
213
|
+
if (!spans.length) return [{ id: WHOLE_MODULE_SECTION_ID, fromPos: 0, toPos: L }];
|
|
214
|
+
const out = spans.map((sp) => ({ ...sp }));
|
|
215
|
+
const last = out[out.length - 1];
|
|
216
|
+
if (L > last.toPos) last.toPos = L;
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
var WHOLE_MODULE_SECTION_ID = "module";
|
|
220
|
+
function toSectionRelative(pos, spans) {
|
|
221
|
+
if (!spans.length) return null;
|
|
222
|
+
const p = Math.max(spans[0].fromPos, Math.min(spans[spans.length - 1].toPos, pos));
|
|
223
|
+
for (const sp of spans) {
|
|
224
|
+
if (p >= sp.fromPos && p < sp.toPos)
|
|
225
|
+
return { sectionId: sp.id, offsetInches: round3(p - sp.fromPos) };
|
|
226
|
+
}
|
|
227
|
+
const last = spans[spans.length - 1];
|
|
228
|
+
return { sectionId: last.id, offsetInches: round3(last.toPos - last.fromPos) };
|
|
229
|
+
}
|
|
230
|
+
function fromSectionRelative(rel, spans) {
|
|
231
|
+
const sp = spans.find((x) => x.id === rel.sectionId);
|
|
232
|
+
if (!sp) return null;
|
|
233
|
+
return round3(sp.fromPos + Math.max(0, Math.min(sp.toPos - sp.fromPos, rel.offsetInches)));
|
|
234
|
+
}
|
|
235
|
+
function remapPos(pos, before, after) {
|
|
236
|
+
const rel = toSectionRelative(pos, before);
|
|
237
|
+
return rel ? fromSectionRelative(rel, after) : null;
|
|
238
|
+
}
|
|
210
239
|
function sectionBreaksFromSections(doc) {
|
|
211
240
|
const spans = sectionSpans(doc);
|
|
212
241
|
return spans.slice(0, -1).map((sp) => sp.toPos);
|
|
@@ -483,6 +512,7 @@ function checkEndplateWidth(input) {
|
|
|
483
512
|
return issues;
|
|
484
513
|
}
|
|
485
514
|
var round2 = (n) => Math.round(n * 100) / 100;
|
|
515
|
+
var round3 = (n) => Math.round(n * 1e3) / 1e3;
|
|
486
516
|
function endplateWidthFor(widths, id) {
|
|
487
517
|
const w = widths?.[id];
|
|
488
518
|
return typeof w === "number" && w > 0 ? w : FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES;
|
|
@@ -716,7 +746,8 @@ function stateToDoc(state, recordNumber) {
|
|
|
716
746
|
kind: t.kind,
|
|
717
747
|
name: t.name || void 0,
|
|
718
748
|
...t.size ? { size: t.size } : {},
|
|
719
|
-
...t.curved ? { curved: true } : {}
|
|
749
|
+
...t.curved ? { curved: true } : {},
|
|
750
|
+
...t.flipped ? { flipped: true } : {}
|
|
720
751
|
})),
|
|
721
752
|
...state.crossings.length > 0 ? {
|
|
722
753
|
crossings: state.crossings.map((x) => ({
|
|
@@ -887,7 +918,8 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
|
|
|
887
918
|
divergeTrack: t.divergeTrack,
|
|
888
919
|
kind: t.kind ?? "right",
|
|
889
920
|
...t.size ? { size: t.size } : {},
|
|
890
|
-
...t.curved ? { curved: true } : {}
|
|
921
|
+
...t.curved ? { curved: true } : {},
|
|
922
|
+
...t.flipped ? { flipped: true } : {}
|
|
891
923
|
})),
|
|
892
924
|
controlPoints: readControlPoints(d, sc),
|
|
893
925
|
industries: (d.industries ?? []).map((ind) => ({
|
|
@@ -1020,9 +1052,9 @@ function buildCrossover(state) {
|
|
|
1020
1052
|
];
|
|
1021
1053
|
return { track, turnouts };
|
|
1022
1054
|
}
|
|
1023
|
-
function divergeSideForHand(kind, stubDir) {
|
|
1055
|
+
function divergeSideForHand(kind, stubDir, flipped) {
|
|
1024
1056
|
if (kind !== "left" && kind !== "right") return 0;
|
|
1025
|
-
const s = stubDir >= 0 ? 1 : -1;
|
|
1057
|
+
const s = (stubDir >= 0 ? 1 : -1) * (flipped ? -1 : 1);
|
|
1026
1058
|
return kind === "left" ? s : -s;
|
|
1027
1059
|
}
|
|
1028
1060
|
function moduleFeatures(doc) {
|
|
@@ -1391,6 +1423,7 @@ exports.MAIN2_TRACK_ID = MAIN2_TRACK_ID;
|
|
|
1391
1423
|
exports.MAIN_TRACK_ID = MAIN_TRACK_ID;
|
|
1392
1424
|
exports.N_CAR_LENGTH_INCHES = N_CAR_LENGTH_INCHES;
|
|
1393
1425
|
exports.N_SCALE_RATIO = N_SCALE_RATIO;
|
|
1426
|
+
exports.WHOLE_MODULE_SECTION_ID = WHOLE_MODULE_SECTION_ID;
|
|
1394
1427
|
exports.asModuleSchematic = asModuleSchematic;
|
|
1395
1428
|
exports.benchworkBand = benchworkBand;
|
|
1396
1429
|
exports.benchworkOutline = benchworkOutline;
|
|
@@ -1407,6 +1440,7 @@ exports.endplateFaceSegments = endplateFaceSegments;
|
|
|
1407
1440
|
exports.endplateTrackOffsetFor = endplateTrackOffsetFor;
|
|
1408
1441
|
exports.endplateTrackOffsetInches = endplateTrackOffsetInches;
|
|
1409
1442
|
exports.endplateWidthInches = endplateWidthInches;
|
|
1443
|
+
exports.fromSectionRelative = fromSectionRelative;
|
|
1410
1444
|
exports.geometryTurnDegrees = geometryTurnDegrees;
|
|
1411
1445
|
exports.inchesToScaleFeet = inchesToScaleFeet;
|
|
1412
1446
|
exports.isLoopDoc = isLoopDoc;
|
|
@@ -1419,6 +1453,7 @@ exports.moduleSections = moduleSections;
|
|
|
1419
1453
|
exports.nextId = nextId;
|
|
1420
1454
|
exports.poseNeedsManual = poseNeedsManual;
|
|
1421
1455
|
exports.poseOverridesFromDoc = poseOverridesFromDoc;
|
|
1456
|
+
exports.remapPos = remapPos;
|
|
1422
1457
|
exports.sampleBenchworkOutline = sampleBenchworkOutline;
|
|
1423
1458
|
exports.samplePath = samplePath;
|
|
1424
1459
|
exports.scaleFeetToInches = scaleFeetToInches;
|
|
@@ -1429,10 +1464,12 @@ exports.sectionComponents = sectionComponents;
|
|
|
1429
1464
|
exports.sectionFootprints = sectionFootprints;
|
|
1430
1465
|
exports.sectionNeighbours = sectionNeighbours;
|
|
1431
1466
|
exports.sectionSpans = sectionSpans;
|
|
1467
|
+
exports.sectionSpansOrWhole = sectionSpansOrWhole;
|
|
1432
1468
|
exports.sectionedCenterline = sectionedCenterline;
|
|
1433
1469
|
exports.sectionedEndPose = sectionedEndPose;
|
|
1434
1470
|
exports.sliceCenterline = sliceCenterline;
|
|
1435
1471
|
exports.stateToDoc = stateToDoc;
|
|
1472
|
+
exports.toSectionRelative = toSectionRelative;
|
|
1436
1473
|
exports.trackPath = trackPath;
|
|
1437
1474
|
//# sourceMappingURL=index.cjs.map
|
|
1438
1475
|
//# sourceMappingURL=index.cjs.map
|