"""Verify bridge bearings (P1-BB) and sole plates (P1-SP), check C11, inside Rhino 8. Expected values typed from D2 ELEVATION TABLE (EL.'X', h3) and 솔플레이트 상세 TABLE (S, L, W, T); orientation is compared with the modelled h2 pads (P1-BP). params.json is not read. Globals: __rhino_doc__, RESULT_PATH; optional FINGERPRINT_REF / FINGERPRINT_OUT (all objects except BB/SP). """ import json import math import Rhino.Geometry as rg from Rhino.DocObjects import ObjectColorSource, ObjectEnumeratorSettings doc = __rhino_doc__ ELX = {1: 43625, 2: 43697, 3: 43768, 4: 43840, 5: 43912, 6: 43600, 7: 43672, 8: 43744, 9: 43816, 10: 43887} S = {1: -1.910, 2: -1.907, 3: -1.905, 4: -1.903, 5: -1.901, 6: -1.910, 7: -1.907, 8: -1.905, 9: -1.903, 10: -1.901} W = {1: 740, 2: 740, 3: 890, 4: 740, 5: 740, 6: 640, 7: 640, 8: 750, 9: 640, 10: 640} L, T, H3 = 800, 30, 181 results = [] def ALL(): s = ObjectEnumeratorSettings() s.HiddenObjects = True s.LockedObjects = True return list(doc.Objects.GetObjectList(s)) def check(item, exp, act, tol=1.0): results.append(dict(check="C11", item=item, expected=round(exp, 4), actual=round(act, 4), diff=round(act - exp, 4), tol=tol, result="PASS" if abs(act - exp) <= tol else "FAIL")) def flag(item, ok, detail=""): results.append(dict(check="C11", item=item, detail=detail, result="PASS" if ok else "FAIL")) def fingerprints(): fp = {} for o in ALL(): oid = o.Attributes.GetUserString("id") if not oid or oid.startswith(("P1-BB", "P1-SP")): continue g = o.Geometry bb = g.GetBoundingBox(True) if isinstance(g, rg.Brep): size = g.Faces.Count if oid.startswith("P1-R-") else rg.VolumeMassProperties.Compute(g).Volume / 1e6 else: size = g.GetLength() if isinstance(g, rg.Curve) else 0 fp[oid] = [round(v, 3) for v in (bb.Min.X, bb.Min.Y, bb.Min.Z, bb.Max.X, bb.Max.Y, bb.Max.Z, size)] return fp def edges_xy(brep): """Return horizontal edge vectors of the lowest face (4 edges).""" zmin = min(v.Location.Z for v in brep.Vertices) out = [] for e in brep.Edges: a, b = e.PointAtStart, e.PointAtEnd if abs(a.Z - zmin) < 0.01 and abs(b.Z - zmin) < 0.01 and a.DistanceTo(b) > 1: out.append(b - a) return out def split_axes(vecs): """Bridge-axis (along) edge = within 45 deg of +Y; the other is across. Not by length: NO.3 has W > L (checker fix 2026-10-08).""" along = [v for v in vecs if abs(v.Y) > abs(v.X)] across = [v for v in vecs if abs(v.Y) <= abs(v.X)] return along[0], across[0] def axis_deg(vec): """Angle of a plan vector from +Y, clockwise positive, folded to [-90, 90).""" a = math.degrees(math.atan2(vec.X, vec.Y)) while a >= 90: a -= 180 while a < -90: a += 180 return a def main(): if "FINGERPRINT_OUT" in globals(): fp = fingerprints() json.dump(fp, open(FINGERPRINT_OUT, "w", encoding="utf-8"), indent=0) print("fingerprints written", len(fp)) return objs = ALL() by = lambda p: {int(o.Attributes.GetUserString("id")[len(p):]): o for o in objs if (o.Attributes.GetUserString("id") or "").startswith(p)} bb, sp, pad = by("P1-BB"), by("P1-SP"), by("P1-BP") check("bearing count", 10, len(bb), tol=0) check("sole plate count", 10, len(sp), tol=0) flag("all 20 closed solids", all(o.Geometry.IsSolid for o in list(bb.values()) + list(sp.values()))) for no in range(1, 11): gb, gs, gp = bb[no].Geometry, sp[no].Geometry, pad[no].Geometry bx, sx = gb.GetBoundingBox(True), gs.GetBoundingBox(True) check(f"NO.{no} bearing bottom = EL.'X'", ELX[no], bx.Min.Z) check(f"NO.{no} bearing height h3", H3, bx.Max.Z - bx.Min.Z, tol=0.01) ab, cb_ = split_axes(edges_xy(gb)) check(f"NO.{no} bearing across (W-100)", W[no] - 100, cb_.Length, tol=0.5) check(f"NO.{no} bearing along (L-100)", L - 100, ab.Length, tol=0.5) e_s = edges_xy(gs) as_, cs_ = split_axes(e_s) check(f"NO.{no} sole plate across W", W[no], cs_.Length, tol=0.5) check(f"NO.{no} sole plate along L", L, as_.Length, tol=0.5) check(f"NO.{no} sole plate bottom = bearing top", bx.Max.Z, sx.Min.Z, tol=0.01) # orientation: long edges of bearing / sole plate vs h2 pad long edge long_b, long_s, long_p = ab, as_, split_axes(edges_xy(gp))[0] # plan centre = pad centre (horizontal position) pc = gp.GetBoundingBox(True).Center for nm, g in (("bearing", gb), ("sole plate", gs)): c = g.GetBoundingBox(True).Center check(f"NO.{no} {nm} plan centre offset from pad (mm)", 0, math.hypot(c.X - pc.X, c.Y - pc.Y), tol=1.0) check(f"NO.{no} bearing axis vs pad (deg)", axis_deg(long_p), axis_deg(long_b), tol=0.01) check(f"NO.{no} sole plate axis vs pad (deg)", axis_deg(long_p), axis_deg(long_s), tol=0.01) # slope along the long axis and thick end at -Y top = [v.Location for v in gs.Vertices if v.Location.Z > sx.Min.Z + 1] ua = rg.Vector3d(long_s.X, long_s.Y, 0) ua.Unitize() if ua.Y < 0: ua = -ua # along points to +Y c = rg.Point3d(sum(p.X for p in top) / 4, sum(p.Y for p in top) / 4, 0) proj = [((p - c) * ua, p.Z) for p in top] lo = [z for s_, z in proj if s_ < 0] hi = [z for s_, z in proj if s_ > 0] slope = (sum(hi) / len(hi) - sum(lo) / len(lo)) / L * 100 check(f"NO.{no} sole plate slope S (%) along +Y-ward axis", S[no], slope, tol=0.01) check(f"NO.{no} sole plate centre thickness T", T, sum(z for _, z in proj) / 4 - sx.Min.Z, tol=0.01) flag(f"NO.{no} thick end at -Y", sum(lo) > sum(hi)) # no transverse slope: the two top vertices at the same along-coordinate have equal Z pairs = sorted(proj) check(f"NO.{no} no transverse slope", 0, max(abs(pairs[0][1] - pairs[1][1]), abs(pairs[2][1] - pairs[3][1])), tol=0.01) for a, b2, name in ((gb, gp, "bearing-pad"), (gb, gs, "bearing-sole plate")): r = rg.Brep.CreateBooleanIntersection(a, b2, 0.01) v = sum(rg.VolumeMassProperties.Compute(x).Volume for x in r) if r else 0.0 check(f"NO.{no} overlap {name} (mm3)", 0, v, tol=1.0) cb, cs = bb[no].Attributes, sp[no].Attributes flag(f"NO.{no} colours (bearing black, sole plate 150)", cb.ColorSource == ObjectColorSource.ColorFromObject and (cb.ObjectColor.R, cb.ObjectColor.G, cb.ObjectColor.B) == (0, 0, 0) and cs.ColorSource == ObjectColorSource.ColorFromObject and (cs.ObjectColor.R, cs.ObjectColor.G, cs.ObjectColor.B) == (150, 150, 150)) if "FINGERPRINT_REF" in globals(): ref = json.load(open(FINGERPRINT_REF, encoding="utf-8")) now = fingerprints() worst = max(abs(a - b) for k in ref for a, b in zip(ref[k], now.get(k, [1e9] * 7))) flag("existing objects (v0.1.08) unchanged", set(ref) == set(now) and worst <= 0.001, f"{len(now)}/{len(ref)} max diff {worst}") summ = dict(total=len(results), passed=sum(r["result"] == "PASS" for r in results), failed=sum(r["result"] == "FAIL" for r in results)) json.dump(dict(summary=summ, results=results), open(RESULT_PATH, "w", encoding="utf-8"), ensure_ascii=False, indent=1) print(json.dumps(summ)) for r in results: if r["result"] == "FAIL": print("FAIL", r) main()