r/codereview • • Nov 01 '26

C/C++ [Code Review] Wrote a fast binary STL inspector/analyzer in C – looking for feedback on memory management and math logic

Hi everyone,

I've been working on a lightweight CLI tool in C called stl-inspector (GitHub repo).

Why I built it:

I got tired of waiting for heavy slicers (PrusaSlicer, Cura, Bambu Studio) just to check basic parameters like watertightness, mesh volume, overhang areas, and bounding dimensions of 3D models.

What it currently does:

  • Parses binary STL headers and triangle arrays
  • Calculates bounding box, volume (tetrahedron method), and surface area
  • Detects overhang areas (default 45°) for 3D printing feasibility
  • Checks if the mesh is watertight
  • Fast build with zero external dependencies (pure C + Makefile)

Where I'd appreciate feedback:

  • Memory safety & cleanup (handling large meshes)
  • Performance of the watertight check (currently O(N^2), looking into spatial hashing / edge mapping)
  • General C code idiomatic style and CLI argument handling

Note: AI was used to help debug directory creation.

Would love to hear your critique or suggestions for improvement.

1 Upvotes

3 comments sorted by

1

u/Jazzlike_Place_1974 Nov 01 '26

for the signed tetrahedron volume calculation, make sure the accumulator is a double even though the STL vertices are 32-bit floats. With high-poly meshes the precision loss adds up super fast if youre summing in single precision.

1

u/[deleted] Nov 01 '26

[removed] — view removed comment

0

u/wajlem Nov 01 '26

Thanks, glad it’s useful! Zero dependencies was the goal.
Good call on the edge hash map. A pairwise check is the obvious bottleneck on bigger meshes, and counting each edge’s occurrences in a map should do the trick. I’ll look at changing that.

And yes, the volume is the divergence theorem, summing signed tetrahedron volumes per triangle. The sign is easy to get wrong. Total black magic, it took me a long time to debug.