"""G5 gate checker: bridge bearings (BB) and sole plates (SP), check C11, inside Rhino 8. Globals: __rhino_doc__, EXPECTED_PATH, RESULT_PATH. Expected values from EXPECTED_PATH section G5 (D2 ELEVATION TABLE, 솔플레이트 상세 TABLE, user rules); orientation is compared with the modelled h2 pads (BP). Generator params are not read. Ported from Code/교각모델링/verify_bearing_plates.py (same checks and order). """ import json import math import os import sys import Rhino.Geometry as rg from Rhino.DocObjects import ObjectColorSource sys.path.insert(0, os.path.dirname(__file__)) from _common import all_objects, load_expected # noqa: E402 doc = __rhino_doc__ X = load_expected(EXPECTED_PATH) PID, G = X["pier_id"], X["G5"] ELX = {int(k): v for k, v in G["el_x"].items()} S = {int(k): v for k, v in G["S"].items()} W = {int(k): v for k, v in G["W"].items()} L, T, H3, SHRINK = G["L"], G["T"], G["h3"], G.get("bearing_shrink") # per-bearing values (Ulsan 2026-10-13): L / T / h3 may be {no: value}; bearing_size {no: [along, across]} replaces # the (L-shrink) x (W-shrink) rule; thick_end "-Y" (Ungok, default) or "+Y" per = lambda v, no: v[str(no)] if isinstance(v, dict) else v BSIZE = {int(k): v for k, v in G.get("bearing_size", {}).items()} THICK = G.get("thick_end", "-Y") COL_B, COL_S = tuple(G["colours"]["bearing"]), tuple(G["colours"]["sole_plate"]) results = [] 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 edges_xy(brep, top=False): """Return horizontal edge vectors of the lowest (or highest) face (4 edges). Pads use the top face: their bottom may follow a sloped pedestal top (Okseong P1, 2026-10-14).""" zref = (max if top else 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 - zref) < 0.01 and abs(b.Z - zref) < 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 (W > L occurs).""" 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(): objs = all_objects(doc) 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(f"{PID}-BB"), by(f"{PID}-SP"), by(f"{PID}-BP") n = len(ELX) check("bearing count", n, len(bb), tol=0) check("sole plate count", n, len(sp), tol=0) flag(f"all {2 * n} closed solids", all(o.Geometry.IsSolid for o in list(bb.values()) + list(sp.values()))) for no in sorted(ELX): 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", per(H3, no), bx.Max.Z - bx.Min.Z, tol=0.01) ab, cb_ = split_axes(edges_xy(gb)) if no in BSIZE: check(f"NO.{no} bearing across (B)", BSIZE[no][1], cb_.Length, tol=0.5) check(f"NO.{no} bearing along (A)", BSIZE[no][0], ab.Length, tol=0.5) else: check(f"NO.{no} bearing across (W-{SHRINK})", W[no] - SHRINK, cb_.Length, tol=0.5) check(f"NO.{no} bearing along (L-{SHRINK})", per(L, no) - SHRINK, ab.Length, tol=0.5) as_, cs_ = split_axes(edges_xy(gs)) check(f"NO.{no} sole plate across W", W[no], cs_.Length, tol=0.5) check(f"NO.{no} sole plate along L", per(L, no), as_.Length, tol=0.5) check(f"NO.{no} sole plate bottom = bearing top", bx.Max.Z, sx.Min.Z, tol=0.01) long_b, long_s, long_p = ab, as_, split_axes(edges_xy(gp, top=True))[0] 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) 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)) / per(L, no) * 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", per(T, no), sum(z for _, z in proj) / 4 - sx.Min.Z, tol=0.01) flag(f"NO.{no} thick end at {THICK}", sum(lo) > sum(hi) if THICK == "-Y" else sum(hi) > sum(lo)) 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 rgb = lambda a: (a.ObjectColor.R, a.ObjectColor.G, a.ObjectColor.B) flag(f"NO.{no} colours (bearing {COL_B}, sole plate {COL_S})", cb.ColorSource == ObjectColorSource.ColorFromObject and rgb(cb) == COL_B and cs.ColorSource == ObjectColorSource.ColorFromObject and rgb(cs) == COL_S) 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)) main()