CM3D-015: Geometry inspection is exact on the B-rep and uses the mesh for wall thickness and pictures

Accepted · 2026-11-19 · @mathisloge

Context

A coding agent designs the parts in code, and a part is not done until the model has proven it (CM3D-009). Beyond the tests, every check needed a scratch script: build the shapes, cut them, render PNGs and measure with single build123d calls. Each script was about forty lines and was written again for the next part. The agent also reads numbers more reliably than pictures, so a thin wall or a tight gap was easy to miss in a PNG. The commands cm3d inspect and cm3d look replace these scripts with a small library in cm3d.tools. The library must decide where it measures: on the B-rep of build123d or on a triangle mesh.

Decision Drivers

  • Same numbers as the tests: a clearance from cm3d inspect must match the number a test computes.

  • Fits of about 0.1 mm: the measurements that check fits must be exact to well below that.

  • Little own code: use libraries where they exist, rather than writing our own geometry code.

  • Large parts: a check over a whole enclosure panel must finish in about a minute.

Decision

Clearance, overlap, holes and pins, sections and joint motion are measured on the B-rep with build123d and OCC. The wall thickness over a whole part is measured on the mesh from cm3d.tools.render.to_pv with trimesh.proximity.thickness (ray method). The pictures of cm3d look are rendered from the same mesh with pyvista, and their section faces come from the exact B-rep section. trimesh, rtree and scipy become dependencies.

Alternatives Considered

Everything on the mesh with trimesh

One representation and very little code.

Rejected: holes are only approximated from triangles, and every distance carries the tessellation error of about 0.05 mm. That is too coarse for fits, and the numbers would differ from the tests.

Everything on the B-rep, no trimesh

Exact everywhere and no new dependency.

Rejected: OCC has no ready-made thickness analysis over a whole part. We would write and keep our own ray casting, and it is slow on large parts.

An MCP server such as build123d-mcp

A ready server that runs build123d code, renders and measures.

Rejected: it runs in its own environment without cm3d and the pinned build123d, and it duplicates cm3d export and cm3d render.

Consequences

  • Good: fits are checked with exact numbers, and tests and cm3d inspect share the same functions.

  • Good: the thickness check covers a whole part in a few seconds and finds walls nobody thought of.

  • Bad: a part exists in two representations, and a thickness value is only as exact as the tessellation.

  • Bad: the thickness check also reports every acute edge, with a thickness near 0, because the wall really gets thin towards such an edge. The tool does not mark them, so whoever reads the report says which regions are such edges.

  • Bad: the check counts a wall as thin only below the threshold minus the tessellation tolerance, so a wall up to 0.05 mm under MIN_WALL passes.