@rulecad/cad 0.7.35 → 0.7.36

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.
package/EXAMPLES.md CHANGED
@@ -460,30 +460,47 @@ export function main (v) {
460
460
  "title": "Slide base",
461
461
  "version": "0.1.0",
462
462
  "uses": ["x1c"],
463
+ "engine": "manifold",
463
464
  "anchors": {
464
465
  "axle": { "at": [0, "centre", "thick"], "axis": [0, 0, 1] },
465
466
  "track": { "at": ["start", 0, "thick"], "axis": [1, 0, 0] }
466
467
  },
467
468
  "variables": {
468
469
  "centre": { "value": 7.2, "unit": "mm", "rule": "The pinion's axle above the rack's pitch line: its pitch radius and its shift, m z / 2 + x m" },
469
- "length": { "value": 140, "unit": "mm", "rule": "Room for the rack's whole travel" },
470
+ "length": { "value": 120, "unit": "mm", "rule": "The rack (75.4 mm) and its travel, ±22 mm" },
470
471
  "start": { "value": -37.7, "unit": "mm", "rule": "The rack's middle under the knob at rest: half its 24 teeth, 12 × π" },
471
- "wide": { "value": 40, "unit": "mm", "rule": "Under the rack and the knob" },
472
- "thick": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Fifteen layers" }
472
+ "strip": { "value": 12, "unit": "mm", "rule": "The strip under the rack, from behind its guide to under its teeth" },
473
+ "boss": { "value": 12, "unit": "mm", "rule": "Round the axle's foot" },
474
+ "foot": { "value": 40, "unit": "mm", "rule": "A foot across the middle, so it stands without rocking" },
475
+ "thick": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Fifteen layers" },
476
+ "pin": { "value": "3.2 - x1c.line / 2", "unit": "mm", "rule": "The axle: the pinion's 3.2 mm bore less half a line, so it turns" },
477
+ "pin_height": { "value": "x1c.layer * 60", "unit": "mm", "rule": "Up through the pinion and its knob" },
478
+ "guide_y": { "value": "0 - 5.45 - x1c.line / 2", "unit": "mm", "rule": "Behind the rack's back (1.25 + 4.2 mm under its pitch line), half a line clear" },
479
+ "guide": { "value": "x1c.line * 4", "unit": "mm", "rule": "The guide wall: four lines" },
480
+ "guide_height": { "value": "x1c.layer * 20", "unit": "mm", "rule": "Most of the rack's width" }
473
481
  }
474
482
  }
475
483
  ```
476
484
 
477
485
  ```js projects/home/objects/rail.js
478
- // The base: a plate under the rack's travel and the knob, the axle above the rack.
486
+ // The base as little as holds it: a strip under the rack's travel with a wall behind the rack (so it slides straight
487
+ // and can't back away from the pinion), a boss carrying the pinion's axle, and a foot across the middle.
479
488
  import jscad from '@jscad/modeling'
489
+ const { cuboid, cylinder } = jscad.primitives
480
490
 
481
491
  export function main (v) {
482
- return jscad.primitives.cuboid({ size: [v.length, v.wide, v.thick], center: [0, v.wide / 4, v.thick / 2] })
492
+ const y0 = v.guide_y - v.guide, strip = cuboid({ size: [v.length, v.strip, v.thick], center: [0, y0 + v.strip / 2, v.thick / 2] })
493
+ const boss = cylinder({ radius: v.boss / 2, height: v.thick, center: [0, v.centre, v.thick / 2] })
494
+ const neck = cuboid({ size: [v.boss, v.centre - y0, v.thick], center: [0, (y0 + v.centre) / 2, v.thick / 2] })
495
+ const foot = cuboid({ size: [v.boss, v.foot, v.thick], center: [0, y0 + v.foot / 2 - v.boss, v.thick / 2] })
496
+ const axle = cylinder({ radius: v.pin / 2, height: v.pin_height, center: [0, v.centre, v.thick + v.pin_height / 2] })
497
+ const guide = cuboid({ size: [v.length, v.guide, v.guide_height], center: [0, v.guide_y - v.guide / 2, v.thick + v.guide_height / 2] })
498
+ return v.ops.union(strip, boss, neck, foot, axle, guide)
483
499
  }
484
500
  ```
485
501
 
486
- The assembly: the knob turns on the base's axle, and the rack slides along its track, its middle under the knob at
502
+ The assembly: the knob turns on the base's axle (a pin printed with the base), and the rack slides along its track
503
+ against a guide wall, its middle under the knob at
487
504
  rest, so half a turn either way (±22 mm) keeps the pinion on its teeth. The slide's joint doesn't say
488
505
  how far it moves for a turn of the knob: its `mesh` says which joint drives it, and the gears' module and teeth (read
489
506
  from the parts, so they can't disagree). The check works out the travel a turn and the phase that puts a tooth in a
@@ -513,7 +530,8 @@ npx cad check home/slider --sweep --steps 12
513
530
  ```
514
531
 
515
532
  The check says `knob drives slide: 43.98 mm of rack a turn`, the contact ratio, and that the axle is where the gears
516
- need it (`centre distance 7.2 mm, as they need`). Set the base's `centre` to 7 and it fails: the teeth would jam. The
533
+ need it (`centre distance 7.2 mm, as they need`). Set the base's `centre` to 6.9 and it fails: 0.3 mm closer is more than the
534
+ teeth's 0.15 mm of backlash allows, and they would jam. The
517
535
  sweep turns the knob from −180° to 180° with the rack following, and names any teeth that touch on the way. The link
518
536
  carries the knob as a slider, with the rack moving with it: `npx cad link home/slider --md`.
519
537
 
