"""Original CadQuery parametric fixture. CC0-1.0. Not scanner test data. Run with Python 3.11, cadquery==2.6.1 and trimesh==4.9.0. Then run verify-step-reader.mjs with Node and occt-import-js==0.0.23. STEP timestamps can differ between runs; validate geometry, not byte equality. """ from pathlib import Path import csv import hashlib import importlib.metadata as metadata import json import math import cadquery as cq import trimesh from OCP.BRepAdaptor import BRepAdaptor_Surface LENGTH_MM = 80.0 WIDTH_MM = 50.0 THICKNESS_MM = 6.0 CORNER_RADIUS_MM = 4.0 HOLE_SPACING_MM = 50.0 HOLE_DIAMETER_MM = 8.0 def parametric_plate(hole_diameter_mm=HOLE_DIAMETER_MM): return ( cq.Workplane("XY").box(LENGTH_MM, WIDTH_MM, THICKNESS_MM, centered=(True, True, False)) .edges("|Z").fillet(CORNER_RADIUS_MM) .faces(">Z").workplane() .pushPoints([(-HOLE_SPACING_MM / 2, 0), (HOLE_SPACING_MM / 2, 0)]) .hole(hole_diameter_mm) ) def brep_measure(file): shape = cq.importers.importStep(str(file)).val() bounds = shape.BoundingBox() radii = sorted(round(BRepAdaptor_Surface(face.wrapped).Cylinder().Radius(), 6) for face in shape.Faces() if face.geomType() == "CYLINDER") return {"file": file.name, "reader": "CadQuery STEP import", "size_mm": [round(bounds.xlen, 6), round(bounds.ylen, 6), round(bounds.zlen, 6)], "volume_mm3": round(shape.Volume(), 6), "solid_count": len(shape.Solids()), "valid_brep": shape.isValid(), "cylinder_radii_mm": radii} def reproduce(): folder = Path(__file__).resolve().parent nominal = parametric_plate() cq.exporters.export(nominal, str(folder / "plate-native-8mm.step")) cq.exporters.export(nominal, str(folder / "plate-native-8mm.stl"), tolerance=0.01, angularTolerance=0.1) # Rebuild the original native operation sequence with a different parameter. rebuilt = parametric_plate(10.0) cq.exporters.export(rebuilt, str(folder / "plate-rebuilt-10mm.step")) cq.exporters.export(rebuilt, str(folder / "plate-rebuilt-10mm.stl"), tolerance=0.01, angularTolerance=0.1) # Start from the imported neutral solid, not the parametric source. direct = (cq.importers.importStep(str(folder / "plate-native-8mm.step")) .faces(">Z").workplane(centerOption="CenterOfMass").hole(5.0)) cq.exporters.export(direct, str(folder / "plate-direct-edit-5mm.step")) cq.exporters.export(direct, str(folder / "plate-direct-edit-5mm.stl"), tolerance=0.01, angularTolerance=0.1) cq.exporters.export(nominal, str(folder / "plate-reference.svg"), exportType=cq.exporters.ExportTypes.SVG, opt={"width": 700, "height": 320, "marginLeft": 24, "marginTop": 24, "showAxes": False, "projectionDir": (-1, -1, 1), "strokeWidth": 1.4, "strokeColor": (16, 27, 70), "hiddenColor": (195, 201, 218)}) results = [] for file in sorted(folder.glob("plate-*.step")): result = brep_measure(file) assert result["size_mm"] == [80.0, 50.0, 6.0] assert result["solid_count"] == 1 and result["valid_brep"] results.append(result) native = next(r for r in results if r["file"] == "plate-native-8mm.step") rebuilt_result = next(r for r in results if r["file"] == "plate-rebuilt-10mm.step") direct_result = next(r for r in results if r["file"] == "plate-direct-edit-5mm.step") assert native["cylinder_radii_mm"].count(4.0) == 6 assert rebuilt_result["cylinder_radii_mm"].count(5.0) == 2 assert direct_result["cylinder_radii_mm"].count(2.5) == 1 assert abs(native["volume_mm3"] - direct_result["volume_mm3"] - math.pi * 2.5 ** 2 * THICKNESS_MM) < 0.00001 for file in sorted(folder.glob("plate-*.stl")): mesh = trimesh.load(file, force="mesh", process=True) size = [round(float(v), 6) for v in mesh.extents] assert all(abs(v - expected) < 0.0001 for v, expected in zip(size, [80, 50, 6])) assert mesh.is_watertight results.append({"file": file.name, "reader": "trimesh STL import", "size_mm": size, "volume_mm3": round(float(mesh.volume), 6), "triangle_count": len(mesh.faces), "watertight": bool(mesh.is_watertight)}) checksums = {file.name: hashlib.sha256(file.read_bytes()).hexdigest() for file in sorted(folder.iterdir()) if file.suffix in {".step", ".stl", ".svg", ".py", ".mjs"}} report = {"checked_at": "2026-10-01", "license": "CC0-1.0", "kind": "Original synthetic CAD fixture, not a scan", "units": "mm", "versions": {name: metadata.version(name) for name in ["cadquery", "cadquery-ocp", "trimesh"]}, "parameters": {"length_mm": LENGTH_MM, "width_mm": WIDTH_MM, "thickness_mm": THICKNESS_MM, "corner_radius_mm": CORNER_RADIUS_MM, "hole_spacing_mm": HOLE_SPACING_MM, "native_hole_diameter_mm": HOLE_DIAMETER_MM}, "checks": results, "sha256": checksums, "limitations": [ "No scan-to-solid reconstruction or scanner hardware was tested.", "CadQuery and the JavaScript STEP reader both use OCCT; this is not independent-kernel validation.", "STEP retains the neutral solid, not this native Python operation history.", "STL is a tessellation; its measured volume differs from the analytic solid.", "A successful direct edit does not prove that every receiving CAD task will succeed."]} (folder / "file-check.json").write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") with (folder / "file-check.csv").open("w", newline="", encoding="utf-8-sig") as handle: writer = csv.writer(handle) writer.writerow(["File", "Reader", "X (mm)", "Y (mm)", "Z (mm)", "Volume (mm3)", "Valid solid or watertight mesh"]) for result in results: writer.writerow([result["file"], result["reader"], *result["size_mm"], result["volume_mm3"], result.get("valid_brep", result.get("watertight"))]) print(json.dumps({"generated": len(results), "all_geometry_checks_passed": True, "versions": report["versions"]})) if __name__ == "__main__": reproduce()