brokkr_kitbash.ram: the record is version 2 and holds no settle block
The reserved block (stiffness, damping, travel; written null, solved by nothing) leaves the ram record: a load-path cylinder's settle is a slide joint's, in the joint records (cut kit-joint-records). VERSION is 2; a version-1 record is refused as another version's, and the key is refused like any the record does not know. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
9ac49d1260
commit
89a3eceecd
2 changed files with 16 additions and 20 deletions
|
|
@ -75,9 +75,8 @@ JOINS = {kind: {"a": ("parent",), "b": ("child",)} if kind == "direct" else
|
|||
{"a": ("parent",), "rocker": ("parent", "rocker"), "p": ("rocker", "coupler"), "c": ("coupler", "child"), "d": ("rocker",)}
|
||||
for kind in KINDS} # pin -> the bodies it joins: only their parts are zoned about it
|
||||
GATES = ("assembly", "stroke", "toggle", "arm", "load", "clash")
|
||||
SCHEMA, VERSION = "brokkr.ram", 1
|
||||
SCHEMA, VERSION = "brokkr.ram", 2
|
||||
ZONE = ("part", "pin", "radius", "depth") # a zone of `touch`, as the record writes it
|
||||
COMPLIANCE = ("stiffness", "damping", "travel") # reserved: a load-path ram's settle, solved by a later version
|
||||
BAND = 1e-9 # the loop is refused within this of a dead centre of the rocker and coupler
|
||||
FINE = 64 # in a zone a segment between samples is halved down to spacing / FINE
|
||||
RAYS = ((0.5377, 0.6211, 0.5701), (-0.7071, 0.2903, 0.6447), (0.1873, -0.8011, -0.5684)) # Signed's, in order
|
||||
|
|
@ -670,21 +669,20 @@ def search(kind, hinge, ram, seats, world=None, limit=20000, steps=25, spacing=N
|
|||
def record(m, ram):
|
||||
"""The mechanism record: plain JSON types, everything a rig or runtime needs to drive the ram from the hinge
|
||||
angle (from_record, then length or extension). It holds what is authored and nothing derived from it: barrel,
|
||||
closed length and link lengths come from the pins and the ram. `compliance` is reserved for a load-path ram's
|
||||
settle (COMPLIANCE: stiffness, damping, travel); version 1 writes it null and solves none."""
|
||||
closed length and link lengths come from the pins and the ram."""
|
||||
return {"schema": SCHEMA, "version": VERSION, "kind": m.kind,
|
||||
"hinge": {"pivot": m.pivot.tolist(), "axis": m.axis.tolist(), "lo": m.lo, "hi": m.hi},
|
||||
"pins": {name: getattr(m, name).tolist() for name in PINS[m.kind]}, "offsets": list(m.offsets),
|
||||
"ram": {f.name: getattr(ram, f.name) for f in fields(Ram)},
|
||||
"parts": dict(m.parts), "compliance": None,
|
||||
"parts": dict(m.parts),
|
||||
"touch": {member: [dict(zip(ZONE, zone)) for zone in zones] for member, zones in m.touch.items()}}
|
||||
|
||||
|
||||
def from_record(data):
|
||||
"""(Mechanism, Ram) of a record. A record of another schema or version (the integer 1: not 1.0, not true), with
|
||||
a key this version does not know or without one it does, with a compliance block, or with a value that is not
|
||||
its field's type (a finite number, three of them, a name), or with a zone wider or deeper than its member is
|
||||
refused whole, as a RamError naming the field: nothing is read past and dropped."""
|
||||
"""(Mechanism, Ram) of a record. A record of another schema or version (the integer 2: not 2.0, not true), with
|
||||
a key this version does not know or without one it does, or with a value that is not its field's type (a finite
|
||||
number, three of them, a name), or with a zone of a body its pin does not join, or wider or deeper than its
|
||||
member, is refused whole, as a RamError naming the field: nothing is read past and dropped."""
|
||||
if not isinstance(data, dict):
|
||||
raise RamError("None", "record", f"a record is an object, got {type(data).__name__}")
|
||||
kind, version = str(data.get("kind")), data.get("version")
|
||||
|
|
@ -704,13 +702,11 @@ def from_record(data):
|
|||
raise RamError(kind, "record", f"three finite numbers, got {value!r}", pin=name)
|
||||
return [_number(kind, name, x) for x in value]
|
||||
|
||||
keys("record", data, ("schema", "version", "kind", "hinge", "pins", "offsets", "ram", "parts", "touch", "compliance"))
|
||||
keys("record", data, ("schema", "version", "kind", "hinge", "pins", "offsets", "ram", "parts", "touch"))
|
||||
hinge, pins, ram = data["hinge"], data["pins"], data["ram"]
|
||||
keys("hinge", hinge, ("pivot", "axis", "lo", "hi"))
|
||||
keys("pins", pins, PINS[kind])
|
||||
keys("ram", ram, [f.name for f in fields(Ram)])
|
||||
if data["compliance"] is not None:
|
||||
raise RamError(kind, "record", f"a compliance block ({', '.join(COMPLIANCE)}) is a later version's: version {VERSION} solves none and will not drop it")
|
||||
for name, value in ram.items():
|
||||
_number(kind, name, value, 0.0 if name == "bore" else None)
|
||||
if not isinstance(data["offsets"], list):
|
||||
|
|
|
|||
|
|
@ -1119,8 +1119,8 @@ class RecordDrives(unittest.TestCase):
|
|||
data = R.record(m, ram)
|
||||
wire = json.loads(json.dumps(data))
|
||||
self.assertEqual(wire, data)
|
||||
self.assertEqual(sorted(data), ["compliance", "hinge", "kind", "offsets", "parts", "pins", "ram", "schema", "touch", "version"])
|
||||
self.assertEqual((data["schema"], data["version"], data["compliance"]), ("brokkr.ram", 1, None))
|
||||
self.assertEqual(sorted(data), ["hinge", "kind", "offsets", "parts", "pins", "ram", "schema", "touch", "version"])
|
||||
self.assertEqual((data["schema"], data["version"]), ("brokkr.ram", 2))
|
||||
again, ram2 = R.from_record(wire)
|
||||
self.assertEqual(R.record(again, ram2), data)
|
||||
self.assertEqual((again.parts, again.touch), (m.parts, m.touch))
|
||||
|
|
@ -1151,18 +1151,18 @@ class RecordDrives(unittest.TestCase):
|
|||
def test_a_record_this_version_cannot_read_is_refused_whole(self):
|
||||
data = R.record(R.Mechanism("direct", O, X, -62, 0, a=(0.05, -0.3, 0.8), b=(0.05, -0.3, -0.6)), R.Ram(BORE))
|
||||
settle = {"stiffness": 2.0e6, "damping": 4.0e3, "travel": 0.02}
|
||||
self.assertEqual(tuple(settle), R.COMPLIANCE)
|
||||
ram = dict(data["ram"], stiffness=2.0e6)
|
||||
short = {k: v for k, v in data.items() if k != "touch"}
|
||||
for change, said in (({"version": 2}, "version 2"), ({"version": 2, "compliance": settle}, "version 2"), ({"compliance": settle}, "compliance block"),
|
||||
for change, said in (({"version": 1}, "reads brokkr.ram version 2; the record is brokkr.ram version 1"), ({"version": 3}, "version 3"), ({"version": 1, "settle": settle}, "version 1"),
|
||||
({"schema": "brokkr.kit"}, "brokkr.kit"), ({"settle": settle}, "unknown ['settle']"), ({"ram": ram}, "unknown ['stiffness']"),
|
||||
({"hinge": dict(data["hinge"], rate=1.0)}, "unknown ['rate']"),
|
||||
# a block that is falsy is a block (S23); the version is the integer 1
|
||||
({"compliance": {}}, "compliance block"), ({"compliance": 0}, "compliance block"), ({"compliance": False}, "compliance block"),
|
||||
({"version": 1.0}, "version 1.0"), ({"version": True}, "version True"), ({"version": "1"}, "version '1'"),
|
||||
# a key the record does not know is refused whatever it holds, null and falsy included (S23): a ram
|
||||
# record carries no settle. The version is the integer 2
|
||||
({"settle": None}, "unknown ['settle']"), ({"settle": {}}, "unknown ['settle']"), ({"settle": False}, "unknown ['settle']"),
|
||||
({"version": 2.0}, "version 2.0"), ({"version": True}, "version True"), ({"version": "2"}, "version '2'"),
|
||||
({"kind": "scissor"}, "kind is one of"),
|
||||
# a pin this kind has not, or a key that is no pin, is refused by name; so is one missing
|
||||
({"pins": dict(data["pins"], q=[0.0, 0.0, 0.0])}, "the pins's keys are not version 1's: unknown ['q']"),
|
||||
({"pins": dict(data["pins"], q=[0.0, 0.0, 0.0])}, "the pins's keys are not version 2's: unknown ['q']"),
|
||||
({"pins": dict(data["pins"], parts={})}, "unknown ['parts']"), ({"pins": {"a": data["pins"]["a"]}}, "missing ['b']"),
|
||||
({"pins": [1, 2]}, "(pin pins): an object, got list"), ({"ram": None}, "(pin ram): an object, got NoneType"),
|
||||
# every number is a finite number, the bore over 0; three of them make a point
|
||||
|
|
|
|||
Loading…
Reference in a new issue