@rulecad/cad 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/AGENTS.md +45 -16
  2. package/CHANGELOG.md +724 -0
  3. package/EXAMPLES.md +61 -54
  4. package/README.md +376 -98
  5. package/TUTORIAL.md +2 -2
  6. package/bin/cad.mjs +2664 -541
  7. package/lib/animate.mjs +173 -49
  8. package/lib/assembly.mjs +1883 -435
  9. package/lib/beams.mjs +256 -52
  10. package/lib/belts.mjs +66 -15
  11. package/lib/board-work.mjs +12 -0
  12. package/lib/bought.mjs +309 -53
  13. package/lib/buildpage.mjs +179 -29
  14. package/lib/cache-file.mjs +105 -0
  15. package/lib/carried.mjs +201 -0
  16. package/lib/clone.mjs +194 -42
  17. package/lib/code-text.mjs +28 -0
  18. package/lib/design-imports.mjs +127 -0
  19. package/lib/design.mjs +871 -147
  20. package/lib/designshapes.mjs +142 -0
  21. package/lib/drive.mjs +187 -63
  22. package/lib/edit.mjs +922 -192
  23. package/lib/errors.mjs +16 -3
  24. package/lib/estimates.mjs +51 -0
  25. package/lib/explain.mjs +62 -13
  26. package/lib/fasten.mjs +2708 -507
  27. package/lib/fe-key.mjs +29 -0
  28. package/lib/fittings.mjs +721 -122
  29. package/lib/fixings.mjs +38 -13
  30. package/lib/framebuild.mjs +790 -175
  31. package/lib/framecheck.mjs +1901 -368
  32. package/lib/framegen.mjs +108 -22
  33. package/lib/frameheat.mjs +225 -42
  34. package/lib/frameprint.mjs +513 -108
  35. package/lib/frames.mjs +86 -18
  36. package/lib/framesize.mjs +719 -120
  37. package/lib/frametip.mjs +235 -0
  38. package/lib/gait.mjs +135 -23
  39. package/lib/grip.mjs +62 -13
  40. package/lib/guides.mjs +1403 -230
  41. package/lib/host.mjs +129 -23
  42. package/lib/inplace.mjs +171 -36
  43. package/lib/jigs.mjs +360 -78
  44. package/lib/joins.mjs +697 -118
  45. package/lib/jsonedit.mjs +88 -26
  46. package/lib/kept.mjs +84 -0
  47. package/lib/kit.mjs +439 -69
  48. package/lib/layout.mjs +2 -1
  49. package/lib/links.mjs +149 -42
  50. package/lib/list.mjs +334 -64
  51. package/lib/live-guard.mjs +68 -0
  52. package/lib/live-shape.mjs +96 -24
  53. package/lib/live.mjs +189 -59
  54. package/lib/loads.mjs +597 -136
  55. package/lib/machine.mjs +372 -74
  56. package/lib/magnets.mjs +162 -44
  57. package/lib/measured.mjs +1080 -117
  58. package/lib/mesh.mjs +526 -119
  59. package/lib/meshcmd.mjs +215 -60
  60. package/lib/motors.mjs +1002 -214
  61. package/lib/motorsvg.mjs +114 -32
  62. package/lib/names.mjs +18 -1
  63. package/lib/optimise.mjs +991 -287
  64. package/lib/order.mjs +515 -114
  65. package/lib/panels.mjs +482 -94
  66. package/lib/parts.mjs +81 -23
  67. package/lib/pins.mjs +163 -44
  68. package/lib/plates.mjs +223 -35
  69. package/lib/player.mjs +37 -9
  70. package/lib/power.mjs +64 -13
  71. package/lib/preview.mjs +83 -16
  72. package/lib/profilemeasure.mjs +572 -129
  73. package/lib/rules.mjs +17 -6
  74. package/lib/sandbox-hooks.mjs +179 -27
  75. package/lib/sandbox-lock.mjs +225 -0
  76. package/lib/sandbox-preload.mjs +2 -2
  77. package/lib/sandbox-run.mjs +122 -25
  78. package/lib/sandbox.mjs +667 -75
  79. package/lib/schema.mjs +42 -11
  80. package/lib/seats.mjs +227 -49
  81. package/lib/services.mjs +261 -52
  82. package/lib/sheet.mjs +963 -179
  83. package/lib/slotnuts.mjs +213 -34
  84. package/lib/targets/gist.mjs +4 -1
  85. package/lib/targets.mjs +22 -4
  86. package/lib/task.mjs +376 -79
  87. package/lib/versions.mjs +285 -39
  88. package/lib/wires.mjs +228 -45
  89. package/lib/workspace.mjs +200 -14
  90. package/package.json +19 -19
  91. package/schemas/assembly.schema.json +2 -2
  92. package/schemas/project.schema.json +6 -0
  93. package/templates/coupons/MEASURE.md +109 -0
  94. package/templates/coupons/assemblies/fixings-test.json +20 -0
  95. package/templates/coupons/assemblies/slot-test.json +11 -0
  96. package/templates/coupons/objects/fixings-coupon.js +88 -0
  97. package/templates/coupons/objects/fixings-coupon.json +26 -0
  98. package/templates/coupons/objects/holds-coupon.js +130 -0
  99. package/templates/coupons/objects/holds-coupon.json +42 -0
  100. package/templates/coupons/objects/slot-coupon.js +89 -0
  101. package/templates/coupons/objects/slot-coupon.json +29 -0
  102. package/templates/coupons/project.json +10 -0
