#!/usr/bin/env python3
"""Verify all final STL dimensions."""
import struct, numpy as np, os

OUT = "/app/projects/esp32-box/exports"

def info(p):
    with open(p, "rb") as f:
        f.read(80)
        n = struct.unpack("<I", f.read(4))[0]
        x1=y1=z1=9e9; x2=y2=z2=-9e9
        for _ in range(n):
            f.read(12)
            for _ in range(3):
                x,y,z = struct.unpack("<fff", f.read(12))
                if x < x1: x1=x
                if x > x2: x2=x
                if y < y1: y1=y
                if y > y2: y2=y
                if z < z1: z1=z
                if z > z2: z2=z
            f.read(2)
        return n, x2-x1, y2-y1, z2-z1

for f in ["base.stl","lid.stl","window_smooth.stl","window_keystone_dc.stl","window_smooth_y.stl","window_usb.stl","screw.stl"]:
    p = os.path.join("/app/projects/esp32-box/exports", f)
    if os.path.exists(p):
        n, x, y, z = info(p)
        print("%s: %.1fx%.1fx%.1f (%d tri)" % (f, x, y, z, n))