diff --git a/surfaces/blender/tests/test_ram.py b/surfaces/blender/tests/test_ram.py index 8a8c12d..1d43a83 100644 --- a/surfaces/blender/tests/test_ram.py +++ b/surfaces/blender/tests/test_ram.py @@ -499,6 +499,15 @@ SWING_BOUND = 0.81 TOGGLE_ARM = 0.0386 +# The clearance gate's zones on the R-3 bell crank. A reading a hand value states is bounded by its deviation from it; +# a shipped deviation of 0 counts as half an ulp of the value (lodur:ruling:deterministic-bound-zero-reading). +ZONED = 2.2e-10 # a rocker sample against its own plates: shipped 0 (half an ulp of link_r, 1.7e-18), W1..W3 (a zone's edge strict, the first zone only, the last zone overriding) 0.0294 and 0.0914 off, separation 1.3e8 each side +BESIDE = 1.2e-10 # a wall 0.02 beside the coupler, read at the nearest sample: shipped 0 (half an ulp of 0.0242, 1.7e-18), B1 (the proof by the nearer end's reading less the span, which halves and reads beside the wall) 0.00423 off, separation 4.9e7 each side +FLOOR_UNDER = 0.319 # how near the axis a wall held outside reads as touched, in spacing / 64: shipped under 0.451, FINE 128 under 0.2255, separation 1.41 each side +FLOOR_OVER = 0.638 # shipped under 0.451, FINE 32 under 0.902, separation 1.41 each side +SPAN_RAM = 0.848 # the ram's span with its base 0.1 from the rocker's pivot: shipped 0.5390 (about that pivot), the span about the knee's pivot 1.3347, separation 1.57 each side + + @unittest.skipIf(np is None, "numpy is not installed") class DeepKnee(unittest.TestCase): """The R-3 knee over 0..-125 (probes P1 to P3).""" @@ -653,6 +662,16 @@ class DeepKnee(unittest.TestCase): self.assertAlmostEqual(R._span(m, "rocker arm"), 0.24, places=9) self.assertGreaterEqual(R._span(m, "rod"), float(R.pose(m, np.linspace(-125.0, 0.0, 126)).L.max())) self.assertEqual([ram.eye(*of) for of in (("barrel", "a"), ("rod", "a"), ("rod", "d"), ("coupler", "c"))], [ram.e_a, ram.e_a, ram.e_b, ram.link_r]) + # a linkage's ram spans from the rocker's pivot, which its eye turns about, not the knee's: a base seated 0.1 + # from the rocker's pivot makes a ram of 0.539 at the most, and a zone between that and the 1.335 the knee's + # pivot would give is refused + seated = replace(m, a=m.rocker + (0.0, 0.0, 0.1), parts=bodies.parts) + self.assertAlmostEqual(R._span(seated, "rod"), 0.1 + math.hypot(X_ROCKER, 0.24), places=12) + for member in ("barrel", "rod"): + replace(seated, touch={member: [("thigh", "a", 0.53, 0.0)]}) + with self.assertRaises(R.RamError) as caught: + replace(seated, touch={member: [("thigh", "a", SPAN_RAM, 0.0)]}) + self.assertEqual((caught.exception.gate, caught.exception.pin), ("record", f"{member} thigh radius")) for member, pin, part in (("barrel", "a", "thigh"), ("rod", "d", "pin d"), ("rocker", "p", "coupler plates"), ("coupler", "c", "horn"), ("rocker arm", "rocker", "bracket")): span, eye = R._span(m, member), ram.eye(member, pin) @@ -727,8 +746,8 @@ class DeepKnee(unittest.TestCase): start = at.P[0] - np.array(X) * ((at.P[0] - at.C[0]) @ np.array(X)) count = int(math.ceil(m.lc / ram.spacing())) + 1 - def seen(n): - return R._into(m, at, "rocker", (start + (at.C[0] - start) * np.linspace(0.0, 1.0, n)[:, None])[None])[0] + def seen(n, body="rocker"): + return R._into(m, at, body, (start + (at.C[0] - start) * np.linspace(0.0, 1.0, n)[:, None])[None])[0] samples = seen(count) spot = 0.5 * (samples[2] + samples[3]) along = (samples[-1] - samples[0]) / m.lc @@ -740,16 +759,22 @@ class DeepKnee(unittest.TestCase): lo[0], hi[0] = X_COUPLER - 0.05 + shift, X_COUPLER + 0.05 + shift bodies = r3_parts(m, ram) bodies.parts["wall"], bodies.shapes["wall"] = "rocker", [("box", lo, hi)] - self.assertGreater(float(bodies("wall", samples).min()), 0.0) + reading.sampled = float(bodies("wall", samples).min()) + self.assertGreater(reading.sampled, 0.0) return R.clearance(dressed(m, bodies, {"coupler": [("wall", "p", 0.28, 0.0)]}), ram, [-60.0], bodies).pairs[("coupler", "wall")][0] for half in (0.01, 0.003, 1e-4, 1e-7, 1e-10): self.assertLess(reading(half), 0.0, half) - # the same walls beside the axis, 0.02 off along the hinge axis: held outside, and let + # the same walls beside the axis, 0.02 off along the hinge axis: held outside, and let. The samples either + # side prove the segment, so the reading is the nearer sample's (0.0242: 0.02 across, 0.0137 along), not the + # 0.02 a point between them would read for half in (0.01, 1e-7): - self.assertGreaterEqual(reading(half, 0.07), 0.02) - # nearer the axis than the floor of the halving, a part the axis is held outside reads as touched - self.assertLess(reading(0.01, 0.05 + 0.2 * ram.spacing() / R.FINE), 0.0) - self.assertGreaterEqual(reading(0.01, 0.05 + 1.2 * ram.spacing() / R.FINE), 0.0) + self.assertLess(abs(reading(half, 0.07) - reading.sampled), BESIDE, half) + self.assertGreater(reading.sampled, 0.024) + # nearer the axis than the floor of the halving, a part the axis is held outside reads as touched. The floor is + # the spacing over 64, written here as the number: the doc's, and what the gate's cost was measured at + self.assertEqual(R.FINE, 64) + self.assertLess(reading(0.01, 0.05 + FLOOR_UNDER * ram.spacing() / 64), 0.0) + self.assertGreaterEqual(reading(0.01, 0.05 + FLOOR_OVER * ram.spacing() / 64), 0.0) # a segment with one end in the zone is proved as well. Sampled 0.3 apart, the sample beyond the zone keeps its # 0.186 from a bead on the axis 0.008 past the last sample in the zone; the bead is read all the same wide = seen(3) @@ -759,6 +784,15 @@ class DeepKnee(unittest.TestCase): self.assertGreaterEqual(float(bodies("bead", wide[2:])[0]), near(ram, "coupler", 0.3)) got = R.clearance(dressed(m, bodies, {"coupler": [("bead", "p", 0.25, 0.0)]}), ram, [-60.0], bodies, spacing=0.3) self.assertLess(got.pairs[("coupler", "bead")][0], 0.0) + # and so is the segment whose far end alone is in the zone: a bead of the shin 0.008 short of the first sample + # in a zone about c, the sample before it out of the zone and keeping its 0.186 + wide = seen(3, "child") + bodies, spot = r3_parts(m, ram), wide[1] - 0.012 * (wide[2] - wide[0]) / m.lc + bodies.parts["bead"], bodies.shapes["bead"] = "child", [("capsule", spot, spot, 0.004)] + self.assertGreater(float(bodies("bead", wide[1:]).min()), 0.0) + self.assertGreaterEqual(float(bodies("bead", wide[:1])[0]), near(ram, "coupler", 0.3)) + got = R.clearance(dressed(m, bodies, {"coupler": [("bead", "c", 0.25, 0.0)]}), ram, [-60.0], bodies, spacing=0.3) + self.assertLess(got.pairs[("coupler", "bead")][0], 0.0) def test_two_zones_of_one_pair_and_a_sample_at_a_zones_radius(self): # Soul's W1..W3. A pair zoned twice: a sample both reach is let the deeper, in either order, and each zone @@ -773,8 +807,11 @@ class DeepKnee(unittest.TestCase): self.assertAlmostEqual(reading(deep, beside, far), 0.0, places=12) self.assertAlmostEqual(reading(beside, deep, far), 0.0, places=12) self.assertAlmostEqual(reading(far, beside, deep), 0.0, places=12) - for short in ((beside, beside, far), (deep, beside), (far, deep[:2] + (0.3 * m.lr, ram.link_r))): - self.assertLess(reading(*short), -0.9 * ram.link_r, short) + # short of that the sample reads what it is: link_r inside its own plate where the zone holds it outside, and + # where no zone reaches it link_r inside and all it keeps short + own = ram.link_r + near(ram, "rocker") + for short, reads in (((beside, beside, far), -ram.link_r), ((deep, beside), -own), ((far, deep[:2] + (0.3 * m.lr, ram.link_r)), -own)): + self.assertLess(abs(reading(*short) - reads), ZONED, short) at = R.pose(m, [-60.0]) end = at.P - np.array(X) * ((at.P - m.rocker) @ np.array(X))[:, None] count = int(math.ceil(m.lr / ram.spacing())) + 1 @@ -782,7 +819,7 @@ class DeepKnee(unittest.TestCase): across = np.linalg.norm(R._flat(pts - m.rocker, np.array(X)), axis=2)[0] edge, beyond = float(across[3]), m.lr - 0.5 * float(across[3] + across[4]) self.assertAlmostEqual(reading(("rocker plates", "rocker", edge, ram.link_r), ("rocker plates", "p", beyond, ram.link_r), degrees=[-60.0]), 0.0, places=12) - self.assertLess(reading(("rocker plates", "rocker", float(np.nextafter(edge, 0.0)), ram.link_r), ("rocker plates", "p", beyond, ram.link_r), degrees=[-60.0]), -0.9 * ram.link_r) + self.assertLess(abs(reading(("rocker plates", "rocker", float(np.nextafter(edge, 0.0)), ram.link_r), ("rocker plates", "p", beyond, ram.link_r), degrees=[-60.0]) + own), ZONED) def test_a_pin_stood_inside_what_it_stands_beside_is_refused(self): # Soul's moved-x probes: the rocker's x moved from its plate's place (0.3675) into the bracket's 0.13..0.35,