@willcgage/module-schematic 0.92.1 → 0.94.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.d.cts CHANGED
@@ -459,6 +459,16 @@ interface ModuleSchematicDoc {
459
459
  piece: string;
460
460
  joint: string;
461
461
  };
462
+ /** Where MAIN 2 starts, on a double-track module — the joint the endplate's
463
+ * SECOND track arrives at. Absent = single track.
464
+ *
465
+ * Two starts rather than a list because a document has exactly two mains,
466
+ * `main` and `main2`. This mirrors the thing downstream instead of inventing
467
+ * a generality nothing can read. */
468
+ start2?: {
469
+ piece: string;
470
+ joint: string;
471
+ } | null;
462
472
  } | null;
463
473
  }
464
474
  /** A benchwork-outline vertex, module-local inches. The edge from this vertex
@@ -2612,6 +2622,22 @@ interface PieceSnap {
2612
2622
  * inch.
2613
2623
  */
2614
2624
  declare function snapPiece(moving: TrackPiece, others: TrackPiece[], library?: TrackPart[], withinInches?: number): PieceSnap | null;
2625
+ /**
2626
+ * Cut a run of flex to fit BETWEEN two joints — the piece's near end already
2627
+ * where it belongs, its far end brought onto another open joint.
2628
+ *
2629
+ * ⭐ WITHOUT THIS A CROSSOVER CANNOT BE BUILT BY HAND. A piece snaps by ONE end,
2630
+ * and a flex run's length handle drags along its own axis, so the far end can
2631
+ * never be steered onto the turnout opposite: an owner would have to type an
2632
+ * angle and a length to a hundredth of an inch. Cutting a piece to fit between
2633
+ * two fixed points is exactly what a builder does with flex, and it is the last
2634
+ * thing standing between "two mains" and "two mains joined".
2635
+ *
2636
+ * ⚠️ STRAIGHT RUNS ONLY. A bend is already fixed by its radius; asking an arc to
2637
+ * meet a second point as well over-constrains it, and quietly re-bending an
2638
+ * owner's curve to reach something is not a fit, it is a guess.
2639
+ */
2640
+ declare function fitFlexBetween(piece: TrackPiece, others: TrackPiece[], library?: TrackPart[], withinInches?: number): TrackPiece | null;
2615
2641
  /** A route the walk found: a continuous run of pieces a train can travel. */