@@ -0,0 +1,130 @@
1
+ // The holds coupon, the fixings coupon's second plate: what holds two parts together without a screw of steel. A plate
2
+ // with a row for each fit, at sizes either side of the one the kit draws: snap pin sockets (S3, S4), holes for a 3 mm
3
+ // steel dowel and for 1.75 mm filament, pressed (D3P, FP) and slipping (D3S, FS), pockets for 6x3 and 8x3 disc magnets
4
+ // pressed in (6x3, 8x3) and held by crush ribs (8x3R), and printed nuts for printed M8 and M10 bolts (M8N, M10N). Beside
5
+ // it, loose: the printed bolts for those nuts, one for each thread gap, a pull bolt to break, and snap pins at three barb
6
+ // depths for each socket row. Every size comes from v.fixings and the printer's rules, so the coupon prints round the
7
+ // figures the kit draws today, and again round yours once they are measured (MEASURE.md, rows 40 to 47).
8
+ // The plate's first layer is one rectangle with a few round holes (the sockets go through it, and each magnet pocket has
9
+ // a hole under it to push the magnet out); every loose piece stands on a plain round or hexagonal foot. Nothing needs a support.
10
+ import jscad from '@jscad/modeling'
11
+ const { cylinder, cylinderElliptic, roundedRectangle, circle, polygon } = jscad.primitives
12
+ const { extrudeLinear, extrudeRotate } = jscad.extrusions
13
+ const { translate } = jscad.transforms
14
+ const { hull } = jscad.hulls
15
+ const { offset } = jscad.expansions
16
+ const { measureBoundingBox } = jscad.measurements
17
+
18
+ export function main (v) {
19
+ const f = v.fixings, base = v.base, wall = v.wall, seg = v.segments
20
+ const fig = (x) => String(Number(x.toFixed(2))) // a figure as it is labelled and written back
21
+ const around = (centre, n, step) => Array.from({ length: n }, (_, i) => Number((centre + (i - (n - 1) / 2) * step).toFixed(v.places)))
22
+ const width = (text) => { const [lo, hi] = measureBoundingBox(v.shapes.text({ text, height: v.label, stroke: v.stroke })); return hi[0] - lo[0] }
23
+ const say = (text, x, y, z) => translate([x, y, z], extrudeLinear({ height: v.emboss }, v.shapes.text({ text, height: v.label, stroke: v.stroke })))
24
+ // the printer as plain values with one figure changed: each feature in a row is drawn as if the printer's rule were its figure
25
+ const printer = (k, x) => ({ ...v.x1c, [k]: x })
26
+ // A feature's stand, its outline rising from the bed to its top, flared at 45° where it meets the base
27
+ const stand = (outline, top) => v.ops.union(extrudeLinear({ height: top }, outline),
28
+ hull(extrudeLinear({ height: base }, offset({ delta: v.root, corners: 'round', segments: seg }, outline)), extrudeLinear({ height: base + v.root }, outline)))
29
+ const round = (across, top, cut) => ({ across, deep: across, top, make: (x, y) => ({ solid: stand(circle({ radius: across / 2, center: [x, y], segments: seg }), top), cut: cut(x, y) }) })
30
+ // A hole down through everything at (x, y): under a magnet's pocket, to push the magnet out with a pin
31
+ const through = (d, x, y, top) => translate([x, y, top / 2], cylinder({ radius: d / 2, height: top + 2, segments: seg }))
32
+
33
+ // ---------- the plate's rows ----------
34
+ // Snap pin sockets: a hole through a boss as thick as the pin's shaft is long, at three clearances round the kit's.
35
+ // The lowest stays a step above 0: a socket's gap has no hole compensation, so at 0 it prints smaller than its peg
36
+ const sockets = (d) => {
37
+ const name = `snap pin ${d}x${v.shaft}`, c0 = f.pinModel(name).hole.clearance / 2, cs = around(Math.max(c0, (v.step * (v.fits + 1)) / 2), v.fits, v.step)
38
+ return { name: `S${d}`, items: cs.map((c) => ({ label: fig(c), ...round(d + 2 * Math.max(...cs) + 2 * wall, v.shaft, (x, y) => f.pinHole(name, { printer: printer('snap_clearance', c), at: [x, y, v.shaft], depth: v.shaft, through: true })) })) }
39
+ }
40
+ // Plain pins: blind holes from the top, pressed (the figure is how much smaller than the pin, before hole_comp) or slipping
41
+ const pins = (pin, label, fit) => {
42
+ const key = fit === 'press' ? 'pin_press' : 'pin_slip', c0 = f.pinModel(pin, { fit }).hole.clearance, x0 = fit === 'press' ? -c0 : c0
43
+ const xs = around(x0, v.fits, fit === 'press' ? v.press_step : v.step), d = f.pinModel(pin, { fit: 'slip', printer: printer('pin_slip', Math.max(...xs)) }).hole.diameter, top = base + v.pin_depth
44
+ return { name: label, items: xs.map((x) => ({ label: fig(x), ...round(d + 2 * wall, top, (cx, cy) => f.pinHole(pin, { fit, printer: printer(key, x), at: [cx, cy, top], depth: v.pin_depth })) })) }
45
+ }
46
+ // Magnet pockets: as deep as the magnet, with the kit's lead-in at the mouth, the plate's base under it and a push-out
47
+ // hole through that. A press pocket is the magnet less the figure, past hole_comp; a ribbed pocket is the kit's glue
48
+ // pocket with three crush ribs whose tips stand the figure inside the magnet. The kit's seat is read once for the
49
+ // figures it draws from (a press either side of the kit's is a test piece, not a design: fixings would rightly fail it),
50
+ // and the pockets are cut with the design's own booleans
51
+ const bore = (d, depth, lead, x, y, top) => v.ops.union(
52
+ translate([x, y, top - depth / 2 + 1 / 2], cylinder({ radius: d / 2, height: depth + 1, segments: seg })),
53
+ translate([x, y, top - lead / 2], cylinderElliptic({ height: lead, startRadius: [d / 2, d / 2], endRadius: [d / 2 + lead, d / 2 + lead], segments: seg })))
54
+ const ribbed = (q, x, y, top) => v.ops.subtract(bore(q.diameter, q.depth, q.lead, x, y, top), ...Array.from({ length: q.ribs.count }, (_, i) => {
55
+ const t = (2 * Math.PI * i) / q.ribs.count + Math.PI / 2, out = q.diameter / 2 + q.ribs.radius - q.ribs.protrude, low = top - q.depth - 1, high = top - q.lead
56
+ return translate([x + out * Math.cos(t), y + out * Math.sin(t), (low + high) / 2], cylinder({ radius: q.ribs.radius, height: high - low, segments: seg / 2 }))
57
+ }))
58
+ const magnets = (size, label, fit) => {
59
+ const name = `disc magnet ${size}`, key = fit === 'press' ? 'magnet_press' : 'magnet_crush', s0 = f.magnetSeatModel(name, { fit }), q0 = s0.pocket
60
+ const x0 = fit === 'press' ? -q0.clearance : s0.rests.find((r) => r.name.endsWith(key)).value, xs = around(x0, v.fits, v.step)
61
+ const top = base + q0.depth, across = q0.nominal[0] + q0.comp + 2 * q0.lead + 2 * wall
62
+ return { name: label, items: xs.map((x) => ({ label: fig(x), ...round(across, top, (cx, cy) => v.ops.union(fit === 'press' ? bore(q0.nominal[0] + q0.comp - x, q0.depth, q0.lead, cx, cy, top)
63
+ : ribbed(f.magnetSeatModel(name, { fit, printer: printer(key, x) }).pocket, cx, cy, top), through(v.push, cx, cy, top))) })) }
64
+ }
65
+ // Printed nuts for printed bolts: a boss a hex nut's height tall (rounded up to whole layers), a thread through it and
66
+ // the plate drawn half the gap off its basic profile (the bolt takes the other half), as deep as printedBoltModel
67
+ // takes a nut's thread to be when it works out the bolt's strength
68
+ const nuts = (t) => {
69
+ const g0 = f.holeModel(t, { kind: 'thread', mate: 'printed' }).threaded.clearance, gaps = around(g0, v.fits, v.step), high = Math.ceil(f.nutModel(t).height / v.x1c.layer - v.tiny) * v.x1c.layer
70
+ const made = gaps.map((gap) => f.holeModel(t, { kind: 'thread', mate: 'printed', gap, depth: high, through: true })), across = Math.max(...made.map((h) => h.diameter)) + 2 * wall
71
+ return { name: `${t}N`, items: gaps.map((gap) => ({ label: fig(gap), ...round(across, high, (x, y) => f.hole(t, { kind: 'thread', mate: 'printed', gap, depth: high, through: true, at: [x, y, high] })) })), gaps, high }
72
+ }
73
+
74
+
75
+ const n8 = nuts('M8'), n10 = nuts('M10')
76
+ const rows = [[sockets(v.small_pin), sockets(v.large_pin), pins('dowel 3x12', 'D3P', 'press')],
77
+ [pins('filament pin 1.75x12', 'FP', 'press'), pins('filament pin 1.75x12', 'FS', 'slip'), pins('dowel 3x12', 'D3S', 'slip')],
78
+ [magnets('6x3', '6x3', 'press'), magnets('8x3', '8x3', 'press'), magnets('8x3', '8x3R', 'ribs')], [n8, n10]]
79
+ const solids = [], cuts = [], labels = []
80
+ let y = v.gap, length = 0
81
+ for (const row of rows) {
82
+ const deep = Math.max(...row.flatMap((g) => g.items.map((it) => it.deep))), line = y + v.label / 2, mid = y + v.label + v.gap + deep / 2
83
+ let x = v.gap
84
+ for (const g of row) {
85
+ const nameWidth = width(g.name)
86
+ labels.push(say(g.name, x + nameWidth / 2, mid, base)); x += nameWidth + v.gap
87
+ for (const it of g.items) {
88
+ const pitch = Math.max(it.across, width(it.label) + v.gap), cx = x + pitch / 2, m = it.make(cx, mid)
89
+ solids.push(m.solid); cuts.push(m.cut); labels.push(say(it.label, cx, line, base)); x += pitch + v.gap
90
+ }
91
+ x += v.gap
92
+ }
93
+ length = Math.max(length, x); y += deep + v.label + v.gap * 2
94
+ }
95
+ const plate = extrudeLinear({ height: base }, roundedRectangle({ size: [length, y], center: [length / 2, y / 2], roundRadius: v.corner, segments: seg }))
96
+ const out = { plate: v.ops.union(v.ops.subtract(v.ops.union(plate, ...solids), ...cuts), ...labels) }
97
+
98
+ // ---------- the loose pieces, in a row behind the plate ----------
99
+ // Marks: one, two or three notches down the side of a bolt's head or a pin's foot, for the first, second and third figure
100
+ const turn = (v.notch_turn * Math.PI) / v.half_turn
101
+ const notches = (count, radius, height) => Array.from({ length: count }, (_, i) => cylinder({ radius: v.notch, height: 2 * height, center: [radius * Math.cos(i * turn), radius * Math.sin(i * turn), 0], segments: seg / 2 }))
102
+ let x = v.gap, deep = 0
103
+ const place = (name, solid, across) => { out[name] = translate([x + across / 2, y + v.gap + across / 2, 0], solid); x += across + v.gap * 2; deep = Math.max(deep, across) }
104
+ // Printed bolts standing on their heads, one for each of the nuts' gaps, long enough to go through the nut and on
105
+ for (const [t, n] of [['M8', n8], ['M10', n10]]) {
106
+ n.gaps.forEach((gap, i) => {
107
+ const length = Math.round(n.high * v.engaged), b = f.printedBolt(`${t}x${length} hex printed`, { gap }), across = b.screw.headDiameter
108
+ place(`bolt-${t.toLowerCase()}-${fig(gap)}`, v.ops.subtract(b, ...notches(i + 1, (across / 2) * Math.cos(turn / 2), b.screw.headHeight)), across + v.gap)
109
+ })
110
+ }
111
+ // The pull bolt: an M8 printed bolt for a bought steel nut, its shank turned down to a waist that breaks within the
112
+ // luggage scale's reach. The waist is reached by 45° cones from the shank, so nothing overhangs past the printer's limit
113
+ {
114
+ const b = f.printedBolt(`M8x${v.pull_length} hex printed`, { nut: 'steel' }), k = b.screw.headHeight, R = b.screw.major / 2, r = v.waist / 2, z1 = k + 1, z2 = z1 + (R - r) + v.waist_length + (R - r)
115
+ const keep = extrudeRotate({ segments: seg }, polygon({ points: [[0, z1], [R, z1], [r, z1 + R - r], [r, z2 - (R - r)], [R, z2], [0, z2]] }))
116
+ const ring = v.ops.subtract(translate([0, 0, (z1 + z2) / 2], cylinder({ radius: R + 2, height: z2 - z1, segments: seg })), keep)
117
+ place('pull-bolt', v.ops.subtract(b, ring), b.screw.headDiameter + v.gap)
118
+ }
119
+ // Snap pins standing on their feet, three barb depths for each socket row, the split ending a millimetre above the foot.
120
+ // They are drawn from their plain figures (snapPin, the same solid f.pin draws), not checked as a design's pins are:
121
+ // on a split this short most bend past the strain the kit holds a pin to (pin.strain), and finding which click and
122
+ // which break is what they are printed for
123
+ for (const d of [v.small_pin, v.large_pin]) {
124
+ around(v.barb, v.fits, v.barb_step).forEach((lip, i) => {
125
+ const r = d / 2, rise = r + lip, slot = v.shaft - 1 + lip + rise, p = f.snapPin({ diameter: d, length: v.shaft, lip, slot, head: r }), foot = d * 2
126
+ place(`snap-pin-${d}-${fig(lip)}`, v.ops.subtract(p, ...notches(i + 1, foot / 2, 2)), foot + 2)
127
+ })
128
+ }
129
+ return out
130
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "holds-coupon",
4
+ "title": "Holds coupon",
5
+ "version": "0.1.0",
6
+ "uses": [
7
+ "x1c"
8
+ ],
9
+ "engine": "manifold",
10
+ "orientation": "Flat on the bed as drawn: the plate on its base with every hole opening upward, the bolts standing on their heads, the snap pins on their feet",
11
+ "description": "The fixings coupon's second plate: snap pin sockets for 3 and 4 mm pins at three clearances, holes for a 3 mm steel dowel and 1.75 mm filament at three press and three slip fits, 6x3 and 8x3 disc magnet pockets at three press fits and an 8x3 with crush ribs at three, and printed nuts, a hex nut's height, for M8 and M10 printed bolts at three thread gaps. Loose beside it: the six printed bolts, a pull bolt to break, and six snap pins at three barb depths. Each figure is the one to write back with cad measured (MEASURE.md, rows 40 to 47). Print it with the fixings coupon, once per printer and plastic.",
12
+ "variables": {
13
+ "base": { "value": "x1c.layer * 6", "unit": "mm", "rule": "The plate every feature stands on: six layers, the floor under every blind hole and pocket, and a first layer that is one plain rectangle but for the socket and push-out holes" },
14
+ "wall": { "value": "x1c.wall_min * 2", "unit": "mm", "rule": "Plastic round every hole and pocket: four print lines, as a design gives a boss" },
15
+ "gap": { "value": "x1c.wall_min", "unit": "mm", "rule": "Between features, between a feature and its figure, between loose pieces, and round the edge" },
16
+ "root": { "value": "x1c.chamfer", "unit": "mm", "rule": "The 45° flare where each boss meets the plate, so no inside corner is square" },
17
+ "step": { "value": "x1c.hole_comp", "unit": "mm", "rule": "Sockets, slip fits, magnet pockets and printed nuts step by the printer's hole compensation either side of what the kit draws: the amount a printed hole comes out wrong by" },
18
+ "press_step": { "value": "x1c.hole_comp / 2", "unit": "mm", "rule": "A pin's press fit steps by half that: a pin grips or splits its boss over a few hundredths of a millimetre" },
19
+ "shaft": { "value": 6, "unit": "mm", "rule": "A snap pin's shaft, and the thickness of its socket's boss from the bed, so the barb clicks out just past the plate's underside" },
20
+ "barb": { "value": 0.4, "unit": "mm", "rule": "The middle snap pin's barb depth, the kit's default; the others are a barb_step either side" },
21
+ "barb_step": { "value": 0.1, "unit": "mm", "rule": "The snap pins' barbs step by a tenth of a millimetre: about a quarter of the barb, enough to feel between a pin that clicks and one that will not go" },
22
+ "pin_depth": { "value": 6, "unit": "mm", "rule": "How deep a dowel or a filament pin goes into its hole: twice a 3 mm dowel's diameter, so it is held straight, and the rest of a 12 mm pin stands out to pull on" },
23
+ "push": { "value": 2, "unit": "mm", "rule": "The hole under each magnet pocket, to push a pressed magnet out with a 1.75 mm filament or a small screwdriver" },
24
+ "engaged": { "value": 2, "rule": "A printed bolt's length as a multiple of its nut's height: it goes right through the nut, with as much again to hold it by" },
25
+ "tiny": { "value": 1e-6, "rule": "What a height may be over a whole number of layers and still count as that number" },
26
+ "pull_length": { "value": 45, "unit": "mm", "rule": "The pull bolt's length under its head: the waist, then 36 mm of full thread, room for blocks up to 20 mm thick (MEASURE.md row 47: an 18 mm plywood offcut), an M8 washer (1.6 mm), a bought M8 nut (6.8 mm at most) and a pitch to start the nut on" },
27
+ "waist": { "value": 3.5, "unit": "mm", "rule": "The pull bolt's waist, across: 9.62 mm², which breaks at about 38 kg if the plastic holds 39 MPa across its layers (less across them in practice), within a 50 kg luggage scale's reach. Thick enough that the bolt prints standing: a sideways push of 1 N at its tip, as the nozzle passes, stresses the waist about 9.9 MPa (16 at 3 mm) and sways the tip about 0.46 mm (1 mm at 3 mm by 6), by beam bending at pla.modulus 2680 MPa: an estimate" },
28
+ "waist_length": { "value": 3.5, "unit": "mm", "rule": "The waist's straight length, one diameter, so it breaks in the waist and not where the cones meet the shank, and short so the bolt sways little as it prints standing" },
29
+ "small_pin": { "value": 3, "unit": "mm", "rule": "The smaller snap pin: the thinnest the kit draws a sampler's pins, above fixings.pin_least (2 mm) by half again" },
30
+ "large_pin": { "value": 4, "unit": "mm", "rule": "The larger snap pin: the size the kit's examples hold a lid with (snap pin 4x6)" },
31
+ "places": { "value": 3, "rule": "Figures in a row are worked to a thousandth of a millimetre, so a step's sum does not leave 0.30000000000000004" },
32
+ "fits": { "value": 3, "rule": "Three of every feature: the kit's figure and a step either side" },
33
+ "notch_turn": { "value": 60, "unit": "°", "rule": "The notches are a sixth of a turn apart, so on a hex head they fall on its flats" },
34
+ "half_turn": { "value": 180, "unit": "°", "rule": "Half a turn, to turn degrees into radians" },
35
+ "notch": { "value": 0.5, "unit": "mm", "rule": "The notches down the side of a loose bolt's head or a snap pin's foot that say which figure it is: one, two or three, for the first, second and third figure in its row" },
36
+ "label": { "value": 2.5, "unit": "mm", "rule": "Figure height: six print lines tall, readable close up, and small enough that a figure is no wider than its feature" },
37
+ "stroke": { "value": "x1c.line", "unit": "mm", "rule": "One print line, for the figures" },
38
+ "emboss": { "value": "x1c.layer * 2", "unit": "mm", "rule": "Two layers proud" },
39
+ "corner": { "value": 3, "unit": "mm", "rule": "The plate's corners, rounded so they stay down" },
40
+ "segments": { "value": 48, "rule": "Facets on round holes, bosses and the pull bolt's waist" }
41
+ }
42
+ }
@@ -0,0 +1,89 @@
1
+ // The slot coupon: what a printed part needs to slide in a bought beam's slot, for the two slot families most hobby
2
+ // beams have (slot 6 on 20 mm beams, slot 8 on 30 and 40 mm beams). For each: five tongues, the part of a printed
3
+ // fitting that keys into the slot's opening; five printed carriers (@rulecad/frames' carrier, a block holding a hex nut
4
+ // that slides along the slot like a slide-in nut); and three short printed slots, standing on end, that a bought slot
5
+ // nut slides into. Every piece lies loose on the bed with its figure, the clearance a side, on top. Each is drawn from
6
+ // the slot's rule set (v.frames.slotModel): print it again once the slot is measured, and it is drawn from yours.
7
+ // Each piece is a part of its own. Everything stands on a plain first layer and nothing needs a support (MEASURE.md, rows 29 to 33).
8
+ import jscad from '@jscad/modeling'
9
+ const { cuboid, polygon } = jscad.primitives
10
+ const { extrudeLinear } = jscad.extrusions
11
+ const { translate, rotateZ } = jscad.transforms
12
+ const { offset } = jscad.expansions
13
+ const { measureBoundingBox } = jscad.measurements
14
+
15
+ // The families, each with the thread its carriers hold: the largest hex nut a carrier takes in that slot at every
16
+ // clearance tried (an M3 nut leaves too little plastic under it in slot 6 at 0.3 mm a side)
17
+ const FAMILIES = [['slot-6', 'M2.5'], ['slot-8', 'M5']]
18
+
19
+ export function main (v) {
20
+ const fig = (x) => String(Number(x.toFixed(2))) // a figure as it is labelled and written back
21
+ const around = (centre, n, step) => Array.from({ length: n }, (_, i) => centre + (i - (n - 1) / 2) * step)
22
+ const width = (text) => { const [lo, hi] = measureBoundingBox(v.shapes.text({ text, height: v.label, stroke: v.stroke })); return hi[0] - lo[0] }
23
+ const say = (text, x, y, z) => translate([x, y, z], extrudeLinear({ height: v.emboss }, v.shapes.text({ text, height: v.label, stroke: v.stroke })))
24
+ const box = (lo, hi) => translate(lo.map((a, i) => (a + hi[i]) / 2), cuboid({ size: lo.map((a, i) => hi[i] - a) }))
25
+ const wordy = Math.max(...around(v.fit, v.fits, v.step).map((c) => width(fig(c))))
26
+
27
+ // ---------- the pieces, each drawn with its length along x from 0 and centred on y = 0, on the bed ----------
28
+ // A tongue: a head that lies on the beam's face, and under it (printed on top) a tongue as deep as the slot's lips,
29
+ // narrower than the opening by the clearance each side. A V-groove at each side of its root, so no inside corner is
30
+ // square; the head runs on past the tongue to carry its figure
31
+ const tongue = (slot, c) => {
32
+ const w = slot.opening - 2 * c, head = slot.opening + 2 * v.wall, long = v.key + v.gap * 2 + wordy, top = v.base + slot.lip
33
+ const solid = v.ops.union(box([0, -head / 2, 0], [long, head / 2, v.base]), box([0, -w / 2, v.base - v.root], [v.key, w / 2, top]))
34
+ const cut = [1, -1].map((s) => groove(s, w / 2, v.base, v.root, v.key))
35
+ return { long, across: head, solid: v.ops.subtract(solid, ...cut), label: say(fig(c), v.key + v.gap + wordy / 2, 0, v.base) }
36
+ }
37
+ // A carrier for a hex nut, as frames draws it with the clearance as the printer's slot fit, long enough that its
38
+ // figure fits beside the screw's hole
39
+ const carrier = (slot, thread, c) => {
40
+ const printer = { ...v.x1c, slot_fit: c }, m0 = v.frames.carrierModel(slot, { thread, printer })
41
+ const length = Math.ceil(Math.max(m0.length, m0.screwHole + 2 * (wordy + v.gap * 2)))
42
+ const m = v.frames.carrierModel(slot, { thread, printer, length }), high = m.levels.bottom - m.levels.top
43
+ return { long: m.total, across: Math.max(...m.section.map(([y]) => Math.abs(y))) * 2, solid: v.frames.carrier(m, { pose: 'print', printer }), label: say(fig(c), (m.total + m.screwHole) / 2 + v.gap + wordy / 2, 0, high), model: m }
44
+ }
45
+ // A short printed slot standing on end: the slot's outline, opened by the clearance each side (its inside corners
46
+ // round by as much), cut down into a block from the top to a floor, the slot's face on the block's side (y = 0)
47
+ const printed = (slot, c) => {
48
+ const path = v.frames.slotPath(slot).map(([u, d]) => [u, -d]), void2 = polygon({ points: [[path[0][0], v.wall], ...path, [path[path.length - 1][0], v.wall]] })
49
+ const open = offset({ delta: c, corners: 'round', segments: v.segments }, void2), across = slot.cavityWidth + 2 * c + 2 * v.wall, deep = slot.cavityDepth + c + v.wall + v.label + v.gap * 2
50
+ const block = box([-across / 2, -deep, 0], [across / 2, 0, v.tall]), cut = translate([0, 0, v.base], extrudeLinear({ height: v.tall }, open))
51
+ return { long: across, across: deep, centre: -deep / 2, solid: v.ops.subtract(block, cut), label: say(fig(c), 0, -deep + v.gap + v.label / 2, v.tall) }
52
+ }
53
+
54
+ // ---------- the rows, front to back: tongues, carriers, printed slots; slot 6 on the left, slot 8 on the right ----------
55
+ const groups = FAMILIES.map(([name, thread]) => {
56
+ const slot = v.frames.slotModel(name)
57
+ return {
58
+ name,
59
+ tongues: around(v.fit, v.fits, v.step).map((c) => ({ c, ...tongue(slot, c) })),
60
+ carriers: around(v.fit, v.fits, v.step).map((c) => ({ c, ...carrier(slot, thread, c) })),
61
+ slots: around(v.fit, v.slots, v.slot_step).map((c) => ({ c, ...printed(slot, c) }))
62
+ }
63
+ })
64
+ const out = {} // each piece a part of its own, named for its family, what it is and its clearance: slot-6-tongue-0.15
65
+ let y = v.gap
66
+ for (const row of ['tongues', 'carriers', 'slots']) {
67
+ let x = v.gap, deep = 0
68
+ for (const g of groups) {
69
+ for (const p of g[row]) {
70
+ // tongues and carriers turned to run along y, side by side in x; a printed slot stands as it is
71
+ const turned = row !== 'slots', span = turned ? p.across : p.long, reach = turned ? p.long : p.across
72
+ const place = (s) => turned ? translate([x + span / 2, y, 0], rotateZ(Math.PI / 2, s)) : translate([x + span / 2, y + reach, 0], s)
73
+ out[`${g.name}-${row.slice(0, -1)}-${fig(p.c)}`] = v.ops.union(place(p.solid), place(p.label))
74
+ x += span + v.gap * 2; deep = Math.max(deep, reach)
75
+ }
76
+ x += v.gap * 2
77
+ }
78
+ y += deep + v.gap * 2
79
+ }
80
+ return out
81
+ }
82
+
83
+ // The V-groove beside a tongue's root, along x: a triangle in y, z with its point down, cut into the head's top beside
84
+ // the tongue's side at y = s × edge
85
+ function groove (s, edge, base, root, key) {
86
+ const tri = s > 0 ? [[edge, base - root], [edge + root, base], [edge, base]] : [[-edge, base - root], [-edge, base], [-edge - root, base]]
87
+ // drawn in x, y as (y, z), extruded along z for the tongue's length, then turned so the extrusion runs along x
88
+ return jscad.transforms.transform([0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1], extrudeLinear({ height: key }, polygon({ points: tri })))
89
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
3
+ "name": "slot-coupon",
4
+ "title": "Slot coupon",
5
+ "version": "0.1.0",
6
+ "uses": [
7
+ "x1c"
8
+ ],
9
+ "engine": "manifold",
10
+ "orientation": "Loose pieces flat on the bed as drawn: tongues head down, carriers floor down, printed slots standing on end with their floor down",
11
+ "description": "For slot 6 (20 mm beams) and slot 8 (30 and 40 mm beams): five tongues and five printed nut carriers (M2.5 in slot 6, M5 in slot 8) at clearances either side of the printer's fit, and three short printed slots for a bought slot nut. Each piece carries its clearance a side, the figure to write back with cad measured (MEASURE.md, rows 29 to 33). Drawn from the slot's rule set: print it again once the slot is measured.",
12
+ "variables": {
13
+ "base": { "value": "x1c.layer * 6", "unit": "mm", "rule": "A tongue's head and a printed slot's floor: six layers, and a first layer that is one plain piece" },
14
+ "wall": { "value": "x1c.wall_min * 2", "unit": "mm", "rule": "Plastic round a printed slot, and a tongue's head beyond the opening each side: four print lines" },
15
+ "gap": { "value": "x1c.wall_min", "unit": "mm", "rule": "Between pieces, between a feature and its figure, and round the edge" },
16
+ "root": { "value": "x1c.chamfer", "unit": "mm", "rule": "The V-groove each side of a tongue's root, so the tongue meets its head with no square inside corner and the head still lies flat on the beam's face" },
17
+ "fit": { "value": "x1c.fit", "unit": "mm", "rule": "The middle clearance a side: what the kit draws a printed part in a slot with until the slot fit is measured" },
18
+ "step": { "value": "x1c.hole_comp / 2", "unit": "mm", "rule": "Tongues and carriers step by half the printer's hole compensation: a printed width comes out about that far either way, and a slot's opening is held to a tenth or two" },
19
+ "slot_step": { "value": "x1c.hole_comp", "unit": "mm", "rule": "Printed slots step by the printer's hole compensation, the amount a printed hole comes out wrong by" },
20
+ "fits": { "value": 5, "rule": "Five tongues and five carriers: the printer's fit and two steps either side" },
21
+ "slots": { "value": 3, "rule": "Three printed slots: the printer's fit and a step either side" },
22
+ "key": { "value": 12, "unit": "mm", "rule": "A tongue's length along the slot: longer than the opening is wide, so it slides straight and cannot twist" },
23
+ "tall": { "value": 15, "unit": "mm", "rule": "A printed slot's height: longer than a bought slide-in nut, so it slides its whole length" },
24
+ "label": { "value": 2.5, "unit": "mm", "rule": "Figure height: six print lines tall, readable close up, and narrow enough to sit across a carrier's top" },
25
+ "stroke": { "value": "x1c.line", "unit": "mm", "rule": "One print line, for the figures" },
26
+ "emboss": { "value": "x1c.layer * 2", "unit": "mm", "rule": "Two layers proud" },
27
+ "segments": { "value": 48, "rule": "Facets on the rounds of a printed slot's corners" }
28
+ }
29
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "coupons",
3
+ "description": "Test prints that settle the kit's figures on your printer and plastic: the fixings, holds and slot coupons. MEASURE.md says how to read each and the cad measured command that writes the figure back.",
4
+ "material": "PLA",
5
+ "objects": [
6
+ "fixings-coupon",
7
+ "holds-coupon",
8
+ "slot-coupon"
9
+ ]
10
+ }