@willcgage/module-schematic 0.31.0 → 0.32.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 +76 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -1
- package/dist/index.d.ts +31 -1
- package/dist/index.js +74 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -327,6 +327,79 @@ function sectionBand(center, fromPos, toPos, widthA = FREEMO_ENDPLATE_WIDTH_RECO
|
|
|
327
327
|
}));
|
|
328
328
|
return [...left, ...right.reverse()];
|
|
329
329
|
}
|
|
330
|
+
function ringEdges(pts) {
|
|
331
|
+
const out = [];
|
|
332
|
+
for (let i = 0; i < pts.length; i++) out.push([pts[i], pts[(i + 1) % pts.length]]);
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
function sharedEdgeLength(e1, e2, gap, angleDeg) {
|
|
336
|
+
const ux = e1[1].x - e1[0].x;
|
|
337
|
+
const uy = e1[1].y - e1[0].y;
|
|
338
|
+
const ul = Math.hypot(ux, uy);
|
|
339
|
+
const vx = e2[1].x - e2[0].x;
|
|
340
|
+
const vy = e2[1].y - e2[0].y;
|
|
341
|
+
const vl = Math.hypot(vx, vy);
|
|
342
|
+
if (ul < 1e-6 || vl < 1e-6) return 0;
|
|
343
|
+
const dx = ux / ul;
|
|
344
|
+
const dy = uy / ul;
|
|
345
|
+
const cross = Math.abs((dx * vy - dy * vx) / vl);
|
|
346
|
+
if (cross > Math.sin(angleDeg * Math.PI / 180)) return 0;
|
|
347
|
+
const perp = (q) => Math.abs((q.x - e1[0].x) * -dy + (q.y - e1[0].y) * dx);
|
|
348
|
+
if (perp(e2[0]) > gap || perp(e2[1]) > gap) return 0;
|
|
349
|
+
const proj = (q) => (q.x - e1[0].x) * dx + (q.y - e1[0].y) * dy;
|
|
350
|
+
const t1 = proj(e2[0]);
|
|
351
|
+
const t2 = proj(e2[1]);
|
|
352
|
+
return Math.max(0, Math.min(ul, Math.max(t1, t2)) - Math.max(0, Math.min(t1, t2)));
|
|
353
|
+
}
|
|
354
|
+
function sectionAdjacency(footprints, opts) {
|
|
355
|
+
const gap = opts?.gapInches ?? 0.5;
|
|
356
|
+
const angle = opts?.angleDegrees ?? 3;
|
|
357
|
+
const min = opts?.minOverlapInches ?? 1;
|
|
358
|
+
const edges = footprints.map((f) => ringEdges(f.outline));
|
|
359
|
+
const out = [];
|
|
360
|
+
for (let i = 0; i < footprints.length; i++) {
|
|
361
|
+
for (let j = i + 1; j < footprints.length; j++) {
|
|
362
|
+
let total = 0;
|
|
363
|
+
for (const e1 of edges[i])
|
|
364
|
+
for (const e2 of edges[j]) total += sharedEdgeLength(e1, e2, gap, angle);
|
|
365
|
+
if (total >= min)
|
|
366
|
+
out.push({
|
|
367
|
+
a: footprints[i].id,
|
|
368
|
+
b: footprints[j].id,
|
|
369
|
+
lengthInches: Math.round(total * 1e3) / 1e3
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return out;
|
|
374
|
+
}
|
|
375
|
+
function sectionNeighbours(id, adj) {
|
|
376
|
+
return adj.filter((x) => x.a === id || x.b === id).map((x) => x.a === id ? x.b : x.a);
|
|
377
|
+
}
|
|
378
|
+
function sectionComponents(ids, adj) {
|
|
379
|
+
const parent = new Map(ids.map((id) => [id, id]));
|
|
380
|
+
const find = (x) => {
|
|
381
|
+
let r = x;
|
|
382
|
+
while (parent.get(r) !== r) r = parent.get(r);
|
|
383
|
+
while (parent.get(x) !== r) {
|
|
384
|
+
const nx = parent.get(x);
|
|
385
|
+
parent.set(x, r);
|
|
386
|
+
x = nx;
|
|
387
|
+
}
|
|
388
|
+
return r;
|
|
389
|
+
};
|
|
390
|
+
for (const { a, b } of adj) {
|
|
391
|
+
if (!parent.has(a) || !parent.has(b)) continue;
|
|
392
|
+
const ra = find(a);
|
|
393
|
+
const rb = find(b);
|
|
394
|
+
if (ra !== rb) parent.set(ra, rb);
|
|
395
|
+
}
|
|
396
|
+
const groups = /* @__PURE__ */ new Map();
|
|
397
|
+
for (const id of ids) {
|
|
398
|
+
const r = find(id);
|
|
399
|
+
groups.set(r, [...groups.get(r) ?? [], id]);
|
|
400
|
+
}
|
|
401
|
+
return [...groups.values()];
|
|
402
|
+
}
|
|
330
403
|
function endplateFaceSegments(center, widthA = FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, widthB = FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES, offsetA = 0, offsetB = 0) {
|
|
331
404
|
if (center.length < 2) return [];
|
|
332
405
|
const n = centerlineNormals(center);
|
|
@@ -1310,9 +1383,12 @@ exports.poseOverridesFromDoc = poseOverridesFromDoc;
|
|
|
1310
1383
|
exports.sampleBenchworkOutline = sampleBenchworkOutline;
|
|
1311
1384
|
exports.samplePath = samplePath;
|
|
1312
1385
|
exports.scaleFeetToInches = scaleFeetToInches;
|
|
1386
|
+
exports.sectionAdjacency = sectionAdjacency;
|
|
1313
1387
|
exports.sectionBand = sectionBand;
|
|
1314
1388
|
exports.sectionBreaksFromSections = sectionBreaksFromSections;
|
|
1389
|
+
exports.sectionComponents = sectionComponents;
|
|
1315
1390
|
exports.sectionFootprints = sectionFootprints;
|
|
1391
|
+
exports.sectionNeighbours = sectionNeighbours;
|
|
1316
1392
|
exports.sectionSpans = sectionSpans;
|
|
1317
1393
|
exports.sectionedCenterline = sectionedCenterline;
|
|
1318
1394
|
exports.sliceCenterline = sliceCenterline;
|