from __future__ import annotations import os import struct from pathlib import Path OUTPUT_ROOT = Path(os.environ.get("EVAL_OUTPUT_ROOT", "/home/user/Desktop")) OUTPUT_NAME = "task-038_output.stl" RIB_CENTERS_X = [-40.0, -20.0, 0.0, 20.0, 40.0] EXPECTED_BOUNDS = [[-50.0, -30.0, 0.0], [50.0, 30.0, 40.0]] EXPECTED_VOLUME_MM3 = 52488.706 GEOMETRY_TOL = 0.2 def _parse_stl(path: Path): data = path.read_bytes() triangles = [] if len(data) >= 84: count = struct.unpack(" 1.0 + 1e-9: return None return a[0] + u * (c[0] - a[0]) + v * (b[0] - a[0]) def _point_inside(mesh: Mesh, point): x, y, z = point hits = [] for triangle in mesh.triangles: hit = _ray_hit_x(y, z, triangle) if hit is None or hit <= x + 1e-7: continue if all(abs(hit - previous) > 1e-6 for previous in hits): hits.append(hit) return len(hits) % 2 == 1 def _rib_ok(mesh: Mesh, center_x): x_bounds = [center_x - 1.5, center_x + 1.5] visible_triangle_points = [ (0.875, 5.0), (25.0, 5.0), (25.0, 32.5714286), ] if not all( _near_vertex(mesh, (x, y, z)) for x in x_bounds for y, z in visible_triangle_points ): return False for y in (5.0, 15.0, 24.0): slope_top_z = 4.0 + (32.0 / 28.0) * y for x_offset in (-1.4, 0.0, 1.4): if not _point_inside(mesh, (center_x + x_offset, y, slope_top_z - 0.3)): return False if _point_inside(mesh, (center_x, y, slope_top_z + 0.3)): return False thickness_outside_probes = [ (center_x - 1.7, 10.0, 10.0), (center_x + 1.7, 10.0, 10.0), ] return not any(_point_inside(mesh, probe) for probe in thickness_outside_probes) def evaluate() -> bool: path = OUTPUT_ROOT / OUTPUT_NAME if not path.is_file() or path.stat().st_size <= 0: return False triangles = _parse_stl(path) if len(triangles) < 40: return False mesh = Mesh(triangles) if len(mesh.vertices) < 24: return False if any( not _close(mesh.mins[axis], EXPECTED_BOUNDS[0][axis]) or not _close(mesh.maxs[axis], EXPECTED_BOUNDS[1][axis]) for axis in range(3) ): return False if not _topology_ok(mesh): return False if abs(abs(_signed_volume(mesh)) - EXPECTED_VOLUME_MM3) > 8.0: return False bracket_solid_probes = [ (0.0, 0.0, 2.5), (0.0, 27.5, 20.0), (-49.0, 0.0, 2.5), (49.0, 27.5, 20.0), ] if not all(_point_inside(mesh, probe) for probe in bracket_solid_probes): return False return all(_rib_ok(mesh, center_x) for center_x in RIB_CENTERS_X) if __name__ == "__main__": try: result = evaluate() except Exception: result = False print("True" if result else "False")