brokkr_kitbash: aim's floor matched to float32 scenes; reach takes the edge of its circle and refuses a socket on the pin

AIM_FLOOR 1.5e-9 was set against float64 rounding, but a scene's matrices and an action's fields are float32:
the pin's own direction, as the scene holds it or typed at 6 or 4 decimals, was aimed at and swung the part to
an arbitrary roll. The floor is 1e-3, the geometric mean of the 4 decimal reading (6.2e-5) and a direction
1 degree off the pin (0.0175).

reach takes a height up to REACH_EDGE (1e-5 m, HELD) past the top or bottom of the circle as the top or bottom,
so the range a refusal names (now 6 decimals) can be typed back; a socket on the pin, or a direction along it,
is refused instead of dividing by a zero swing. Half a turn is pinned as 180.

Soul's verdict cut-kit-roll-aim.s1: findings aim-floor-below-float32-noise and
reach-exact-edge-refused-and-unpinned; survivors S6, S7, S8.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 04:31:37 +01:00
commit fb3382a923
6 changed files with 188 additions and 39 deletions

View file

@ -201,7 +201,7 @@
},
{
"name": "brokkr_kitbash.aim",
"doc": "Turn an attached kit part about its pin until one of its own axes points as near a world direction as the pin lets it. The roll is solved exactly, not searched. Refuses an axis or a direction that lies along the pin, and a zero direction. Reports the part, aimed: {roll, dot} (dot 1 when the axis reaches the direction) and closures as roll does.",
"doc": "Turn an attached kit part about its pin until one of its own axes points as near a world direction as the pin lets it. The roll is solved exactly, not searched. Refuses an axis or a direction that lies along the pin (within about 0.06 degrees), and a zero direction. Reports the part, aimed: {roll, dot} (dot 1 when the axis reaches the direction) and closures as roll does.",
"changesScene": true,
"editModeSafe": false,
"result": "brokkr_mesh_polish_result",
@ -254,7 +254,7 @@
},
{
"name": "brokkr_kitbash.reach",
"doc": "Turn an attached kit part about its pin until one of its sockets' origins stands at a height along a world direction (by default world z): of the two rolls that do it, the one nearer the roll it has. Solved exactly. Refuses a height the socket cannot reach, naming the range it can. Reports the part, reached: {roll, residual} and closures as roll does.",
"doc": "Turn an attached kit part about its pin until one of its sockets' origins stands at a height along a world direction (by default world z): of the two rolls that do it, the one nearer the roll it has. Solved exactly. Refuses a height the socket cannot reach, naming the range it can (either end of the range is taken), and a socket that lies on the pin. Reports the part, reached: {roll, residual} and closures as roll does.",
"changesScene": true,
"editModeSafe": false,
"result": "brokkr_mesh_polish_result",

View file

@ -655,10 +655,19 @@ def roll_terms(parent_world, parent_socket: dict, child_socket: dict, local, w:
return (float(e[0] * q[0] + e[1] * q[1]), float(e[1] * q[0] - e[0] * q[1]), float(e[2] * q[2] + w * (direction @ M[:3, 3])))
# The least hypot(A, B) aim_roll solves for: below it the axis or the direction lies along the pin and no roll turns
# one toward the other. Least aimable case of the tests 0.0175 (a direction 1 degree off the pin); a degenerate case
# reads at most 1.2e-16 (float rounding of an axis along the pin); the geometric mean, separation 1.2e7 each side.
AIM_FLOOR = 1.5e-9
# The least hypot(A, B) aim_roll solves for: at or below it the axis or the direction lies along the pin, as nearly as
# the scene can say, and no roll turns one toward the other. A scene's matrices and an action's fields are float32
# and a direction read from a report has 6 decimals or fewer, so "along the pin" is never exact: the worst reading
# of the tests for a pin direction through a float32 world, as float32, at 6 and at 4 decimals is 6.2e-05 (the 4
# decimal case); the least aimable case is 0.0175 (a direction 1 degree off the pin). The geometric mean,
# separation 17 each side: a direction within about 0.06 degrees of the pin is refused.
AIM_FLOOR = 1e-3
# How far past the top or bottom of its circle a reach may ask, in metres: such a height is taken as the top or
# bottom, and the residual says how far off the socket stands. A rule, the add-on's HELD: a height typed back from
# the range a refusal names (6 decimals, through a float32 field) is within 6.5e-07 of it in the tests, and float32
# steps 1e-06 for parts within 16 m of the origin. A socket whose circle is this small lies on the pin: no roll
# moves it.
REACH_EDGE = 1e-5
def _wrapped(degrees: float) -> float:
@ -669,7 +678,7 @@ def _wrapped(degrees: float) -> float:
def aim_roll(parent_world, parent_socket: dict, child_socket: dict, axis, direction) -> tuple[float, float]:
"""(roll in degrees in (-180, 180], the dot it achieves) that turns the child's own `axis` as far toward the
world `direction` as its pin lets it: roll = atan2(B, A), dot = C + hypot(A, B), for unit vectors. Refuses an
axis or a direction along the pin, which no roll turns."""
axis or a direction along the pin (hypot(A, B) at most AIM_FLOOR), which no roll turns."""
direction = np.asarray(direction, dtype=np.float64)
direction = direction / np.linalg.norm(direction)
A, B, C = roll_terms(parent_world, parent_socket, child_socket, axis, 0.0, direction)
@ -682,16 +691,21 @@ def aim_roll(parent_world, parent_socket: dict, child_socket: dict, axis, direct
def reach_roll(parent_world, parent_socket: dict, child_socket: dict, point, direction, height: float, current_roll: float) -> tuple[float, float]:
"""(roll in degrees in (-180, 180], residual |direction . p - height| in metres) that brings the child's own
`point` to the plane direction . x = height, for a unit direction: atan2(B, A) +- acos((height - C) / hypot(A, B)),
of the two the one nearer current_roll round the circle (a tie takes the smaller roll). Refuses a height the
point cannot reach, naming the range it can."""
of the two the one nearer current_roll round the circle (a tie takes the smaller roll). A height up to REACH_EDGE
past the top or bottom of the circle is taken as the top or bottom. Refuses a height farther out, naming the
range the point reaches, and a point no roll moves along the direction (it lies on the pin, or the direction
does)."""
direction = np.asarray(direction, dtype=np.float64)
direction = direction / np.linalg.norm(direction)
A, B, C = roll_terms(parent_world, parent_socket, child_socket, point, 1.0, direction)
swing = math.hypot(A, B)
if abs(height - C) > swing:
raise KitError(f"socket {child_socket['name']!r} on parent socket {parent_socket['name']!r}: no roll brings the point to {height:.6g} m along "
f"{tuple(round(float(v), 6) for v in direction)}; it reaches {C - swing:.6g} m to {C + swing:.6g} m")
middle, spread = math.degrees(math.atan2(B, A)), math.degrees(math.acos((height - C) / swing)) if swing > 0 else 0.0
swing, here = math.hypot(A, B), f"socket {child_socket['name']!r} on parent socket {parent_socket['name']!r}"
if swing <= REACH_EDGE:
raise KitError(f"{here}: no roll moves the point along {tuple(round(float(v), 6) for v in direction)}: it lies on the pin, or the direction "
f"runs along it; it stays at {C:.6f} m")
if abs(height - C) > swing + REACH_EDGE:
raise KitError(f"{here}: no roll brings the point to {height:.6f} m along {tuple(round(float(v), 6) for v in direction)}; "
f"it reaches {C - swing:.6f} m to {C + swing:.6f} m")
middle, spread = math.degrees(math.atan2(B, A)), math.degrees(math.acos(max(-1.0, min(1.0, (height - C) / swing))))
roots = sorted({_wrapped(middle - spread), _wrapped(middle + spread)})
roll = min(roots, key=lambda root: (round(abs(_wrapped(root - current_roll)), 9), root))
return roll, abs(A * math.cos(math.radians(roll)) + B * math.sin(math.radians(roll)) + C - height)

View file

@ -207,8 +207,17 @@ re-aims it.
They refuse, changing nothing: a part that states no connection (`attach` it first), one whose parent was
cleared, a connection `attach` would refuse now (sockets that no longer mate), a zero direction, an `aim` whose
axis or direction lies along the pin (no roll turns one toward the other), and a `reach` to a height the socket's
circle does not cross, naming the range it does. A leg is posed with them from the hip down: `aim` the yoke's
axis or direction lies along the pin (no roll turns one toward the other), a `reach` with a socket that lies on
the pin or a direction along it (no roll moves it), and a `reach` to a height the socket's circle does not cross,
naming the range it does.
A scene's matrices and an action's fields are float32, and a direction read from a report has 6 decimals, so
neither test is exact. "Along the pin" is `hypot(A, B)` at most 1e-3 (`core.AIM_FLOOR`): a direction within about
0.06 degrees of the pin, which covers the pin's own direction read from a report and typed at 4 decimals. A
`reach` to a height up to 1e-5 m past the top or bottom of the circle (`core.REACH_EDGE`) is taken as the top or
bottom, so the range a refusal names can be typed back; `residual` then says how far short the socket stands.
A leg is posed with them from the hip down: `aim` the yoke's
front at where the leg should point, `reach` the last link's clevis to the ground plus the foot's drop, `aim`
the foot's sole at the ground. Each reports `closures` as `set_params` does, the part's own first: a roll moves
everything below the part, can open a closure anywhere there, and never seats one.

View file

@ -78,6 +78,9 @@ REACHED = 3.0e-4
# Degrees the other root stands farther from the roll the part had than the root reach took. A rule, the sign: shipped
# least 74; R2 (the farther root) reads -74.
NEARER = 0.0
# Metres past the top of its circle a reach may ask (core.REACH_EDGE, a rule: HELD). A height typed back from a
# refusal's range overshoots by at most 3.2e-07 here and is taken; PAST is refused. The two sit sqrt(10) either side.
EDGE, PAST = 1e-5, 3.2e-5
def check(name, ok, detail=None):
@ -276,9 +279,23 @@ refused("aim of the axis along the pin", "brokkr_kitbash.aim", {"object_name": "
refused("aim at no direction", "brokkr_kitbash.aim", {"object_name": "Strut", "axis": "+z", "direction_x": 0.0, "direction_y": 0.0, "direction_z": 0.0}, "The direction is zero")
refused("reach past the circle the socket turns on, naming what it reaches", "brokkr_kitbash.reach",
{"object_name": "Strut", "socket": "end_b", "height": 900.0, "direction_x": direction[0], "direction_y": direction[1], "direction_z": direction[2]},
f"no roll brings the point to 900 m along ({unit[0]:.6f}".rstrip("0"))
f"no roll brings the point to 900.000000 m along ({unit[0]:.6f}".rstrip("0"))
receipt, _ = send("brokkr_kitbash.reach", object_name="Strut", socket="end_b", height=900.0, direction_x=direction[0], direction_y=direction[1], direction_z=direction[2])
check("and the range it names is the one core solves", f"it reaches {low:.6g} m to {high:.6g} m" in str(receipt["message"]) and high - low > 1.0, [receipt["message"], low, high])
check("and the range it names is the one core solves", f"it reaches {low:.6f} m to {high:.6f} m" in str(receipt["message"]) and high - low > 1.0, [receipt["message"], low, high])
skew = {"direction_x": direction[0], "direction_y": direction[1], "direction_z": direction[2]}
refused("reach a little past the top it names", "brokkr_kitbash.reach", {"object_name": "Strut", "socket": "end_b", "height": float(f"{high:.6f}") + PAST, **skew}, "no roll brings the point to")
receipt, report = send("brokkr_kitbash.reach", object_name="Strut", socket="end_b", height=float(f"{high:.6f}"), **skew)
reached = (report or {}).get("reached") or {"roll": 1e9, "residual": 1e9}
over, stands = reading("edge typed past", max(float(np.float32(f"{high:.6f}")) - high, 0.0)), reading("edge reached", abs(float(frame(strut, "end_b")[:3, 3] @ unit) - high))
check("reach to the top of the circle, typed back from the range the refusal named, is taken: the socket stands at the top", receipt["status"] == "accepted"
and reached["residual"] <= EDGE and over <= EDGE and stands < REACHED and holds(report["connection"], "Mount", "end_a", "pivot", reached["roll"]),
[receipt["message"], reached, over, stands, high])
refused("reach with the socket the part hangs by: it lies on the pin", "brokkr_kitbash.reach", {"object_name": "Strut", "socket": "end_a", "height": 0.0},
"'Strut' on 'Mount': socket 'end_a' on parent socket 'pivot': no roll moves the point along (0.0, 0.0, 1.0): it lies on the pin")
pin = np.array(mount.matrix_world, dtype=np.float64) @ socket(mount, "pivot")["matrix"]
for label, along in (("as the scene holds it", pin[:3, 2]), ("to 6 decimals", np.round(pin[:3, 2], 6)), ("to 4 decimals", np.round(pin[:3, 2], 4)), ("reversed, to 4 decimals", -np.round(pin[:3, 2], 4))):
refused(f"aim at the pin's own direction {label}", "brokkr_kitbash.aim",
{"object_name": "Strut", "axis": "+z", "direction_x": float(along[0]), "direction_y": float(along[1]), "direction_z": float(along[2])}, "lies along the pin, so no roll turns one toward the other")
refused("reach with a socket the part does not have", "brokkr_kitbash.reach", {"object_name": "Strut", "socket": "end_c", "height": 0.0},
"'Strut' has no socket 'end_c'; its sockets: end_a, end_a_back, end_b, end_b_back")
refused("reach along no direction", "brokkr_kitbash.reach", {"object_name": "Strut", "socket": "end_b", "height": 0.0, "direction_z": 0.0}, "The direction is zero")

View file

@ -176,6 +176,41 @@
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: reach a little past the top it names",
"ok": true,
"detail": null
},
{
"name": "reach to the top of the circle, typed back from the range the refusal named, is taken: the socket stands at the top",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: reach with the socket the part hangs by: it lies on the pin",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: aim at the pin's own direction as the scene holds it",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: aim at the pin's own direction to 6 decimals",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: aim at the pin's own direction to 4 decimals",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: aim at the pin's own direction reversed, to 4 decimals",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: reach with a socket the part does not have",
"ok": true,
@ -201,6 +236,8 @@
"readings": {
"aimed": 3.3e-07,
"aimed short": 0.0,
"edge reached": 2.6e-08,
"edge typed past": 3.2e-07,
"reach other root": 74.0,
"reached": 2.1e-07,
"roll": 8.4e-06,

View file

@ -1006,6 +1006,7 @@ class PoseTests(unittest.TestCase):
self.assertEqual((round(roll, 9), round(dot, 12)), (-90.0, 1.0))
roll, dot = core.aim_roll(np.eye(4), ident, ident, (1.0, 0.0, 0.0), (1.0, 1.0, 5.0)) # its x at (-cos, -sin, 0): the pin lets it reach 0.272 of the way
self.assertEqual((round(roll, 9), round(dot, 12)), (-135.0, round(math.sqrt(2.0 / 27.0), 12)))
self.assertEqual(core.aim_roll(np.eye(4), ident, ident, (0.0, 1.0, 0.0), (0.0, -1.0, 0.0)), (180.0, 1.0)) # half a turn is 180, never -180 (S6)
worst = self.aim_readings()
self.assertEqual(worst["cases"], 80)
self.assertLess(worst["aimed"], self.AIMED)
@ -1030,7 +1031,7 @@ class PoseTests(unittest.TestCase):
worst["nearer"] = max(worst["nearer"], apart(roll) - apart(2.0 * middle - roll)) # the other root mirrors it about the middle
worst["cases"] += 1
for beyond in (-1.01, 1.01):
with self.assertRaisesRegex(core.KitError, re.escape(f"it reaches {C - swing:.6g} m to {C + swing:.6g} m")):
with self.assertRaisesRegex(core.KitError, re.escape(f"it reaches {C - swing:.6f} m to {C + swing:.6f} m")):
core.reach_roll(world, sp, sc, point, d, C + beyond * swing, 0.0)
return worst
@ -1044,7 +1045,10 @@ class PoseTests(unittest.TestCase):
self.assertEqual(reach(0.5, -90.0), (-150.0, 0.0)) # a tie
self.assertEqual(reach(0.5, 90.0), (-150.0, 0.0)) # and the tie across the circle
self.assertEqual(reach(0.5, 330.0), (-30.0, 0.0)) # the current roll is read round the circle
with self.assertRaisesRegex(core.KitError, r"no roll brings the point to 1\.5 m along \(1\.0, 0\.0, 0\.0\); it reaches -1 m to 1 m"):
self.assertEqual(reach(0.0, 170.0), (180.0, 0.0)) # rolls 0 and 180: half a turn is 180, never -180 (mutant S6, the wrap's other end)
self.assertEqual(reach(0.0, -170.0), (180.0, 0.0))
self.assertEqual([core._wrapped(v) for v in (-180.0, 180.0, 540.0, -179.0, 0.0, 359.0)], [180.0, 180.0, 180.0, -179.0, 0.0, -1.0])
with self.assertRaisesRegex(core.KitError, r"no roll brings the point to 1\.500000 m along \(1\.0, 0\.0, 0\.0\); it reaches -1\.000000 m to 1\.000000 m"):
reach(1.5, 0.0)
worst = self.reach_readings()
self.assertEqual(worst["cases"], 300)
@ -1053,36 +1057,104 @@ class PoseTests(unittest.TestCase):
self.assertLess(worst["nearer"], self.NEARER)
def floor_readings(self):
"""(the largest hypot(A, B) of an axis or a direction along the pin, the least of an axis 1 degree off it)."""
along, least = 0.0, math.inf
"""(the largest hypot(A, B) of an axis along the pin or a direction along it in doubles; the largest for the pin's
direction as a scene gives it: through a float32 world, as float32, at 6 and at 4 decimals; the least of a
direction 1 degree off the pin, through the same float32 world)."""
along, scene, least = 0.0, 0.0, math.inf
for world, sp, sc, rng in self.joints("floor"):
pin_local, pin_world = sc["matrix"][:3, 2], (world @ sp["matrix"])[:3, 2]
side = (world @ sp["matrix"])[:3, 0]
near = math.cos(math.radians(1.0)) * pin_world + math.sin(math.radians(1.0)) * side
for axis, d, refused in ((pin_local, self.direction(rng), True), ((1.0, 0.0, 0.0) if abs(pin_local[0]) < 0.5 else (0.0, 1.0, 0.0), pin_world, True),
((1.0, 0.0, 0.0) if abs(pin_local[0]) < 0.5 else (0.0, 1.0, 0.0), near, False)):
A, B, _ = core.roll_terms(world, sp, sc, axis, 0.0, d)
if refused:
along = max(along, math.hypot(A, B))
with self.assertRaisesRegex(core.KitError, "lies along the pin, so no roll turns one toward the other"):
core.aim_roll(world, sp, sc, axis, d)
else:
other = (1.0, 0.0, 0.0) if abs(pin_local[0]) < 0.5 else (0.0, 1.0, 0.0) # an axis of the child across its pin
single = world.astype(np.float32).astype(np.float64) # the parent's matrix_world as Blender holds it
near = math.cos(math.radians(1.0)) * pin_world + math.sin(math.radians(1.0)) * (world @ sp["matrix"])[:3, 0]
for frame, axis, d, kind in ((world, pin_local, self.direction(rng), "along"), (world, other, pin_world, "along"),
(single, other, pin_world.astype(np.float32).astype(np.float64), "scene"),
(single, other, np.round(pin_world, 6).astype(np.float32).astype(np.float64), "scene"),
(single, other, np.round(pin_world, 4).astype(np.float32).astype(np.float64), "scene"),
(single, other, near.astype(np.float32).astype(np.float64), "near")):
A, B, _ = core.roll_terms(frame, sp, sc, axis, 0.0, d / np.linalg.norm(d))
if kind == "near":
least = min(least, math.hypot(A, B))
core.aim_roll(world, sp, sc, axis, d)
return along, least
core.aim_roll(frame, sp, sc, axis, d)
continue
along, scene = (max(along, math.hypot(A, B)), scene) if kind == "along" else (along, max(scene, math.hypot(A, B)))
with self.assertRaisesRegex(core.KitError, "lies along the pin, so no roll turns one toward the other", msg=f"{kind} {d}"):
core.aim_roll(frame, sp, sc, axis, d)
return along, scene, least
def test_aim_along_the_pin_is_refused(self):
"""aim-floor. An axis along the pin, or a direction along it, is refused; a direction 1 degree off it is solved.
AIM_FLOOR sits between the two readings by the margin rule. Mutant R5 (no floor: aim along the pin returns a roll)."""
along, least = self.floor_readings()
self.assertLess(along * 1.2, core.AIM_FLOOR)
"""aim-floor. An axis along the pin, or a direction along it as a scene can give it (a float32 world, the pin as
float32, at 6 and at 4 decimals), is refused; a direction 1 degree off it is solved. AIM_FLOOR sits between the
two readings by the margin rule. Mutants R5 (no floor) and E4 (the floor at float64 rounding, 1.5e-9)."""
along, scene, least = self.floor_readings()
self.assertLess(along, 1e-15)
self.assertGreater(scene, 2e-5) # the 4 decimal pin: far above float64 rounding, so the floor is set against it
self.assertLess(scene * 1.2, core.AIM_FLOOR)
self.assertGreater(least, core.AIM_FLOOR * 1.2)
self.assertLess(least, 0.0175) # sin(1 degree): the least case the floor is set against
self.assertLess(least, 0.0175) # sin(1 degree): the least case the floor is set against
self.assertGreater(min(self.aim_readings()["least"], least), core.AIM_FLOOR * 1.2)
ident = {"name": "s", "matrix": np.eye(4)}
with self.assertRaisesRegex(core.KitError, r"socket 's' on parent socket 's': the axis \(0\.0, 0\.0, 1\.0\) of the part or the direction \(1\.0, 0\.0, 0\.0\) lies along the pin"):
core.aim_roll(np.eye(4), ident, ident, (0.0, 0.0, 1.0), (1.0, 0.0, 0.0))
def edge_readings(self):
"""Reach asked for the top and bottom of its circle: exactly, as typed back from a refusal (6 decimals through
float32), 0.32 of REACH_EDGE past and 3.2 of it past (the two sit sqrt(10) either side of the rule)."""
worst = {"exact": 0.0, "typed": 0.0, "typed past": 0.0, "inside": 0.0, "cases": 0}
for world, sp, sc, rng in self.joints("edge"):
for _ in range(3):
point, d = [rng.uniform(-1, 1) for _ in range(3)], self.direction(rng)
A, B, C = core.roll_terms(world, sp, sc, point, 1.0, d)
swing, middle = math.hypot(A, B), math.degrees(math.atan2(B, A))
for sign in (1.0, -1.0):
end = core._wrapped(middle if sign > 0 else middle + 180.0) # the one roll at the top, or at the bottom
roll, residual = core.reach_roll(world, sp, sc, point, d, C + sign * swing, rng.uniform(-360, 360))
worst["exact"] = max(worst["exact"], residual, abs(core._wrapped(roll - end)) * 1e-9)
typed = float(np.float32(f"{C + sign * swing:.6f}"))
roll, residual = core.reach_roll(world, sp, sc, point, d, typed, 0.0)
worst["typed"] = max(worst["typed"], residual)
worst["typed past"] = max(worst["typed past"], sign * (typed - C) - swing)
roll, residual = core.reach_roll(world, sp, sc, point, d, C + sign * (swing + 0.32 * core.REACH_EDGE), 0.0)
worst["inside"] = max(worst["inside"], abs(residual - 0.32 * core.REACH_EDGE), abs(core._wrapped(roll - end)) * 1e-9)
with self.assertRaisesRegex(core.KitError, re.escape(f"it reaches {C - swing:.6f} m to {C + swing:.6f} m")):
core.reach_roll(world, sp, sc, point, d, C + sign * (swing + 3.2 * core.REACH_EDGE), 0.0)
worst["cases"] += 1
return worst
def test_reach_takes_the_edge_of_its_circle(self):
"""reach-edge. A height at the top or bottom of the circle is reached, exactly and as typed back from the range a
refusal names; one within REACH_EDGE past it is taken as the edge and the residual says how far off the point
stands; one farther is refused. Mutants E1 (no tolerance: the edge refused a quarter of the time), E2 (the
ratio not clamped into acos) and S7 (Soul's >= at the edge)."""
worst = self.edge_readings()
self.assertEqual(worst["cases"], 120)
self.assertLess(worst["exact"], 6.6e-8) # PoseTests.REACHED: the edge is on the plane as any other height is
self.assertLess(worst["typed"], core.REACH_EDGE / 1.2)
self.assertLess(worst["typed past"], core.REACH_EDGE / 1.2) # a typed edge overshoots by at most a rounding: inside the rule
self.assertGreater(worst["typed past"], 1e-7) # and it does overshoot: without the tolerance these are refused
self.assertLess(worst["inside"], 1e-12)
ident = {"name": "s", "matrix": np.eye(4)}
reach = lambda height, current: 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), height, current)) # noqa: E731
self.assertEqual((reach(1.0, 0.0), reach(-1.0, 0.0)), ((-90.0, 0.0), (90.0, 0.0))) # the point stands at x = -sin(roll)
self.assertEqual(reach(1.000003, 0.0), (-90.0, 3e-06))
def test_reach_refuses_a_point_no_roll_moves(self):
"""reach-on-the-pin. A point on the pin's axis, or a direction along the pin, is refused whatever the height: no
roll moves the point along the direction, and solving would divide by its swing. Mutant E3 (the guard dropped:
Soul's S8, zero swing with the point on the pin)."""
ident = {"name": "s", "matrix": np.eye(4)}
for point, d, height in (((0.0, 0.0, 2.0), (1.0, 0.0, 0.0), 0.0), ((0.0, 0.0, 2.0), (1.0, 0.0, 0.0), 0.5), ((0.3, 0.4, 2.0), (0.0, 0.0, 1.0), -2.0),
((0.3, 0.4, 2.0), (0.0, 0.0, 1.0), 1.0), ((0.0, 3e-6, 2.0), (1.0, 0.0, 0.0), 0.0)):
with self.assertRaisesRegex(core.KitError, r"socket 's' on parent socket 's': no roll moves the point along .*: it lies on the pin, or the direction runs along it; it stays at -?\d+\.\d{6} m"):
core.reach_roll(np.eye(4), ident, ident, point, d, height, 0.0)
self.assertEqual(round(core.reach_roll(np.eye(4), ident, ident, (0.0, 3.2e-5, 2.0), (1.0, 0.0, 0.0), 0.0, 10.0)[0], 9), 0.0) # sqrt(10) past REACH_EDGE off the pin: solved
for world, sp, sc, rng in self.joints("pin"):
on_pin = sc["matrix"] @ np.array([0.0, 0.0, rng.uniform(-1, 1), 1.0]) # on the child socket's own normal
_, _, C = core.roll_terms(world, sp, sc, on_pin[:3], 1.0, self.direction(rng))
with self.assertRaisesRegex(core.KitError, "no roll moves the point"):
core.reach_roll(world, sp, sc, on_pin[:3], self.direction(rng), C, 0.0)
with self.assertRaisesRegex(core.KitError, "no roll moves the point"):
core.reach_roll(world, sp, sc, [rng.uniform(-1, 1) for _ in range(3)], (world @ sp["matrix"])[:3, 2], 0.0, 0.0)
ROWS = ["brokkr_kitbash.place_part", "brokkr_kitbash.set_params", "brokkr_kitbash.describe", "brokkr_kitbash.report",
"brokkr_kitbash.attach", "brokkr_kitbash.detach", "brokkr_kitbash.roll", "brokkr_kitbash.aim", "brokkr_kitbash.reach", "brokkr_kitbash.close",