Components / Method
Method

Fit checks

Four questions to ask the model before every slice.

A model that looks right can still be unbuildable. These run in seconds and catch what a picture does not: parts that overlap, parts that collide partway through a motion, parts that cannot be put in, and screws that no tool can reach.

Method: A practice or a tool, not a printed part.Each check exists because its absence cost a reprint or a redesign.
3D model: Fit checksLoading 3D view
wall and floorpost in the wayscrewscrewdriver path

Use it in code

typescript
import { ready, checks } from "partkit";
await ready();

const r = new checks.Report();
r.check("lid vs base, closed", lid, base);
r.add("lid vs base through the swing", checks.sweep((a) => [lidAt(a), base], angles).worst);
r.add("cover slides on", checks.pathClear(cover, [0, 0, 1], [0, 10, 20, 30], [lid, hingeBody]));
console.log(r.toString());            // ends with ALL CLEAR or CHECKS FAILED
if (!r.ok) process.exit(1);

Functions

CallWhat it gives you
checks.overlap(a, b)Shared volume in mm3; 0 is clear.
checks.sweep(pairAt, positions)Worst overlap through a motion, and where.
checks.pathClear(part, direction, steps, obstacles)Can the part be slid or dropped into place?
checks.driverBlocked(place, obstacles)Is a straight screwdriver's path clear?
new checks.Report()Collects named checks; prints ALL CLEAR or what failed.

Check before you print

  • Overlap between every pair of neighbouring parts
  • The same through the full motion
  • Assembly path, in the order things are built
  • Tool access for every screw
  • Each printed part is one solid

Learned the hard way

  • Do not call a part ready until the test it depends on has passed.
  • Say which results come from a printer and which only from the model.

Open it in Fusion 360

The scene above as a STEP file: real solid bodies, each part its own named component, in position. In Fusion 360 use File, Open, then Open from my computer. It also opens in FreeCAD, SolidWorks and Onshape. It carries the shapes, not the sizes you can change; for different sizes, use Make it above or change them in code.

Source: ts/src/checks.ts
typescript
/** Fit checks. Run them on every change, before slicing. A model that looks right can still be unbuildable.
 *  1. Do any two parts overlap?  2. Do they still clear through the whole motion?
 *  3. Can the part be put in, and can a tool reach?  4. Is each printed part one piece? */
import { measureVolume } from "replicad";
import { moved, type Solid } from "./geom";
import * as fasteners from "./fasteners";

/** Shared volume of two parts in mm3 (0 = clear). */
export function overlap(a: Solid, b: Solid): number {
  try {
    return measureVolume(a.intersect(b));
  } catch {
    return 0;
  }
}

export const solids = (part: Solid): number => Math.max(1, (part as any).solids?.length ?? 1);

/** Worst overlap over a motion. pairAt(p) returns [a, b] at position p. */
export function sweep<P>(pairAt: (p: P) => [Solid, Solid], positions: P[]): { worst: number; at: P | null } {
  let worst = 0, at: P | null = null;
  for (const p of positions) {
    const [a, b] = pairAt(p);
    const v = overlap(a, b);
    if (v > worst) { worst = v; at = p; }
  }
  return { worst, at };
}

/** Can `part` be slid in along `direction`? Checks it at each distance in `steps` (mm) against the obstacles. */
export function pathClear(part: Solid, direction: [number, number, number], steps: number[], obstacles: Solid[]): number {
  let worst = 0;
  for (const d of steps) {
    const m = moved(part, direction[0] * d, direction[1] * d, direction[2] * d);
    for (const o of obstacles) worst = Math.max(worst, overlap(m, o));
  }
  return worst;
}

/** Volume of obstacle inside a straight screwdriver's path. place() moves a tool built along +z from the screw head
 *  (see fasteners.driverPath) to the real screw. 0 = a straight driver reaches it. */
export function driverBlocked(place: (tool: Solid) => Solid, obstacles: Solid[], length = 150, r = fasteners.DRIVER_R): number {
  const path = place(fasteners.driverPath(length, r));
  return obstacles.reduce((n, o) => n + overlap(path, o), 0);
}

export interface Row { name: string; value: number; ok: boolean }

/** Collects named checks; `ok` is true when every one passed. */
export class Report {
  rows: Row[] = [];
  constructor(private tol = 0.01) {}
  add(name: string, value: number, limit = this.tol) {
    const ok = value <= limit;
    this.rows.push({ name, value, ok });
    return ok;
  }
  check(name: string, a: Solid, b: Solid) { return this.add(name, overlap(a, b)); }
  get ok() { return this.rows.every((r) => r.ok); }
  toString() {
    return this.rows.map((r) => `${r.ok ? "ok  " : "FAIL"} ${r.value.toFixed(2).padStart(9)}  ${r.name}`).join("\n") + (this.ok ? "\nALL CLEAR" : "\nCHECKS FAILED");
  }
}

View this module on GitHub