diff --git a/surfaces/blender/tests/fixtures/ram_rays.json b/surfaces/blender/tests/fixtures/ram_rays.json new file mode 100644 index 0000000..788d9ee --- /dev/null +++ b/surfaces/blender/tests/fixtures/ram_rays.json @@ -0,0 +1 @@ +{"about":"The rocker's twin plates of the R-3 bell crank as Imagination's jointlib builds them (one shell, triangulated, at rest), and points between the plates (|x| under 0.349, the plates begin at 0.35): each stands on the oracle's first ray 0.004 to 0.02 short of a vertex or an edge of the shell. Every point is outside.","verts":[[-0.349999994,0.740011215,0.389170021],[-0.349999994,0.752862871,0.394919485],[-0.349999994,0.763308823,0.404358923],[-0.349999994,0.770326555,0.416564375],[-0.349999994,0.773229182,0.430341005],[-0.349999994,0.77173245,0.444340348],[-0.349999994,0.765982985,0.457191974],[-0.349999994,0.756543517,0.467637926],[-0.349999994,0.744338095,0.474655658],[-0.349999994,0.730561495,0.477558255],[-0.349999994,0.716562152,0.476061553],[-0.349999994,0.305388123,0.365099549],[-0.349999994,0.292536497,0.359350085],[-0.349999994,0.282090545,0.349910617],[-0.349999994,0.275072783,0.337705195],[-0.349999994,0.272170216,0.323928565],[-0.349999994,0.273666918,0.309929222],[-0.349999994,0.279416382,0.297077596],[-0.349999994,0.288855821,0.286631644],[-0.349999994,0.301061243,0.279613912],[-0.349999994,0.314837903,0.276711315],[-0.349999994,0.328837216,0.278208017],[-0.38499999,0.740011215,0.389170021],[-0.38499999,0.752862871,0.394919485],[-0.38499999,0.763308823,0.404358923],[-0.38499999,0.770326555,0.416564375],[-0.38499999,0.773229182,0.430341005],[-0.38499999,0.77173245,0.444340348],[-0.38499999,0.765982985,0.457191974],[-0.38499999,0.756543517,0.467637926],[-0.38499999,0.744338095,0.474655658],[-0.38499999,0.730561495,0.477558255],[-0.38499999,0.716562152,0.476061553],[-0.38499999,0.305388123,0.365099549],[-0.38499999,0.292536497,0.359350085],[-0.38499999,0.282090545,0.349910617],[-0.38499999,0.275072783,0.337705195],[-0.38499999,0.272170216,0.323928565],[-0.38499999,0.273666918,0.309929222],[-0.38499999,0.279416382,0.297077596],[-0.38499999,0.288855821,0.286631644],[-0.38499999,0.301061243,0.279613912],[-0.38499999,0.314837903,0.276711315],[-0.38499999,0.328837216,0.278208017],[-0.349999994,0.514849424,0.463428885],[-0.349999994,0.522187293,0.473566681],[-0.349999994,0.526033282,0.485475808],[-0.349999994,0.526010931,0.497990549],[-0.349999994,0.522122383,0.509885848],[-0.349999994,0.514748275,0.519997358],[-0.349999994,0.504610479,0.527335227],[-0.349999994,0.492701381,0.531181216],[-0.349999994,0.480186641,0.531158805],[-0.349999994,0.468291312,0.527270257],[-0.349999994,0.458179832,0.519896209],[-0.349999994,0.288777888,0.349887431],[-0.349999994,0.28144002,0.339749664],[-0.349999994,0.27759403,0.327840507],[-0.349999994,0.277616382,0.315325767],[-0.349999994,0.281504929,0.303430468],[-0.349999994,0.288879007,0.293318987],[-0.349999994,0.299016804,0.285981119],[-0.349999994,0.310925931,0.282135129],[-0.349999994,0.323440671,0.282157511],[-0.349999994,0.335336,0.286046058],[-0.349999994,0.345447481,0.293420136],[-0.38499999,0.514849424,0.463428885],[-0.38499999,0.522187293,0.473566681],[-0.38499999,0.526033282,0.485475808],[-0.38499999,0.526010931,0.497990549],[-0.38499999,0.522122383,0.509885848],[-0.38499999,0.514748275,0.519997358],[-0.38499999,0.504610479,0.527335227],[-0.38499999,0.492701381,0.531181216],[-0.38499999,0.480186641,0.531158805],[-0.38499999,0.468291312,0.527270257],[-0.38499999,0.458179832,0.519896209],[-0.38499999,0.288777888,0.349887431],[-0.38499999,0.28144002,0.339749664],[-0.38499999,0.27759403,0.327840507],[-0.38499999,0.277616382,0.315325767],[-0.38499999,0.281504929,0.303430468],[-0.38499999,0.288879007,0.293318987],[-0.38499999,0.299016804,0.285981119],[-0.38499999,0.310925931,0.282135129],[-0.38499999,0.323440671,0.282157511],[-0.38499999,0.335336,0.286046058],[-0.38499999,0.345447481,0.293420136],[0.349999994,0.740011215,0.389170021],[0.349999994,0.752862871,0.394919485],[0.349999994,0.763308823,0.404358923],[0.349999994,0.770326555,0.416564375],[0.349999994,0.773229182,0.430341005],[0.349999994,0.77173245,0.444340348],[0.349999994,0.765982985,0.457191974],[0.349999994,0.756543517,0.467637926],[0.349999994,0.744338095,0.474655658],[0.349999994,0.730561495,0.477558255],[0.349999994,0.716562152,0.476061553],[0.349999994,0.305388123,0.365099549],[0.349999994,0.292536497,0.359350085],[0.349999994,0.282090545,0.349910617],[0.349999994,0.275072783,0.337705195],[0.349999994,0.272170216,0.323928565],[0.349999994,0.273666918,0.309929222],[0.349999994,0.279416382,0.297077596],[0.349999994,0.288855821,0.286631644],[0.349999994,0.301061243,0.279613912],[0.349999994,0.314837903,0.276711315],[0.349999994,0.328837216,0.278208017],[0.38499999,0.740011215,0.389170021],[0.38499999,0.752862871,0.394919485],[0.38499999,0.763308823,0.404358923],[0.38499999,0.770326555,0.416564375],[0.38499999,0.773229182,0.430341005],[0.38499999,0.77173245,0.444340348],[0.38499999,0.765982985,0.457191974],[0.38499999,0.756543517,0.467637926],[0.38499999,0.744338095,0.474655658],[0.38499999,0.730561495,0.477558255],[0.38499999,0.716562152,0.476061553],[0.38499999,0.305388123,0.365099549],[0.38499999,0.292536497,0.359350085],[0.38499999,0.282090545,0.349910617],[0.38499999,0.275072783,0.337705195],[0.38499999,0.272170216,0.323928565],[0.38499999,0.273666918,0.309929222],[0.38499999,0.279416382,0.297077596],[0.38499999,0.288855821,0.286631644],[0.38499999,0.301061243,0.279613912],[0.38499999,0.314837903,0.276711315],[0.38499999,0.328837216,0.278208017],[0.349999994,0.514849424,0.463428885],[0.349999994,0.522187293,0.473566681],[0.349999994,0.526033282,0.485475808],[0.349999994,0.526010931,0.497990549],[0.349999994,0.522122383,0.509885848],[0.349999994,0.514748275,0.519997358],[0.349999994,0.504610479,0.527335227],[0.349999994,0.492701381,0.531181216],[0.349999994,0.480186641,0.531158805],[0.349999994,0.468291312,0.527270257],[0.349999994,0.458179832,0.519896209],[0.349999994,0.288777888,0.349887431],[0.349999994,0.28144002,0.339749664],[0.349999994,0.27759403,0.327840507],[0.349999994,0.277616382,0.315325767],[0.349999994,0.281504929,0.303430468],[0.349999994,0.288879007,0.293318987],[0.349999994,0.299016804,0.285981119],[0.349999994,0.310925931,0.282135129],[0.349999994,0.323440671,0.282157511],[0.349999994,0.335336,0.286046058],[0.349999994,0.345447481,0.293420136],[0.38499999,0.514849424,0.463428885],[0.38499999,0.522187293,0.473566681],[0.38499999,0.526033282,0.485475808],[0.38499999,0.526010931,0.497990549],[0.38499999,0.522122383,0.509885848],[0.38499999,0.514748275,0.519997358],[0.38499999,0.504610479,0.527335227],[0.38499999,0.492701381,0.531181216],[0.38499999,0.480186641,0.531158805],[0.38499999,0.468291312,0.527270257],[0.38499999,0.458179832,0.519896209],[0.38499999,0.288777888,0.349887431],[0.38499999,0.28144002,0.339749664],[0.38499999,0.27759403,0.327840507],[0.38499999,0.277616382,0.315325767],[0.38499999,0.281504929,0.303430468],[0.38499999,0.288879007,0.293318987],[0.38499999,0.299016804,0.285981119],[0.38499999,0.310925931,0.282135129],[0.38499999,0.323440671,0.282157511],[0.38499999,0.335336,0.286046058],[0.38499999,0.345447481,0.293420136]],"faces":[[19,21,11],[24,22,32],[22,1,0],[23,2,1],[24,3,2],[25,4,3],[26,5,4],[27,6,5],[28,7,6],[29,8,7],[30,9,8],[31,10,9],[32,11,10],[33,12,11],[34,13,12],[35,14,13],[36,15,14],[37,16,15],[38,17,16],[39,18,17],[40,19,18],[41,20,19],[42,21,20],[43,0,21],[63,65,55],[68,66,76],[66,45,44],[67,46,45],[68,47,46],[69,48,47],[70,49,48],[71,50,49],[72,51,50],[73,52,51],[74,53,52],[75,54,53],[76,55,54],[77,56,55],[78,57,56],[79,58,57],[80,59,58],[81,60,59],[82,61,60],[83,62,61],[84,63,62],[85,64,63],[86,65,64],[87,44,65],[95,93,91],[122,124,128],[89,110,88],[90,111,89],[91,112,90],[92,113,91],[93,114,92],[94,115,93],[95,116,94],[96,117,95],[97,118,96],[98,119,97],[99,120,98],[100,121,99],[101,122,100],[102,123,101],[103,124,102],[104,125,103],[105,126,104],[106,127,105],[107,128,106],[108,129,107],[109,130,108],[88,131,109],[141,139,135],[166,168,172],[133,154,132],[134,155,133],[135,156,134],[136,157,135],[137,158,136],[138,159,137],[139,160,138],[140,161,139],[141,162,140],[142,163,141],[143,164,142],[144,165,143],[145,166,144],[146,167,145],[147,168,146],[148,169,147],[149,170,148],[150,171,149],[151,172,150],[152,173,151],[153,174,152],[132,175,153],[21,0,10],[0,1,10],[1,2,3],[3,4,5],[5,6,7],[7,8,9],[9,10,3],[10,11,21],[3,10,1],[11,12,13],[13,14,15],[15,16,19],[16,17,19],[17,18,19],[19,20,21],[3,5,7],[7,9,3],[11,13,19],[13,15,19],[22,43,33],[43,42,33],[42,41,40],[40,39,38],[38,37,40],[37,36,40],[36,35,34],[34,33,40],[33,32,22],[40,33,42],[32,31,30],[30,29,28],[28,27,26],[26,25,28],[25,24,28],[24,23,22],[36,34,40],[32,30,24],[30,28,24],[22,23,1],[23,24,2],[24,25,3],[25,26,4],[26,27,5],[27,28,6],[28,29,7],[29,30,8],[30,31,9],[31,32,10],[32,33,11],[33,34,12],[34,35,13],[35,36,14],[36,37,15],[37,38,16],[38,39,17],[39,40,18],[40,41,19],[41,42,20],[42,43,21],[43,22,0],[65,44,54],[44,45,54],[45,46,47],[47,48,49],[49,50,47],[50,51,47],[51,52,53],[53,54,47],[54,55,65],[47,54,45],[55,56,57],[57,58,59],[59,60,61],[61,62,63],[63,64,65],[51,53,47],[55,57,63],[57,59,63],[59,61,63],[66,87,77],[87,86,77],[86,85,84],[84,83,80],[83,82,80],[82,81,80],[80,79,78],[78,77,84],[77,76,66],[84,77,86],[76,75,74],[74,73,72],[72,71,68],[71,70,68],[70,69,68],[68,67,66],[80,78,84],[76,74,68],[74,72,68],[66,67,45],[67,68,46],[68,69,47],[69,70,48],[70,71,49],[71,72,50],[72,73,51],[73,74,52],[74,75,53],[75,76,54],[76,77,55],[77,78,56],[78,79,57],[79,80,58],[80,81,59],[81,82,60],[82,83,61],[83,84,62],[84,85,63],[85,86,64],[86,87,65],[87,66,44],[89,88,98],[88,109,99],[109,108,107],[107,106,105],[105,104,107],[104,103,107],[103,102,101],[101,100,99],[99,98,88],[98,97,91],[97,96,95],[95,94,93],[93,92,91],[91,90,89],[109,107,99],[103,101,107],[101,99,107],[98,91,89],[97,95,91],[130,131,121],[131,110,120],[110,111,112],[112,113,116],[113,114,116],[114,115,116],[116,117,118],[118,119,120],[120,121,131],[121,122,128],[122,123,124],[124,125,128],[125,126,128],[126,127,128],[128,129,130],[110,112,120],[116,118,112],[118,120,112],[121,128,130],[89,111,110],[90,112,111],[91,113,112],[92,114,113],[93,115,114],[94,116,115],[95,117,116],[96,118,117],[97,119,118],[98,120,119],[99,121,120],[100,122,121],[101,123,122],[102,124,123],[103,125,124],[104,126,125],[105,127,126],[106,128,127],[107,129,128],[108,130,129],[109,131,130],[88,110,131],[133,132,142],[132,153,143],[153,152,151],[151,150,149],[149,148,147],[147,146,145],[145,144,143],[143,142,132],[142,141,135],[141,140,139],[139,138,135],[138,137,135],[137,136,135],[135,134,133],[153,151,143],[151,149,147],[147,145,151],[145,143,151],[142,135,133],[174,175,165],[175,154,164],[154,155,156],[156,157,158],[158,159,156],[159,160,156],[160,161,162],[162,163,164],[164,165,175],[165,166,172],[166,167,168],[168,169,170],[170,171,168],[171,172,168],[172,173,174],[154,156,164],[160,162,156],[162,164,156],[165,172,174],[133,155,154],[134,156,155],[135,157,156],[136,158,157],[137,159,158],[138,160,159],[139,161,160],[140,162,161],[141,163,162],[142,164,163],[143,165,164],[144,166,165],[145,167,166],[146,168,167],[147,169,168],[148,170,169],[149,171,170],[150,172,171],[151,173,172],[152,174,173],[153,175,174],[132,154,175]],"points":[[0.34569818,0.758339776,0.399797897],[0.34569818,0.765357508,0.412003349],[0.33924546,0.757903937,0.405161809],[0.34569818,0.768260135,0.425779979],[0.343547274,0.765775611,0.423499465],[0.33924546,0.760806564,0.418938439],[0.34569818,0.766763402,0.439779322],[0.343547274,0.764278879,0.437498808],[0.33924546,0.759309832,0.432937782],[0.34569818,0.761013938,0.452630947],[0.343547274,0.758529415,0.450350434],[0.33924546,0.753560368,0.445789407],[0.34569818,0.75157447,0.4630769],[0.343547274,0.749089947,0.460796386],[0.33924546,0.744120899,0.45623536],[0.347849087,0.741853572,0.472375145],[0.34569818,0.739369048,0.470094631],[0.343547274,0.736884525,0.467814118],[0.33924546,0.731915478,0.463253092],[0.347849087,0.728076971,0.475277742],[0.34569818,0.725592448,0.472997229],[0.343547274,0.723107924,0.470716715],[0.33924546,0.718138877,0.466155689],[0.347849087,0.714077628,0.473781039]]} \ No newline at end of file diff --git a/surfaces/blender/tests/live/ram_knee.py b/surfaces/blender/tests/live/ram_knee.py index d364092..33dc608 100644 --- a/surfaces/blender/tests/live/ram_knee.py +++ b/surfaces/blender/tests/live/ram_knee.py @@ -1,7 +1,7 @@ """Live proof, in a background Blender, of brokkr_kitbash/ram.py's clearance gate on meshes: the R-3 knee (thigh, shin, the bracket and horn, a bell crank's or a four-bar's plates, pins and clevises), every piece a closed mesh this -file generates, each a named part of a body, and the gate answered by a signed BVH oracle over them. Not part of the -unittest run: it needs Blender (mathutils' BVHTree). +file generates, each a named part of a body, and the gate answered by the package's signed BVH oracle (ram.Signed) +over them. Not part of the unittest run: it needs Blender (mathutils' BVHTree). blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/ram_knee.py -- @@ -9,9 +9,9 @@ Run it with private BLENDER_USER_CONFIG, BLENDER_USER_EXTENSIONS and BLENDER_USE without them). is an absolute path; writes .result.json and .r3_.png (the bell crank at 0, -62.5 and -125) and exits 1 when a check failed. -The oracle. distance(part, points) is the nearest face's distance, negative where the point is inside one of the -part's shells. Inside is the crossing parity of three rays, by majority: one ray that grazes an edge or a vertex -miscounts, and an isolated sample then reads inside a plate it stands clear of. +The oracle is ram.Signed, three rays by majority. Its ray count is held by tests/fixtures/ram_rays.json: the rocker +plates as Imagination's jointlib builds them and points between the plates that stand on the first ray short of an +edge or a vertex. One ray reads them inside a plate they stand clear of; the oracle as it is made reads none inside. A clearance verdict is a sign, the gate's own. FLAT follows lodur:ruling:deterministic-bound-margin. The checks run inside one try: an uncaught error is a failed check that names its section, and the result file is always written. @@ -30,7 +30,6 @@ import bmesh import bpy import numpy as np from mathutils import Matrix, Vector -from mathutils.bvhtree import BVHTree SURFACE = Path(__file__).resolve().parents[2] sys.path.insert(0, str(SURFACE / "tools")) @@ -46,6 +45,7 @@ spec = importlib.util.spec_from_file_location("brokkr_kitbash_ram", SURFACE / "b R = importlib.util.module_from_spec(spec) # ram.py as the unit tests load it sys.modules[spec.name] = R spec.loader.exec_module(R) +Signed = R.Signed RES = {"blender": bpy.app.version_string, "checks": [], "readings": {}} SECTION = ["setup"] @@ -67,7 +67,6 @@ CRANK = {"a": (0.45, 1.15), "rocker": (0.3171126791600819, 0.3216537818398838), "c": (0.34929485118682846, 0.14862538079826304), "d": (0.48651463351122515, 0.49166254003196397)} ROOTS = {"bell_crank": {"horn": (0.10, -0.40), "bracket": (0.10, 0.55)}, "four_bar": {"horn": (0.0, -0.42), "bracket": (-0.10, 0.55)}} THIGH_FRONT, EMBED = 0.14, 0.01 # the thigh core's faces stand at y +-0.14; a foot runs this far into it -RAYS = [Vector(v).normalized() for v in ((0.5377, 0.6211, 0.5701), (-0.7071, 0.2903, 0.6447), (0.1873, -0.8011, -0.5684))] def check(name, ok, detail=None): @@ -138,44 +137,6 @@ def knee(kind, pn, links=True): return shells, {part: {"parent": "parent", "child": "child", "rocker": "rocker", "coupler": "coupler"}[part.split(".")[0]] for part in shells} -class Signed: - """distance(part, points): negative inside a part's shell (the depth below its nearest face), capped outside - only. Inside is the crossing parity of `rays` rays, by majority. An unknown part raises.""" - - def __init__(self, shells, cap=None, rays=3): - self.cap, self.asked, self.rays = cap, 0, RAYS[:rays] - self.trees = {part: [(BVHTree.FromPolygons(v.tolist(), f, epsilon=0.0), v.min(axis=0), v.max(axis=0)) for v, f in made] for part, made in shells.items()} - - @staticmethod - def crossings(tree, v, ray): - count, o = 0, v - for _ in range(64): - loc = tree.ray_cast(o, ray)[0] - if loc is None: - break - count, o = count + 1, loc + ray * 1e-6 - return count - - def inside(self, tree, v): - return 2 * sum(self.crossings(tree, v, ray) % 2 for ray in self.rays) > len(self.rays) - - def __call__(self, part, pts): - pts = np.asarray(pts, dtype=float) - self.asked += len(pts) - out = np.full(len(pts), math.inf if self.cap is None else self.cap) - for tree, lo, hi in self.trees[part]: - boxed = ((pts >= lo) & (pts <= hi)).all(axis=1) - for i, p in enumerate(pts): - v = Vector(p) - if boxed[i] and self.inside(tree, v): - out[i] = min(out[i], -tree.find_nearest(v)[3]) - continue - hit = tree.find_nearest(v, self.cap) if self.cap else tree.find_nearest(v) - if hit[0] is not None and hit[3] < out[i]: - out[i] = hit[3] - return out - - def near(ram, member): return {"barrel": ram.barrel_r, "rod": ram.rod}.get(member, ram.link_r) + ram.gap + ram.spacing() / 2 @@ -205,23 +166,30 @@ def crossing(m, kind): def zones(m, ram, parts): """Each member's zones. About a pin: the pin's, collar's or cheek's radius plus what the member keeps, as deep as the pin where it runs through the member's eye and 0 beside a collar, a cheek, the bracket or the horn; a link's - own plate over its length, half its thickness deep; a plate beside a link as far as the two part. A depth that - is not 0 is stated SLACK over the burial.""" + own plate about both its pins, each a little over half its length (a zone is no wider than its member), half + the plate's thickness deep; a plate beside a link as far as the two part. A depth that is not 0 is stated SLACK + over the burial.""" kind, link, at = m.kind, near(ram, "rocker"), crossing(m, m.kind) PIN, AXLE, HALF = (value + SLACK for value in (globals()["PIN"], globals()["AXLE"], globals()["HALF"])) reach = {"pin": globals()["PIN"] + link, "axle": globals()["AXLE"] + link} eye = "rocker.pin.d" if kind == "bell_crank" else "rocker.pin.p" + + def own(part, a, b, span): + return [(part, a, 0.51 * span, HALF), (part, b, 0.51 * span, HALF)] + + def parts_at(member, w, degrees): # never wider than the member: two that cross at a few degrees part beyond its length + return min(parting(ram, w, degrees), R._span(m, member)) touch = {member: [("parent.seat", "a", 1.7 * BORE + near(ram, member), 0.0), ("rocker.seat", "d", COLLAR + near(ram, member), 0.0), (eye, "d", globals()["PIN"] + near(ram, member), PIN if member == "rod" else 0.0)] for member in ("barrel", "rod")} pivot = [("parent.bracket", "rocker", None, 0.0), ("rocker.pin.R", "rocker", reach["axle"], AXLE)] - touch["rocker"] = pivot + [("rocker.pin.p", "p", reach["pin"], PIN), ("rocker.plate", "rocker", 1.01 * m.lr, HALF), ("coupler.plate", "p", parting(ram, W_COUPLER, at["p"]), 0.0)] - touch["coupler"] = [("child.horn", "c", parting(ram, W_HORN, at["coupler"]), 0.0), ("coupler.pin.c", "c", reach["pin"], PIN), ("rocker.pin.p", "p", reach["pin"], PIN), - ("coupler.plate", "p", 1.01 * m.lc, HALF), ("rocker.plate", "p", parting(ram, W_ROCKER, at["p"]), 0.0)] + touch["rocker"] = pivot + [("rocker.pin.p", "p", reach["pin"], PIN), *own("rocker.plate", "rocker", "p", m.lr), ("coupler.plate", "p", parts_at("rocker", W_COUPLER, at["p"]), 0.0)] + touch["coupler"] = [("child.horn", "c", parts_at("coupler", W_HORN, at["coupler"]), 0.0), ("coupler.pin.c", "c", reach["pin"], PIN), ("rocker.pin.p", "p", reach["pin"], PIN), + *own("coupler.plate", "p", "c", m.lc), ("rocker.plate", "p", parts_at("coupler", W_ROCKER, at["p"]), 0.0)] if kind == "bell_crank": - touch["rocker arm"] = pivot + [("rocker.pin.d", "d", reach["pin"], PIN), ("rocker.plate", "rocker", 1.01 * float(np.linalg.norm(R._flat(m.d - m.rocker, m.axis))), HALF)] + touch["rocker arm"] = pivot + [("rocker.pin.d", "d", reach["pin"], PIN), *own("rocker.plate", "rocker", "d", R._span(m, "rocker arm"))] for member in ("rocker", "rocker arm"): if member in touch: - touch[member][0] = ("parent.bracket", "rocker", parting(ram, W_BRACKET, at[member]), 0.0) + touch[member][0] = ("parent.bracket", "rocker", parts_at(member, W_BRACKET, at[member]), 0.0) return {member: [zone for zone in given if zone[0] in parts] for member, given in touch.items()} @@ -353,6 +321,16 @@ try: exact = np.maximum.reduce([np.abs(cloud[:, 0]) - 0.13, np.abs(cloud[:, 1]) - 0.14, np.abs(cloud[:, 2] - 0.725) - 0.425]) check("three-rays: 4000 random points about a box are signed as the box signs them", ((core < 0) == (exact < 0)).all(), int(((core < 0) != (exact < 0)).sum())) + # the ray count: the jointlib rocker plates, and points between them aimed along the first ray at an edge or a vertex + fixture = json.loads((SURFACE / "tests" / "fixtures" / "ram_rays.json").read_text(encoding="utf-8")) + plates, aimed = {"plates": [(np.array(fixture["verts"]), fixture["faces"])]}, np.array(fixture["points"]) + made, single = Signed(plates)("plates", aimed), Signed(plates, rays=1)("plates", aimed) + RES["readings"]["jointlib plates: points one ray signs inside, of %d" % len(aimed)] = int((single < 0).sum()) + RES["readings"]["jointlib plates: points the oracle signs inside"] = int((made < 0).sum()) + # one ray reads all 24 inside; the oracle as made reads none. The bound on one ray's count is the geometric mean of 1 and 24 + check("ray-count: between the jointlib rocker plates, points on the first ray short of an edge or a vertex read outside by the oracle as it is made, inside by one ray", + (np.abs(aimed[:, 0]) < 0.349).all() and (made > 0).all() and (single < 0).sum() >= 5, [int((made < 0).sum()), int((single < 0).sum())]) + SECTION[0] = "seat" seat = np.concatenate([v for v, _ in shells["parent.seat"]]) deepest = float(Signed(shells)("parent.body", seat).min()) @@ -375,8 +353,15 @@ try: check(f"bell-crank-clears-on-meshes (side {side:+.0f}): and at 251 steps with the oracle uncapped", fine.ok, [fine.report(), refused(fine)]) bare = R._fit(replace(m, touch={}), ram, steps=49, distance=Signed(shells, ram.reach())) need = needs(m, ram, parts, Signed(shells)) - stated = {(label(member), zone[0]): zone for member, given in touch.items() for zone in given} - slack = {pair: (stated[pair][1] == pin and stated[pair][2] >= radius and stated[pair][3] >= depth) for pair, (pin, radius, depth) in need.items() if pair in stated} + stated = {} + for member, given in touch.items(): + for zone in given: + stated.setdefault((label(member), zone[0]), []).append(zone) + + def takes(given, pin, radius, depth): # one zone about the pin, or zones about both of the member's pins that meet + return all(zone[3] >= depth for zone in given) and (any(zone[1] == pin and zone[2] >= radius for zone in given) + or (len({zone[1] for zone in given}) == 2 and sum(zone[2] for zone in given) >= radius)) + slack = {pair: takes(stated[pair], *least) for pair, least in need.items() if pair in stated} check(f"zones (side {side:+.0f}): with nothing let the gate refuses, and only pairs the record zones; each stated zone takes in the least that lets its pair", {pair for pair, _, _ in refused(bare)} == set(need) and set(need) <= zoned and all(slack.values()), [refused(bare), sorted(set(need) - zoned), [k for k, v in slack.items() if not v]]) if side > 0: @@ -387,7 +372,7 @@ try: "bell crank: least margin of a zoned pair, 251 steps uncapped": min(reading[0] for pair, reading in fine.pairs.items() if pair in zoned), "bell crank: pairs": len(f.pairs), "bell crank: zoned pairs": len(f.allowed), "bell crank: pairs refused with nothing let": len(refused(bare)), "bell crank: seconds, 49 steps capped": seconds}) - RES["zones"] = {f"{pair[0]} | {pair[1]}": {"stated": list(stated[pair][1:]), "least": [pin, round(radius, 4), round(depth, 4)]} for pair, (pin, radius, depth) in sorted(need.items()) if pair in stated} + RES["zones"] = {f"{pair[0]} | {pair[1]}": {"stated": [list(zone[1:]) for zone in stated[pair]], "least": [pin, round(radius, 4), round(depth, 4)]} for pair, (pin, radius, depth) in sorted(need.items()) if pair in stated} RES["least pairs"] = sorted((round(v[0], 4), v[1], k[0], k[1]) for k, v in fine.pairs.items() if k not in zoned)[:8] SECTION[0] = "zones end" diff --git a/surfaces/blender/tests/live/ram_knee.result.json b/surfaces/blender/tests/live/ram_knee.result.json index 6ad67fe..8bd0d66 100644 --- a/surfaces/blender/tests/live/ram_knee.result.json +++ b/surfaces/blender/tests/live/ram_knee.result.json @@ -16,6 +16,11 @@ "ok": true, "detail": null }, + { + "name": "ray-count: between the jointlib rocker plates, points on the first ray short of an edge or a vertex read outside by the oracle as it is made, inside by one ray", + "ok": true, + "detail": null + }, { "name": "the base clevis is seated: its foot runs 0.01 into the thigh's core, through the front plate", "ok": true, @@ -103,9 +108,11 @@ "bell crank: least margin of a zoned pair, 251 steps uncapped": 0.000118, "bell crank: pairs": 60, "bell crank: pairs refused with nothing let": 19, - "bell crank: seconds, 49 steps capped": 0.835, + "bell crank: seconds, 49 steps capped": 2.12, "bell crank: zoned pairs": 20, "four bar: barrel inside the shin's clearance": -0.122, + "jointlib plates: points one ray signs inside, of 24": 24, + "jointlib plates: points the oracle signs inside": 0, "moved x: both": -0.0543, "moved x: the coupler at x 0.25, inside the horn's 0.23..0.31": -0.02, "moved x: the rocker at x 0.25, inside the bracket's 0.13..0.35": -0.0543, @@ -113,16 +120,18 @@ "search: candidates": 13824, "search: pass the gates before clearance": 78, "search: refused on their own parts": 21, - "search: seconds": 42.8, + "search: seconds": 43.3, "search: worlds built": 22, "the base clevis's foot inside the thigh": -0.01 }, "zones": { "barrel[0] | parent.seat": { "stated": [ - "a", - 0.15645000000000003, - 0.0 + [ + "a", + 0.15645000000000003, + 0.0 + ] ], "least": [ "a", @@ -132,9 +141,11 @@ }, "barrel[0] | rocker.pin.d": { "stated": [ - "d", - 0.11105000000000001, - 0.0 + [ + "d", + 0.11105000000000001, + 0.0 + ] ], "least": [ "d", @@ -144,9 +155,11 @@ }, "barrel[0] | rocker.seat": { "stated": [ - "d", - 0.13505, - 0.0 + [ + "d", + 0.13505, + 0.0 + ] ], "least": [ "d", @@ -156,9 +169,11 @@ }, "coupler | child.horn": { "stated": [ - "c", - 0.11195, - 0.0 + [ + "c", + 0.11195, + 0.0 + ] ], "least": [ "c", @@ -168,9 +183,11 @@ }, "coupler | coupler.pin.c": { "stated": [ - "c", - 0.08795, - 0.027 + [ + "c", + 0.08795, + 0.027 + ] ], "least": [ "c", @@ -180,9 +197,16 @@ }, "coupler | coupler.plate": { "stated": [ - "p", - 0.47832364050530635, - 0.018500000000000016 + [ + "p", + 0.24152975906703586, + 0.018500000000000016 + ], + [ + "c", + 0.24152975906703586, + 0.018500000000000016 + ] ], "least": [ "p", @@ -192,9 +216,11 @@ }, "coupler | rocker.pin.p": { "stated": [ - "p", - 0.08795, - 0.027 + [ + "p", + 0.08795, + 0.027 + ] ], "least": [ "p", @@ -204,9 +230,11 @@ }, "coupler | rocker.plate": { "stated": [ - "p", - 0.2818973893266964, - 0.0 + [ + "p", + 0.2818973893266964, + 0.0 + ] ], "least": [ "p", @@ -216,9 +244,11 @@ }, "rocker | coupler.plate": { "stated": [ - "p", - 0.26840002998268986, - 0.0 + [ + "p", + 0.26840002998268986, + 0.0 + ] ], "least": [ "p", @@ -228,9 +258,11 @@ }, "rocker | parent.bracket": { "stated": [ - "rocker", - 0.11695, - 0.0 + [ + "rocker", + 0.11695, + 0.0 + ] ], "least": [ "rocker", @@ -240,9 +272,11 @@ }, "rocker | rocker.pin.R": { "stated": [ - "rocker", - 0.08995, - 0.029 + [ + "rocker", + 0.08995, + 0.029 + ] ], "least": [ "rocker", @@ -252,9 +286,11 @@ }, "rocker | rocker.pin.p": { "stated": [ - "p", - 0.08795, - 0.027 + [ + "p", + 0.08795, + 0.027 + ] ], "least": [ "p", @@ -264,9 +300,16 @@ }, "rocker | rocker.plate": { "stated": [ - "rocker", - 0.43014219644091495, - 0.018500000000000016 + [ + "rocker", + 0.2172005150345214, + 0.018500000000000016 + ], + [ + "p", + 0.2172005150345214, + 0.018500000000000016 + ] ], "least": [ "rocker", @@ -276,9 +319,11 @@ }, "rocker arm | parent.bracket": { "stated": [ - "rocker", - 0.11695, - 0.0 + [ + "rocker", + 0.11695, + 0.0 + ] ], "least": [ "rocker", @@ -288,9 +333,11 @@ }, "rocker arm | rocker.pin.R": { "stated": [ - "rocker", - 0.08995, - 0.029 + [ + "rocker", + 0.08995, + 0.029 + ] ], "least": [ "rocker", @@ -300,9 +347,11 @@ }, "rocker arm | rocker.pin.d": { "stated": [ - "d", - 0.08795, - 0.027 + [ + "d", + 0.08795, + 0.027 + ] ], "least": [ "d", @@ -312,9 +361,16 @@ }, "rocker arm | rocker.plate": { "stated": [ - "rocker", - 0.24240000000000003, - 0.018500000000000016 + [ + "rocker", + 0.12240000000000001, + 0.018500000000000016 + ], + [ + "d", + 0.12240000000000001, + 0.018500000000000016 + ] ], "least": [ "rocker", @@ -324,9 +380,11 @@ }, "rod[0] | rocker.pin.d": { "stated": [ - "d", - 0.07955, - 0.027 + [ + "d", + 0.07955, + 0.027 + ] ], "least": [ "d", @@ -336,9 +394,11 @@ }, "rod[0] | rocker.seat": { "stated": [ - "d", - 0.10355, - 0.0 + [ + "d", + 0.10355, + 0.0 + ] ], "least": [ "d", @@ -436,9 +496,9 @@ } }, "renders": [ - "F:/aeth-wt/fable-ramcore/scratch/h3/out/live3.r3_0.png", - "F:/aeth-wt/fable-ramcore/scratch/h3/out/live3.r3_62p5.png", - "F:/aeth-wt/fable-ramcore/scratch/h3/out/live3.r3_125.png" + "F:/aeth-wt/fable-ramcore/scratch/h4/out/live_h4.r3_0.png", + "F:/aeth-wt/fable-ramcore/scratch/h4/out/live_h4.r3_62p5.png", + "F:/aeth-wt/fable-ramcore/scratch/h4/out/live_h4.r3_125.png" ], "ok": true } \ No newline at end of file