Calculation Methodology, Tolerances and Testing
Engineering File Tools runs two deterministic analysis engines—cad-core-ts in the browser and cad-worker-py on the batch server—under a single shared output contract (version 0.1.0). Rather than treating geometry metrics as a black box, this page documents every formula, deflection setting, graph rule, and measured benchmark so mechanical engineers, estimators, and buyers know exactly what was computed before quoting or cutting parts.
1. DXF Path Length & Transform Rules
All DXF calculations operate strictly on Model Space. Paper Space entities (group code 67 = 1 or *Paper_Space* blocks) are ignored and flagged with paper_space_ignored. Text (TEXT, MTEXT, DIMENSION, ACAD_TABLE) and non-path entities (HATCH, 3DFACE, MESH, SOLID, 3DSOLID) are excluded from path lengths and reported separately.
Exact Geometric Primitives
| Entity | Formula / Method | Error Bound |
|---|---|---|
LINE | Euclidean distance √(Δx² + Δy²) | Exact (IEEE 754 float64) |
CIRCLE | Circumference 2πr | Exact |
ARC | Circular arc length `r · | Δθ |
LWPOLYLINE / POLYLINE bulge | Chord c = ‖P2 − P1‖, sweep `θ = 4 · atan( | b |
Numerical Integration (ELLIPSE, SPLINE, Non-Uniform INSERT)
ELLIPSE: Arc length∫ √((a · sin t)² + (b · cos t)²) dtfromt₁tot₂is integrated via adaptive Gauss-Legendre / Simpson quadrature to relative error< 10⁻⁷.SPLINE: Evaluated from knots, control points, and rational weights (De Boor / NURBS derivative) and integrated numerically. If only fit points exist, a cubic spline without end tangents is interpolated and flagged withspline_approximated.INSERT&MINSERT: Expanded recursively up to depth16applying translation, rotation, uniform/non-uniform scaling (including negative scale mirroring), andMINSERTrow/column grids. Entities on block layer0inherit theINSERTlayer per DXF rules. When anINSERTapplies non-uniform scaling (|sx| ≠ |sy|) to aCIRCLEorARC, it becomes an elliptical arc and is integrated numerically (non_uniform_scalewarning).
Units Policy
If $INSUNITS is 1 (in), 2 (ft), 4 (mm), 5 (cm), or 6 (m), results use that unit. If $INSUNITS is missing or 0 (unitless), we never silently assume millimetres: the UI flags unknown_units, withholds a pass verdict, and prompts you to select the true drawing unit.
2. Open Contour & Duplicate Detection
Endpoint Graph & Clustering
- Path endpoints from the selected cutting layers are indexed into a spatial grid at cell size
tolerance(default0.01drawing units). - Closed primitives (
CIRCLE, closedLWPOLYLINE/POLYLINE, fullELLIPSE, closedSPLINE) are counted directly as closed contours. - Connected components of open segments are classified by node degree:
- All nodes degree
2→ closed contour (multi-entity loops such as 4LINEs or slotLINE+ARCs are recognised as closed). - Any node degree
1→ open contour, emittingopen_endpoint. If anotherdegree 1endpoint lies within10 × tolerance, agapissue with the measured distance is reported. - Any node degree
≥ 3→ needs review (branchissue).
- All nodes degree
Exact & Near Duplicates
Each segment/polyline is canonicalised (ignoring reversal on LINE and reversing/rotating vertex rings on LWPOLYLINE) and bucketed in a spatial hash:
- Exact: identical geometry within
10⁻⁹relative tolerance. - Near: identical topology within user
tolerance. - Not checked: Partial collinear overlaps (e.g., a 20 mm line resting on top of a 100 mm line), mid-span T-junctions, and crossing contours.
3. STEP Tessellation & STL Export
STEP (.step/.stp, ISO 10303-21) files are parsed and tessellated in-browser by OpenCascade via occt-import-js (0.0.23, LGPL-2.1). OCCT converts the file's SI_UNIT or CONVERSION_BASED_UNIT to millimetres on import (linearUnit: "millimeter").
| Quality Preset | Deflection Type | Linear Deflection Ratio | Angular Deflection |
|---|---|---|---|
low | bounding_box_ratio | 0.004 | 0.5 rad |
standard | bounding_box_ratio | 0.001 | 0.3 rad |
high | bounding_box_ratio | 0.0002 | 0.1 rad |
Because curved B-Rep surfaces are approximated by flat triangles, the bounding box displayed in the STEP Viewer is always approximate (mesh-derived) and never claimed as exact B-Rep metrology. STL export verifies triangle counts and bounding boxes before and after writing the binary (84 + 50 × n bytes) or ASCII payload.
4. Measured Benchmark & Corpus Verification
Every engine release is verified against deterministic analytic baselines and public real-world CAD corpora rather than toy smoke checks:
STEP Mesh Accuracy vs. Exact CAD Primitives (occt-import-js 0.0.23)
| Synthetic CAD Model | Preset | Triangles | Volume Error | Max BBox Shortfall |
|---|---|---|---|---|
cube_10mm, box_100x50x20 (mm / inch / AP203 / AP242) | low / standard / high | 12 | 0.0000% | 0.0000 mm |
cylinder_r10_h30 | standard | 260 | -0.1510% | 0.0113 mm |
cylinder_r10_h30 | high | 580 | -0.0309% | 0.0023 mm |
sphere_r25 | standard | 5,008 | -0.288% | 0.024 mm |
plate_100x60x10_two_holes_d10 | high | 1,028 | +0.001% | 0.0000 mm |
assembly_two_parts | high | 512 | -0.0068% | 0.0016 mm |
Real-World & Adversarial Corpus Runs
- STEP Real Corpus (
113public AP203/AP214/AP242 files):112parsed cleanly,101produced meshes,1zero-byte file returnedinvalid_file,11external-reference assembly roots returnedempty_result,0crashes. - STEP Robustness Stress Test (
266malformed/adversarial files):0crashes or hangs; malformed inputs fail cleanly with typed error codes. - DXF Golden & Real-World Corpus:
49analytic golden scenarios (147/147TypeScript checks and49/49Python checks passing) plus1,528public DXF files (ezdxf,dxf-parser,LibreCAD) parsed in~3.1 swith cross-engine TS-vs-Python parity verified under a< 2%discrepancy threshold. - Batch Server Throughput:
25DXF files preflighted end-to-end into PDF, XLSX, CSV, and JSON in4.78 s(191 ms/file,51.8 MBpeak child RSS).
5. Changelog
- 2026-11-30 (
0.1.0): Initial release ofcad-core-tsandcad-worker-py, STEP Viewer, STEP to STL, DXF Viewer, Cutting Length, Open Contour, Duplicate Checker, and DXF Batch Preflight Report.