@@ -533,7 +551,7 @@ planetary({ module: 1, ratio: 0.25, planets: 3, held: 'ring', input: 'carrier',
533
551
 
534
552
  The ring is the sun and two planets across (18 + 2 × 18 = 54), and the planets go in evenly: 18 + 54 = 72 is a whole
535
553
  number of threes. The parts: a case with the ring on it and a pin for the sun, the sun with the spool's shaft, three
536
- planets, and the carrier with the planets' pins and the crank.
554
+ planets, the carrier with the planets' pins and the crank arm, and the crank's handle.
537
555
 
538
556
  ```json projects/home/objects/winder-case.json
539
557
  {
@@ -544,21 +562,36 @@ planets, and the carrier with the planets' pins and the crank.
544
562
  "uses": ["x1c"],
545
563
  "engine": "manifold",
546
564
  "variables": {
547
- "radius": { "value": 34, "unit": "mm", "rule": "Round the ring's rim (62.5 mm across)" },
565
+ "radius": { "value": 33, "unit": "mm", "rule": "The ring's rim: the case is a rim under it" },
566
+ "rim": { "value": "x1c.line * 14", "unit": "mm", "rule": "The rim under the ring's, wide enough for its push pins" },
567
+ "snap": { "value": 2, "unit": "mm", "rule": "Two push pins hold the ring still: their shafts" },
568
+ "snap_lip": { "value": 0.3, "unit": "mm", "rule": "The barb's lip, clicking over the floor of the ring's counterbore" },
569
+ "snap_back": { "value": 90, "unit": "deg", "rule": "A square back: it holds for good" },
570
+ "snap_at": { "value": 30.6, "unit": "mm", "rule": "Halfway across the ring's rim, between its roots and its outside" },
571
+ "snap_length": { "value": 4, "unit": "mm", "rule": "Up the ring's 6 mm rim to its 2 mm counterbore" },
572
+ "flange": { "value": 2, "unit": "mm", "rule": "A push pin's foot flange, buried in the rim" },
573
+ "hub": { "value": 12, "unit": "mm", "rule": "Round the sun's axle" },
574
+ "spoke": { "value": "x1c.line * 12", "unit": "mm", "rule": "Three spokes from the hub to the rim" },
575
+ "spokes": { "value": 3, "rule": "Three: it stands without rocking" },
548
576
  "t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Base, fifteen layers" },
549
577
  "pin": { "value": 3, "unit": "mm", "rule": "The sun's axle" },
550
- "pin_height": { "value": 24, "unit": "mm", "rule": "Up through the sun and its shaft" }
578
+ "pin_height": { "value": 22, "unit": "mm", "rule": "Up through the sun and its shaft" }
551
579
  }
552
580
  }
553
581
  ```
554
582
 
555
583
  ```js projects/home/objects/winder-case.js
556
- // The case: a base with the sun's axle standing in the middle. The ring sits on it.
584
+ // The case as little as holds it: a rim the ring sits on (two push pins hold it still), a hub with the sun's axle
585
+ // standing in it, and spokes between.
557
586
  import jscad from '@jscad/modeling'
558
- const { cylinder } = jscad.primitives
587
+ const { cylinder, cuboid } = jscad.primitives
588
+ const { rotateZ } = jscad.transforms
559
589
 
560
590
  export function main (v) {
561
- return v.ops.union(cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.t / 2] }),
591
+ const rim = v.ops.subtract(cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.t / 2] }), cylinder({ radius: v.radius - v.rim, height: v.t, center: [0, 0, v.t / 2] }))
592
+ const spokes = Array.from({ length: v.spokes }, (_, k) => rotateZ((2 * Math.PI * k) / v.spokes, cuboid({ size: [v.radius - v.rim / 2, v.spoke, v.t], center: [(v.radius - v.rim / 2) / 2, 0, v.t / 2] })))
593
+ const snaps = [0, Math.PI].map((a) => jscad.transforms.translate([v.snap_at * Math.cos(a), v.snap_at * Math.sin(a), v.t - v.flange], v.flexures.snapPin({ diameter: v.snap, length: v.snap_length, lip: v.snap_lip, back: v.snap_back }, v.ops)))
594
+ return v.ops.union(rim, cylinder({ radius: v.hub / 2, height: v.t, center: [0, 0, v.t / 2] }), ...spokes, ...snaps,
562
595
  cylinder({ radius: v.pin / 2, height: v.pin_height, center: [0, 0, v.t + v.pin_height / 2] }))
563
596
  }
564
597
  ```
@@ -570,17 +603,33 @@ export function main (v) {
570
603
  "title": "Winder ring gear",
571
604
  "version": "0.1.0",
572
605
  "uses": ["x1c"],
606
+ "engine": "manifold",
573
607
  "variables": {
608
+ "rim": { "value": 66, "unit": "mm", "rule": "Across the outside: a rim wide enough for the push pins' holes" },
609
+ "snap": { "value": 2, "unit": "mm", "rule": "The case's push pins" },
610
+ "clear": { "value": "x1c.line / 2", "unit": "mm", "rule": "Half a line round a pin" },
611
+ "snap_at": { "value": 30.6, "unit": "mm", "rule": "As the case's pins" },
612
+ "counterbore": { "value": 2, "unit": "mm", "rule": "Deep enough that a barb clicks below the ring's top, clear of the crank arm" },
613
+ "barb": { "value": 1.6, "unit": "mm", "rule": "The counterbore's radius: the barb and its clearance" },
574
614
  "module": { "value": 1, "unit": "mm", "rule": "3.6 lines across a tooth on the X1C" },
575
615
  "teeth": { "value": 54, "rule": "The sun and two planets across: 18 + 2 × 18" },
576
- "width": { "value": "x1c.layer * 40", "unit": "mm", "rule": "Face width, forty layers" }
616
+ "width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "Face width, thirty layers: plenty for a spool's pull" }
577
617
  }
578
618
  }
579
619
  ```
580
620
 
581
621
  ```js projects/home/objects/winder-ring.js
622
+ // The ring gear, held to the case by two push pins: through-holes in its rim, counterbored at the top for the barbs.
623
+ import jscad from '@jscad/modeling'
624
+ const { cylinder } = jscad.primitives
625
+
582
626
  export function main (v) {
583
- return v.gears.internal({ module: v.module, teeth: v.teeth, width: v.width })
627
+ const holes = [0, Math.PI].flatMap((a) => {
628
+ const x = v.snap_at * Math.cos(a), y = v.snap_at * Math.sin(a)
629
+ return [cylinder({ radius: v.snap / 2 + v.clear, height: v.width, center: [x, y, v.width / 2] }),
630
+ cylinder({ radius: v.barb, height: v.counterbore, center: [x, y, v.width - v.counterbore / 2] })]
631
+ })
632
+ return v.ops.subtract(v.gears.internal({ module: v.module, teeth: v.teeth, width: v.width, rim: v.rim }), ...holes)
584
633
  }
585
634
  ```
586
635
 
@@ -595,7 +644,7 @@ export function main (v) {
595
644
  "variables": {
596
645
  "module": { "value": 1, "unit": "mm", "rule": "As the ring" },
597
646
  "teeth": { "value": 18, "rule": "From planetary(): 18 for 4 : 1 with three planets" },
598
- "width": { "value": "x1c.layer * 40", "unit": "mm", "rule": "As the ring" },
647
+ "width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "As the ring" },
599
648
  "bore": { "value": "3 + x1c.line / 2", "unit": "mm", "rule": "A 3 mm pin and half a line's clearance" }
600
649
  }
601
650
  }
@@ -621,7 +670,7 @@ The sun is a planet with the spool's shaft on top, bored through for its axle:
621
670
  "variables": {
622
671
  "module": { "value": 1, "unit": "mm", "rule": "As the ring" },
623
672
  "teeth": { "value": 18, "rule": "From planetary()" },
624
- "width": { "value": "x1c.layer * 40", "unit": "mm", "rule": "As the ring" },
673
+ "width": { "value": "x1c.layer * 30", "unit": "mm", "rule": "As the ring" },
625
674
  "bore": { "value": "3 + x1c.line / 2", "unit": "mm", "rule": "On the case's 3 mm axle" },
626
675
  "shaft": { "value": 8, "unit": "mm", "rule": "The spool's shaft, inside the sun's roots" },
627
676
  "shaft_height": { "value": 12, "unit": "mm", "rule": "Up through the carrier, and a spool's width over it" }
@@ -641,54 +690,89 @@ export function main (v) {
641
690
  }
642
691
  ```
643
692
 
644
- The carrier: a disc over the gears, inside the ring's tips, with a pin down into each planet and the crank on top. Its
645
- anchors are where the planets turn, every 120° at the sun-to-planet distance (m (S + P) / 2 = 18 mm).
693
+ The carrier is drawn as it prints: a flat plate on the bed (the disc over the gears, inside the ring's tips, and the
694
+ crank arm in the same plane, reaching out over the ring), with a pin standing up from it for each planet. The assembly
695
+ turns it over, so its pins hang down into the planets. The planets turn every 120° at the sun-to-planet distance
696
+ (m (S + P) / 2 = 18 mm). The handle is a part of its own, printed upright and pressed into the arm's end, as a crank
697
+ handle usually is.
646
698
 
647
699
  ```json projects/home/objects/winder-carrier.json
648
700
  {
649
701
  "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
650
702
  "name": "winder-carrier",
651
- "title": "Winder carrier and crank",
703
+ "title": "Winder carrier and crank arm",
652
704
  "version": "0.1.0",
653
705
  "uses": ["x1c"],
654
706
  "engine": "manifold",
655
707
  "anchors": {
656
- "axis": { "at": [0, 0, 0], "axis": [0, 0, 1] },
657
- "p0": { "at": ["a", 0, "0 - drop"], "axis": [0, 0, 1] },
658
- "p1": { "at": ["0 - a / 2", "a * 0.8660254", "0 - drop"], "axis": [0, 0, 1] },
659
- "p2": { "at": ["0 - a / 2", "0 - a * 0.8660254", "0 - drop"], "axis": [0, 0, 1] }
708
+ "axis": { "at": [0, 0, 0], "axis": [0, 0, -1] },
709
+ "grip": { "at": ["arm", 0, 0], "axis": [0, 0, -1] },
710
+ "p0": { "at": ["a", 0, "t + drop"], "axis": [0, 0, -1] },
711
+ "p1": { "at": ["0 - a / 2", "a * 0.8660254", "t + drop"], "axis": [0, 0, -1] },
712
+ "p2": { "at": ["0 - a / 2", "0 - a * 0.8660254", "t + drop"], "axis": [0, 0, -1] }
660
713
  },
661
714
  "variables": {
662
715
  "a": { "value": 18, "unit": "mm", "rule": "Sun to planet: m (S + P) / 2" },
663
- "drop": { "value": "8 + x1c.layer * 2", "unit": "mm", "rule": "A planet's width and two layers' gap above it" },
716
+ "drop": { "value": "6 + x1c.layer * 2", "unit": "mm", "rule": "A planet's width and two layers' gap above it" },
664
717
  "radius": { "value": 25, "unit": "mm", "rule": "Inside the ring's tips (26 mm)" },
665
718
  "t": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Fifteen layers" },
666
719
  "hole": { "value": 9, "unit": "mm", "rule": "Round the sun's 8 mm shaft" },
667
720
  "pin": { "value": 3, "unit": "mm", "rule": "The planets' axles" },
668
- "arm": { "value": 45, "unit": "mm", "rule": "The crank's reach" },
721
+ "arm": { "value": 45, "unit": "mm", "rule": "The crank's reach, out over the ring" },
669
722
  "bar": { "value": 10, "unit": "mm", "rule": "The crank arm's width" },
670
- "handle": { "value": 20, "unit": "mm", "rule": "The handle's height" },
671
- "grip": { "value": 8, "unit": "mm", "rule": "The handle's diameter" }
723
+ "peg": { "value": 4, "unit": "mm", "rule": "The handle's peg" },
724
+ "fit": { "value": "x1c.line / 4", "unit": "mm", "rule": "A press fit for the handle's peg: a quarter line" },
725
+ "planets": { "value": 3, "rule": "From planetary(): three planets" }
672
726
  }
673
727
  }
674
728
  ```
675
729
 
676
730
  ```js projects/home/objects/winder-carrier.js
731
+ // The carrier as it prints: a flat plate (the disc and the crank arm) on the bed, the planets' pins standing up from it.
677
732
  import jscad from '@jscad/modeling'
678
733
  const { cylinder, cuboid } = jscad.primitives
679
734
 
680
735
  export function main (v) {
681
- const disc = cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.t / 2] })
682
- const arm = cuboid({ size: [v.arm, v.bar, v.t], center: [v.arm / 2, 0, v.t + v.t / 2] })
683
- const handle = cylinder({ radius: v.grip / 2, height: v.handle, center: [v.arm - v.grip / 2, 0, v.t * 2 + v.handle / 2] })
684
- const third = (2 * Math.PI) / 3
685
- const pins = [0, 1, 2].map((k) => cylinder({ radius: v.pin / 2, height: v.drop, center: [v.a * Math.cos(k * third), v.a * Math.sin(k * third), 0 - v.drop / 2] }))
686
- const hole = cylinder({ radius: v.hole / 2, height: v.t * 2, center: [0, 0, v.t] })
687
- return v.ops.subtract(v.ops.union(disc, arm, handle, ...pins), hole)
736
+ const plate = v.ops.union(cylinder({ radius: v.radius, height: v.t, center: [0, 0, v.t / 2] }),
737
+ cuboid({ size: [v.arm, v.bar, v.t], center: [v.arm / 2, 0, v.t / 2] }), cylinder({ radius: v.bar / 2, height: v.t, center: [v.arm, 0, v.t / 2] }))
738
+ const third = (2 * Math.PI) / v.planets
739
+ const pins = [0, 1, 2].map((k) => cylinder({ radius: v.pin / 2, height: v.drop, center: [v.a * Math.cos(k * third), v.a * Math.sin(k * third), v.t + v.drop / 2] }))
740
+ const hole = cylinder({ radius: v.hole / 2, height: v.t, center: [0, 0, v.t / 2] })
741
+ const socket = cylinder({ radius: v.peg / 2 - v.fit, height: v.t, center: [v.arm, 0, v.t / 2] })
742
+ return v.ops.subtract(v.ops.union(plate, ...pins), hole, socket)
743
+ }
744
+ ```
745
+
746
+ ```json projects/home/objects/winder-handle.json
747
+ {
748
+ "$schema": "https://jonibach.github.io/rulecad/schemas/object.schema.json",
749
+ "name": "winder-handle",
750
+ "title": "Winder handle",
751
+ "version": "0.1.0",
752
+ "uses": ["x1c"],
753
+ "anchors": { "peg": { "at": [0, 0, "grip_height"], "axis": [0, 0, -1] } },
754
+ "variables": {
755
+ "grip": { "value": 9, "unit": "mm", "rule": "A finger round it" },
756
+ "grip_height": { "value": 22, "unit": "mm", "rule": "A finger's width and a little" },
757
+ "peg": { "value": 4, "unit": "mm", "rule": "Into the arm's socket" },
758
+ "peg_height": { "value": "x1c.layer * 15", "unit": "mm", "rule": "Through the arm" }
759
+ }
760
+ }
761
+ ```
762
+
763
+ ```js projects/home/objects/winder-handle.js
764
+ // The handle as it prints: the grip on the bed, its peg standing on top.
765
+ import jscad from '@jscad/modeling'
766
+ const { cylinder } = jscad.primitives
767
+
768
+ export function main (v) {
769
+ return v.ops.union(cylinder({ radius: v.grip / 2, height: v.grip_height, center: [0, 0, v.grip_height / 2] }),
770
+ cylinder({ radius: v.peg / 2, height: v.peg_height, center: [0, 0, v.grip_height + v.peg_height / 2] }))
688
771
  }
689
772
  ```
690
773
 
691
- The assembly holds the ring in the case and turns the carrier on the crank; the `planetary` turns the sun and the
774
+ The assembly holds the ring on the case, by two push pins up from the case's rim into counterbored holes in the
775
+ ring's (the fit that says so is what the check reads as holding it), and turns the carrier on the crank; the `planetary` turns the sun and the
692
776
  planets with it, in phase. The gears sit two layers off the case, so nothing rubs as it turns. The case, the sun and the carrier
693
777
  are built with Manifold's booleans (`"engine": "manifold"`): closed solids, so the check measures them quickly.
694
778
 
@@ -701,13 +785,15 @@ are built with Manifold's booleans (`"engine": "manifold"`): closed solids, so t
701
785
  { "id": "ring", "object": "winder-ring", "at": [0, 0, "case.t"] },
702
786
  { "id": "sun", "object": "winder-sun" },
703
787
  { "id": "carrier", "object": "winder-carrier" },
788
+ { "id": "handle", "object": "winder-handle" },
704
789
  { "id": "p0", "object": "winder-gear" },
705
790
  { "id": "p1", "object": "winder-gear" },
706
791
  { "id": "p2", "object": "winder-gear" }
707
792
  ],
708
793
  "joints": [
709
794
  { "id": "sun", "type": "revolute", "parent": { "item": "case", "at": [0, 0, "case.t + 0.4"], "axis": [0, 0, 1] }, "child": "sun.axis", "min": -3000, "max": 3000 },
710
- { "id": "crank", "type": "revolute", "parent": { "item": "case", "at": [0, 0, "case.t + 0.8 + ring.width"], "axis": [0, 0, 1] }, "child": "carrier.axis", "min": -180, "max": 180, "label": "Crank" },
795
+ { "id": "crank", "type": "revolute", "parent": { "item": "case", "at": [0, 0, "case.t + 0.8 + ring.width + carrier.t"], "axis": [0, 0, 1] }, "child": "carrier.axis", "min": -180, "max": 180, "label": "Crank" },
796
+ { "id": "handle", "type": "fixed", "parent": "carrier.grip", "child": "handle.peg" },
711
797
  { "id": "p0", "type": "revolute", "parent": "carrier.p0", "child": "p0.axis", "min": -3000, "max": 3000 },
712
798
  { "id": "p1", "type": "revolute", "parent": "carrier.p1", "child": "p1.axis", "min": -3000, "max": 3000 },
713
799
  { "id": "p2", "type": "revolute", "parent": "carrier.p2", "child": "p2.axis", "min": -3000, "max": 3000 }
@@ -716,6 +802,8 @@ are built with Manifold's booleans (`"engine": "manifold"`): closed solids, so t
716
802
  { "sun": "sun", "carrier": "carrier", "ring": "ring", "planets": ["p0", "p1", "p2"], "drive": "carrier",
717
803
  "module": "ring.module", "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }
718
804
  ],
805
+ "fits": [{ "a": "handle", "b": "carrier", "min": "0 - carrier.fit * 2", "note": "The handle's peg pressed into the arm" },
806
+ { "a": "ring", "b": "case", "fastens": true, "note": "The ring held still on the case by its two push pins" }],
719
807
  "poses": { "rest": { "crank": 0 }, "quarter": { "crank": 90 } }
720
808
  }
721
809
  ```
package/README.md CHANGED
@@ -366,9 +366,14 @@ then y, then z, as `rotate` does.
366
366
  true` makes it a ring gear round its pinion. `shift` ([the driver's, this one's]), `pressureAngle` and `backlash` are
367
367
  as `@rulecad/gears` takes them. Each gear is drawn as `v.gears` draws it (axis up its z, first tooth on +x; a rack
368
368
  along its x, teeth up +y) and its joint is anchored at its centre, along its axis. The check gives the ratio, the
369
- contact ratio and the centre distance (`mesh.centre`: closer than the gears need jams them, further adds backlash),
370
- each placed between the two axes; `--sweep` turns the train and looks for teeth that touch. Both gears' axes sit on
369
+ contact ratio and the centre distance (`mesh.centre`: closer than the gears need eats their backlash, and past it they jam; further adds backlash),
370
+ each placed between the two axes, and measures the pair from its drawn teeth (`mesh.backlash`, `mesh.interference`,
371
+ kept in `.cache/gears/`); `--sweep` turns the train and looks for teeth that touch. Both gears' axes sit on
371
372
  one part, or on parts held still; planets on a carrier are a `planetary`.
373
+ - **Worms and bevels:** `"worm": true` (or `{ "diameter", "hand" }`) in a mesh makes the driving joint a worm and
374
+ this one its wheel, `teeth` [starts, the wheel's], the axes crossed at right angles; the check says the ratio,
375
+ whether it locks, and the centre distance. `"bevel": true` makes the two bevel gears, their axes meeting at the
376
+ shaft angle; the cones must share their apex (`mesh.bevel`). Both follow in phase, so `--sweep` turns them clean.
372
377
  - **Planetary gearboxes:** `"planetary": [{ "sun": "sun", "carrier": "carrier", "ring": "ring", "planets": ["p0", "p1",
373
378
  "p2"], "drive": "carrier", "module": 1, "teeth": ["sun.teeth", "p0.teeth", "ring.teeth"] }]` names the items. One of
374
379
  the sun, carrier and ring is held (no joint, or a fixed one); the one `drive` names turns on its revolute, and the
@@ -376,6 +381,10 @@ then y, then z, as `rotate` does.
376
381
  centre distance and contact ratio, and fails a planet that can't mesh with the sun and the ring where it is
377
382
  (`planetary.phase`: planets go every 360° / n, and (S + R) / n is whole). `planetary()` in `@rulecad/gears` finds
378
383
  teeth for a ratio.
384
+ - **What holds each part:** in an assembly that moves, every part but the first turns or slides on a joint, or is
385
+ fastened to the first through fits with `"fastens": true` (the pins, screws or press that do it, named in the fit's
386
+ note): `{ "a": "ring", "b": "case", "fastens": true, "note": "Two push pins" }`. A part only placed somewhere is
387
+ said (`assembly.loose`): a ring gear resting on its case would turn with its planets.
379
388
  - **Loops:** each item has one joint to its parent. Where parts join in a ring (two links between the same two
380
389
  parts), let joints place every part, then name the meeting that closes the ring in `loops`. The check measures it
381
390
  in every pose: `"loops": [{ "a": "link_l.top", "b": "mount_l.axis", "label": "Left pivot lines up" }]`. Its anchors
package/lib/assembly.mjs CHANGED
@@ -20,6 +20,7 @@ import { host, readJson } from './host.mjs';
20
20
  import fs from 'node:fs';
21
21
  import crypto from 'node:crypto';
22
22
  import path from 'node:path';
23
+ import { fileURLToPath } from 'node:url';
23
24
  import { evaluate, loadRuleSet } from './rules.mjs';
24
25
  import { paths, printerOf } from './workspace.mjs';
25
26
  import { locate, build, readObject, jscad } from './design.mjs';
@@ -29,7 +30,7 @@ import { bounds } from '@rulecad/printcheck';
29
30
  import { closest, closestAt, inside, distanceToFace, overlapAt } from '@rulecad/fit';
30
31
  import { keys as keyCentres, readLayout, hasLayout } from './layout.mjs';
31
32
  import { DOFS, frame, turn, mul, pathLength, jointValues, placeItems, jointMatrix } from '@rulecad/model-link';
32
- import { gearModel, internalModel, rackModel, mesh as meshOf, phase, rackPhase } from '@rulecad/gears';
33
+ import { gearModel, internalModel, rackModel, mesh as meshOf, phase, rackPhase, contact, wormModel, wormMesh, bevelModel, bevelMesh } from '@rulecad/gears';
33
34
  import { ops as booleans } from '@rulecad/shapes';
34
35
 
35
36
  export const assemblyPath = (ref) => { const [project, name] = String(ref).split('/'); return path.join(paths.project(project || ''), 'assemblies', `${name || ''}.json`); };
@@ -366,6 +367,18 @@ function motionOf(a, placed, num, ref) {
366
367
  return { items, joints, poses, pose: a.pose || Object.keys(poses)[0], loops, ref, marks, meshes };
367
368
  }
368
369
 
370
+ // A pair measured from its drawn teeth (@rulecad/gears contact: backlash, transmission error, interference), kept in
371
+ // .cache/gears/ by the pair, the centre distance and the gears package's code, as it takes half a second
372
+ let gearsCode = null;
373
+ function measured(a, b, centre) {
374
+ gearsCode ||= (() => { const dir = path.dirname(fileURLToPath(import.meta.resolve('@rulecad/gears'))); return fs.readdirSync(dir).filter((f) => f.endsWith('.mjs') && f !== 'test.mjs').sort().map((f) => fs.readFileSync(path.join(dir, f), 'utf8')).join(''); })();
375
+ const file = paths.cache('gears', `${crypto.createHash('sha256').update(JSON.stringify([gearsCode, a, b, +centre.toFixed(6)])).digest('hex')}.json`);
376
+ if (!process.env.CAD_NO_CACHE && host.exists(file)) return JSON.parse(host.readText(file));
377
+ const r = contact(a, b, { centre, steps: 12 }), keep = { findings: r.findings, backlash: r.backlash, error: r.error };
378
+ try { host.writeText(file, JSON.stringify(keep)); } catch {} // (only slower without it)
379
+ return keep;
380
+ }
381
+
369
382
  // A planetary gearbox: "planetary": [{ "sun", "carrier", "ring", "planets": [items], "drive": "sun" | "carrier" | "ring",
370
383
  // "module", "teeth": [sun, planet, ring] }]. One of the sun, carrier and ring is held (no joint, or a fixed one); the
371
384
  // one named by drive turns on its joint, and every other moving part (the third, and each planet on the carrier)
@@ -432,6 +445,10 @@ function planetaries(list, joints, items, num) {
432
445
  if (Math.abs(miss) > 1e-6) f('fail', `planet ${p.id} can't mesh with the sun and the ring at once where it is (${(p.beta / DEG).toFixed(2)}° round the sun): planets go every ${(360 / planets.length).toFixed(2)}°, and (S + R) / planets must be whole (${S + R} / ${planets.length})`, 'planetary.phase', [O, centre]);
433
446
  const m = meshOf(sun, planet, { centre: p.r });
434
447
  for (const x of m.findings) f(x.level, `sun and ${p.id}: ${x.text}`, x.code, [O, centre]);
448
+ if (i === 0) {
449
+ for (const x of measured({ ...common, teeth: S }, { ...common, teeth: P }, p.r).findings) f(x.level, `sun and ${p.id}: ${x.text}`, x.code, [O, centre]);
450
+ for (const x of measured({ ...common, teeth: P }, { ...common, teeth: R, kind: 'internal' }, p.r).findings) f(x.level, `${p.id} and the ring: ${x.text}`, x.code, [O, centre]);
451
+ }
435
452
  });
436
453
  const ratioText = `the ${drive} drives the ${third}${held[0] === 'carrier' ? '' : ' and the planets'} (the ${held[0]} held): ${Number(Math.abs(k3).toFixed(4))} turns of the ${third} for each turn of the ${drive}, ${k3 * sg[drive] * sg[third] < 0 ? 'opposite ways' : 'the same way'}`;
437
454
  out.push({ joint: follower.id, with: lead.id, kind: 'planetary', text: ratioText, findings, between: [O, O], planetary: true });
@@ -439,6 +456,80 @@ function planetaries(list, joints, items, num) {
439
456
  return out;
440
457
  }
441
458
 
459
+ // Bevel gears: "mesh": { "with": <the other's joint>, "module", "teeth": [its, this one's], "bevel": true } on revolutes
460
+ // whose axes meet at the shaft angle, each gear drawn as @rulecad/gears draws one (back end at z = 0, apex up z). The
461
+ // cones must share their apex. The ratio is the surface speeds' where the pitch cones touch; the phase puts a tooth
462
+ // of one against a space of the other along that line.
463
+ function bevelDrive(j, lead, spec, teeth, common, joints, items, num) {
464
+ const what = `joint ${j.id}: mesh`, DEG = Math.PI / 180;
465
+ const col = (W, k) => [W[k], W[4 + k], W[8 + k]], org = (W) => [W[3], W[7], W[11]];
466
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2], sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]], add = (a, b) => a.map((x, i) => x + b[i]), times = (a, k) => a.map((x) => x * k);
467
+ const crossP = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]], len = (v) => Math.hypot(...v), unit = (v) => times(v, 1 / len(v));
468
+ const ang = (v, x0, z) => Math.atan2(dot(crossP(x0, v), z), dot(x0, v));
469
+ const v = jointValues({ joints, poses: {} }, {}); v[lead.id] = [0]; v[j.id] = [0];
470
+ const worlds = placeItems({ items, joints }, v), W1 = worlds[lead.child], W2 = worlds[j.child];
471
+ const O1 = org(W1), Z1 = col(W1, 2), X1 = col(W1, 0), O2 = org(W2), Z2 = col(W2, 2), X2 = col(W2, 0);
472
+ const shaft = Math.acos(Math.max(-1, Math.min(1, dot(Z1, Z2)))) / DEG;
473
+ let g1, g2;
474
+ try { g1 = bevelModel({ ...common, teeth: teeth[0], mate: teeth[1], shaftAngle: shaft }); g2 = bevelModel({ ...common, teeth: teeth[1], mate: teeth[0], shaftAngle: shaft }); } catch (e) { throw new Error(`${what}: ${e.message}`); }
475
+ // each cone's apex: along its axis, its cone distance × cos δ from its back end
476
+ const A1 = add(O1, times(Z1, g1.coneDistance * Math.cos(g1.pitchAngle * DEG))), A2 = add(O2, times(Z2, g2.coneDistance * Math.cos(g2.pitchAngle * DEG)));
477
+ const findings = [];
478
+ const apart = len(sub(A1, A2));
479
+ if (apart > 0.01) findings.push({ level: 'fail', text: `the cones' apexes are ${Number(apart.toFixed(3))} mm apart: bevel gears mesh only when their cones meet at one point (move one along its axis)`, code: 'mesh.bevel' });
480
+ // where the pitch cones touch: from the apex, δ1 from the first's axis toward the second's (both pointing away)
481
+ const out1 = times(Z1, -1), out2 = times(Z2, -1), across = unit(sub(out2, times(out1, dot(out1, out2))));
482
+ const g = add(times(out1, Math.cos(g1.pitchAngle * DEG)), times(across, Math.sin(g1.pitchAngle * DEG))), P = add(A1, times(g, g1.coneDistance));
483
+ const radial = (Z, X) => { const r = sub(g, times(Z, dot(g, Z))); return ang(r, X, Z); };
484
+ const b1 = radial(Z1, X1), b2 = radial(Z2, X2);
485
+ // the second turns so the surface speeds match where they touch: ω2 = ω1 (Z1 × P)·(Z2 × P) / |Z2 × P|², P from the apex
486
+ const p = sub(P, A1), r = dot(crossP(Z1, p), crossP(Z2, p)) / dot(crossP(Z2, p), crossP(Z2, p));
487
+ const sgn = (jt, Z) => Math.sign(dot(col(mul(jt.parent < 0 ? [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0] : worlds[jt.parent], jt.a), 2), Z));
488
+ const s1 = sgn(lead, Z1), s2 = sgn(j, Z2), z2 = teeth[1];
489
+ const phi = b2 - Math.PI / z2 - r * b1;
490
+ j.follow = [lead.id, s2 * r * s1, (s2 * phi) / DEG];
491
+ const m = bevelMesh({ ...common, teeth: teeth[0], shaftAngle: shaft }, { ...common, teeth: teeth[1], shaftAngle: shaft });
492
+ findings.push(...m.findings);
493
+ return { joint: j.id, with: lead.id, kind: 'bevel', findings, between: [O1, O2], text: `bevel gears at ${Number(shaft.toFixed(2))}°, ${Number((teeth[0] / teeth[1]).toFixed(4))} turns of the second for each of the first (cones of ${Number(g1.pitchAngle.toFixed(2))}° and ${Number(g2.pitchAngle.toFixed(2))}°)` };
494
+ }
495
+
496
+ // A worm and its wheel: "mesh": { "with": <the worm's joint>, "module", "teeth": [starts, wheel's teeth], "worm": {
497
+ // "diameter"?, "hand"? } } on the wheel's revolute, the axes crossed. In the wheel's middle plane the worm's thread is a
498
+ // rack along the worm's axis, moving a lead a turn: the wheel follows it as a pinion does a rack, its helix's turn at
499
+ // that plane taken into account. The worm is drawn as @rulecad/gears draws it (axis up its z, from z = 0).
500
+ function wormDrive(j, lead, spec, teeth, common, joints, items, num) {
501
+ const what = `joint ${j.id}: mesh`, DEG = Math.PI / 180;
502
+ const col = (W, k) => [W[k], W[4 + k], W[8 + k]], org = (W) => [W[3], W[7], W[11]];
503
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2], sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
504
+ const crossP = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]], len = (v) => Math.hypot(...v);
505
+ const ang = (v, x0, z) => Math.atan2(dot(crossP(x0, v), z), dot(x0, v));
506
+ const ws = spec.worm === true ? {} : spec.worm;
507
+ let w, wheel;
508
+ try {
509
+ w = wormModel({ ...common, starts: teeth[0], ...(ws.diameter != null ? { diameter: num(ws.diameter) } : {}), ...(ws.hand ? { hand: ws.hand } : {}) });
510
+ wheel = gearModel({ ...common, teeth: teeth[1], helix: w.leadAngle, hand: w.hand });
511
+ } catch (e) { throw new Error(`${what}: ${e.message}`); }
512
+ const v = jointValues({ joints, poses: {} }, {}); v[lead.id] = [0]; v[j.id] = [0];
513
+ const worlds = placeItems({ items, joints }, v), Ww = worlds[lead.child], W2 = worlds[j.child];
514
+ const Ow = org(Ww), U = col(Ww, 2), Xw = col(Ww, 0), O2 = org(W2), Z2 = col(W2, 2), X2 = col(W2, 0);
515
+ if (Math.abs(dot(U, Z2)) > 1e-6) throw new Error(`${what}: a worm's axis and its wheel's cross at right angles`);
516
+ // the line between the axes: across both (the worm's along U, the wheel's along Z2)
517
+ const rel = sub(O2, Ow), at = dot(rel, U), toWheel = sub(sub(rel, U.map((x) => x * at)), Z2.map((x) => x * dot(rel, Z2))), dist = len(toWheel), Y = toWheel.map((x) => x / dist), Zr = crossP(U, Y);
518
+ const sense = w.hand === 'left' ? -1 : 1, sw = Math.sign(dot(col(mul(lead.parent < 0 ? [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0] : worlds[lead.parent], lead.a), 2), U));
519
+ const s2 = Math.sign(dot(Z2, Zr)), tw = ang(Y, Xw, U), g2 = ang(X2, U, Zr) * 1, r2 = wheel.pitch / 2;
520
+ // the wheel's helix: its tooth 0 at the worm's plane is turned by k z there
521
+ const zMid = dot(sub(Ow, O2), Z2), k = (sense * Math.tan(w.leadAngle * DEG)) / r2;
522
+ const phr = rackPhase(wheel, at), L = w.lead;
523
+ // space centres of the thread, at the wheel, sit at z0 = sense L (tw − θw) / 2π along the worm; the wheel turns as on a rack
524
+ const theta = (dw) => { const z0 = (sense * L * (tw - sw * dw * DEG)) / (2 * Math.PI); return s2 * ((z0 - phr) / r2 - g2) - k * zMid; };
525
+ const a0 = theta(0), a1 = theta(1);
526
+ j.follow = [lead.id, (a1 - a0) / DEG, a0 / DEG];
527
+ const m = wormMesh({ ...common, starts: teeth[0], ...(ws.diameter != null ? { diameter: num(ws.diameter) } : {}), ...(ws.hand ? { hand: ws.hand } : {}) }, { teeth: teeth[1] });
528
+ const c = meshOf(wheel, rackModel({ ...common, teeth: 4 }), { centre: dist - w.pitch / 2 });
529
+ const findings = [...m.findings, ...c.findings.filter((x) => x.code === 'mesh.centre').map((x) => ({ ...x, text: x.text.replace("centre to the rack's pitch line", "the wheel's centre to the worm's pitch cylinder") }))];
530
+ return { joint: j.id, with: lead.id, kind: 'worm', findings, between: [Ow.map((x, i) => x + U[i] * at), O2], text: `a worm of ${teeth[0]} start${teeth[0] > 1 ? 's' : ''}, ${Number((teeth[1] / teeth[0]).toFixed(3))} turns of the worm for one of the wheel` };
531
+ }
532
+
442
533
  // Gears that mesh: "mesh": { "with": <the driving joint>, "module", "teeth": [its, this one's], "shift"?, "ring"? } on
