Download CODE/evaluation/eval/eval_geometric041.py from QLU-LLM/CAD: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/datasets/QLU-LLM/CAD/resolve/main/CODE/evaluation/eval/eval_geometric041.py
- Command line
-
hf download hf://datasets/QLU-LLM/CAD/CODE/evaluation/eval/eval_geometric041.py
-
curl -L -o eval_geometric041.py https://huggingface.co/datasets/QLU-LLM/CAD/resolve/main/CODE/evaluation/eval/eval_geometric041.py
2.7 kB
| #!/usr/bin/env python3 | |
| """Metric-v4.1 representation normalisation. | |
| Some CAD exports encode an almost-straight outline edge as a huge-radius ARC. | |
| At engineering-drawing tolerance that is the same geometry as its chord, but a | |
| primitive-family matcher treats it as unrelated to a LINE. V4.1 flattens only | |
| arcs whose sagitta is below 0.05 mm or 0.1% of the drawing diagonal, then uses | |
| the otherwise unchanged and tested v4 implementation. | |
| """ | |
| from __future__ import annotations | |
| import math | |
| from typing import Any | |
| try: | |
| from . import eval_geometric02 as EV2 | |
| from . import eval_geometric04 as BASE | |
| except ImportError: | |
| import eval_geometric02 as EV2 | |
| import eval_geometric04 as BASE | |
| extract_entities = BASE.extract_entities | |
| legacy_dimension_entities = BASE.legacy_dimension_entities | |
| representation_quality = BASE.representation_quality | |
| score_dimension_consistency = BASE.score_dimension_consistency | |
| score_disk_semantics = BASE.score_disk_semantics | |
| def _arc_chord(arc: tuple[Any, ...]) -> tuple[float, float, float, float, str]: | |
| cx, cy, radius, start, end, layer = arc | |
| start_rad = math.radians(float(start)) | |
| end_rad = math.radians(float(end)) | |
| return ( | |
| float(cx) + float(radius) * math.cos(start_rad), | |
| float(cy) + float(radius) * math.sin(start_rad), | |
| float(cx) + float(radius) * math.cos(end_rad), | |
| float(cy) + float(radius) * math.sin(end_rad), | |
| str(layer), | |
| ) | |
| def _sagitta(arc: tuple[Any, ...]) -> float: | |
| radius = abs(float(arc[2])) | |
| span = math.radians(float((float(arc[4]) - float(arc[3])) % 360.0)) | |
| return radius * (1.0 - math.cos(span / 2.0)) | |
| def canonicalize_entities( | |
| entities: dict[str, Any], | |
| *, | |
| abs_tol: float = BASE.CANONICAL_ABS_TOL, | |
| rel_tol: float = BASE.CANONICAL_REL_TOL, | |
| ) -> dict[str, Any]: | |
| """Flatten visually straight arcs, then apply v4 collinear merging.""" | |
| diagonal = max(BASE.EV2.bbox_diagonal(entities), 1.0) | |
| flatten_tolerance = max(0.05, 0.001 * diagonal) | |
| prepared = { | |
| "lines": list(entities.get("lines", [])), | |
| "circles": list(entities.get("circles", [])), | |
| "arcs": [], | |
| "dims": list(entities.get("dims", [])), | |
| } | |
| for arc in entities.get("arcs", []): | |
| if _sagitta(arc) <= flatten_tolerance: | |
| prepared["lines"].append(_arc_chord(arc)) | |
| else: | |
| prepared["arcs"].append(arc) | |
| return BASE.canonicalize_entities( | |
| prepared, | |
| abs_tol=abs_tol, | |
| rel_tol=rel_tol, | |
| ) | |
| __all__ = [ | |
| "canonicalize_entities", | |
| "extract_entities", | |
| "legacy_dimension_entities", | |
| "representation_quality", | |
| "score_dimension_consistency", | |
| "score_disk_semantics", | |
| ] | |