feat(review): 几何干涉检查 find_collisions(BVH 粗筛 + 容器过滤)
C++(cad_mcp_plugins):
- 新增 bvh.h:header-only 2D BVH(质心中位分割,叶<=4,SelfPairs 交叉对枚举)
- 新增 find_collisions.cpp:粗筛 AABB 相交实体对,附重叠盒 + 逐轴重叠比 ratio
(= 逐轴重叠长/较短长 之积,退化轴取 1.0),按 ratio 降序 + 分页;
narrow=true 只对返回页跑 intersectWith 细筛(附 exact)
- 容器过滤(关键):图框块/分区边界会与一切相交,用重叠【度】判定
deg >= max(exclude_container_deg=8, exclude_container_frac=0.25 * 其他实体数),
与图幅/缩放无关;被剔除者在 excluded_containers 里如实报告
(初版用面积判据对多图框并排失效:3 框只占并集 27/13/7% 全部漏过,
全模型 163 对噪声;改度判据后图框 deg=35/25/23 vs 其余 deg<=3,分离干净)
- cmakelists.txt + 两个 mcp_config.json 注册(28 工具)
agent 侧(Python):
- cad_tools.READ_ONLY_TOOLS += find_collisions(受控子循环可调用)
- checks.check_collisions + run_deterministic_checks(受 CHECK_COLLISIONS 开关,默认关)
- config += CHECK_COLLISIONS=False / COLLISION_MIN_OVERLAP=0.5
- checklist.py / review_checklist.json += 「干涉/碰撞」类别(high)+ 提示词协议
(先 find_collisions 拿候选 → inspect_region 目视确认;AABB 相交 != 真干涉)
验证:
- verify_collisions.py 17/17 PASS:全模型候选 163→80(全部 ratio=0.000),
min_overlap=0.5 → 0 对;逐图框 0 对;narrow top-5 中 4 条 exact=true;
--inject 注入深重叠矩形报出 ratio=0.902 并清理 2/2
- pytest 355 passed(新增 12 项)
- 端到端:LLM 主动调用 find_collisions{min_overlap:0.2,narrow:true,window:<图框>},未误报
This commit is contained in:
1 parent
a77a090281
commit
d4a9442e30
20 files changed
+1152
-13
No files matched your search
@@ -1,6 +1,6 @@
|
||||
"""`dwg_review.cad_tools` 单元测试。"""
|
||||
|
||||
from dwg_review.cad_tools import CadTools, is_write_tool
|
||||
from dwg_review.cad_tools import READ_ONLY_TOOLS, CadTools, is_write_tool
|
||||
from dwg_review.mcp_client import result_json
|
||||
from tests.fakes import FakeMcpClient, ok_text, tool_schema
|
||||
|
||||
@@ -19,10 +19,15 @@ def test_write_exact_names_detected():
|
||||
|
||||
|
||||
def test_readonly_tools_are_not_write():
|
||||
for name in ("query_entities", "get_text_content", "zoom_to_window", "find_zero_length"):
|
||||
for name in ("query_entities", "get_text_content", "zoom_to_window",
|
||||
"find_zero_length", "find_collisions"):
|
||||
assert is_write_tool(name) is False
|
||||
|
||||
|
||||
def test_find_collisions_is_whitelisted():
|
||||
assert "find_collisions" in READ_ONLY_TOOLS
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 注册表
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user