tests/test_kitbash: the fittings kit's shapes pinned by name, place, size, topology and defaults (cut plate-fittings-kit, Soul s1)
Nine kit mutants (Soul's seven, heads on 0.9 r, louvre slant sign) each die in FittingsKitTests, not only by the plate hash. Bound 4.7e-10 by the margin rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
12022a423d
commit
34da146b5a
1 changed files with 98 additions and 0 deletions
|
|
@ -944,6 +944,13 @@ class FittingsKitTests(unittest.TestCase):
|
|||
self.assertEqual(self.kit["socketTypes"], {})
|
||||
self.assertEqual([part["sockets"] for part in self.kit["parts"].values()], [[]] * 9)
|
||||
|
||||
def test_the_defaults_are_the_kits_doc(self):
|
||||
"""What a row that names no params gets, part by part."""
|
||||
self.assertEqual({name: {p["name"]: p["default"] for p in part["params"]} for name, part in self.kit["parts"].items()}, {
|
||||
"bolt": {"r": 0.017}, "slot": {"w": 0.2, "h": 0.04}, "pit": {"w": 0.2, "h": 0.04, "depth": 0.012, "count": 1, "pitch": 0},
|
||||
"vents": {"w": 0.3, "h": 0.03, "count": 4}, "access_port": {"r": 0.12}, "port_bolts": {"r": 0.12}, "handle": {"length": 0.3, "lift": 0.065, "r": 0.016},
|
||||
"eye": {"size": 0.1}, "louvres": {"w": 0.6, "h": 0.72, "n": 6, "depth": 0.05, "frame": 0.07, "slant": 25}})
|
||||
|
||||
def test_every_part_builds_closed_and_wound_out_from_the_face(self):
|
||||
for name, part in self.kit["parts"].items():
|
||||
rng = random.Random(f"fittings.{name}")
|
||||
|
|
@ -976,6 +983,97 @@ class FittingsKitTests(unittest.TestCase):
|
|||
self.assertLess(abs(float(head[0, 0])), 1e-15) # a corner on +y, as the tracks' heads stand
|
||||
|
||||
|
||||
# Shapes: each part at params off its defaults, every shell's place and size from the kit's doc. A reading is how
|
||||
# far a built point or extent stands from the stated one (metres). Shipped: float rounding, held as 2.2e-16 a metre.
|
||||
# Least claimed mutants: port_bolts' heads on 0.9 r (0.91 shipped) at r 0.1, a slot bar 0.001 off, the port's heads
|
||||
# 0.001 up: each reads 1e-3. The bound is the geometric mean, 4.7e-10 (lodur:ruling:deterministic-bound-margin).
|
||||
SHAPED = 4.7e-10
|
||||
TOPOLOGY = {"slot": (32, 24, 4), "pit": (24, 18, 3), "vents": (24, 18, 3), "access_port": (170, 196, 1), "port_bolts": (96, 64, 8),
|
||||
"handle": (112, 82, 5), "eye": (200, 188, 5), "louvres": (64, 48, 8)}
|
||||
|
||||
def pieces(self, built, each=None):
|
||||
"""Each shape's points; a repeat's copies apart, `each` points a copy."""
|
||||
counts = built.counts.tolist()
|
||||
starts = np.concatenate([[0], np.cumsum(counts)[:-1]]).astype(int)
|
||||
out = []
|
||||
for index in sorted(set(built.shape.tolist())):
|
||||
points = built.V[sorted({int(v) for k in range(len(counts)) if built.shape[k] == index for v in built.faces[starts[k]:starts[k] + counts[k]]})]
|
||||
out += [points[i:i + each] for i in range(0, len(points), each)] if each else [points]
|
||||
return out
|
||||
|
||||
def box(self, points, centre, size, slant=0.0):
|
||||
"""How far a box's extents stand from a box of size about centre, turned slant degrees about x."""
|
||||
c, s = math.cos(math.radians(slant)), abs(math.sin(math.radians(slant)))
|
||||
half = np.array([size[0] / 2, size[1] / 2 * c + size[2] / 2 * s, size[1] / 2 * s + size[2] / 2 * c])
|
||||
return float(np.abs(np.array([points.min(axis=0), points.max(axis=0)]) - [np.array(centre) - half, np.array(centre) + half]).max())
|
||||
|
||||
def tube(self, points, axis, radius, low, high):
|
||||
"""How far a tube's points stand from radius about the vertical through axis (x, y), from low to high."""
|
||||
return max(float(np.abs(np.linalg.norm(points[:, :2] - axis, axis=1) - radius).max()), abs(float(points[:, 2].min()) - low), abs(float(points[:, 2].max()) - high))
|
||||
|
||||
def built(self, name, params):
|
||||
b = core.build(self.kit["parts"][name], core.parse_params(params))
|
||||
self.assertEqual((len(b.V), len(b.counts), b.shell_count), self.TOPOLOGY[name], name)
|
||||
self.assertTrue(closed_and_oriented(b), name)
|
||||
return b
|
||||
|
||||
def test_slot_and_pit_are_their_boxes(self):
|
||||
"""The slot's four bars around a w by h opening, 0.032 wide and 0.028 tall; the pit's count boxes pitch apart."""
|
||||
w, h = 0.3, 0.1
|
||||
bars = self.pieces(self.built("slot", "w=0.3; h=0.1"))
|
||||
for points, centre, size in zip(bars, ([0, h / 2 + 0.016, 0.014], [0, -h / 2 - 0.016, 0.014], [w / 2 + 0.016, 0, 0.014], [-w / 2 - 0.016, 0, 0.014]),
|
||||
([w + 0.06, 0.032, 0.028],) * 2 + ([0.032, h, 0.028],) * 2):
|
||||
self.assertLess(self.box(points, centre, size), self.SHAPED, centre)
|
||||
for k, points in enumerate(self.pieces(self.built("pit", "w=0.1; h=0.03; depth=0.02; count=3; pitch=0.08"), 8)):
|
||||
self.assertLess(self.box(points, [0, -0.08 + 0.08 * k, 0.01], [0.1, 0.03, 0.02]), self.SHAPED, k)
|
||||
|
||||
def test_vents_and_louvres_lean_their_own_ways(self):
|
||||
"""A vents lip is tilted 28 degrees with its upper edge down to the face; a louvre slat is turned slant
|
||||
degrees with its upper edge up off it."""
|
||||
h = 0.04
|
||||
for k, points in enumerate(self.pieces(self.built("vents", "w=0.2; h=0.04; count=3"), 8)):
|
||||
self.assertLess(self.box(points, [0, 0.75 * h - 2.7 * h + 2.7 * h * k, 0.014], [0.24, 0.9 * h, 0.012], 28), self.SHAPED, k)
|
||||
self.assertLess(float(points[np.argmax(points[:, 1]), 2]), 0.014, k)
|
||||
w, h, n, depth, frame = 0.5, 0.4, 4, 0.06, 0.05
|
||||
louvres = self.built("louvres", "w=0.5; h=0.4; n=4; depth=0.06; frame=0.05; slant=30")
|
||||
for points, centre, size in zip(self.pieces(louvres)[:4], ([0, -h / 2, depth / 2], [0, h / 2, depth / 2], [-w / 2, 0, depth / 2], [w / 2, 0, depth / 2]),
|
||||
([w + frame, frame, depth],) * 2 + ([frame, h + frame, depth],) * 2):
|
||||
self.assertLess(self.box(points, centre, size), self.SHAPED, centre)
|
||||
pitch = (h - frame) / n
|
||||
for k, points in enumerate(self.pieces(louvres, 8)[4:]):
|
||||
self.assertLess(self.box(points, [0, -0.5 * (h - frame) + 0.5 * pitch + pitch * k, 0.3 * depth], [w - frame, 0.75 * pitch, 0.25 * depth], 30), self.SHAPED, k)
|
||||
self.assertGreater(float(points[np.argmax(points[:, 1]), 2]), 0.3 * depth, k)
|
||||
|
||||
def test_access_port_is_its_profile_turned_and_its_heads_on_the_rim(self):
|
||||
"""The port's 28 turns of its eight profile points; eight hex heads of 0.07 r on 0.91 r at 45 degree steps,
|
||||
from the shoulder (0.035) up 0.012."""
|
||||
r = 0.1
|
||||
port = self.built("access_port", "r=0.1")
|
||||
turned = {(round(float(np.hypot(x, y)) / r, 9), round(float(z), 9)) for x, y, z in port.V}
|
||||
self.assertEqual(turned, {(0.0, 0.0), (1.0, 0.0), (1.0, 0.035), (0.82, 0.05), (0.82, 0.022), (0.34, 0.022), (0.34, 0.045), (0.0, 0.045)})
|
||||
for k, points in enumerate(self.pieces(self.built("port_bolts", "r=0.1"))):
|
||||
turn = math.radians(45 * k)
|
||||
self.assertLess(self.tube(points, 0.91 * r * np.array([math.cos(turn), math.sin(turn)]), 0.07 * r, 0.035, 0.047), self.SHAPED, k)
|
||||
|
||||
def test_handle_and_eye_stand_their_shells(self):
|
||||
"""The handle's bar 2 r square from 0.004 under the face to lift + r, its posts length apart on a washer of
|
||||
2.3 r and a hex foot of 1.5 r; the eye's pad, two heads 0.72 size off its middle, a neck, and a ring of 0.29
|
||||
to 0.55 size about 0.012 + 0.62 size, 0.26 size thick across x."""
|
||||
length, lift, r = 0.4, 0.08, 0.012
|
||||
bar, *feet = self.pieces(self.built("handle", "length=0.4; lift=0.08; r=0.012"))
|
||||
self.assertLess(float(np.abs(np.array([bar.min(axis=0), bar.max(axis=0)]) - [[-r, -length / 2 - r, -0.004], [r, length / 2 + r, lift + r]]).max()), self.SHAPED)
|
||||
for points, y, radius, low in zip(feet, (-1, 1, -1, 1), (2.3 * r, 2.3 * r, 1.5 * r, 1.5 * r), (0.0, 0.0, 0.008, 0.008)):
|
||||
self.assertLess(self.tube(points, [0, y * length / 2], radius, low, low + 0.008), self.SHAPED, (y, radius))
|
||||
size = 0.12
|
||||
pad, *heads, neck, ring = self.pieces(self.built("eye", "size=0.12"))
|
||||
self.assertLess(self.box(pad, [0, 0, 0.004], [1.1 * size, 2 * size, 0.012]), self.SHAPED)
|
||||
for points, y in zip(heads, (-1, 1)):
|
||||
self.assertLess(self.tube(points, [0, y * 0.72 * size], 0.11 * size, 0.01, 0.018), self.SHAPED, y)
|
||||
self.assertLess(self.box(neck, [0, 0, 0.012 + 0.1 * size], [0.34 * size, 0.5 * size, 0.24 * size]), self.SHAPED)
|
||||
across = np.hypot(ring[:, 1], ring[:, 2] - (0.012 + 0.62 * size))
|
||||
self.assertLess(max(abs(float(across.min()) - 0.29 * size), abs(float(across.max()) - 0.55 * size), abs(float(np.abs(ring[:, 0]).max()) - 0.13 * size)), self.SHAPED)
|
||||
|
||||
|
||||
class SurfaceFrameTests(unittest.TestCase):
|
||||
"""surface-frame: the frame brokkr_kitbash.cut gives a cutter. Bounds: a shipped reading is float rounding (worst
|
||||
4.4e-16 over the draws) and the least mutant's is 0.31 (S4, the roll dropped, at roll 18); 1e-9 separates them by
|
||||
|
|
|
|||
Loading…
Reference in a new issue