From ed4d7729eb6aefb1de2fbfcf6c9e2eb33a9a9f9f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 22:33:01 +0100 Subject: [PATCH] kits: pivot is revolute; a prismatic slide type; ram_barrel and ram_rod cut from the actuator at its gland Slide 0 is closed and the slide is the extension: a rod of length body_len + 1.1 body_r in its barrel stands as the actuator does. JointRecordTests: slide, within, limits on aim and reach, dof across kits; mutants J1 J2 J3 J4 J6 each die there. Co-Authored-By: Claude Fable 5.2 --- .../blender/brokkr_kitbash/kits/frame.v0.json | 2 +- .../brokkr_kitbash/kits/mechanical.v0.json | 56 ++++- surfaces/blender/tests/test_kitbash.py | 192 +++++++++++++++++- 3 files changed, 245 insertions(+), 5 deletions(-) diff --git a/surfaces/blender/brokkr_kitbash/kits/frame.v0.json b/surfaces/blender/brokkr_kitbash/kits/frame.v0.json index e25c7fe..f4848aa 100644 --- a/surfaces/blender/brokkr_kitbash/kits/frame.v0.json +++ b/surfaces/blender/brokkr_kitbash/kits/frame.v0.json @@ -4,7 +4,7 @@ "doc": "Chassis structure: sectioned beams, a truss, a portal, a gusset and a wedge, each a section swept along a path. Metres.", "socketTypes": { "mount": {"match": "fits", "doc": "flat seat; size is the free diameter around the socket"}, - "pivot": {"match": "equal", "doc": "pin joint; size is the pin diameter"} + "pivot": {"match": "equal", "dof": "revolute", "doc": "pin joint; size is the pin diameter"} }, "parts": [ { diff --git a/surfaces/blender/brokkr_kitbash/kits/mechanical.v0.json b/surfaces/blender/brokkr_kitbash/kits/mechanical.v0.json index 027e85a..325773c 100644 --- a/surfaces/blender/brokkr_kitbash/kits/mechanical.v0.json +++ b/surfaces/blender/brokkr_kitbash/kits/mechanical.v0.json @@ -5,7 +5,8 @@ "socketTypes": { "flange": {"match": "equal", "doc": "bolted pipe or duct face; size is the bore diameter"}, "mount": {"match": "fits", "doc": "flat seat; size is the free diameter around the socket"}, - "pivot": {"match": "equal", "doc": "pin joint; size is the pin diameter"}, + "pivot": {"match": "equal", "dof": "revolute", "doc": "pin joint; size is the pin diameter"}, + "slide": {"match": "equal", "dof": "prismatic", "doc": "telescoping bore; size is the bore diameter; the child slides along the socket's z"}, "hose": {"match": "fits", "doc": "hose port; size is the widest bundle it takes"} }, "parts": [ @@ -179,6 +180,59 @@ {"name": "port_rod", "type": "hose", "size": "0.4*body_r", "at": ["1.45*body_r", 0, "2.25*body_r+body_len"], "z": "+x", "y": "+z"} ] }, + { + "name": "ram_barrel", + "doc": "The barrel of a tie-rod hydraulic cylinder, the actuator's up to its gland: base eye on a cross pin with a socket on each end face, square caps, barrel, ports, and a bore a ram_rod slides in.", + "params": [ + {"name": "body_r", "type": "number", "min": 0.05, "max": 0.12, "default": 0.06, "doc": "barrel radius"}, + {"name": "body_len", "type": "number", "min": 0.2, "max": 1.0, "default": 0.4, "doc": "barrel length between caps"}, + {"name": "rod_r", "type": "number", "min": 0.01, "max": 0.02, "default": 0.018, "doc": "radius of the rod its gland takes"}, + {"name": "segments", "type": "integer", "min": 8, "max": 48, "default": 24, "doc": "sides of every round"} + ], + "bevel": "0.04*body_r", + "shapes": [ + {"shape": "box", "size": ["1.2*body_r", "0.9*body_r", "1.6*body_r"], "at": [0, 0, "0.8*body_r"]}, + {"shape": "tube", "r0": "0.45*body_r", "r1": "0.45*body_r", "length": "1.3*body_r", "segments": "segments", "smooth": true, "rot": [-90, 0, 0], "at": [0, "-0.65*body_r", "0.8*body_r"]}, + {"shape": "box", "size": ["2.4*body_r", "2.4*body_r", "0.5*body_r"], "at": [0, 0, "1.75*body_r"]}, + {"shape": "tube", "r0": "body_r", "r1": "body_r", "length": "body_len+0.2*body_r", "segments": "segments", "smooth": true, "at": [0, 0, "1.9*body_r"]}, + {"shape": "box", "size": ["2.4*body_r", "2.4*body_r", "0.5*body_r"], "at": [0, 0, "2.25*body_r+body_len"]}, + {"shape": "repeat", "count": 2, "step": ["1.9*body_r", 0, 0], "of": + {"shape": "tube", "r0": "0.12*body_r", "r1": "0.12*body_r", "length": "body_len+1.3*body_r", "segments": 6, "at": ["-0.95*body_r", "-0.95*body_r", "1.35*body_r"]}}, + {"shape": "repeat", "count": 2, "step": ["1.9*body_r", 0, 0], "of": + {"shape": "tube", "r0": "0.12*body_r", "r1": "0.12*body_r", "length": "body_len+1.3*body_r", "segments": 6, "at": ["-0.95*body_r", "0.95*body_r", "1.35*body_r"]}}, + {"shape": "repeat", "count": 2, "step": [0, 0, "body_len+0.5*body_r"], "of": + {"shape": "tube", "r0": "0.2*body_r", "r1": "0.2*body_r", "length": "0.45*body_r", "segments": "segments", "smooth": true, "rot": [0, 90, 0], "at": ["body_r", 0, "1.75*body_r"]}}, + {"shape": "tube", "r0": "rod_r+0.25*body_r", "r1": "rod_r+0.25*body_r", "length": "0.4*body_r", "segments": "segments", "smooth": true, "at": [0, 0, "2.4*body_r+body_len"]} + ], + "sockets": [ + {"name": "base", "type": "pivot", "size": "0.9*body_r", "at": [0, "0.65*body_r", "0.8*body_r"], "z": "+y", "y": "+z"}, + {"name": "base_back", "type": "pivot", "size": "0.9*body_r", "at": [0, "-0.65*body_r", "0.8*body_r"], "z": "-y", "y": "+z"}, + {"name": "bore", "type": "slide", "size": "2*rod_r", "at": [0, 0, "2*body_r"], "z": "+z", "y": "+y"}, + {"name": "port_cap", "type": "hose", "size": "0.4*body_r", "at": ["1.45*body_r", 0, "1.75*body_r"], "z": "+x", "y": "+z"}, + {"name": "port_rod", "type": "hose", "size": "0.4*body_r", "at": ["1.45*body_r", 0, "2.25*body_r+body_len"], "z": "+x", "y": "+z"} + ] + }, + { + "name": "ram_rod", + "doc": "The rod of a hydraulic cylinder, the actuator's from its gland: a rod from its piston face to a rod eye on a cross pin with a socket on each end face. Its piston slides in a ram_barrel's bore: slide 0 is closed, the slide is the extension.", + "params": [ + {"name": "body_r", "type": "number", "min": 0.05, "max": 0.12, "default": 0.06, "doc": "its barrel's radius: sizes the rod eye"}, + {"name": "rod_r", "type": "number", "min": 0.01, "max": 0.02, "default": 0.018, "doc": "rod radius"}, + {"name": "length", "type": "number", "min": 0.2, "max": 2.0, "default": 0.466, "doc": "piston face to the rod eye's block; its barrel's body_len + 1.1*body_r stands as the actuator does at extension 0"}, + {"name": "segments", "type": "integer", "min": 8, "max": 48, "default": 24, "doc": "sides of every round"} + ], + "bevel": "0.04*body_r", + "shapes": [ + {"shape": "tube", "r0": "rod_r", "r1": "rod_r", "length": "length+0.2*body_r", "segments": "segments", "smooth": true, "at": [0, 0, 0]}, + {"shape": "box", "size": ["1.2*body_r", "0.9*body_r", "1.4*body_r"], "at": [0, 0, "length+0.7*body_r"]}, + {"shape": "tube", "r0": "0.45*body_r", "r1": "0.45*body_r", "length": "1.3*body_r", "segments": "segments", "smooth": true, "rot": [-90, 0, 0], "at": [0, "-0.65*body_r", "length+0.7*body_r"]} + ], + "sockets": [ + {"name": "piston", "type": "slide", "size": "2*rod_r", "at": [0, 0, 0], "z": "-z", "y": "+y"}, + {"name": "rod_end", "type": "pivot", "size": "0.9*body_r", "at": [0, "0.65*body_r", "length+0.7*body_r"], "z": "+y", "y": "+z"}, + {"name": "rod_end_back", "type": "pivot", "size": "0.9*body_r", "at": [0, "-0.65*body_r", "length+0.7*body_r"], "z": "-y", "y": "+z"} + ] + }, { "name": "pipe_fitting", "doc": "Flanged tee: a run along +z with a branch along +x at its middle, a reinforced hub and bolted flanges.", diff --git a/surfaces/blender/tests/test_kitbash.py b/surfaces/blender/tests/test_kitbash.py index 746ee5a..626f77a 100644 --- a/surfaces/blender/tests/test_kitbash.py +++ b/surfaces/blender/tests/test_kitbash.py @@ -559,21 +559,24 @@ class ParamTests(unittest.TestCase): @unittest.skipIf(np is None, "numpy is not installed") class MechanicalKitTests(unittest.TestCase): - PARTS = ["nozzle", "tank", "ribbed_cylinder", "strut", "actuator", "pipe_fitting", "radiator_stack", "vent", "plate", "reducer", "bracket"] + PARTS = ["nozzle", "tank", "ribbed_cylinder", "strut", "actuator", "ram_barrel", "ram_rod", "pipe_fitting", "radiator_stack", "vent", "plate", "reducer", "bracket"] @classmethod def setUpClass(cls): cls.kit = core.load_kit("mechanical") - def test_the_kit_is_the_eleven_parts_and_four_socket_types(self): + def test_the_kit_is_the_thirteen_parts_and_five_socket_types(self): self.assertEqual(list(self.kit["parts"]), self.PARTS) - self.assertEqual({k: v["match"] for k, v in self.kit["socketTypes"].items()}, {"flange": "equal", "mount": "fits", "pivot": "equal", "hose": "fits"}) + self.assertEqual({k: (v["match"], v.get("dof")) for k, v in self.kit["socketTypes"].items()}, + {"flange": ("equal", None), "mount": ("fits", None), "pivot": ("equal", "revolute"), "slide": ("equal", "prismatic"), "hose": ("fits", None)}) self.assertEqual({name: [(s["name"], s["type"]) for s in part["sockets"]] for name, part in self.kit["parts"].items()}, { "nozzle": [("mount", "flange")], "tank": [("port_a", "flange"), ("port_b", "flange"), ("saddle", "mount"), ("lug_a", "mount"), ("lug_b", "mount"), ("lug_a_back", "mount"), ("lug_b_back", "mount")], "ribbed_cylinder": [("end_a", "flange"), ("end_b", "flange")], "strut": [("end_a", "pivot"), ("end_a_back", "pivot"), ("end_b", "pivot"), ("end_b_back", "pivot")], "actuator": [("base", "pivot"), ("base_back", "pivot"), ("rod_end", "pivot"), ("rod_end_back", "pivot"), ("port_cap", "hose"), ("port_rod", "hose")], + "ram_barrel": [("base", "pivot"), ("base_back", "pivot"), ("bore", "slide"), ("port_cap", "hose"), ("port_rod", "hose")], + "ram_rod": [("piston", "slide"), ("rod_end", "pivot"), ("rod_end_back", "pivot")], "pipe_fitting": [("a", "flange"), ("b", "flange"), ("c", "flange")], "radiator_stack": [("base", "mount")], "vent": [("back", "mount")], "plate": [("back", "mount"), ("front", "mount")], "reducer": [("big", "flange"), ("small", "flange")], "bracket": [("mount", "mount"), ("pivot", "pivot"), ("pivot_back", "pivot")]}) @@ -1409,6 +1412,189 @@ class PoseTests(unittest.TestCase): core.reach_roll(world, sp, sc, [rng.uniform(-1, 1) for _ in range(3)], (world @ sp["matrix"])[:3, 2], 0.0, 0.0) +@unittest.skipIf(np is None, "numpy is not installed") +class JointRecordTests(unittest.TestCase): + """What a connection's joint record rests on in core: the socket type's dof, mate and residual with a slide, + within, and aim_roll and reach_roll inside limits. Bounds sit at the geometric mean of the shipped worst reading + and the least claimed mutant's (lodur:ruling:deterministic-bound-margin); a reading that is exact is asserted + equal.""" + PAIRS = MateTests.PAIRS + SLIDES = (-0.04, 0.025, 0.3) + SLID = 2.4e-8 # metres from the point `slide` along the parent socket's z. shipped 9.7e-16; least mutant 0.6 (J1); separation 6.2e14 + RAM = 1.9e-8 # a socket of barrel and rod against the actuator's. shipped 0, taken as one float step; least mutant 1.6 (J1); separation 7.2e15 + BEATEN = 1.2e-8 # how far a roll inside the limits may pass the dot aim reports. shipped 1.1e-16; least mutant 1.26 (J2), J3 reads 1.99; separation 1.1e16 + + @classmethod + def setUpClass(cls): + cls.kit = core.load_kit("mechanical") + + def slide_readings(self): + """Read from the two world frames, not through core.residual: how far the child socket's origin stands from + the point `slide` along the parent socket's z, the normals, and the residual at the stated slide.""" + rng, parts, worst = random.Random("slide"), self.kit["parts"], {"slid": 0.0, "normal": 0.0, "residual": 0.0} + for parent, parent_params, parent_socket, child, child_params, child_socket in self.PAIRS: + sp, sc = core.joint(parts[parent], core.build(parts[parent], parent_params), parent_socket, + parts[child], core.build(parts[child], child_params), child_socket) + world = np.eye(4) + world[:3, :3] = core._rotation([rng.uniform(-180, 180) for _ in range(3)]) + world[:3, 3] = [rng.uniform(-5, 5) for _ in range(3)] + for roll in (0.0, 30.0, -115.0): + self.assertEqual(core.mate(sp, sc, roll, 0.0).tolist(), core.mate(sp, sc, roll).tolist()) # slide 0 is the mate there was + for slide in self.SLIDES: + placed = world @ core.mate(sp, sc, roll, slide) + a, b = world @ sp["matrix"], placed @ sc["matrix"] + worst["slid"] = max(worst["slid"], float(np.linalg.norm(b[:3, 3] - a[:3, 3] - slide * a[:3, 2]))) + worst["normal"] = max(worst["normal"], float(np.abs(a[:3, 2] + b[:3, 2]).max())) + worst["residual"] = max(worst["residual"], core.residual(world, sp, placed, sc, roll, slide)) + self.assertAlmostEqual(core.residual(world, sp, placed, sc, roll, 0.0), abs(slide) * float(np.abs(a[:3, 2]).max()), places=12) # read at another slide it stands that far off + return worst + + def test_a_slide_stands_the_child_along_the_parent_socket_z(self): + """slide-mates. Mutant J1 (the slide applied after FLIP, so along the child's side of the joint: the child + stands -slide along the parent socket's z).""" + worst = self.slide_readings() + self.assertLess(worst["slid"], self.SLID) + self.assertLess(worst["normal"], MateTests.NORMAL) + self.assertLess(worst["residual"], MateTests.RESIDUAL) + + def ram_reading(self): + parts, worst = self.kit["parts"], 0.0 + for body_r, body_len, extension in ((0.06, 0.4, 0.0), (0.05, 0.2, 0.15), (0.12, 1.0, 0.8), (0.09, 0.55, 0.31)): + barrel = core.build(parts["ram_barrel"], {"body_r": body_r, "body_len": body_len}) + rod = core.build(parts["ram_rod"], {"body_r": body_r, "length": body_len + 1.1 * body_r}) + whole = {s["name"]: s["matrix"] for s in core.build(parts["actuator"], {"body_r": body_r, "body_len": body_len, "extension": extension}).sockets} + sp, sc = core.joint(parts["ram_barrel"], barrel, "bore", parts["ram_rod"], rod, "piston") + self.assertIsNone(core.mate_refusal(self.kit["socketTypes"], sp, sc)) + placed = core.mate(sp, sc, 0.0, extension) + for socket in barrel.sockets: + if socket["name"] != "bore": + worst = max(worst, float(np.abs(socket["matrix"] - whole[socket["name"]]).max())) + for socket in rod.sockets[1:]: + worst = max(worst, float(np.abs(placed @ socket["matrix"] - whole[socket["name"]]).max())) + return worst + + def test_a_rod_in_its_barrel_is_the_actuator_at_that_extension(self): + """slide-mates, on the kit: ram_rod's piston on ram_barrel's bore at slide e puts every socket where the + actuator has it at extension e. Slide 0 is closed. Mutant J1.""" + self.assertEqual([(s["name"], s["type"]) for s in core.build(self.kit["parts"]["ram_barrel"]).sockets], + [("base", "pivot"), ("base_back", "pivot"), ("bore", "slide"), ("port_cap", "hose"), ("port_rod", "hose")]) + self.assertEqual([(s["name"], s["type"]) for s in core.build(self.kit["parts"]["ram_rod"]).sockets], + [("piston", "slide"), ("rod_end", "pivot"), ("rod_end_back", "pivot")]) + self.assertLess(self.ram_reading(), self.RAM) + + def test_a_socket_type_states_its_dof(self): + """dof-by-type, the format. A type states revolute or prismatic or nothing (rigid); anything else is refused + naming the type.""" + doc = document() + doc["socketTypes"] = {"mount": {"match": "fits", "doc": ""}, "pin": {"match": "equal", "doc": "", "dof": "revolute"}, "bore": {"match": "equal", "dof": "prismatic", "doc": ""}} + self.assertEqual({name: entry.get("dof") for name, entry in core.check_kit(doc)["socketTypes"].items()}, {"mount": None, "pin": "revolute", "bore": "prismatic"}) + self.assertNotIn("dof", core.check_kit(doc)["socketTypes"]["mount"]) + for odd in ("hinge", "", None, ["revolute"], "rigid"): + doc["socketTypes"]["pin"]["dof"] = odd + with self.assertRaisesRegex(core.KitError, r"kit 't' socket type 'pin': dof must be 'revolute' or 'prismatic'"): + core.check_kit(doc) + doc["socketTypes"]["pin"] = {"match": "equal", "doc": "", "axis": "z"} + with self.assertRaisesRegex(core.KitError, r"socket type 'pin' has no key 'axis'"): + core.check_kit(doc) + types = {kit: core.load_kit(kit)["socketTypes"] for kit in ("mechanical", "frame", "cutters")} + self.assertEqual({(kit, name): entry["dof"] for kit, found in types.items() for name, entry in found.items() if "dof" in entry}, + {("mechanical", "pivot"): "revolute", ("mechanical", "slide"): "prismatic", ("frame", "pivot"): "revolute"}) + self.assertEqual(core.describe(self.kit, "ram_rod")["socketTypes"]["slide"]["dof"], "prismatic") + + def test_two_kits_mate_a_type_only_when_its_dof_agrees(self): + """dof-by-type, across kits. Mutant J6 (mate_refusal ignores dof across kits): a pivot another kit declares + without dof mates.""" + types, frame = self.kit["socketTypes"], core.load_kit("frame")["socketTypes"] + socket = lambda name, kind, size: {"name": name, "type": kind, "size": size, "matrix": np.eye(4)} # noqa: E731 + self.assertIsNone(core.mate_refusal(frame, socket("p", "pivot", 0.05), socket("c", "pivot", 0.05), types, ("frame", "mechanical"))) + self.assertIsNone(core.mate_refusal(types, socket("p", "pivot", 0.05), socket("c", "pivot", 0.05), frame, ("mechanical", "frame"))) + rigid = {**types, "pivot": {"match": "equal", "doc": ""}} + self.assertRegex(core.mate_refusal(types, socket("p", "pivot", 0.05), socket("c", "pivot", 0.05), rigid, ("mechanical", "odd")), + r"kit 'mechanical' declares socket type 'pivot' with dof revolute and kit 'odd' with dof none \(rigid\); parts of two kits mate by socket types both declare alike") + self.assertRegex(core.mate_refusal(rigid, socket("p", "pivot", 0.05), socket("c", "pivot", 0.05), types, ("odd", "mechanical")), + r"kit 'odd' declares socket type 'pivot' with dof none \(rigid\) and kit 'mechanical' with dof revolute") + sliding = {**types, "pivot": {"match": "equal", "doc": "", "dof": "prismatic"}} + self.assertIn("with dof revolute and kit 'odd' with dof prismatic", core.mate_refusal(types, socket("p", "pivot", 0.05), socket("c", "pivot", 0.05), sliding, ("mechanical", "odd"))) + self.assertIsNone(core.mate_refusal(rigid, socket("p", "pivot", 0.05), socket("c", "pivot", 0.05), None)) # one kit: its own type + + def test_within_is_the_value_s_representative_inside_the_limits(self): + """limits-everywhere, the one rule. Mutant J2 (within without the 360 k shift): -170 has no representative in + 150..210.""" + self.assertEqual(core.within(190.0, 150.0, 210.0, True), 190.0) + self.assertEqual(core.within(-170.0, 150.0, 210.0, True), 190.0) + self.assertEqual(core.within(550.0, 150.0, 210.0, True), 190.0) + self.assertIsNone(core.within(-170.0, 150.0, 210.0, False)) + self.assertIsNone(core.within(100.0, 150.0, 210.0, True)) + self.assertIsNone(core.within(-100.0, 150.0, 210.0, True)) + self.assertEqual(core.within(180.0, -180.0, 180.0, True), 180.0) # a value inside is itself + self.assertEqual(core.within(-180.0, -180.0, 180.0, True), -180.0) + self.assertEqual(core.within(270.0, -180.0, 180.0, True), -90.0) + self.assertEqual(core.within(-350.0, 0.0, 20.0, True), 10.0) + self.assertEqual(core.within(0.12, 0.0, 0.3, False), 0.12) + self.assertIsNone(core.within(0.31, 0.0, 0.3, False)) + self.assertIsNone(core.within(-0.001, 0.0, 0.3, False)) + self.assertEqual(core.within(float(np.float32(0.3)), 0.0, 0.3, False), 0.3) # a float32 field's 0.3 is 1.2e-08 over: the end + self.assertEqual(core.within(float(np.float32(-20.1)), -20.1, 90.0, True), -20.1) + self.assertEqual(core.within(-1e-7, 0.0, 0.3, False), 0.0) + self.assertIsNone(core.within(0.3 + 3e-6, 0.0, 0.3, False)) # 3 slacks over + + def aim_readings(self): + """Over PoseTests' joints, each under limits drawn about it: how far a roll on a quarter-degree grid inside + the limits passes the dot aim_roll reports there, and how far the reported dot is from the one read back.""" + worst, pose = {"beaten": -math.inf, "read": 0.0, "ends": 0, "cases": 0}, PoseTests() + pose.kit = self.kit + for world, sp, sc, rng in pose.joints("aim-limits"): + for name, axis in core.AXES.items(): + if abs(np.array(axis) @ sc["matrix"][:3, 2]) == 1.0: + continue + d, lo = pose.direction(rng), rng.uniform(-360.0, 300.0) + hi = lo + rng.uniform(5.0, min(360.0, 360.0 - lo)) + roll, dot = core.aim_roll(world, sp, sc, axis, d, (lo, hi)) + turned = lambda r: float(d @ (world @ core.mate(sp, sc, r))[:3, :3] @ np.array(axis)) # noqa: E731 + self.assertTrue(lo <= roll <= hi, (roll, lo, hi)) + worst["read"] = max(worst["read"], abs(dot - turned(roll))) + worst["beaten"] = max(worst["beaten"], max(turned(float(r)) for r in np.arange(lo, hi, 0.25)) - dot) + worst["ends"] += roll in (lo, hi) + worst["cases"] += 1 + return worst + + def test_aim_inside_limits_takes_the_best_roll_they_hold(self): + """limits-everywhere, aim. The free roll's representative when the limits hold one (150..210 and a free roll + of -170: 190), else the end with the larger dot. Mutant J3 (the end nearer the free roll by angle, read along + the line and not round the circle: 100..185 and a free roll of -170 takes 100).""" + ident = {"name": "s", "matrix": np.eye(4)} + toward = lambda roll: (-math.sin(math.radians(roll)), math.cos(math.radians(roll)), 0.0) # noqa: E731 the child's y stands there at that roll + aim = lambda free, limits: tuple(round(v, 9) for v in core.aim_roll(np.eye(4), ident, ident, (0.0, 1.0, 0.0), toward(free), limits)) # noqa: E731 + self.assertEqual(aim(-170.0, None), (-170.0, 1.0)) + self.assertEqual(aim(-170.0, (150.0, 210.0)), (190.0, 1.0)) + self.assertEqual(aim(-170.0, (100.0, 185.0)), (185.0, round(math.cos(math.radians(5.0)), 9))) + self.assertEqual(aim(-170.0, (-90.0, 20.0)), (-90.0, round(math.cos(math.radians(80.0)), 9))) + self.assertEqual(aim(90.0, (-20.0, 200.0)), (90.0, 1.0)) + self.assertEqual(aim(0.0, (170.0, 190.0)), (170.0, round(math.cos(math.radians(170.0)), 9))) # a tie takes lo + with self.assertRaisesRegex(core.KitError, "lies along the pin"): + core.aim_roll(np.eye(4), ident, ident, (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), (0.0, 90.0)) + worst = self.aim_readings() + self.assertEqual(worst["cases"], 80) + self.assertGreater(worst["ends"], 20) # the limits bind in a share of the cases + self.assertLess(worst["read"], PoseTests.AIMED) + self.assertLess(worst["beaten"], self.BEATEN) + + def test_reach_inside_limits_takes_a_root_they_hold(self): + """limits-everywhere, reach. Mutant J4 (the nearer root whatever the limits).""" + ident = {"name": "s", "matrix": np.eye(4)} + reach = lambda current, limits: tuple(round(v, 9) for v in core.reach_roll(np.eye(4), ident, ident, (0.0, 1.0, 0.0), (1.0, 0.0, 0.0), 0.5, current, limits)) # noqa: E731 + self.assertEqual(reach(0.0, None), (-30.0, 0.0)) # the roots are -30 and -150 + self.assertEqual(reach(0.0, (-160.0, -100.0)), (-150.0, 0.0)) # the nearer root is outside + self.assertEqual(reach(0.0, (200.0, 220.0)), (210.0, 0.0)) # as its representative + self.assertEqual(reach(0.0, (-180.0, 180.0)), (-30.0, 0.0)) # both inside: the nearer + self.assertEqual(reach(-170.0, (-180.0, 180.0)), (-150.0, 0.0)) + self.assertEqual(reach(300.0, (180.0, 360.0)), (330.0, 0.0)) + with self.assertRaisesRegex(core.KitError, r"socket 's' on parent socket 's': the rolls that bring the point to 0\.500000 m, -150 and -30, are outside the joint's limits 0 to 90$"): + reach(0.0, (0.0, 90.0)) + with self.assertRaisesRegex(core.KitError, "it reaches -1.000000 m to 1.000000 m"): + core.reach_roll(np.eye(4), ident, ident, (0.0, 1.0, 0.0), (1.0, 0.0, 0.0), 1.5, 0.0, (0.0, 90.0)) + + @unittest.skipIf(np is None, "numpy is not installed") class StructureTests(unittest.TestCase): """core's sweep, band, crossings, resample and spans: what brokkr_kitbash.ribs builds a frame from. Every reading is