443
534
  // a revolute (a gear, or a ring with "ring": true) or a prismatic (a rack). It becomes a follow: the ratio from the
444
535
  // teeth, and the offset that puts a tooth in a gap, read from where the two gears are with their joints at 0. Each
@@ -464,11 +555,13 @@ function gearMeshes(joints, items, num) {
464
555
  if (!lead) throw new Error(`${what}: "with" names the driving joint (${joints.filter((x) => x !== j).map((x) => x.id).join(', ')}; got ${JSON.stringify(spec.with)})`);
465
556
  if (lead.type !== 'revolute') throw new Error(`${what}: ${lead.id} is a ${lead.type}; the driver is a gear turning on a revolute`);
466
557
  if (j.type !== 'revolute' && j.type !== 'prismatic') throw new Error(`${what}: a gear turns on a revolute, a rack slides on a prismatic (this is a ${j.type})`);
467
- const kind = j.type === 'prismatic' ? 'rack' : spec.ring ? 'internal' : 'external';
558
+ const kind = spec.bevel ? 'bevel' : spec.worm ? 'worm' : j.type === 'prismatic' ? 'rack' : spec.ring ? 'internal' : 'external';
468
559
  if (!(lead.parent === j.parent || (still(lead.parent) && still(j.parent)))) throw new Error(`${what}: ${lead.id} and ${j.id} turn on parts that move apart (a planet on a carrier): a mesh needs both on one part, or both on parts held still`);
469
560
  const teeth = list(spec.teeth).map(num), shift = list(spec.shift ?? [0, 0]).map(num);
470
561
  if (teeth.length !== 2) throw new Error(`${what}: teeth is [the driver's, this one's] (got ${JSON.stringify(spec.teeth)})`);
471
562
  const common = { module: num(spec.module), ...(spec.pressureAngle != null ? { pressureAngle: num(spec.pressureAngle) } : {}), ...(spec.backlash != null ? { backlash: num(spec.backlash) } : {}) };
563
+ if (kind === 'worm') { out.push(wormDrive(j, lead, spec, teeth, common, joints, items, num)); continue; }
564
+ if (kind === 'bevel') { out.push(bevelDrive(j, lead, spec, teeth, common, joints, items, num)); continue; }
472
565
  let A, B;
473
566
  try {
474
567
  A = gearModel({ ...common, teeth: teeth[0], shift: shift[0] });
@@ -492,13 +585,14 @@ function gearMeshes(joints, items, num) {
492
585
  const k = (Math.PI * A.pitch) / 360, g1 = angleIn(along(X1, Zr), U, Zr);
493
586
  j.follow = [lead.id, sTravel * s1 * k, sTravel * (k * g1 + rackPhase(A, at))];
494
587
  const m = meshOf(A, B, { centre: height });
495
- result.findings = m.findings; result.between = [O1, [R0[0] + at * U[0], R0[1] + at * U[1], R0[2] + at * U[2]]]; result.text = m.text;
588
+ result.findings = [...m.findings, ...measured({ ...common, teeth: teeth[0], shift: shift[0] }, { ...common, teeth: teeth[1], kind: 'rack' }, height).findings]; result.between = [O1, [R0[0] + at * U[0], R0[1] + at * U[1], R0[2] + at * U[2]]]; result.text = m.text;
496
589
  } else {
497
590
  const O2 = org(W2), X2 = col(W2, 0), Z2 = col(W2, 2), ax2 = axisOf(j);
498
591
  if (Math.abs(Math.abs(dot(ax2.dir, Z2)) - 1) > 1e-6 || len(along(sub(O2, ax2.at), ax2.dir)) > 1e-4) throw new Error(`${what}: ${j.id} doesn't turn its gear about the gear's own centre and axis: anchor the gear's joint at its centre, along its axis`);
499
592
  if (Math.abs(Math.abs(dot(Z1, Z2)) - 1) > 1e-6) throw new Error(`${what}: ${lead.id} and ${j.id} turn about axes that aren't parallel (spur gears need parallel axes)`);
500
593
  const s = Math.sign(dot(Z1, Z2)), d = along(sub(O2, O1), Z1), beta = angleIn(d, X1, Z1), g2 = angleIn(along(X2, Z1), X1, Z1);
501
594
  const m = meshOf(A, B, { centre: len(d) });
595
+ m.findings.push(...measured({ ...common, teeth: teeth[0], shift: shift[0] }, { ...common, teeth: teeth[1], shift: shift[1] ?? 0, kind }, len(d)).findings);
502
596
  // b's angle in the driver's frame is ratio × a's + phase; its joint measures about its own z (the other way when flipped)
503
597
  j.follow = [lead.id, s * m.ratio, s * (phase(A, B, beta) - g2)];
504
598
  result.findings = m.findings; result.between = [O1, O2]; result.text = m.text;
@@ -667,6 +761,18 @@ export function checkAssembly(s) {
667
761
  }
668
762
  if (outside.length) f('fail', `joints out of range: ${outside.join(', ')}`, `${outside.length} joints out of range`, { code: 'joint.range', refs: { joints: outside } });
669
763
  for (const l of loopGaps(s)) f(l.ok ? 'pass' : 'fail', `${l.label}: ${l.ok ? 'closed' : 'apart'} (${mm(l.gap)} mm, axes ${mm(l.angle)}° apart)`, `${l.label}: ${l.ok ? 'closed' : 'apart'}`, { code: 'loop', values: { gap: l.gap, angle: l.angle }, refs: { label: l.label } });
764
+ // Held by something: in a mechanism, every part but the first either turns or slides on a joint, or is fastened,
765
+ // through a chain of fits with "fastens", to the first. A part only placed somewhere stays there in the model and
766
+ // nowhere else: a ring gear resting on its case turns with the planets; a pawl resting on its post walks off it.
767
+ if (s.motion.joints.some((j) => j.type !== 'fixed')) {
768
+ const ids = s.motion.items.map((x) => x[0]), top = (n) => String(n).split(/[.@]/)[0];
769
+ const held = new Set([ids[0], ...s.motion.joints.map((j) => ids[j.child])]), links = s.fits.filter((x) => x.fastens).map((x) => [top(x.a), top(x.b)]);
770
+ for (let grew = true; grew;) { grew = false; for (const [a, b] of links) { if (held.has(a) && !held.has(b)) { held.add(b); grew = true; } if (held.has(b) && !held.has(a)) { held.add(a); grew = true; } } }
771
+ const placed = new Set(s.objects.filter((o) => !o.unplaced && o.role !== 'reference').map((o) => top(o.id)));
772
+ const loose = ids.filter((id) => !held.has(id) && placed.has(id));
773
+ if (loose.length) f('warn', `${loose.join(', ')} ${loose.length > 1 ? 'are' : 'is'} placed, but nothing holds ${loose.length > 1 ? 'them' : 'it'}: give ${loose.length > 1 ? 'each' : 'it'} a joint, or fasten it to what it sits on (pins, screws, a press) and say so with a fit that "fastens"`, `${loose.length} loose`, { code: 'assembly.loose', refs: { items: loose } });
774
+ else f('pass', `every part turns or slides on a joint, or is fastened to the ${ids[0]}`, null, { code: 'assembly.held' });
775
+ }
670
776
  // Gears: each mesh's centre distance and contact ratio, said between the two axes (the rest by --sweep)
671
777
  for (const g of s.motion.meshes || []) {
672
778
  f('info', g.planetary ? g.text : `${g.with} drives ${g.joint}: ${g.text}`, null, { code: 'mesh.ratio', refs: { joints: [g.with, g.joint] } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/cad",
3
- "version": "0.7.35",
3
+ "version": "0.7.36",
4
4
  "description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -70,7 +70,7 @@
70
70
  "@rulecad/fea": "^0.2.1",
71
71
  "@rulecad/topopt": "^0.3.0",
72
72
  "@rulecad/flexures": "^0.5.0",
73
- "@rulecad/gears": "^0.2.0"
73
+ "@rulecad/gears": "^0.3.0"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0"
@@ -64,6 +64,7 @@
64
64
  "properties": {
65
65
  "a": { "$ref": "#/$defs/names" },
66
66
  "b": { "$ref": "#/$defs/names" },
67
+ "fastens": { "type": "boolean", "description": "a and b are fastened together (pins, screws, a press): what holds a part that has no joint" },
67
68
  "min": { "$ref": "#/$defs/expr" },
68
69
  "max": { "$ref": "#/$defs/expr" },
69
70
  "note": { "type": "string" },
@@ -114,7 +115,9 @@
114
115
  "shift": { "type": "array", "minItems": 2, "maxItems": 2, "items": { "$ref": "#/$defs/expr" } },
115
116
  "pressureAngle": { "$ref": "#/$defs/expr" },
116
117
  "backlash": { "$ref": "#/$defs/expr" },
117
- "ring": { "type": "boolean" }
118
+ "ring": { "type": "boolean" },
119
+ "bevel": { "type": "boolean" },
120
+ "worm": { "anyOf": [{ "type": "boolean" }, { "type": "object", "additionalProperties": false, "properties": { "diameter": { "$ref": "#/$defs/expr" }, "hand": { "enum": ["right", "left"] } } }] }
118
121
  }
119
122
  }
120
123
  }