@rulecad/printcheck 0.3.1 → 0.3.2
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/package.json +1 -1
- package/printcheck.d.mts +2 -0
- package/printcheck.mjs +12 -1
package/package.json
CHANGED
package/printcheck.d.mts
CHANGED
|
@@ -62,8 +62,10 @@ export function islands(polys: any, { layer, overhang, line, firstGap, onLayer }
|
|
|
62
62
|
islands: any[];
|
|
63
63
|
layers: number;
|
|
64
64
|
overhang: number;
|
|
65
|
+
firstSprawl?: undefined;
|
|
65
66
|
fused?: undefined;
|
|
66
67
|
} | {
|
|
68
|
+
firstSprawl: number;
|
|
67
69
|
islands: {
|
|
68
70
|
z: number;
|
|
69
71
|
area: number;
|
package/printcheck.mjs
CHANGED
|
@@ -211,6 +211,10 @@ export function check(polys, printer, { eps = 1e-3, parts = null, slice = true }
|
|
|
211
211
|
// further apart there than the gap that prints apart higher up, or they print as one)
|
|
212
212
|
const firstGap = printer.foot > 0 && printer.print_gap > 0 ? printer.print_gap + 2 * printer.foot : 0;
|
|
213
213
|
const sliced = islands(tris, { layer: printer.layer ?? 0.2, overhang: printer.overhang, line: printer.line ?? LINE, firstGap }), isl = sliced.islands;
|
|
214
|
+
// A big part whose first layer is cut up (bars, spokes, a skeleton) has far more edge to lift than a plain footprint
|
|
215
|
+
// of the same area. A small part (a gear) is allowed its small shapes.
|
|
216
|
+
const { lo: lo0, hi: hi0 } = bounds(tris), across = Math.max(hi0[0] - lo0[0], hi0[1] - lo0[1]);
|
|
217
|
+
if (across > FIRST_LARGE && sliced.firstSprawl > FIRST_SPRAWL) f('warn', `the first layer's outline is ${mm(sliced.firstSprawl)} times a plain shape's of the same area, on a part ${mm(across)} mm across: edges are where a first layer lifts and curls. Make the footprint smaller and solid, and take material out above the first layer`, 'print.first-layer.sprawl', { sprawl: sliced.firstSprawl });
|
|
214
218
|
for (const x of sliced.fused) f('warn', `on the first layer, two parts are about ${mm(x.gap)} mm apart at (${mm(x.at[0])}, ${mm(x.at[1])}): the first layer spreads ${printer.foot} mm each side as it is squashed on, so under ${mm(firstGap)} mm they print as one. Keep them ${mm(firstGap)} mm apart on the bed, or lift one off it`, 'print.first-layer', { gap: x.gap, need: firstGap }, { lo: [x.at[0] - 1, x.at[1] - 1, 0], hi: [x.at[0] + 1, x.at[1] + 1, printer.layer ?? 0.2] });
|
|
215
219
|
if (firstGap && !sliced.fused.length) f('pass', `on the first layer, nothing printed in place stands within ${mm(firstGap)} mm of another part (the first layer spreads ${printer.foot} mm each side)`, 'print.first-layer', { need: firstGap });
|
|
216
220
|
// Overhang as the printer meets it: layers lying out past the one below, less the flat undersides the bridge check
|
|
@@ -293,6 +297,7 @@ function spans(polys, held, under) {
|
|
|
293
297
|
// seams(polys) -> { gaps, tjunctions, hairlines }: edges not matched by a reverse edge, split into T-junctions (covered
|
|
294
298
|
// all along by reverse edges on the same line, or lying along a longer reverse edge), hairlines (within HAIRLINE of
|
|
295
299
|
// another face) and real gaps.
|
|
300
|
+
const FIRST_LARGE = 80, FIRST_SPRAWL = 8; // mm, and times a circle's outline: a part over 80 mm across whose first layer has eight times the edge a plain shape would
|
|
296
301
|
export const HAIRLINE = 0.01; // mm: a fortieth of a print line
|
|
297
302
|
const vsub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]], vdot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
298
303
|
function pointToTriangle(p, a, b, c) { // Ericson, Real-Time Collision Detection 5.1.5
|
|
@@ -394,6 +399,7 @@ export function islands(polys, { layer = 0.2, overhang = 45, line = LINE, firstG
|
|
|
394
399
|
const byLayer = Array.from({ length: count }, () => []);
|
|
395
400
|
for (let t = 0; t < tris.length; t++) for (let L = Math.max(0, Math.ceil((zmin[t] - lo[2]) / layer - 0.5)); L <= Math.min(count - 1, Math.floor((zmax[t] - lo[2]) / layer - 0.5)); L++) byLayer[L].push(t);
|
|
396
401
|
let below = null, held = null, prev = null, counted = null, overhangArea = 0;
|
|
402
|
+
let firstSprawl = 0; // the first layer's outline against a circle's of the same area
|
|
397
403
|
const fused = []; // on the first layer, regions nearer each other than firstGap: { at, gap } (the first layer spreads, and they print as one)
|
|
398
404
|
const px = (x) => Math.floor((x - lo[0]) / pitch) + 3;
|
|
399
405
|
// Only what the printer can lay counts: each layer is opened by half a line (eroded, then grown back), so anything
|
|
@@ -444,6 +450,11 @@ export function islands(polys, { layer = 0.2, overhang = 45, line = LINE, firstG
|
|
|
444
450
|
if (same) continue;
|
|
445
451
|
const filled = opened(raw);
|
|
446
452
|
history[L] = filled;
|
|
453
|
+
if (L === 0) { // how long the first layer's outline is, against a circle's of the same area: 1 for a disc, more the more it's cut up
|
|
454
|
+
let area = 0, edges = 0;
|
|
455
|
+
for (let n = 0; n < nx * ny; n++) if (filled[n]) { area++; if (!filled[n - 1]) edges++; if (!filled[n + 1]) edges++; if (!filled[n - nx]) edges++; if (!filled[n + nx]) edges++; }
|
|
456
|
+
firstSprawl = area ? (edges * pitch) / (2 * Math.sqrt(Math.PI * area * pitch * pitch)) : 0;
|
|
457
|
+
}
|
|
447
458
|
if (L === 0 && firstGap > 0) {
|
|
448
459
|
// Each region labelled; grown by half the gap, two that meet were nearer than it. Where they meet is the spot
|
|
449
460
|
const label = (mask) => { const lab = new Int32Array(nx * ny), stack = new Int32Array(nx * ny); let n = 0; for (let st = 0; st < nx * ny; st++) { if (!mask[st] || lab[st]) continue; n++; let top = 0; stack[top++] = st; lab[st] = n; while (top) { const e = stack[--top], i = e % nx; for (const d of [i + 1 < nx ? e + 1 : -1, i > 0 ? e - 1 : -1, e + nx < nx * ny ? e + nx : -1, e >= nx ? e - nx : -1]) if (d >= 0 && mask[d] && !lab[d]) { lab[d] = n; stack[top++] = d; } } } return { lab, n }; };
|
|
@@ -505,7 +516,7 @@ export function islands(polys, { layer = 0.2, overhang = 45, line = LINE, firstG
|
|
|
505
516
|
}
|
|
506
517
|
below = filled;
|
|
507
518
|
}
|
|
508
|
-
return { islands: out, layers: count, overhang: overhangArea, fused };
|
|
519
|
+
return { firstSprawl, islands: out, layers: count, overhang: overhangArea, fused };
|
|
509
520
|
}
|
|
510
521
|
|
|
511
522
|
export function shape(polys, eps = 1e-3, drop = 0.05, hang = 1) {
|