2616
2642
  interface GraphRoute {
2617
2643
  id: string;
@@ -2644,6 +2670,11 @@ interface GraphWalk {
2644
2670
  * sentence, so a caller can act on it (and say it ONCE) instead of matching
2645
2671
  * on prose. */
2646
2672
  danglingDiverges: string[];
2673
+ /** Pieces this walk never got to. ⚠️ "Unreached BY THIS WALK" is not the same
2674
+ * as "unreachable": a double-track module's second main is unreached by the
2675
+ * first walk and perfectly well connected. Ids, so a caller running more than
2676
+ * one walk can tell the difference. */
2677
+ unreached: string[];
2647
2678
  }
2648
2679
  /**
2649
2680
  * Walk the graph from an endplate and read the topology off it.
@@ -2686,6 +2717,11 @@ interface GraphDocInput {
2686
2717
  piece: string;
2687
2718
  joint: string;
2688
2719
  };
2720
+ /** Where MAIN 2 begins, on a double-track module. Absent = single track. */
2721
+ start2?: {
2722
+ piece: string;
2723
+ joint: string;
2724
+ } | null;
2689
2725
  /**
2690
2726
  * The rest of the document — module id, endplate identities, the benchwork,
2691
2727
  * industries and signals. Merged UNDERNEATH the derived keys, so the graph
@@ -3029,4 +3065,4 @@ declare function poseOverridesFromDoc(doc: ModuleSchematicDoc): Record<string, {
3029
3065
  heading: number;
3030
3066
  }>;
3031
3067
 
3032
- export { ATLAS_CODE55_N, BUILT_IN_TRACK_PARTS, type BenchworkPoint, type BranchConnector, CLEARANCE_SPACING_INCHES, CODE55_RAIL_HEIGHT_INCHES, DEFAULT_FLEX_PART_ID, type DimensionSource, type DrawCrossing, type DrawCrossover, type DrawIndustry, type DrawSignal, type DrawTrack, type DrawTurnout, ENDPLATE_FASCIA_CLEAR_INCHES, ENDPLATE_LEAD_INCHES, type EditorBranch, type EditorControlPoint, type EditorCpSignal, type EditorCrossing, type EditorIndustry, type EditorState, type EditorTrack, type EditorTurnout, type EndplateBConfig, type EndplateEdge, type EndplateEdgePose, type EndplatePose, type EndplateTrackIssue, type EndplateWidthIssue, FAST_TRACKS_N_ME55, FAST_TRACKS_N_ME55_CROSSOVERS, FLEX_TRACK_PARTS, FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES, FREEMO_ENDPLATE_WIDTH_MIN_INCHES, FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, FREEMO_MAIN_MIN_RADIUS_INCHES, FREEMO_REVERSE_CURVE_STRAIGHT_INCHES, FREEMO_TRACK_SPACING_INCHES, type FlexPiece, type FlexPieceEnd, type FrogCasting, type GeometryType, type GraphAnchor, type GraphConflict, type GraphConnection, type GraphDocInput, type GraphDocResult, type GraphRoute, type GraphTurnout, type GraphWalk, type ImportedPart, type IndustryLabelMode, type IndustrySpot, JOINT_SNAP_INCHES, type LanePinch, MAIN2_TRACK_ID, MAIN_TRACK_ID, type ModuleFeatures, type ModuleFootprint, type ModuleFootprintInput, type ModuleGeometryInput, type ModuleSchematicDoc, type ModuleTrackRow, N_CAR_LENGTH_INCHES, N_SCALE_RATIO, type OccupiedSpan, type OutlineFace, PINCH_EASE_INCHES, type PartAngle, type PartDimension, type PartEnd, type PartExtent, type PartGeometry, type PartJoint, type PartJointRole, type PartSegment, type PieceSnap, type PlacedJoint, RAIL_GAUGE_INCHES, type ResolvedAnchor, type ReturnLoopGeometry, type ReturnLoopShape, type RouteSpan, type SchematicBlock, type SchematicControlPoint, type SchematicCrossing, type SchematicEndplate, type SchematicEndplateTrack, type SchematicIndustry, type SchematicSection, type SchematicSignal, type SchematicTrack, type SchematicTurnout, type SectionAdjacency, type SectionEnd, type SectionEndAssessment, type SectionFootprint, type SectionJointAssessment, type SectionRelativePos, type SignalFacing, type SignalSide, type SpanOverhang, type StoredTrackPart, TIE_HALF_LENGTH_INCHES, TURNOUT_LEAD_INCHES_PER_FROG, type TrackConfig, type TrackGraph, type TrackPart, type TrackPiece, type TrackRole, type TurnoutClosure, type TurnoutKind, type UsableCapacity, WHOLE_MODULE_SECTION_ID, asModuleSchematic, assessSectionEnd, assessSectionJoint, benchworkBand, benchworkOutline, buildCrossover, buildPassingSiding, buildTrackGraph, buildTransition, carCapacity, checkEndplateWidth, clearancePointPastFrogInches, crossoverPinches, deriveEndplatePoses, deriveGraphDoc, divergeSideForHand, docToState, emptyEditorState, endplateCentreOffsetInches, endplateEdgePose, endplateFaceSegments, endplateLead, endplateTrackOffsetInches, endplateWidthInches, flexPartFor, flexParts, flexPieces, flexRunEnd, flexUsage, frogCasting, frogNumberFromName, fromSectionRelative, geometryTurnDegrees, graphToDoc, hasNoFarEndplate, importedPartToTrackPart, inchesToScaleFeet, isLoopDoc, isTransitionTurnout, laneOffsetAt, leadInchesForSize, maxFlexPieceInches, mergeImportedParts, mergeStoredParts, moduleCenterline, moduleFeatures, moduleFootprint, moduleLengthFromSections, moduleSections, nextId, parseXtpLibrary, partExtent, partExtentForSize, partGeometry, partGeometryGap, partOutlineAtFrog, partsPlaceable, pastFrogInchesForSize, pathLengthInches, pieceRoutePaths, placedJoints, poseNeedsManual, poseOverridesFromDoc, remapPos, resizeFlexPiece, resolveGraphAnchor, returnLoop, sampleBenchworkOutline, samplePartSegments, samplePath, scaleFeetToInches, sectionAdjacency, sectionBand, sectionBreaksFromSections, sectionComponents, sectionFootprints, sectionNeighbours, sectionSpans, sectionSpansOrWhole, sectionedCenterline, sectionedEndPose, sliceCenterline, snapPiece, spanOverhang, stateToDoc, storedPartToTrackPart, toSectionRelative, trackMeetsEndplateIssues, trackPart, trackPath, turnoutClosure, turnoutFacing, turnoutOccupiedSpan, turnoutPartForSize, usableCapacity, walkTrackGraph };
3068
+ export { ATLAS_CODE55_N, BUILT_IN_TRACK_PARTS, type BenchworkPoint, type BranchConnector, CLEARANCE_SPACING_INCHES, CODE55_RAIL_HEIGHT_INCHES, DEFAULT_FLEX_PART_ID, type DimensionSource, type DrawCrossing, type DrawCrossover, type DrawIndustry, type DrawSignal, type DrawTrack, type DrawTurnout, ENDPLATE_FASCIA_CLEAR_INCHES, ENDPLATE_LEAD_INCHES, type EditorBranch, type EditorControlPoint, type EditorCpSignal, type EditorCrossing, type EditorIndustry, type EditorState, type EditorTrack, type EditorTurnout, type EndplateBConfig, type EndplateEdge, type EndplateEdgePose, type EndplatePose, type EndplateTrackIssue, type EndplateWidthIssue, FAST_TRACKS_N_ME55, FAST_TRACKS_N_ME55_CROSSOVERS, FLEX_TRACK_PARTS, FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES, FREEMO_ENDPLATE_WIDTH_MIN_INCHES, FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, FREEMO_MAIN_MIN_RADIUS_INCHES, FREEMO_REVERSE_CURVE_STRAIGHT_INCHES, FREEMO_TRACK_SPACING_INCHES, type FlexPiece, type FlexPieceEnd, type FrogCasting, type GeometryType, type GraphAnchor, type GraphConflict, type GraphConnection, type GraphDocInput, type GraphDocResult, type GraphRoute, type GraphTurnout, type GraphWalk, type ImportedPart, type IndustryLabelMode, type IndustrySpot, JOINT_SNAP_INCHES, type LanePinch, MAIN2_TRACK_ID, MAIN_TRACK_ID, type ModuleFeatures, type ModuleFootprint, type ModuleFootprintInput, type ModuleGeometryInput, type ModuleSchematicDoc, type ModuleTrackRow, N_CAR_LENGTH_INCHES, N_SCALE_RATIO, type OccupiedSpan, type OutlineFace, PINCH_EASE_INCHES, type PartAngle, type PartDimension, type PartEnd, type PartExtent, type PartGeometry, type PartJoint, type PartJointRole, type PartSegment, type PieceSnap, type PlacedJoint, RAIL_GAUGE_INCHES, type ResolvedAnchor, type ReturnLoopGeometry, type ReturnLoopShape, type RouteSpan, type SchematicBlock, type SchematicControlPoint, type SchematicCrossing, type SchematicEndplate, type SchematicEndplateTrack, type SchematicIndustry, type SchematicSection, type SchematicSignal, type SchematicTrack, type SchematicTurnout, type SectionAdjacency, type SectionEnd, type SectionEndAssessment, type SectionFootprint, type SectionJointAssessment, type SectionRelativePos, type SignalFacing, type SignalSide, type SpanOverhang, type StoredTrackPart, TIE_HALF_LENGTH_INCHES, TURNOUT_LEAD_INCHES_PER_FROG, type TrackConfig, type TrackGraph, type TrackPart, type TrackPiece, type TrackRole, type TurnoutClosure, type TurnoutKind, type UsableCapacity, WHOLE_MODULE_SECTION_ID, asModuleSchematic, assessSectionEnd, assessSectionJoint, benchworkBand, benchworkOutline, buildCrossover, buildPassingSiding, buildTrackGraph, buildTransition, carCapacity, checkEndplateWidth, clearancePointPastFrogInches, crossoverPinches, deriveEndplatePoses, deriveGraphDoc, divergeSideForHand, docToState, emptyEditorState, endplateCentreOffsetInches, endplateEdgePose, endplateFaceSegments, endplateLead, endplateTrackOffsetInches, endplateWidthInches, fitFlexBetween, flexPartFor, flexParts, flexPieces, flexRunEnd, flexUsage, frogCasting, frogNumberFromName, fromSectionRelative, geometryTurnDegrees, graphToDoc, hasNoFarEndplate, importedPartToTrackPart, inchesToScaleFeet, isLoopDoc, isTransitionTurnout, laneOffsetAt, leadInchesForSize, maxFlexPieceInches, mergeImportedParts, mergeStoredParts, moduleCenterline, moduleFeatures, moduleFootprint, moduleLengthFromSections, moduleSections, nextId, parseXtpLibrary, partExtent, partExtentForSize, partGeometry, partGeometryGap, partOutlineAtFrog, partsPlaceable, pastFrogInchesForSize, pathLengthInches, pieceRoutePaths, placedJoints, poseNeedsManual, poseOverridesFromDoc, remapPos, resizeFlexPiece, resolveGraphAnchor, returnLoop, sampleBenchworkOutline, samplePartSegments, samplePath, scaleFeetToInches, sectionAdjacency, sectionBand, sectionBreaksFromSections, sectionComponents, sectionFootprints, sectionNeighbours, sectionSpans, sectionSpansOrWhole, sectionedCenterline, sectionedEndPose, sliceCenterline, snapPiece, spanOverhang, stateToDoc, storedPartToTrackPart, toSectionRelative, trackMeetsEndplateIssues, trackPart, trackPath, turnoutClosure, turnoutFacing, turnoutOccupiedSpan, turnoutPartForSize, usableCapacity, walkTrackGraph };
package/dist/index.d.ts CHANGED
@@ -459,6 +459,16 @@ interface ModuleSchematicDoc {
459
459
  piece: string;
460
460
  joint: string;
461
461
  };
462
+ /** Where MAIN 2 starts, on a double-track module — the joint the endplate's
463
+ * SECOND track arrives at. Absent = single track.
464
+ *
465
+ * Two starts rather than a list because a document has exactly two mains,
466
+ * `main` and `main2`. This mirrors the thing downstream instead of inventing
467
+ * a generality nothing can read. */
468
+ start2?: {
469
+ piece: string;
470
+ joint: string;
471
+ } | null;
462
472
  } | null;
