feat(spatial): 接触边的三个局部几何谓词
加入 area.free 之后 area.sup2/sup3 从 1.000 掉到一位规则的 0.594/0.656: "T 有一条接触"不再等于"稳定",模型必须真的判断支撑是否成立,而它得从两个坐标 向量里自己重算——这是把算术交给分类器。 现在每条接触边带上面接触、上块形心是否落在重叠矩形内、上块底面积覆盖率。 这是卡尺和直尺能给出的测量值,不是答案:链是否走到地面仍然要模型自己传播。
This commit is contained in:
1 parent
46b084433f
commit
6fcf644115
2 files changed
+35
-15
No files matched your search
+29
-13
@@ -74,24 +74,38 @@ def entity_features(sc: Scenario, e) -> list:
|
||||
return f
|
||||
|
||||
|
||||
def _contact_area(by_id: dict, ed, per_unit: int = 1) -> float:
|
||||
"""Overlap area of two boxes, normalised so a unit change cannot move it.
|
||||
def _contact_geom(by_id: dict, ed, per_unit: int = 1):
|
||||
"""(area, faces_meet, centroid_inside, area_ratio) for a contact edge.
|
||||
|
||||
Stability depends on how much material two blocks share, not on the fact
|
||||
that they touch; without this the model has to recompute geometry from two
|
||||
coordinate vectors that the value stream never even carried.
|
||||
The checker's stability rule is local: two boxes support each other when
|
||||
their faces actually meet and the upper centroid falls inside the overlap
|
||||
rectangle. Leaving that predicate to be recomputed from two coordinate
|
||||
vectors is leaving arithmetic to a classifier; measuring it per edge is what
|
||||
a caliper would do and it says nothing about the answer.
|
||||
"""
|
||||
a, b = by_id.get(ed.a), by_id.get(ed.b)
|
||||
if a is None or b is None:
|
||||
return 0.0
|
||||
return 0.0, 0.0, 0.0, 0.0
|
||||
ba, bb = a.attrs.get("box"), b.attrs.get("box")
|
||||
if not ba or not bb:
|
||||
return 0.0
|
||||
ox = min(ba[3], bb[3]) - max(ba[0], bb[0])
|
||||
oy = min(ba[4], bb[4]) - max(ba[1], bb[1])
|
||||
if ox <= 0 or oy <= 0:
|
||||
return 0.0
|
||||
return min(1.0, ox * oy / (400.0 * max(1, per_unit) ** 2))
|
||||
return 0.0, 0.0, 0.0, 0.0
|
||||
scale = 400.0 * max(1, per_unit) ** 2
|
||||
ox0, oy0 = max(ba[0], bb[0]), max(ba[1], bb[1])
|
||||
ox1, oy1 = min(ba[3], bb[3]), min(ba[4], bb[4])
|
||||
if ox0 >= ox1 or oy0 >= oy1:
|
||||
return 0.0, 0.0, 0.0, 0.0
|
||||
area = min(1.0, (ox1 - ox0) * (oy1 - oy0) / scale)
|
||||
meet = 1.0 if (ba[5] == bb[2] or bb[5] == ba[2]) else 0.0
|
||||
# the support is the lower one; its centroid has to sit on the overlap
|
||||
up = ba if ba[2] >= bb[2] else bb
|
||||
cx2, cy2 = up[0] + up[3], up[1] + up[4] # twice the centroid, stays integer
|
||||
inside = 1.0 if (2 * ox0 <= cx2 <= 2 * ox1 and 2 * oy0 <= cy2 <= 2 * oy1) else 0.0
|
||||
foot = max(1, (up[3] - up[0]) * (up[4] - up[1]))
|
||||
return area, meet, inside, min(1.0, (ox1 - ox0) * (oy1 - oy0) / foot)
|
||||
|
||||
|
||||
def _contact_area(by_id: dict, ed, per_unit: int = 1) -> float:
|
||||
return _contact_geom(by_id, ed, per_unit)[0]
|
||||
|
||||
|
||||
def edge_features(sc: Scenario, ed, removed: bool, dangling: bool = False) -> list:
|
||||
@@ -103,8 +117,10 @@ def edge_features(sc: Scenario, ed, removed: bool, dangling: bool = False) -> li
|
||||
f[N_EDGE + N_AXIS] = 1.0 if removed else 0.0
|
||||
f[N_EDGE + N_AXIS + 1] = ed.layer / 6.0
|
||||
by_id = {e.eid: e for e in sc.obs.entities}
|
||||
f[N_EDGE + N_AXIS + 2] = _contact_area(by_id, ed, sc.obs.units.get("per_unit", 1))
|
||||
geom = _contact_geom(by_id, ed, sc.obs.units.get("per_unit", 1))
|
||||
f[N_EDGE + N_AXIS + 2] = geom[0]
|
||||
f[N_EDGE + N_AXIS + 3] = 1.0 if dangling else 0.0
|
||||
f[N_EDGE + N_AXIS + 4:N_EDGE + N_AXIS + 7] = list(geom[1:])
|
||||
return f
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user