@willcgage/module-schematic 0.35.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 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;
@@ -1393,6 +1423,7 @@ exports.MAIN2_TRACK_ID = MAIN2_TRACK_ID;
1393
1423
  exports.MAIN_TRACK_ID = MAIN_TRACK_ID;
1394
1424
  exports.N_CAR_LENGTH_INCHES = N_CAR_LENGTH_INCHES;
1395
1425
  exports.N_SCALE_RATIO = N_SCALE_RATIO;
1426
+ exports.WHOLE_MODULE_SECTION_ID = WHOLE_MODULE_SECTION_ID;
1396
1427
  exports.asModuleSchematic = asModuleSchematic;
1397
1428
  exports.benchworkBand = benchworkBand;
1398
1429
  exports.benchworkOutline = benchworkOutline;
@@ -1409,6 +1440,7 @@ exports.endplateFaceSegments = endplateFaceSegments;
1409
1440
  exports.endplateTrackOffsetFor = endplateTrackOffsetFor;
1410
1441
  exports.endplateTrackOffsetInches = endplateTrackOffsetInches;
1411
1442
  exports.endplateWidthInches = endplateWidthInches;
1443
+ exports.fromSectionRelative = fromSectionRelative;
1412
1444
  exports.geometryTurnDegrees = geometryTurnDegrees;
1413
1445
  exports.inchesToScaleFeet = inchesToScaleFeet;
1414
1446
  exports.isLoopDoc = isLoopDoc;
@@ -1421,6 +1453,7 @@ exports.moduleSections = moduleSections;
1421
1453
  exports.nextId = nextId;
1422
1454
  exports.poseNeedsManual = poseNeedsManual;
1423
1455
  exports.poseOverridesFromDoc = poseOverridesFromDoc;
1456
+ exports.remapPos = remapPos;
1424
1457
  exports.sampleBenchworkOutline = sampleBenchworkOutline;
1425
1458
  exports.samplePath = samplePath;
1426
1459
  exports.scaleFeetToInches = scaleFeetToInches;
@@ -1431,10 +1464,12 @@ exports.sectionComponents = sectionComponents;
1431
1464
  exports.sectionFootprints = sectionFootprints;
1432
1465
  exports.sectionNeighbours = sectionNeighbours;
1433
1466
  exports.sectionSpans = sectionSpans;
1467
+ exports.sectionSpansOrWhole = sectionSpansOrWhole;
1434
1468
  exports.sectionedCenterline = sectionedCenterline;
1435
1469
  exports.sectionedEndPose = sectionedEndPose;
1436
1470
  exports.sliceCenterline = sliceCenterline;
1437
1471
  exports.stateToDoc = stateToDoc;
1472
+ exports.toSectionRelative = toSectionRelative;
1438
1473
  exports.trackPath = trackPath;
1439
1474
  //# sourceMappingURL=index.cjs.map
1440
1475
  //# sourceMappingURL=index.cjs.map