463
473
  }
464
474
  /** A benchwork-outline vertex, module-local inches. The edge from this vertex
@@ -2612,6 +2622,22 @@ interface PieceSnap {
2612
2622
  * inch.
2613
2623
  */
2614
2624
  declare function snapPiece(moving: TrackPiece, others: TrackPiece[], library?: TrackPart[], withinInches?: number): PieceSnap | null;
2625
+ /**
2626
+ * Cut a run of flex to fit BETWEEN two joints — the piece's near end already
2627
+ * where it belongs, its far end brought onto another open joint.
2628
+ *
2629
+ * ⭐ WITHOUT THIS A CROSSOVER CANNOT BE BUILT BY HAND. A piece snaps by ONE end,
2630
+ * and a flex run's length handle drags along its own axis, so the far end can
2631
+ * never be steered onto the turnout opposite: an owner would have to type an
2632
+ * angle and a length to a hundredth of an inch. Cutting a piece to fit between
2633
+ * two fixed points is exactly what a builder does with flex, and it is the last
2634
+ * thing standing between "two mains" and "two mains joined".
2635
+ *
2636
+ * ⚠️ STRAIGHT RUNS ONLY. A bend is already fixed by its radius; asking an arc to
2637
+ * meet a second point as well over-constrains it, and quietly re-bending an
2638
+ * owner's curve to reach something is not a fit, it is a guess.
2639
+ */
2640
+ declare function fitFlexBetween(piece: TrackPiece, others: TrackPiece[], library?: TrackPart[], withinInches?: number): TrackPiece | null;
2615
2641
  /** A route the walk found: a continuous run of pieces a train can travel. */
