@willcgage/module-schematic 0.101.0 → 0.103.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 +49 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3214,7 +3214,25 @@ function docToGraph(doc, answers = {}, library = BUILT_IN_TRACK_PARTS) {
|
|
|
3214
3214
|
);
|
|
3215
3215
|
return out;
|
|
3216
3216
|
};
|
|
3217
|
-
const turnoutsOn = (trackId, hostY) =>
|
|
3217
|
+
const turnoutsOn = (trackId, hostY) => {
|
|
3218
|
+
const laid = turnouts.filter((t) => t.onTrack === trackId && chosen.has(t.id)).map((t) => layTurnout(t, hostY)).sort((a, b) => a.span.fromPos - b.span.fromPos);
|
|
3219
|
+
const clashed = /* @__PURE__ */ new Set();
|
|
3220
|
+
for (let i = 1; i < laid.length; i += 1) {
|
|
3221
|
+
const prev = laid[i - 1];
|
|
3222
|
+
const cur = laid[i];
|
|
3223
|
+
if (cur.span.fromPos < prev.span.toPos - 1e-6) {
|
|
3224
|
+
clashed.add(prev.t.id);
|
|
3225
|
+
clashed.add(cur.t.id);
|
|
3226
|
+
const gap = Math.abs(cur.t.pos - prev.t.pos);
|
|
3227
|
+
const body = prev.span.toPos - prev.span.fromPos;
|
|
3228
|
+
notLaid.push({
|
|
3229
|
+
id: cur.t.divergeTrack,
|
|
3230
|
+
why: `${prev.t.name || prev.t.id} and ${cur.t.name || cur.t.id} are ${gap.toFixed(1)}\u2033 apart on the same track, but the turnout chosen is ${body.toFixed(1)}\u2033 long \u2014 their mouldings would overlap, which is why this is sold as one assembly rather than two turnouts`
|
|
3231
|
+
});
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
return laid.filter((l) => !clashed.has(l.t.id));
|
|
3235
|
+
};
|
|
3218
3236
|
const main = trackById.get(MAIN_TRACK_ID) ?? tracks.find((t) => t.role === "main");
|
|
3219
3237
|
if (!main) return refuse("this module's document has no mainline to convert");
|
|
3220
3238
|
const mains = [main, ...tracks.filter((t) => t.role === "main" && t.id !== main.id)];
|
|
@@ -3246,6 +3264,35 @@ function docToGraph(doc, answers = {}, library = BUILT_IN_TRACK_PARTS) {
|
|
|
3246
3264
|
notLaid.push({ id: branch.id, why: `turnout ${t.id} has no diverging end to leave from` });
|
|
3247
3265
|
continue;
|
|
3248
3266
|
}
|
|
3267
|
+
const farSw0 = turnouts.find(
|
|
3268
|
+
(o) => o.id !== t.id && o.divergeTrack === branch.id && laidTurnouts.has(o.id)
|
|
3269
|
+
);
|
|
3270
|
+
const farJoint0 = farSw0 ? (() => {
|
|
3271
|
+
const f = laidTurnouts.get(farSw0.id);
|
|
3272
|
+
return jointAt(f.piece, f.divergeId);
|
|
3273
|
+
})() : null;
|
|
3274
|
+
if (branch.role === "crossover" && farJoint0) {
|
|
3275
|
+
const dx = farJoint0.x - dj.x;
|
|
3276
|
+
const dy = farJoint0.y - dj.y;
|
|
3277
|
+
const len = Math.hypot(dx, dy);
|
|
3278
|
+
if (len > 1e-6) {
|
|
3279
|
+
pieces.push({
|
|
3280
|
+
id: `x-${branch.id}`,
|
|
3281
|
+
partId: flexId,
|
|
3282
|
+
x: dj.x,
|
|
3283
|
+
y: dj.y,
|
|
3284
|
+
rotationDeg: Math.atan2(dy, dx) * 180 / Math.PI,
|
|
3285
|
+
lengthInches: r3(len),
|
|
3286
|
+
...branch.trackName ? { name: branch.trackName } : {}
|
|
3287
|
+
});
|
|
3288
|
+
} else {
|
|
3289
|
+
notLaid.push({
|
|
3290
|
+
id: branch.id,
|
|
3291
|
+
why: "this crossover's two turnouts meet at the same point, so there is no connector between them to lay"
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3294
|
+
continue;
|
|
3295
|
+
}
|
|
3249
3296
|
const branchY = laneOffsetAt(branch.lane ?? 0, 0);
|
|
3250
3297
|
const curve = transition(branch.id, { x: dj.x, y: dj.y, headingDeg: dj.headingDeg }, branchY);
|
|
3251
3298
|
let start = { x: dj.x, y: dj.y, headingDeg: dj.headingDeg };
|
|
@@ -3254,13 +3301,7 @@ function docToGraph(doc, answers = {}, library = BUILT_IN_TRACK_PARTS) {
|
|
|
3254
3301
|
const e = jointAt(curve, "b");
|
|
3255
3302
|
if (e) start = { x: e.x, y: e.y, headingDeg: e.headingDeg };
|
|
3256
3303
|
}
|
|
3257
|
-
const
|
|
3258
|
-
(o) => o.id !== t.id && o.divergeTrack === branch.id && laidTurnouts.has(o.id)
|
|
3259
|
-
);
|
|
3260
|
-
const farJoint = farSw ? (() => {
|
|
3261
|
-
const f = laidTurnouts.get(farSw.id);
|
|
3262
|
-
return jointAt(f.piece, f.divergeId);
|
|
3263
|
-
})() : null;
|
|
3304
|
+
const farJoint = farJoint0;
|
|
3264
3305
|
let endX = farJoint != null ? farJoint.x : Math.max(branch.fromPos ?? t.pos, branch.toPos ?? t.pos);
|
|
3265
3306
|
let farCurve = null;
|
|
3266
3307
|
if (farJoint) {
|