"""Are the hulls closed once coincident vertices are merged? (every object and setting of hull.py)"""
import sys
sys.argv = [sys.argv[0], "x"]
from hull import OBJECTS, SETTINGS, N_T  # noqa: E402
import numpy as np, trimesh, fcp  # noqa: E402
from fcp_hull import convex_hull  # noqa: E402
for name, path in OBJECTS.items():
    m = trimesh.load(path, force="mesh")
    out = []
    for layers, atoms, M in SETTINGS:
        V, T = convex_hull(fcp.encode(m, atoms=atoms, layers=layers, device="cpu"), M, N_T[M])
        raw = trimesh.Trimesh(V, T, process=False)
        mg = trimesh.Trimesh(V, T, process=False); mg.merge_vertices(digits_vertex=10); mg.remove_degenerate_faces() if hasattr(mg, "remove_degenerate_faces") else None
        dup = len(V) - len(np.unique(V, axis=0))
        E = np.sort(np.concatenate([T[:, [0, 1]], T[:, [1, 2]], T[:, [2, 0]]]), 1)
        _, c = np.unique(E, axis=0, return_counts=True)
        out.append(f"{layers}/{atoms}/{M}: open {(c == 1).sum()} over-shared {(c > 2).sum()} of {len(c)}")
    print(name, " | ".join(out), flush=True)