2616
2642
  interface GraphRoute {
2617
2643
  id: string;
@@ -2644,6 +2670,11 @@ interface GraphWalk {
2644
2670
  * sentence, so a caller can act on it (and say it ONCE) instead of matching
2645
2671
  * on prose. */
2646
2672
  danglingDiverges: string[];
2673
+ /** Pieces this walk never got to. ⚠️ "Unreached BY THIS WALK" is not the same
2674
+ * as "unreachable": a double-track module's second main is unreached by the
2675
+ * first walk and perfectly well connected. Ids, so a caller running more than
2676
+ * one walk can tell the difference. */
2677
+ unreached: string[];
2647
2678
  }
2648
2679
  /**
2649
2680
  * Walk the graph from an endplate and read the topology off it.
@@ -2686,6 +2717,11 @@ interface GraphDocInput {
2686
2717
  piece: string;
2687
2718
  joint: string;
2688
2719
  };
2720
+ /** Where MAIN 2 begins, on a double-track module. Absent = single track. */
2721
+ start2?: {
2722
+ piece: string;
2723
+ joint: string;
2724
+ } | null;
2689
2725
  /**
2690
2726
  * The rest of the document — module id, endplate identities, the benchwork,
2691
2727
  * industries and signals. Merged UNDERNEATH the derived keys, so the graph
@@ -3029,4 +3065,4 @@ declare function poseOverridesFromDoc(doc: ModuleSchematicDoc): Record<string, {
3029
3065
  heading: number;
3030
3066
  }>;
3031
3067
 
3032
- export { ATLAS_CODE55_N, BUILT_IN_TRACK_PARTS, type BenchworkPoint, type BranchConnector, CLEARANCE_SPACING_INCHES, CODE55_RAIL_HEIGHT_INCHES, DEFAULT_FLEX_PART_ID, type DimensionSource, type DrawCrossing, type DrawCrossover, type DrawIndustry, type DrawSignal, type DrawTrack, type DrawTurnout, ENDPLATE_FASCIA_CLEAR_INCHES, ENDPLATE_LEAD_INCHES, type EditorBranch, type EditorControlPoint, type EditorCpSignal, type EditorCrossing, type EditorIndustry, type EditorState, type EditorTrack, type EditorTurnout, type EndplateBConfig, type EndplateEdge, type EndplateEdgePose, type EndplatePose, type EndplateTrackIssue, type EndplateWidthIssue, FAST_TRACKS_N_ME55, FAST_TRACKS_N_ME55_CROSSOVERS, FLEX_TRACK_PARTS, FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES, FREEMO_ENDPLATE_WIDTH_MIN_INCHES, FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, FREEMO_MAIN_MIN_RADIUS_INCHES, FREEMO_REVERSE_CURVE_STRAIGHT_INCHES, FREEMO_TRACK_SPACING_INCHES, type FlexPiece, type FlexPieceEnd, type FrogCasting, type GeometryType, type GraphAnchor, type GraphConflict, type GraphConnection, type GraphDocInput, type GraphDocResult, type GraphRoute, type GraphTurnout, type GraphWalk, type ImportedPart, type IndustryLabelMode, type IndustrySpot, JOINT_SNAP_INCHES, type LanePinch, MAIN2_TRACK_ID, MAIN_TRACK_ID, type ModuleFeatures, type ModuleFootprint, type ModuleFootprintInput, type ModuleGeometryInput, type ModuleSchematicDoc, type ModuleTrackRow, N_CAR_LENGTH_INCHES, N_SCALE_RATIO, type OccupiedSpan, type OutlineFace, PINCH_EASE_INCHES, type PartAngle, type PartDimension, type PartEnd, type PartExtent, type PartGeometry, type PartJoint, type PartJointRole, type PartSegment, type PieceSnap, type PlacedJoint, RAIL_GAUGE_INCHES, type ResolvedAnchor, type ReturnLoopGeometry, type ReturnLoopShape, type RouteSpan, type SchematicBlock, type SchematicControlPoint, type SchematicCrossing, type SchematicEndplate, type SchematicEndplateTrack, type SchematicIndustry, type SchematicSection, type SchematicSignal, type SchematicTrack, type SchematicTurnout, type SectionAdjacency, type SectionEnd, type SectionEndAssessment, type SectionFootprint, type SectionJointAssessment, type SectionRelativePos, type SignalFacing, type SignalSide, type SpanOverhang, type StoredTrackPart, TIE_HALF_LENGTH_INCHES, TURNOUT_LEAD_INCHES_PER_FROG, type TrackConfig, type TrackGraph, type TrackPart, type TrackPiece, type TrackRole, type TurnoutClosure, type TurnoutKind, type UsableCapacity, WHOLE_MODULE_SECTION_ID, asModuleSchematic, assessSectionEnd, assessSectionJoint, benchworkBand, benchworkOutline, buildCrossover, buildPassingSiding, buildTrackGraph, buildTransition, carCapacity, checkEndplateWidth, clearancePointPastFrogInches, crossoverPinches, deriveEndplatePoses, deriveGraphDoc, divergeSideForHand, docToState, emptyEditorState, endplateCentreOffsetInches, endplateEdgePose, endplateFaceSegments, endplateLead, endplateTrackOffsetInches, endplateWidthInches, flexPartFor, flexParts, flexPieces, flexRunEnd, flexUsage, frogCasting, frogNumberFromName, fromSectionRelative, geometryTurnDegrees, graphToDoc, hasNoFarEndplate, importedPartToTrackPart, inchesToScaleFeet, isLoopDoc, isTransitionTurnout, laneOffsetAt, leadInchesForSize, maxFlexPieceInches, mergeImportedParts, mergeStoredParts, moduleCenterline, moduleFeatures, moduleFootprint, moduleLengthFromSections, moduleSections, nextId, parseXtpLibrary, partExtent, partExtentForSize, partGeometry, partGeometryGap, partOutlineAtFrog, partsPlaceable, pastFrogInchesForSize, pathLengthInches, pieceRoutePaths, placedJoints, poseNeedsManual, poseOverridesFromDoc, remapPos, resizeFlexPiece, resolveGraphAnchor, returnLoop, sampleBenchworkOutline, samplePartSegments, samplePath, scaleFeetToInches, sectionAdjacency, sectionBand, sectionBreaksFromSections, sectionComponents, sectionFootprints, sectionNeighbours, sectionSpans, sectionSpansOrWhole, sectionedCenterline, sectionedEndPose, sliceCenterline, snapPiece, spanOverhang, stateToDoc, storedPartToTrackPart, toSectionRelative, trackMeetsEndplateIssues, trackPart, trackPath, turnoutClosure, turnoutFacing, turnoutOccupiedSpan, turnoutPartForSize, usableCapacity, walkTrackGraph };
3068
+ export { ATLAS_CODE55_N, BUILT_IN_TRACK_PARTS, type BenchworkPoint, type BranchConnector, CLEARANCE_SPACING_INCHES, CODE55_RAIL_HEIGHT_INCHES, DEFAULT_FLEX_PART_ID, type DimensionSource, type DrawCrossing, type DrawCrossover, type DrawIndustry, type DrawSignal, type DrawTrack, type DrawTurnout, ENDPLATE_FASCIA_CLEAR_INCHES, ENDPLATE_LEAD_INCHES, type EditorBranch, type EditorControlPoint, type EditorCpSignal, type EditorCrossing, type EditorIndustry, type EditorState, type EditorTrack, type EditorTurnout, type EndplateBConfig, type EndplateEdge, type EndplateEdgePose, type EndplatePose, type EndplateTrackIssue, type EndplateWidthIssue, FAST_TRACKS_N_ME55, FAST_TRACKS_N_ME55_CROSSOVERS, FLEX_TRACK_PARTS, FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES, FREEMO_ENDPLATE_WIDTH_MIN_INCHES, FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, FREEMO_MAIN_MIN_RADIUS_INCHES, FREEMO_REVERSE_CURVE_STRAIGHT_INCHES, FREEMO_TRACK_SPACING_INCHES, type FlexPiece, type FlexPieceEnd, type FrogCasting, type GeometryType, type GraphAnchor, type GraphConflict, type GraphConnection, type GraphDocInput, type GraphDocResult, type GraphRoute, type GraphTurnout, type GraphWalk, type ImportedPart, type IndustryLabelMode, type IndustrySpot, JOINT_SNAP_INCHES, type LanePinch, MAIN2_TRACK_ID, MAIN_TRACK_ID, type ModuleFeatures, type ModuleFootprint, type ModuleFootprintInput, type ModuleGeometryInput, type ModuleSchematicDoc, type ModuleTrackRow, N_CAR_LENGTH_INCHES, N_SCALE_RATIO, type OccupiedSpan, type OutlineFace, PINCH_EASE_INCHES, type PartAngle, type PartDimension, type PartEnd, type PartExtent, type PartGeometry, type PartJoint, type PartJointRole, type PartSegment, type PieceSnap, type PlacedJoint, RAIL_GAUGE_INCHES, type ResolvedAnchor, type ReturnLoopGeometry, type ReturnLoopShape, type RouteSpan, type SchematicBlock, type SchematicControlPoint, type SchematicCrossing, type SchematicEndplate, type SchematicEndplateTrack, type SchematicIndustry, type SchematicSection, type SchematicSignal, type SchematicTrack, type SchematicTurnout, type SectionAdjacency, type SectionEnd, type SectionEndAssessment, type SectionFootprint, type SectionJointAssessment, type SectionRelativePos, type SignalFacing, type SignalSide, type SpanOverhang, type StoredTrackPart, TIE_HALF_LENGTH_INCHES, TURNOUT_LEAD_INCHES_PER_FROG, type TrackConfig, type TrackGraph, type TrackPart, type TrackPiece, type TrackRole, type TurnoutClosure, type TurnoutKind, type UsableCapacity, WHOLE_MODULE_SECTION_ID, asModuleSchematic, assessSectionEnd, assessSectionJoint, benchworkBand, benchworkOutline, buildCrossover, buildPassingSiding, buildTrackGraph, buildTransition, carCapacity, checkEndplateWidth, clearancePointPastFrogInches, crossoverPinches, deriveEndplatePoses, deriveGraphDoc, divergeSideForHand, docToState, emptyEditorState, endplateCentreOffsetInches, endplateEdgePose, endplateFaceSegments, endplateLead, endplateTrackOffsetInches, endplateWidthInches, fitFlexBetween, flexPartFor, flexParts, flexPieces, flexRunEnd, flexUsage, frogCasting, frogNumberFromName, fromSectionRelative, geometryTurnDegrees, graphToDoc, hasNoFarEndplate, importedPartToTrackPart, inchesToScaleFeet, isLoopDoc, isTransitionTurnout, laneOffsetAt, leadInchesForSize, maxFlexPieceInches, mergeImportedParts, mergeStoredParts, moduleCenterline, moduleFeatures, moduleFootprint, moduleLengthFromSections, moduleSections, nextId, parseXtpLibrary, partExtent, partExtentForSize, partGeometry, partGeometryGap, partOutlineAtFrog, partsPlaceable, pastFrogInchesForSize, pathLengthInches, pieceRoutePaths, placedJoints, poseNeedsManual, poseOverridesFromDoc, remapPos, resizeFlexPiece, resolveGraphAnchor, returnLoop, sampleBenchworkOutline, samplePartSegments, samplePath, scaleFeetToInches, sectionAdjacency, sectionBand, sectionBreaksFromSections, sectionComponents, sectionFootprints, sectionNeighbours, sectionSpans, sectionSpansOrWhole, sectionedCenterline, sectionedEndPose, sliceCenterline, snapPiece, spanOverhang, stateToDoc, storedPartToTrackPart, toSectionRelative, trackMeetsEndplateIssues, trackPart, trackPath, turnoutClosure, turnoutFacing, turnoutOccupiedSpan, turnoutPartForSize, usableCapacity, walkTrackGraph };
package/dist/index.js CHANGED
@@ -2440,7 +2440,35 @@ function snapPiece(moving, others, library = BUILT_IN_TRACK_PARTS, withinInches
2440
2440
  to: best.t.key
2441
2441
  };
2442
2442
  }
2443
+ function fitFlexBetween(piece, others, library = BUILT_IN_TRACK_PARTS, withinInches = 0.5) {
2444
+ const part = library.find((p) => p.id === piece.partId);
2445
+ if (part?.kind !== "flex" || piece.radiusInches) return null;
2446
+ const mine = placedJoints([piece], library);
2447
+ const far = mine.find((j) => j.joint === "b");
2448
+ const near = mine.find((j) => j.joint === "a");
2449
+ if (!far || !near) return null;
2450
+ const graph = buildTrackGraph(others, library);
2451
+ const taken = new Set(graph.connections.flatMap((c) => [c.a, c.b]));
2452
+ let best = null;
2453
+ for (const j of graph.joints) {
2454
+ if (taken.has(j.key)) continue;
2455
+ if (Math.hypot(j.x - near.x, j.y - near.y) <= JOINT_SNAP_INCHES) continue;
2456
+ const d = Math.hypot(j.x - far.x, j.y - far.y);
2457
+ if (d <= withinInches && (!best || d < best.d)) best = { j, d };
2458
+ }
2459
+ if (!best) return null;
2460
+ const dx = best.j.x - piece.x;
2461
+ const dy = best.j.y - piece.y;
2462
+ const len = Math.hypot(dx, dy);
2463
+ if (!(len > 0)) return null;
2464
+ return {
2465
+ ...piece,
2466
+ rotationDeg: norm360(Math.atan2(dy, dx) * 180 / Math.PI),
2467
+ lengthInches: Math.round(len * 1e3) / 1e3
2468
+ };
2469
+ }
2443
2470
  var danglingDivergeWarning = (id) => `the route diverging at ${id} is not connected to anything`;
2471
+ var unreachedWarning = (id) => `${id} is not reachable from the endplate \u2014 nothing connects it`;
2444
2472
  function walkTrackGraph(graph, pieces, startAt, library = BUILT_IN_TRACK_PARTS) {
2445
2473
  const byKey = new Map(graph.joints.map((j) => [j.key, j]));
2446
2474
  const pieceById = new Map(pieces.map((p) => [p.id, p]));
@@ -2578,11 +2606,14 @@ function walkTrackGraph(graph, pieces, startAt, library = BUILT_IN_TRACK_PARTS)
2578
2606
  if (sw && !sw.divergeRoute) sw.divergeRoute = r.id;
2579
2607
  }
2580
2608
  const reached = new Set(routes.flatMap((r) => r.pieces));
2609
+ const unreached = [];
2581
2610
  for (const p of pieces)
2582
- if (!reached.has(p.id) && !graph.unplaceable.some((u) => u.piece === p.id))
2583
- warnings.push(`${p.id} is not reachable from the endplate \u2014 nothing connects it`);
2611
+ if (!reached.has(p.id) && !graph.unplaceable.some((u) => u.piece === p.id)) {
2612
+ warnings.push(unreachedWarning(p.id));
2613
+ unreached.push(p.id);
2614
+ }
2584
2615
  for (const c of graph.conflicts) warnings.push(c.reason);
2585
- return { routes, turnouts, warnings, danglingDiverges };
2616
+ return { routes, turnouts, warnings, danglingDiverges, unreached };
2586
2617
  }
2587
2618
  function resolveGraphAnchor(anchor, walk, pieces, library = BUILT_IN_TRACK_PARTS) {
2588
2619
  const piece = pieces.find((p) => p.id === anchor.piece);
@@ -2611,14 +2642,36 @@ function graphToDoc(pieces, input) {
2611
2642
  const epA = endplates[0];
2612
2643
  const epB = endplates[1];
2613
2644
  const main = walk.routes.find((r) => r.id === "main");
2614
- const lengthInches = round(main.toPos);
2615
- const branches = walk.routes.filter((r) => r.id !== "main" && r.pieces.length);
2645
+ const walk2 = input.start2 ? walkTrackGraph(graph, pieces, input.start2, library) : null;
2646
+ const main2 = walk2?.routes.find((r) => r.id === "main") ?? null;
2647
+ const claimed = new Set(walk.routes.flatMap((r) => r.pieces));
2648
+ if (main2 && main2.pieces.some((p) => claimed.has(p))) {
2649
+ warnings.push(
2650
+ "Main 2 starts on track that Main 1 already runs along \u2014 they are one run, not two"
2651
+ );
2652
+ }
2653
+ const twoMains = !!main2 && !main2.pieces.some((p) => claimed.has(p));
2654
+ const main2Lane = twoMains ? (graph.joints.find((j) => j.key === `${input.start2.piece}.${input.start2.joint}`)?.y ?? 1) >= 0 ? 1 : -1 : 0;
2655
+ const lengthInches = round(Math.max(main.toPos, twoMains ? main2.toPos : 0));
2656
+ const branches = [
2657
+ ...walk.routes.filter((r) => r.id !== "main" && r.pieces.length),
2658
+ ...twoMains ? walk2.routes.filter((r) => r.id !== "main" && r.pieces.length).map((r) => ({ ...r, id: `main2:${r.id}`, bornAt: r.bornAt })) : []
2659
+ ];
2616
2660
  const trackIdOf = /* @__PURE__ */ new Map([["main", MAIN_TRACK_ID]]);
2661
+ if (twoMains) trackIdOf.set("main2:main", MAIN2_TRACK_ID);
2617
2662
  for (const r of branches) trackIdOf.set(r.id, r.pieces[0]);
2618
- const laneOf = (r) => {
2663
+ const emitted = /* @__PURE__ */ new Set();
2664
+ const uniqueBranches = branches.filter((r) => {
2665
+ const id = trackIdOf.get(r.id);
2666
+ if (emitted.has(id)) return false;
2667
+ emitted.add(id);
2668
+ return true;
2669
+ });
2670
+ const laneOf = (r, among) => {
2619
2671
  const side = Math.sign(r.lateral) || 1;
2620
- const sameSide = branches.filter((x) => (Math.sign(x.lateral) || 1) === side).sort((a, b) => Math.abs(a.lateral) - Math.abs(b.lateral));
2621
- return side * (sameSide.indexOf(r) + 1);
2672
+ const sameSide = among.filter((x) => (Math.sign(x.lateral) || 1) === side).sort((a, b) => Math.abs(a.lateral) - Math.abs(b.lateral));
2673
+ const taken = side === main2Lane ? 1 : 0;
2674
+ return side * (sameSide.indexOf(r) + 1 + taken);
2622
2675
  };
2623
2676
  const tracks = [
2624
2677
  {
@@ -2627,9 +2680,22 @@ function graphToDoc(pieces, input) {
2627
2680
  lane: 0,
2628
2681
  from: epA?.id ?? "A",
2629
2682
  ...epB ? { to: epB.id } : {}
2630
- }
2683
+ },
2684
+ ...twoMains ? [
2685
+ {
2686
+ id: MAIN2_TRACK_ID,
2687
+ role: "main",
2688
+ lane: main2Lane,
2689
+ from: epA?.id ?? "A",
2690
+ ...epB ? { to: epB.id } : {},
2691
+ // ⚠️ Its own extent, because a second main need not run the whole
2692
+ // module: on a transition module it starts or stops partway.
2693
+ fromPos: round(Math.min(main2.fromPos, main2.toPos)),
2694
+ toPos: round(Math.max(main2.fromPos, main2.toPos))
2695
+ }
2696
+ ] : []
2631
2697
  ];
2632
- for (const r of branches) {
2698
+ for (const r of uniqueBranches) {
2633
2699
  const id = trackIdOf.get(r.id);
2634
2700
  const meta = input.meta?.[id] ?? {};
2635
2701
  tracks.push({
@@ -2637,7 +2703,7 @@ function graphToDoc(pieces, input) {
2637
2703
  // It runs back into a second turnout, or it doesn't. That is the whole
2638
2704
  // difference between a siding and a spur, and it is read, not declared.
2639
2705
  role: r.endsAt ? "siding" : "spur",
2640
- lane: laneOf(r),
2706
+ lane: laneOf(r, uniqueBranches),
2641
2707
  fromPos: round(Math.min(r.fromPos, r.toPos)),
2642
2708
  toPos: round(Math.max(r.fromPos, r.toPos)),
2643
2709
  ...meta.trackName ? { trackName: meta.trackName } : {},
@@ -2645,9 +2711,29 @@ function graphToDoc(pieces, input) {
2645
2711
  ...meta.moduleTrackId != null ? { moduleTrackId: meta.moduleTrackId } : {}
2646
2712
  });
2647
2713
  }
2714
+ if (walk2) {
2715
+ const seen = /* @__PURE__ */ new Set([
2716
+ ...walk.routes.flatMap((r) => r.pieces),
2717
+ ...walk2.routes.flatMap((r) => r.pieces)
2718
+ ]);
2719
+ const covered = new Set([...walk.unreached, ...walk2.unreached].filter((id) => seen.has(id)));
2720
+ const drop = new Set([...covered].map(unreachedWarning));
2721
+ const d2 = new Set(walk2.danglingDiverges.map(danglingDivergeWarning));
2722
+ for (let i = warnings.length - 1; i >= 0; i--) if (drop.has(warnings[i])) warnings.splice(i, 1);
2723
+ for (const w of walk2.warnings)
2724
+ if (!d2.has(w) && !drop.has(w) && !warnings.includes(w)) warnings.push(w);
2725
+ }
2648
2726
  const pieceById = new Map(pieces.map((p) => [p.id, p]));
2649
2727
  const turnouts = [];
2650
- for (const t of walk.turnouts) {
2728
+ const allTurnouts = [
2729
+ ...walk.turnouts,
2730
+ ...twoMains ? walk2.turnouts.map((t) => ({
2731
+ ...t,
2732
+ onRoute: t.onRoute === "main" ? "main2:main" : `main2:${t.onRoute}`,
2733
+ divergeRoute: t.divergeRoute ? `main2:${t.divergeRoute}` : null
2734
+ })) : []
2735
+ ];
2736
+ for (const t of allTurnouts) {
2651
2737
  const diverge = t.divergeRoute ? trackIdOf.get(t.divergeRoute) : void 0;
2652
2738
  if (!diverge) {
2653
2739
  warnings.push(
@@ -2668,6 +2754,12 @@ function graphToDoc(pieces, input) {
2668
2754
  });
2669
2755
  }
2670
2756
  turnouts.sort((a, b) => a.pos - b.pos);
2757
+ for (const t of tracks) {
2758
+ if (t.role === "main") continue;
2759
+ const ends = turnouts.filter((sw) => sw.divergeTrack === t.id);
2760
+ if (ends.length >= 2 && new Set(ends.map((sw) => sw.onTrack)).size >= 2)
2761
+ t.role = "crossover";
2762
+ }
2671
2763
  const place = (a, what) => {
2672
2764
  if (!a) return null;
2673
2765
  const hit = resolveGraphAnchor(a, walk, pieces, library);
@@ -2729,7 +2821,13 @@ function deriveGraphDoc(doc, library = BUILT_IN_TRACK_PARTS) {
2729
2821
  ...t.moduleTrackId != null ? { moduleTrackId: t.moduleTrackId } : {}
2730
2822
  };
2731
2823
  }
2732
- const out = graphToDoc(g.pieces, { startAt: g.startAt, base: doc, meta, library });
2824
+ const out = graphToDoc(g.pieces, {
2825
+ startAt: g.startAt,
2826
+ start2: g.start2 ?? null,
2827
+ base: doc,
2828
+ meta,
2829
+ library
2830
+ });
2733
2831
  return { doc: out.doc, warnings: out.warnings };
2734
2832
  }
2735
2833
  function frogCasting(cl, opts = {}) {
@@ -3365,6 +3463,6 @@ function poseOverridesFromDoc(doc) {
3365
3463
  return out;
3366
3464
  }
3367
3465
 
3368
- export { ATLAS_CODE55_N, BUILT_IN_TRACK_PARTS, CLEARANCE_SPACING_INCHES, CODE55_RAIL_HEIGHT_INCHES, DEFAULT_FLEX_PART_ID, ENDPLATE_FASCIA_CLEAR_INCHES, ENDPLATE_LEAD_INCHES, FAST_TRACKS_N_ME55, FAST_TRACKS_N_ME55_CROSSOVERS, FLEX_TRACK_PARTS, FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES, FREEMO_ENDPLATE_WIDTH_MIN_INCHES, FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, FREEMO_MAIN_MIN_RADIUS_INCHES, FREEMO_REVERSE_CURVE_STRAIGHT_INCHES, FREEMO_TRACK_SPACING_INCHES, JOINT_SNAP_INCHES, MAIN2_TRACK_ID, MAIN_TRACK_ID, N_CAR_LENGTH_INCHES, N_SCALE_RATIO, PINCH_EASE_INCHES, RAIL_GAUGE_INCHES, TIE_HALF_LENGTH_INCHES, TURNOUT_LEAD_INCHES_PER_FROG, WHOLE_MODULE_SECTION_ID, asModuleSchematic, assessSectionEnd, assessSectionJoint, benchworkBand, benchworkOutline, buildCrossover, buildPassingSiding, buildTrackGraph, buildTransition, carCapacity, checkEndplateWidth, clearancePointPastFrogInches, crossoverPinches, deriveEndplatePoses, deriveGraphDoc, divergeSideForHand, docToState, emptyEditorState, endplateCentreOffsetInches, endplateEdgePose, endplateFaceSegments, endplateLead, endplateTrackOffsetInches, endplateWidthInches, flexPartFor, flexParts, flexPieces, flexRunEnd, flexUsage, frogCasting, frogNumberFromName, fromSectionRelative, geometryTurnDegrees, graphToDoc, hasNoFarEndplate, importedPartToTrackPart, inchesToScaleFeet, isLoopDoc, isTransitionTurnout, laneOffsetAt, leadInchesForSize, maxFlexPieceInches, mergeImportedParts, mergeStoredParts, moduleCenterline, moduleFeatures, moduleFootprint, moduleLengthFromSections, moduleSections, nextId, parseXtpLibrary, partExtent, partExtentForSize, partGeometry, partGeometryGap, partOutlineAtFrog, partsPlaceable, pastFrogInchesForSize, pathLengthInches, pieceRoutePaths, placedJoints, poseNeedsManual, poseOverridesFromDoc, remapPos, resizeFlexPiece, resolveGraphAnchor, returnLoop, sampleBenchworkOutline, samplePartSegments, samplePath, scaleFeetToInches, sectionAdjacency, sectionBand, sectionBreaksFromSections, sectionComponents, sectionFootprints, sectionNeighbours, sectionSpans, sectionSpansOrWhole, sectionedCenterline, sectionedEndPose, sliceCenterline, snapPiece, spanOverhang, stateToDoc, storedPartToTrackPart, toSectionRelative, trackMeetsEndplateIssues, trackPart, trackPath, turnoutClosure, turnoutFacing, turnoutOccupiedSpan, turnoutPartForSize, usableCapacity, walkTrackGraph };
3466
+ export { ATLAS_CODE55_N, BUILT_IN_TRACK_PARTS, CLEARANCE_SPACING_INCHES, CODE55_RAIL_HEIGHT_INCHES, DEFAULT_FLEX_PART_ID, ENDPLATE_FASCIA_CLEAR_INCHES, ENDPLATE_LEAD_INCHES, FAST_TRACKS_N_ME55, FAST_TRACKS_N_ME55_CROSSOVERS, FLEX_TRACK_PARTS, FREEMO_ENDPLATE_TRACK_FASCIA_CLEARANCE_INCHES, FREEMO_ENDPLATE_WIDTH_MIN_INCHES, FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, FREEMO_MAIN_MIN_RADIUS_INCHES, FREEMO_REVERSE_CURVE_STRAIGHT_INCHES, FREEMO_TRACK_SPACING_INCHES, JOINT_SNAP_INCHES, MAIN2_TRACK_ID, MAIN_TRACK_ID, N_CAR_LENGTH_INCHES, N_SCALE_RATIO, PINCH_EASE_INCHES, RAIL_GAUGE_INCHES, TIE_HALF_LENGTH_INCHES, TURNOUT_LEAD_INCHES_PER_FROG, WHOLE_MODULE_SECTION_ID, asModuleSchematic, assessSectionEnd, assessSectionJoint, benchworkBand, benchworkOutline, buildCrossover, buildPassingSiding, buildTrackGraph, buildTransition, carCapacity, checkEndplateWidth, clearancePointPastFrogInches, crossoverPinches, deriveEndplatePoses, deriveGraphDoc, divergeSideForHand, docToState, emptyEditorState, endplateCentreOffsetInches, endplateEdgePose, endplateFaceSegments, endplateLead, endplateTrackOffsetInches, endplateWidthInches, fitFlexBetween, flexPartFor, flexParts, flexPieces, flexRunEnd, flexUsage, frogCasting, frogNumberFromName, fromSectionRelative, geometryTurnDegrees, graphToDoc, hasNoFarEndplate, importedPartToTrackPart, inchesToScaleFeet, isLoopDoc, isTransitionTurnout, laneOffsetAt, leadInchesForSize, maxFlexPieceInches, mergeImportedParts, mergeStoredParts, moduleCenterline, moduleFeatures, moduleFootprint, moduleLengthFromSections, moduleSections, nextId, parseXtpLibrary, partExtent, partExtentForSize, partGeometry, partGeometryGap, partOutlineAtFrog, partsPlaceable, pastFrogInchesForSize, pathLengthInches, pieceRoutePaths, placedJoints, poseNeedsManual, poseOverridesFromDoc, remapPos, resizeFlexPiece, resolveGraphAnchor, returnLoop, sampleBenchworkOutline, samplePartSegments, samplePath, scaleFeetToInches, sectionAdjacency, sectionBand, sectionBreaksFromSections, sectionComponents, sectionFootprints, sectionNeighbours, sectionSpans, sectionSpansOrWhole, sectionedCenterline, sectionedEndPose, sliceCenterline, snapPiece, spanOverhang, stateToDoc, storedPartToTrackPart, toSectionRelative, trackMeetsEndplateIssues, trackPart, trackPath, turnoutClosure, turnoutFacing, turnoutOccupiedSpan, turnoutPartForSize, usableCapacity, walkTrackGraph };
3369
3467
  //# sourceMappingURL=index.js.map
3370
3468
  //# sourceMappingURL=index.js.map