fix(engine): 支持倒角角度参数并新增回归测试

This commit is contained in:
2026-08-27 18:48:27 +08:00
parent 9e5aa48c3d
commit 7e199d785d
3 changed files with 170 additions and 3 deletions
@@ -658,6 +658,40 @@ class EngineRuntimeFoundationTests(unittest.TestCase):
self.assertLess(chamfer_result["volume_mm3"], baseline["volume_mm3"])
self.assertAlmostEqual(pattern_result["volume_mm3"], 1000 - 3 * 10 * 3.141592653589793, places=5)
def test_chamfer_consumes_angle_rad_instead_of_silent_45_degree_fallback(self) -> None:
from cdsl_engine.runtime import rebuild_cdsl
import math
base = self._base_block()
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
baseline = rebuild_cdsl(base, root / "baseline.step")
edge = next(item for item in baseline["topology_records"] if item["kind"] == "edge")
selector = {
"kind": "edge", "stable_id": "edge", "source": "solidworks", "confidence": 1,
"owner_feature_id": "base_add", "geometry": edge["geometry"],
}
equal = deepcopy(base)
equal["features"].append({
"id": "chamfer_45", "atomic_id": "chamfer", "depends_on": ["base_add"],
"params": {"distance_mm": 1, "angle_rad": math.pi / 4}, "selectors": [deepcopy(selector)],
})
equal_result = rebuild_cdsl(equal, root / "chamfer-45.step")
# 45° Distance-Angle 等价于等距倒角:tan(45°)=1,切掉 0.5*1*1*10=5 mm³。
self.assertAlmostEqual(equal_result["volume_mm3"], 1000 - 5, places=5)
slanted = deepcopy(base)
slanted["features"].append({
"id": "chamfer_30", "atomic_id": "chamfer", "depends_on": ["base_add"],
"params": {"distance_mm": 1, "angle_rad": math.pi / 6}, "selectors": [deepcopy(selector)],
})
slanted_result = rebuild_cdsl(slanted, root / "chamfer-30.step")
# 30°:第二距离 = 1*tan(30°)≈0.577,切掉 0.5*1*0.577*10≈2.887 mm³,
# 体积明显大于 45° 等距倒角(995),验证 angle_rad 被消费而非静默 45°。
self.assertAlmostEqual(slanted_result["volume_mm3"], 1000 - 0.5 * math.tan(math.pi / 6) * 10, places=5)
def test_linear_pattern_replays_hole_with_explicit_host_frame(self) -> None:
from cdsl_engine.runtime import rebuild_cdsl