@rulecad/fixings 0.1.5 → 0.1.6

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/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ What changed in each release, for someone upgrading a workspace. A **printed siz
4
4
  print (a hole's diameter, a seat's depth, a part's outline). Each release says whether any printed size moved, and
5
5
  why.
6
6
 
7
+ ## 0.1.6: the annular snap: lids that click on (#76)
8
+
9
+ ### Added
10
+
11
+ - **Annular snaps** (`snaps.mjs`, issue 76): a lid that clicks on to a round box. `annularSnapModel` gives the bead,
12
+ the undercut, the share of it the box's wall and the lid's skirt each take as two springs in series, the hoop strain
13
+ in each against the plastic's limit, and the forces to push the lid on and pull it off, from the Bayer snap-fit
14
+ guide's annular joint (P = y d Es X, its geometric factors `hubFactor` and `shaftFactor`); without a bead height it
15
+ is sized from `pull` with twice the margin. `annularBead` and `annularGroove` draw the bead and the groove (with a
16
+ lead-in at the skirt's mouth). Findings: `snap.undercut`, `snap.strain`, `snap.least`, `snap.forces`, `snap.remote`,
17
+ `snap.hold`, `snap.printable`. `SNAP_USES`. Bound in `fixingsFor`.
18
+ - **A closed end near an annular snap** (`boxFloor`, `lidTop`): `tubeRing` works out a ring load on a tube's wall as
19
+ Hetényi's beam on an elastic foundation, each end free, closed or long. A lid's top within a few times 1/β of its
20
+ groove holds the skirt round, so the skirt is stiffer and the box's wall takes more of the snap; the bending strain
21
+ at the closed end's root is held to the same limit. Findings `snap.closed` and `snap.root`. `snap.remote` reports
22
+ the free ends' share alone.
23
+ - Refused by name: a lead that friction locks (μ tan α of 1 or more), and a bead as deep as the skirt, whose groove
24
+ would cut through it. `snap.skirt` fails where the groove leaves less than one of the printer's `line` behind it.
25
+ Given `push`, `snap.push` warns where pushing the lid on square takes more.
26
+ - A sized bead is rounded up to what its pull needs and down to what its strain allows, and the strains are judged
27
+ unrounded (they are shown to 4 places), so a bead held to the strain passes its own strain check whatever the
28
+ limit rounds to.
29
+ - Refused by name: a closed end (`boxFloor`, `lidTop`) nearer the joint than its part's wall, 0 mm included, where
30
+ the wall cannot give and the sums came out as NaN and Infinity.
31
+ - `DEFAULTS` gains `snap_brief` (70% of the yield strain) and `snap_often` (60% of that) and `snap_remote` (3), from
32
+ the guide, and `snap_friction` (0.5) and `snap_least` (0.2 mm), estimates.
33
+
34
+ No printed size moved: nothing drawn before reads these.
35
+
7
36
  ## 0.1.5: pins, magnet seats and printed bolts (Fixings 4)
8
37
 
9
38
  ### Added
package/README.md CHANGED
@@ -69,6 +69,7 @@ and stresses in MPa.
69
69
  | [Pins](#pins) | `pinModel`, `pinHole`, `pin`, `snapPin`, `snapSocket`, `snapPinModel`, `parsePin`, `isPinName` |
70
70
  | [Printed bolts](#printed-bolts) | `printedBoltModel`, `printedBolt` |
71
71
  | [Magnets](#magnets) | `magnetModel`, `magnetSeatModel`, `magnetSeat`, `magnet`, `parseMagnet`, `isMagnetName`, `fieldShare` |
72
+ | [Annular snaps](#annular-snaps) | `annularSnapModel`, `annularBead`, `annularGroove`, `hubFactor`, `shaftFactor`, `tubeRing` |
72
73
  | [Measuring the printer's fits](#measuring-the-printers-fits) | the fixings coupon and the holds coupon |
73
74
  | [Refusals and printability](#refusals-and-printability) | `printable` |
74
75
 
@@ -84,6 +85,7 @@ live elsewhere, each for a reason:
84
85
  | Snap pins (`snapPin`, `snapSocket`, `snapPinModel`), plain pins | here | moved from `@rulecad/flexures`, which passes the three snap pin functions on unchanged |
85
86
  | Magnets and their pockets | here | `@rulecad/frames`' magnet catch takes its pocket and pull from `magnetSeatModel` |
86
87
  | Printed bolts | here | a screw named with the word printed |
88
+ | Annular snaps, a lid that clicks on (`annularSnapModel`, `annularBead`, `annularGroove`) | here | their job is to hold a lid on its box; issue 76 listed them with the flexures, which keep the snap hook |
87
89
  | Snap hooks, ratchets, pin joints printed in place, travel and angle stops | `@rulecad/flexures` | their bending is their job |
88
90
  | A countersink, a nut pocket and a nut trap from plain figures, crush ribs, a teardrop hole | `@rulecad/shapes` | shapes draws from plain numbers and reads no rule sets; this package calls the same shapes with a thread's figures, so moving them would make a cycle |
89
91
  | Slot nuts, carriers, brackets, hinges, latches, cable clips | `@rulecad/frames` | each is shaped to a beam's slot |
@@ -693,6 +695,107 @@ is the field on a magnet's axis at z from its face over the field at its face. I
693
695
  name magnets (`{ "magnet": "disc magnet 8x3", "count": 2 }`): `cad check` finds their pockets and reports their pull,
694
696
  and `cad list` lists them as bought.
695
697
 
698
+ ## Annular snaps
699
+
700
+ An annular snap holds a lid on a round box with no screw: it clicks on and pulls off. A bead runs round the outside
701
+ of the box's wall near its rim, and the lid's skirt has a groove inside it, the bead's shape grown by the printer's
702
+ `fit` all round, with a lead-in at the skirt's mouth. Pushed on, the bead's lead face spreads the skirt and squeezes
703
+ the wall; past it, both spring back and the bead sits in the groove touching neither, so nothing is strained at rest.
704
+ Pulled, the bead's return face has to spread the skirt again. A part whose job is to hold two parts together lives in
705
+ this package, so the annular snap is here, beside the snap pin; a snap hook, whose bending is its job alone, stays in
706
+ `@rulecad/flexures`.
707
+
708
+ `annularSnapModel(figures, options)` gives the numbers and findings; `annularBead` is the bead to add to the box's
709
+ wall and `annularGroove` the groove (and with `mouth`, the lead-in) to cut from the lid's skirt, each about the z axis
710
+ with the bead's foot at `at`, and each with the model on it as `.model`.
711
+
712
+ **The figures.** `diameter` is the box's wall outside at the joint, `wall` its thickness, `skirt` the lid's skirt
713
+ thickness. `bead` is how far the bead stands off the wall; less the clearance (the printer's `fit`) it is the undercut
714
+ the skirt is spread by. `lead` is the angle of the face the lid pushes over, from the axis (default 30°), `back` the
715
+ return face's (default 45°, the steepest the printer's `overhang` allows: it is the underside of the bead as the box
716
+ stands, and the face over the groove as the lid lies on its top). `land` is the bead's flat top (two layers), and
717
+ `boxEnd` and `lidEnd` how far the joint is from each part's free end (the rim, the skirt's mouth). `boxFloor` and
718
+ `lidTop` are how far it is from each part's closed end: the box's floor, and the underside of the lid's top. Each is
719
+ at least its part's own wall (the box's wall, the skirt): nearer than that the corner is solid and cannot give, so
720
+ it is refused.
721
+
722
+ **The sums.** Both parts are tubes. The Bayer snap-fit guide gives each one's transverse force for a spread y on the
723
+ diameter as P = y d Es X, with a geometric factor X from its proportions (X_N for the skirt spread over a rigid
724
+ shaft, X_W for the wall squeezed in a rigid tube). Here both give, so they are two springs in series and share the
725
+ interference by their stiffness: the guide's graphical method for two flexible parts, worked out. The hoop strain in
726
+ each is its share over its diameter, held to the plastic's limit: about 70% of its yield strain for a brief snap in an
727
+ amorphous plastic, and 60% of that for a lid opened often (`uses: 'often'`, the default; `'once'` for a joint snapped
728
+ once). The yield strain is taken as strength over modulus, below the real one. A joint further than 1.8 √(d t) from a
729
+ free end is about three times as stiff; nearer, the kit takes a straight line from 1 to 3. The forces along the push
730
+ are the guide's W = P (μ + tan α) / (1 - μ tan α), over the lead face going on and the return face coming off.
731
+
732
+ **A closed end near the joint.** The guide's tubes are open. A lid's skirt hangs from its top, and the top holds the
733
+ skirt round where they meet: a tube's wall bends over a length of about 1/β, with β⁴ = 3 (1 - ν²) / (R² t²), so a
734
+ groove within a few times 1/β of the top sits in a skirt far stiffer than a free tube, and the box's wall takes most
735
+ of the interference. `tubeRing` works this out as Hetényi's beam on an elastic foundation (the theory the guide's own
736
+ annular joint rests on): a ring load on the tube's wall, each end free, closed or long. The part's stiffness is
737
+ multiplied by the beam's deflection with that end open over the deflection with it closed, and the bending strain at
738
+ the closed end's root, 6 M (1 - ν²) / (E t²), is held to the same limit as the hoop strain (`snap.root`). The end is
739
+ taken as fully closed, the stiffest it can be, so the forces and the mate's strain err high. For the 60 mm pot's lid,
740
+ 1/β is 4.9 mm: a groove 1.3 mm under the top makes the skirt 46 times as stiff, and 5.8 mm under it 1.3 times.
741
+
742
+ **Refused and failed.** A lead that friction locks (μ tan α of 1 or more) is refused: no push slides the skirt over
743
+ it. So is a bead as deep as the skirt, whose groove would cut right through it. The groove must leave at least one of
744
+ the printer's `line` behind it (`snap.skirt`). Given `push`, the force the lid is pushed on with, a square push over
745
+ it warns (`snap.push`).
746
+
747
+ **Sizing.** Given no bead, it is sized: the least the print holds (`fixings.snap_least`, 0.2 mm of undercut), or
748
+ more where `pull` asks for it, so the lid stays on against twice the pull (`load_margin`), up to the most the strain
749
+ allows, rounded up to what the pull needs and down to what the strain allows. A bead given too tall fails by name
750
+ (`snap.strain`), with the most undercut that would do.
751
+
752
+ ```js
753
+ import { annularSnapModel, annularBead, annularGroove, tubeRing } from '@rulecad/fixings';
754
+
755
+ const joint = { diameter: 60, wall: 1.68, skirt: 1.26, boxEnd: 6, lidEnd: 1.5, lidTop: 5.8, boxFloor: 30.3 };
756
+ const lid = annularSnapModel(joint, { pull: 10 });
757
+ console.log(lid.bead, lid.undercut, lid.box.strain, lid.lid.strain, lid.lid.root, lid.permissible);
758
+ console.log(lid.force, lid.insertion, lid.removal, lid.margin, lid.lid.stiffer, lid.lid.decay);
759
+ const bead = annularBead(lid, { at: 30 }), groove = annularGroove(lid, { at: 30, mouth: 28 });
760
+ console.log(bead.model.length, groove.model.groove);
761
+ const near = annularSnapModel({ ...joint, boxEnd: 1.5, lidTop: 1.3 }, { pull: 10 });
762
+ console.log(near.lid.stiffer, near.box.strain, near.undercut, near.findings.filter((f) => f.level === 'warn').map((f) => f.code));
763
+ const tight = annularSnapModel({ ...joint, bead: 0.9 });
764
+ console.log(tight.findings.filter((f) => f.level === 'fail').map((f) => `${f.code} ${f.refs?.part ?? ''}`), tight.most.undercut);
765
+ console.log(+tubeRing(6, 6).w.toFixed(4), +tubeRing(0, 6, { A: 'free' }).w.toFixed(4));
766
+ try { annularSnapModel({ ...joint, bead: 0.2 }); } catch (e) { console.log(e.message.slice(0, 93)); }
767
+ try { annularSnapModel({ ...joint, lead: 60 }, { friction: 0.6 }); } catch (e) { console.log(e.message.slice(0, 93)); }
768
+ ```
769
+
770
+ ```text
771
+ 0.4 0.2 0.0023 0.0043 0.0032 0.0061
772
+ 231.8 351.1 695.4 69.54 1.3 4.9
773
+ 1.493 { inner: 30.2, outer: 30.6, depth: 0.4 }
774
+ 45.93 0.0061 0.19 [ 'snap.least' ]
775
+ [
776
+ 'snap.strain box',
777
+ 'snap.strain lid',
778
+ 'snap.root lid',
779
+ 'snap.skirt '
780
+ ] 0.284
781
+ 0.125 0.5
782
+ annularSnapModel: a bead of 0.2 mm is no taller than the x1c.fit clearance of 0.2 mm round th
783
+ annularSnapModel: a 60° lead at friction 0.6 locks: μ tan α is 1.04, 1 or more, so no push sl
784
+ ```
785
+
786
+ The first line reads: a pot 60 mm across with a wall of four lines and a skirt of three, its lid to stay on against
787
+ 10 N, the bead 6 mm under the rim and so the groove 5.8 mm under the lid's top. That needs far less than the least the
788
+ print holds, so the bead is 0.4 mm: 0.2 mm of undercut past the 0.2 mm fit. The wall takes 0.23% hoop strain, the
789
+ skirt 0.43% and the skirt's root 0.32%, under PLA's 0.61% (0.7 × 0.6 × 39 / 2680). Pushed on square it takes 351.1 N
790
+ and pulled off square 695.4 N, 69.54 times the pull. The top makes the skirt 1.3 times as stiff. Those are the guide's forces for the whole bead
791
+ at once: a lid put on by hand goes on at a tilt, a part of the bead at a time, and takes much less, which is why it
792
+ has a tab to lift it by. With the groove 1.3 mm under the top instead, the skirt is 46 times as stiff, the wall takes
793
+ almost all of the snap, and the strain holds the undercut to 0.19 mm, under the least the print holds. A 0.9 mm bead
794
+ strains both parts past the limit and leaves the skirt thinner than a line behind its groove; 0.284 mm of undercut is
795
+ the most. The beam's own checks: a long tube deflects 1/8 under a ring load, and 1/2 with the load at a free end. The
796
+ example project `enclosures` in the repository's bench draws this pot and lid (`snap-pot`) and puts the lid on
797
+ (`snap-pot-closed`).
798
+
696
799
  ## Measuring the printer's fits
697
800
 
698
801
  Every clearance a hole, a seat or a pocket is drawn with is a rule of the printer's, and most are estimates until two
@@ -778,13 +881,17 @@ hole: depth is a number above 0, in mm (got -2)
778
881
  - **Measured**: the X1C's M3 pilot (`x1c.pilot_m3`, 2.9 mm, from the kit's fit bar). It is the only measured figure
779
882
  so far. The fixings coupon and the holds coupon measure the rest, per printer and plastic, and `cad measured`
780
883
  writes each result to the printer's rule set (see [Measuring the printer's fits](#measuring-the-printers-fits)).
781
- - **Community**: magnets' pulls straight off steel (the seller's figures, supermagnete) and the grades' remanence, heat-set inserts (CNC Kitchen's sheet), pilots for M2 to M4 (Bambu Lab's figures for PLA) and for
884
+ - **Community**: the annular snap's share of the yield strain for a brief snap (`snap_brief`, 70%) and for one opened often
885
+ (`snap_often`, 60% of that) and its remote joint's factor (`snap_remote`, 3), from the Bayer snap-fit guide for its own
886
+ plastics, applied to printed PLA and PETG unchecked; magnets' pulls straight off steel (the seller's figures, supermagnete) and the grades' remanence, heat-set inserts (CNC Kitchen's sheet), pilots for M2 to M4 (Bambu Lab's figures for PLA) and for
782
887
  the PT screws (the maker's factor for ABS), the engagement rules, the printer's `hole_comp`, `fit` and `bridge`,
783
888
  the two layers a nut pocket is sunk, and the three quarters of proof load a fully tightened screw is taken to carry.
784
889
  - **Estimates**: pilots for M1.6, M5 and up, and every inch size (nobody has published one); the printer's `slip`,
785
890
  `press`, `thread_gap`, `snap_clearance`, `pin_press`, `pin_slip`, `magnet_press`, `magnet_glue` and `magnet_crush`; a steel dowel's shear strength and the play a
786
891
  snap pin's shaft may have; a magnet's pull at a grade other than its seller's and across a gap, the grip of a press
787
892
  or of crush ribs on a magnet, the three layers under a magnet's pocket, and every strength of a printed bolt; the layers and line a printed thread needs; the layer left over a nut put in mid-print;
893
+ an annular snap's friction (`snap_friction`, 0.5) and least undercut (`snap_least`), its stiffness between a free end
894
+ and a remote joint, a closed end taken as fully closed, the skirt's full thickness at its groove, and its plastic's yield strain (strength over modulus) and modulus in place of the guide's secant modulus;
788
895
  a material's shear strength (its tensile strength over √3) and what it bears under a head (its strength); the nut
789
896
  factor K (0.2); the diameter of thread asked in an insert; the millimetre kept at a screw's tip; and every mass.
790
897
  A mass comes from the part's outline, with no socket and no knurls, and an insert's alloy is assumed.
@@ -841,6 +948,12 @@ with its `rule`, `kind` and `source`.
841
948
  | A press's grip on a magnet | p = E i / d / (1 + ν), i = magnet_press; hold = μ p π d h; the pocket's wall stretched round its hoop at p | A rigid disc pressed into a hole in a wide plate (Lamé's thick cylinder with an infinite outer radius); μ is clamp_friction. An estimate, which creep lowers |
842
949
  | Crush ribs' grip | hold = μ × strength × n w h, n ribs a line w wide, crushed to the plastic's strength | An estimate of this package |
843
950
  | A magnet's mass | m = 7.5 g/cm³ × its volume | magnets.density, worked from sellers' weights |
951
+ | An annular snap's geometric factor | X_N = 0.62 √((k - 1)/(k + 1)) / ((k² + 1)/(k² - 1) + ν), k = d0 / d, for the skirt; X_W the same with - ν and k = d / di, for the wall | Bayer, Snap-Fit Joints for Plastics, the annular snap joint (pages 21 and 22) |
952
+ | Its transverse force | P = y d Es X for each part alone, y on the diameter; the two in series, k = 1 / (1/k_box + 1/k_lid) with k = factor × d E X; factor 1 at a free end, 3 from 1.8 √(d t) in, a straight line between | The same guide (pages 21 and 22, and page 24 for two flexible parts); Es taken as the modulus, and the line an estimate |
953
+ | Its hoop strain | ε = (P / k_part) / d_part, held to 0.7 × strength / modulus, × 0.6 for a joint opened often | The same guide (page 11, and the note to Table 2 on page 12); yield strain as strength over modulus, an estimate on the safe side |
954
+ | Its forces along the push | W = P (μ + tan α) / (1 - μ tan α), α the lead going on and the return face coming off; refused where μ tan α ≥ 1 on the lead | The same guide (page 14) |
955
+ | A closed end near the joint | w'''' + 4 w = 0 in ξ = βx, β⁴ = 3 (1 - ν²) / (R² t²); a ring load q steps w''' by q / (D β³), D = E t³ / 12 (1 - ν²); a free end has w'' = w''' = 0, a closed one w = w' = 0; the part is stiffer by w(open) / w(closed) | Hetényi, Beams on Elastic Foundation (1946): a long tube gives w = Pβ / 2k, a free end 2Pβ / k; the end taken as fully closed, an estimate on the stiff side |
956
+ | The bending at a closed end | M = w''(ξ) q / β, q = P / (π d); ε = 6 M (1 - ν²) / (E t²) | Plate bending, with the same beam |
844
957
 
845
958
  VDI 2230 and Machinery's Handbook are named because the plan asked for them. Neither was read at first hand for
846
959
  this package: the handbook's thread shear area and stress area are applied as the pages above give them, and VDI
@@ -848,6 +961,8 @@ this package: the handbook's thread shear area and stress area are applied as th
848
961
 
849
962
  ## Glossary
850
963
 
964
+ - **Annular snap**: a bead round a round part that clicks into a groove round its mate: a lid that snaps on.
965
+ - **Hoop strain**: how much a ring is stretched (or squeezed) round its circumference, the change in its diameter over its diameter.
851
966
  - **Clearance hole**: a hole a screw passes through without touching, a little wider than the thread.
852
967
  - **Clamp force, preload**: the force a tightened screw presses the parts together with.
853
968
  - **Counterbore**: a wider, flat-bottomed step at the mouth of a hole that hides a screw's head.
@@ -870,8 +985,10 @@ this package: the handbook's thread shear area and stress area are applied as th
870
985
  - **Rule set**: a JSON file of named, sourced values in `@rulecad/rules`: one per thread, printer or material.
871
986
  - **Start**: one of the separate threads wound side by side on a multi-start screw.
872
987
  - **Stripping**: a thread failing by its teeth shearing off.
988
+ - **Secant modulus**: a plastic's stress over its strain at a given strain, a little under its modulus at small strains.
873
989
  - **Teardrop**: a round hole with a pointed top, so a hole lying on its side prints with no support.
874
990
  - **Trapezoidal thread**: the flat-topped thread of a lead screw, with flanks 30° apart.
991
+ - **Undercut**: how far a snap's bead stands past the part it has to pass, so the parts must bend to let it by.
875
992
 
876
993
  ## Sources
877
994
 
@@ -885,8 +1002,10 @@ Each figure's own source is in its rule (`m.figures.<name>.source`, and `DEFAULT
885
1002
  - [Bolt group capacity](https://steelcalculator.pages.dev/reference/bolt-group-capacity/), the elastic method: direct and torsional shear in a group.
886
1003
  - [Von Mises yield criterion](https://en.wikipedia.org/wiki/Von_Mises_yield_criterion), Wikipedia: shear yield from tensile yield.
887
1004
  - [How do you calculate the magnetic flux density?](https://www.supermagnete.de/eng/faq/How-do-you-calculate-the-magnetic-flux-density), supermagnete: the field on a disc's and a block's axis; [Physical magnet data](https://www.supermagnete.de/eng/physical-magnet-data), supermagnete: each grade's remanence; and [Force between magnets](https://en.wikipedia.org/wiki/Force_between_magnets), Wikipedia: the force on an iron face, F = B² A / 2μ0. Read on 2026-11-21; each magnet's pull is its seller's page, named in its rule.
1005
+ - [Snap-Fit Joints for Plastics: A Design Guide](https://fab.cba.mit.edu/classes/S62.12/people/vernelle.noel/Plastic_Snap_fit_design.pdf), Bayer MaterialScience: the annular snap joint (its geometric factors, deflection and mating forces and worked lamp cover), the permissible strain for a snap and the friction table. Read on 2026-11-23.
1006
+ - M. Hetényi, Beams on Elastic Foundation, University of Michigan Press, 1946: a thin tube's wall under a ring load as a beam on an elastic foundation, with its long-tube and free-end deflections (Pβ / 2k and 2Pβ / k), which `tubeRing` reproduces in its tests. Not read at first hand for this package: the equation and the two results are the textbook ones, and the kit checks its solution against them and against a short cantilever's P L³ / 3 D.
888
1007
 
889
- All were read on 2026-11-15. The plan for this package is [issue 212](https://github.com/JoniBach/rulecad/issues/212),
1008
+ The rest were read on 2026-11-15. The plan for this package is [issue 212](https://github.com/JoniBach/rulecad/issues/212),
890
1009
  and its specification is `docs/fixings-and-frames.md` in the repository. In `@rulecad/cad` the package is to become
891
1010
  `v.fixings` in designs and a `fasten` relation in assemblies: that work is not in this release.
892
1011
 
package/fixings.d.mts CHANGED
@@ -36,3 +36,4 @@ export { engagement, stripping, preload, torqueFor, seating, lengthFor, screwGro
36
36
  export { pinModel, pinHole, pin, snapPin, snapSocket, snapPinModel, parsePin, isPinName, PIN_KINDS, PIN_FITS, PIN_GRAMMAR } from "./pins.mjs";
37
37
  export { printedBoltModel, printedBolt, BOLT_NUTS } from "./bolts.mjs";
38
38
  export { magnetModel, magnetSeatModel, magnetSeat, magnet, parseMagnet, isMagnetName, fieldShare, MAGNET_GRADES, MAGNET_FITS, MAGNET_SIZES, MAGNET_GRAMMAR } from "./magnets.mjs";
39
+ export { annularSnapModel, annularBead, annularGroove, hubFactor, shaftFactor, tubeRing, SNAP_USES } from "./snaps.mjs";
package/fixings.mjs CHANGED
@@ -7,7 +7,8 @@
7
7
  // (engagement, stripping, preload, seating, lengthFor), and pins that hold two parts with no thread: a printed snap pin, a
8
8
  // steel dowel, a length of filament or a printed peg, each with its hole's fit from the printer's rules (pinModel, pinHole,
9
9
  // pin), and magnets pressed, glued or held by crush ribs in a pocket from the printer's rules, with their pull (magnetModel,
10
- // magnetSeatModel, magnetSeat, magnet), and printed bolts with their own strength (printedBoltModel, printedBolt). Where it applies each comes as a pair: one function gives the
10
+ // magnetSeatModel, magnetSeat, magnet), printed bolts with their own strength (printedBoltModel, printedBolt), and annular snaps, a
11
+ // lid that clicks on to a round box, with the forces and hoop strain from the Bayer snap-fit guide (annularSnapModel, annularBead, annularGroove). Where it applies each comes as a pair: one function gives the
11
12
  // numbers with findings (holeModel), its twin the solid (hole). Every thread's figures live in @rulecad/rules as open data: this package holds no
12
13
  // screw's numbers of its own. Units: mm, degrees, grams. The plan is https://github.com/JoniBach/rulecad/issues/212.
13
14
  import { fixingModel } from './model.mjs';
@@ -19,6 +20,7 @@ import { engagement, stripping, preload, torqueFor, seating, lengthFor, screwGro
19
20
  import { pinModel, pinHole, pin, snapPin, snapSocket, snapPinModel, parsePin, isPinName } from './pins.mjs';
20
21
  import { printedBoltModel, printedBolt } from './bolts.mjs';
21
22
  import { magnetModel, magnetSeatModel, magnetSeat, magnet, parseMagnet, isMagnetName, fieldShare } from './magnets.mjs';
23
+ import { annularSnapModel, annularBead, annularGroove, hubFactor, shaftFactor, tubeRing } from './snaps.mjs';
22
24
 
23
25
  export { fixingModel, parseName, threads, GRAMMAR, HEADS, NUTS, DEFAULTS } from './model.mjs';
24
26
  export { holeModel, hole, HOLE_KINDS } from './holes.mjs';
@@ -29,6 +31,7 @@ export { engagement, stripping, preload, torqueFor, seating, lengthFor, screwGro
29
31
  export { pinModel, pinHole, pin, snapPin, snapSocket, snapPinModel, parsePin, isPinName, PIN_KINDS, PIN_FITS, PIN_GRAMMAR } from './pins.mjs';
30
32
  export { printedBoltModel, printedBolt, BOLT_NUTS } from './bolts.mjs';
31
33
  export { magnetModel, magnetSeatModel, magnetSeat, magnet, parseMagnet, isMagnetName, fieldShare, MAGNET_GRADES, MAGNET_FITS, MAGNET_SIZES, MAGNET_GRAMMAR } from './magnets.mjs';
34
+ export { annularSnapModel, annularBead, annularGroove, hubFactor, shaftFactor, tubeRing, SNAP_USES } from './snaps.mjs';
32
35
 
33
36
  /**
34
37
  * What this release is. `release` is `'placeholder'` until the package has functions to call (0.1.0), then `'ready'`:
@@ -37,8 +40,8 @@ export { magnetModel, magnetSeatModel, magnetSeat, magnet, parseMagnet, isMagnet
37
40
  */
38
41
  export const status = Object.freeze({ release: 'ready', plan: 'https://github.com/JoniBach/rulecad/issues/212' });
39
42
 
40
- const MODELS = { engagement, stripping, preload, torqueFor, seating, screwLoad, threadModel, holeModel, counterboreModel, countersinkModel, nutPocketModel, nutTrapModel, squareNutSlotModel, captiveNutModel, insertBossModel, screwModel, nutModel, washerModel, insertModel, pinModel, magnetModel, magnetSeatModel, printedBoltModel };
41
- const SOLIDS = { thread, hole, counterbore, countersink, nutPocket, nutTrap, squareNutSlot, captiveNut, insertBoss, nut, washer, insert, pinHole, magnetSeat, magnet }, JOINED = { screw, pin, printedBolt };
43
+ const MODELS = { engagement, stripping, preload, torqueFor, seating, screwLoad, threadModel, holeModel, counterboreModel, countersinkModel, nutPocketModel, nutTrapModel, squareNutSlotModel, captiveNutModel, insertBossModel, screwModel, nutModel, washerModel, insertModel, pinModel, magnetModel, magnetSeatModel, printedBoltModel, annularSnapModel };
44
+ const SOLIDS = { thread, hole, counterbore, countersink, nutPocket, nutTrap, squareNutSlot, captiveNut, insertBoss, nut, washer, insert, pinHole, magnetSeat, magnet, annularBead, annularGroove }, JOINED = { screw, pin, printedBolt };
42
45
 
43
46
  /**
44
47
  * Every function of this package with a workspace's rule sets and printer already in hand, so a design writes
@@ -59,7 +62,7 @@ export function fixingsFor({ sets, printer, ops, display } = {}) {
59
62
  out.lengthFor = (stack, m, o = {}) => lengthFor(stack, m, with_(o));
60
63
  out.screwGroup = screwGroup;
61
64
  // (a snap pin from plain figures, as @rulecad/flexures draws it, built with the design's booleans)
62
- Object.assign(out, { snapPin: (p, o) => snapPin(p, o ?? ops ?? undefined), snapSocket, snapPinModel, parsePin, isPinName, parseMagnet, isMagnetName, fieldShare });
65
+ Object.assign(out, { snapPin: (p, o) => snapPin(p, o ?? ops ?? undefined), snapSocket, snapPinModel, parsePin, isPinName, parseMagnet, isMagnetName, fieldShare, hubFactor, shaftFactor, tubeRing });
63
66
  for (const [k, f] of Object.entries(JOINED)) out[k] = (m, o = {}) => (ops ? f(m, with_(o), ops) : f(m, with_(o)));
64
67
  return out;
65
68
  }
package/model.mjs CHANGED
@@ -57,7 +57,12 @@ export const DEFAULTS = {
57
57
  snap_play: { value: 0.5, unit: 'mm', rule: 'A snap pin\'s shaft may be at most this much longer than the parts it goes through: the barb clicks out that far past the far face. Longer, and the pin rattles in its hole', kind: 'estimate', source: 'A working figure of this package: the launcher\'s pins are drawn 0.2 mm (x1c.fit) longer than their parts. No coupon row measures it, so it stays an estimate: snap pins a step longer each through one plate, the longest that does not rattle, would measure it', checked: '2026-11-21' },
58
58
  pin_least: { value: 2, unit: 'mm', rule: 'The thinnest snap pin or printed plain pin: under this a peg is a few print lines across and breaks as it goes in. Thinner pins are filament or steel', kind: 'estimate', source: 'A working figure of this package: about five 0.42 mm lines across, the thinnest the kit draws a snap pin (2.5 mm, the tensioner\'s) less a margin. No coupon row measures it (the holds coupon\'s thinnest snap pin is 3 mm), so it stays an estimate: snap pins of 1.5, 2 and 2.5 mm pushed through their sockets, the thinnest that does not break, would measure it', checked: '2026-11-21' },
59
59
  magnet_floor: { value: 3, unit: 'layers', rule: 'The least floor left under a magnet\'s pocket: three solid layers, so the floor prints whole and the magnet cannot be pulled through it. A floor the magnet pulls through is also its gap, so thinner pulls harder', kind: 'estimate', source: 'A working figure of this package, after Bambu Studio\'s default of three bottom shell layers. No coupon row measures it (the holds coupon\'s pockets have a hole under them), so it stays an estimate: pockets with floors of 2, 3 and 4 layers, the thinnest a magnet does not pull through or show through, would measure it', checked: '2026-11-21' },
60
- brass_density: { value: 8.47, unit: 'g/cm³', rule: 'Density of free-machining brass CW614N (CuZn39Pb3), taken for a heat-set insert. The insert maker\'s sheet names no alloy, so the alloy is assumed', kind: 'estimate', source: 'Aalco, CW614N brass rod datasheet, https://www.aalco.co.uk/datasheets/Copper-and-Copper-Alloys-CW614N-Brass-Rod_31.ashx', checked: '2026-11-15' }
60
+ brass_density: { value: 8.47, unit: 'g/cm³', rule: 'Density of free-machining brass CW614N (CuZn39Pb3), taken for a heat-set insert. The insert maker\'s sheet names no alloy, so the alloy is assumed', kind: 'estimate', source: 'Aalco, CW614N brass rod datasheet, https://www.aalco.co.uk/datasheets/Copper-and-Copper-Alloys-CW614N-Brass-Rod_31.ashx', checked: '2026-11-15' },
61
+ snap_brief: { value: 0.7, unit: '× yield strain', rule: 'An annular snap may strain a plastic to this share of its yield strain as it snaps: the guide gives about 70% for an amorphous plastic in a single brief snap (a partly crystalline one may go almost to yield). Printed PLA and PETG are amorphous and the guide lists neither, so it is applied to them unchecked; the yield strain is taken as strength over modulus, which sits below the real one, on the safe side', kind: 'community', source: 'Bayer MaterialScience, Snap-Fit Joints for Plastics: A Design Guide, copy at https://fab.cba.mit.edu/classes/S62.12/people/vernelle.noel/Plastic_Snap_fit_design.pdf, page 11, Permissible undercut', checked: '2026-11-23' },
62
+ snap_often: { value: 0.6, unit: '× brief strain', rule: 'A snap opened and closed often, as a lid is, is held to this share of the brief-snap strain', kind: 'community', source: 'Bayer MaterialScience, Snap-Fit Joints for Plastics: A Design Guide, copy at https://fab.cba.mit.edu/classes/S62.12/people/vernelle.noel/Plastic_Snap_fit_design.pdf, page 12, Table 2: for frequent separation and rejoining, use about 60% of these values', checked: '2026-11-23' },
63
+ snap_remote: { value: 3, unit: '× near-end force', rule: 'An annular snap at least 1.8 √(d t) in from its tube\'s free end is about this many times as stiff as one at the end: four times in theory, and tests rarely give more than three. Between the two the kit takes a straight line, an estimate', kind: 'community', source: 'Bayer MaterialScience, Snap-Fit Joints for Plastics: A Design Guide, copy at https://fab.cba.mit.edu/classes/S62.12/people/vernelle.noel/Plastic_Snap_fit_design.pdf, page 22', checked: '2026-11-23' },
64
+ snap_friction: { value: 0.5, unit: 'μ', rule: 'Friction between two printed parts of one plastic sliding over each other as a snap goes home: an estimate. The guide lists no PLA or PETG; for the glassy plastics nearest them it gives 0.40 to 0.60 on steel (PS, SAN, PC, PMMA), and 1.2 times that for a plastic on itself', kind: 'estimate', source: 'Bayer MaterialScience, Snap-Fit Joints for Plastics: A Design Guide, copy at https://fab.cba.mit.edu/classes/S62.12/people/vernelle.noel/Plastic_Snap_fit_design.pdf, page 15, Table 3', checked: '2026-11-23' },
65
+ snap_least: { value: 0.2, unit: 'mm', rule: 'The least radial undercut an annular snap is drawn with: twice x1c.hole_comp, the error a printed round comes out with, so the print\'s own error cannot take the whole of it', kind: 'estimate', source: 'A working figure of this package, from x1c.hole_comp (0.1 mm); the fixings coupon has no snap ring yet to measure it', checked: '2026-11-23' }
61
66
  };
62
67
 
63
68
  // ---------- small things every module here uses ----------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/fixings",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Screws, nuts, washers and inserts from rule sets, and the holes and seats they need in printed parts: a fixing as a model with sourced figures, holes sized by what they are for, counterbores, countersinks, nut pockets and insert bosses that print without supports, light solids of the hardware for an assembly, threads cut for printing, and first sums for a joint (engagement, stripping, preload, seating, the sold length that fits).",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,6 +22,7 @@
22
22
  "pins.mjs",
23
23
  "magnets.mjs",
24
24
  "bolts.mjs",
25
+ "snaps.mjs",
25
26
  "fixings.d.mts",
26
27
  "model.d.mts",
27
28
  "holes.d.mts",
@@ -33,6 +34,7 @@
33
34
  "pins.d.mts",
34
35
  "magnets.d.mts",
35
36
  "bolts.d.mts",
37
+ "snaps.d.mts",
36
38
  "README.md",
37
39
  "CHANGELOG.md",
38
40
  "LICENSE"
package/snaps.d.mts ADDED
@@ -0,0 +1,185 @@
1
+ /**
2
+ * A ring load on a thin tube, as Hetényi's beam on an elastic foundation (the theory the Bayer guide's annular joint is
3
+ * built on): the tube's wall in ξ = βx, with β⁴ = 3 (1 − ν²) / (R² t²), bends as w'''' + 4 w = 0, and a ring load q
4
+ * per mm round it puts a step of q / (D β³) in w''' (D = E t³ / (12 (1 − ν²))). The load is a from one end and b from
5
+ * the other (each in 1/β), and each end is 'free' (no moment, no shear), 'closed' (held by an end wall: no deflection,
6
+ * no slope, the stiffest an end can be) or 'long' (far enough off not to count). Gives the deflection under the load and
7
+ * the curvature w'' at each end, both per q / (D β³). The free-standing checks: a long tube both ways gives w = 1/8,
8
+ * a free end at the load gives 1/2 (Hetényi, Beams on Elastic Foundation, 1946: w = Pβ / 2k and 2Pβ / k).
9
+ * @param {number} a the load's distance from end A, in 1/β @param {number} b from end B
10
+ * @param {{ A?: 'free' | 'closed' | 'long', B?: 'free' | 'closed' | 'long' }} [ends] (default both long)
11
+ * @returns {{ w: number, bendA: number, bendB: number }}
12
+ */
13
+ export function tubeRing(a: number, b: number, ends?: {
14
+ A?: "free" | "closed" | "long";
15
+ B?: "free" | "closed" | "long";
16
+ }): {
17
+ w: number;
18
+ bendA: number;
19
+ bendB: number;
20
+ };
21
+ /**
22
+ * @typedef {{ diameter: number, inside: number, outside: number, wall: number, end: number, far: number, factor: number,
23
+ * remote: number, X: number, stiffness: number, deflection: number, strain: number, closed: number | null, stiffer?: number, decay?: number, root?: number }} SnapPart
24
+ * one part of the joint: its diameters at the joint, wall, how far the joint is from its free end and the guide's
25
+ * "remote" distance, the stiffening that gives (remote), and with a closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter),
26
+ * how much of the interference it takes (on the diameter) and the hoop strain that leaves in it; with a closed end
27
+ * (closed, its distance from the joint), how much stiffer that end makes it, the length 1/β over which its wall
28
+ * bends, and the bending strain at the end's root
29
+ */
30
+ /**
31
+ * @typedef {{ kind: 'annular snap', diameter: number, wall: number, skirt: number, clearance: number, bead: number, length: number, undercut: number,
32
+ * interference: number, lead: number, back: number, land: number, sized: boolean, uses: 'often' | 'once', material: string,
33
+ * lidMaterial: string, friction: number, permissible: number, box: SnapPart, lid: SnapPart, force: number, insertion: number,
34
+ * removal: number, holds: boolean, pull: number | null, margin: number | null, most: { undercut: number, removal: number },
35
+ * groove: { inner: number, outer: number, depth: number }, rests: object[], findings: object[] }} AnnularSnap
36
+ * diameter: the box's wall outside at the joint; bead: how far the bead stands off it (radial); length: the bead's
37
+ * height along the axis, return face, land and lead face; undercut: the
38
+ * bead less the clearance, the radial overlap the skirt is spread by; interference: the same on the diameter, shared
39
+ * between the parts; force: the transverse force P that takes; insertion and removal: along the push, N;
40
+ * permissible: the hoop strain each part may see; most: the largest undercut that strain allows and the removal
41
+ * force it would give; groove: the groove's radii and depth in the skirt
42
+ */
43
+ /**
44
+ * An annular snap: a lid with a skirt that clicks over a bead round a round box's rim. Each part is a tube; the
45
+ * interference (the bead less the clearance, on the diameter) is shared between them as two springs in series, each
46
+ * P = y d Es X (Bayer, Snap-Fit Joints for Plastics, the annular snap joint), with Es taken as the material's modulus.
47
+ * The hoop strain in each is its share over its diameter, held to the plastic's limit: about 70% of its yield strain
48
+ * for a brief snap in an amorphous plastic, and 60% of that for a joint opened often (the same guide). Without a bead
49
+ * height, the bead is sized: the smallest the print can hold (fixings.snap_least), or more where pull asks it, up to
50
+ * what the strain allows. Refused by name: a bead no taller than the clearance (it never catches), walls that leave no
51
+ * tube, angles outside 0° to 90°, a lead friction locks, a groove deeper than the skirt. A closed end near the joint
52
+ * (the box's floor, the lid's top) is a beam on an elastic foundation held round there (Hetényi): the part is stiffer,
53
+ * so its mate takes more of the interference, and the bending at that end's root is held to the same limit.
54
+ * @param {{ diameter: number, wall: number, skirt: number, bead?: number, lead?: number, back?: number, land?: number, boxEnd?: number, lidEnd?: number, boxFloor?: number, lidTop?: number }} p
55
+ * diameter: the box's wall outside, at the joint, mm; wall: the box's wall thickness there; skirt: the lid's skirt
56
+ * thickness; bead: how far the bead stands off the wall (default sized); lead: the face the lid pushes over, its
57
+ * angle from the axis (default 30); back: the return face's (default 45: the steepest the box prints without support,
58
+ * as it is the underside of the bead); land: the bead's flat top, along the axis (default two layers); boxEnd: from the
59
+ * bead to the box's rim, its free end; lidEnd: from the groove to the skirt's mouth (each default 0, at the end);
60
+ * boxFloor: from the bead to the box's floor, its closed end; lidTop: from the groove to the underside of the lid's
61
+ * top (each default none: far enough off not to count; each at least its part's wall, the box's wall or the skirt)
62
+ * @param {{ material?: string | object, lidMaterial?: string | object, printer?: object, sets?: object, uses?: 'often' | 'once', friction?: number, pull?: number, push?: number }} [o]
63
+ * material: the box's plastic (default PLA); lidMaterial: the lid's (default the box's); printer: the printer's rule
64
+ * set or values (default the X1C: its fit is the clearance, its overhang the steepest return face); uses: often (the
65
+ * default, a lid) or once; friction: μ between the parts (default fixings.snap_friction); pull: the force along the
66
+ * axis the lid must stay on against, N, held to fixings.load_margin; push: the force it is pushed on with, N (warns
67
+ * where pushing it on square takes more)
68
+ * @returns {AnnularSnap}
69
+ */
70
+ export function annularSnapModel(p: {
71
+ diameter: number;
72
+ wall: number;
73
+ skirt: number;
74
+ bead?: number;
75
+ lead?: number;
76
+ back?: number;
77
+ land?: number;
78
+ boxEnd?: number;
79
+ lidEnd?: number;
80
+ boxFloor?: number;
81
+ lidTop?: number;
82
+ }, o?: {
83
+ material?: string | object;
84
+ lidMaterial?: string | object;
85
+ printer?: object;
86
+ sets?: object;
87
+ uses?: "often" | "once";
88
+ friction?: number;
89
+ pull?: number;
90
+ push?: number;
91
+ }): AnnularSnap;
92
+ /**
93
+ * The bead to add to the box: a ring round the wall's outside, its foot (the bottom of the return face) at z = at.
94
+ * Union it with a box whose wall's outside is the model's diameter about the z axis.
95
+ * @param {object | AnnularSnap} p the joint's figures, as annularSnapModel takes them, or its model
96
+ * @param {object} [o] as annularSnapModel, and at: the bead's foot, mm up z (default 0); segments: faces round (default 96)
97
+ * @returns {object} a JSCAD geom3 with .model
98
+ */
99
+ export function annularBead(p: object | AnnularSnap, o?: object): object;
100
+ /**
101
+ * The groove to cut from the lid's skirt, in the same place as the bead it takes (at, as annularBead's): the bead's
102
+ * outline grown by the clearance all round, so the seated bead touches nothing, and with mouth, the skirt's mouth's z,
103
+ * a lead-in cone there at the lead angle, as wide as the bead, so the skirt's edge starts over it.
104
+ * @param {object | AnnularSnap} p the joint's figures or its model
105
+ * @param {object} [o] as annularSnapModel, and at: the bead's foot (default 0); mouth: the z of the skirt's open end,
106
+ * below at (default none: no lead-in); segments: faces round (default 96)
107
+ * @returns {object} a JSCAD geom3 to subtract, with .model
108
+ */
109
+ export function annularGroove(p: object | AnnularSnap, o?: object): object;
110
+ /** The uses an annular snap is sized for: opened often (a lid, the guide's 60% of the brief-snap strain) or snapped once. */
111
+ export const SNAP_USES: string[];
112
+ export function hubFactor(k: number, nu: number): number;
113
+ export function shaftFactor(k: number, nu: number): number;
114
+ /**
115
+ * one part of the joint: its diameters at the joint, wall, how far the joint is from its free end and the guide's
116
+ * "remote" distance, the stiffening that gives (remote), and with a closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter),
117
+ * how much of the interference it takes (on the diameter) and the hoop strain that leaves in it; with a closed end
118
+ * (closed, its distance from the joint), how much stiffer that end makes it, the length 1/β over which its wall
119
+ * bends, and the bending strain at the end's root
120
+ */
121
+ export type SnapPart = {
122
+ diameter: number;
123
+ inside: number;
124
+ outside: number;
125
+ wall: number;
126
+ end: number;
127
+ far: number;
128
+ factor: number;
129
+ remote: number;
130
+ X: number;
131
+ stiffness: number;
132
+ deflection: number;
133
+ strain: number;
134
+ closed: number | null;
135
+ stiffer?: number;
136
+ decay?: number;
137
+ root?: number;
138
+ };
139
+ /**
140
+ * diameter: the box's wall outside at the joint; bead: how far the bead stands off it (radial); length: the bead's
141
+ * height along the axis, return face, land and lead face; undercut: the
142
+ * bead less the clearance, the radial overlap the skirt is spread by; interference: the same on the diameter, shared
143
+ * between the parts; force: the transverse force P that takes; insertion and removal: along the push, N;
144
+ * permissible: the hoop strain each part may see; most: the largest undercut that strain allows and the removal
145
+ * force it would give; groove: the groove's radii and depth in the skirt
146
+ */
147
+ export type AnnularSnap = {
148
+ kind: "annular snap";
149
+ diameter: number;
150
+ wall: number;
151
+ skirt: number;
152
+ clearance: number;
153
+ bead: number;
154
+ length: number;
155
+ undercut: number;
156
+ interference: number;
157
+ lead: number;
158
+ back: number;
159
+ land: number;
160
+ sized: boolean;
161
+ uses: "often" | "once";
162
+ material: string;
163
+ lidMaterial: string;
164
+ friction: number;
165
+ permissible: number;
166
+ box: SnapPart;
167
+ lid: SnapPart;
168
+ force: number;
169
+ insertion: number;
170
+ removal: number;
171
+ holds: boolean;
172
+ pull: number | null;
173
+ margin: number | null;
174
+ most: {
175
+ undercut: number;
176
+ removal: number;
177
+ };
178
+ groove: {
179
+ inner: number;
180
+ outer: number;
181
+ depth: number;
182
+ };
183
+ rests: object[];
184
+ findings: object[];
185
+ };
package/snaps.mjs ADDED
@@ -0,0 +1,293 @@
1
+ // Annular snaps: a lid that clicks on. A bead runs round the outside of a round box's wall near its rim; the lid's
2
+ // skirt has a groove inside it the bead's shape plus a clearance. Pushed on, the bead's lead face spreads the skirt and
3
+ // squeezes the box's wall; past it, both spring back and the bead sits in the groove with no stress left in either.
4
+ // Pulled, the bead's return face has to spread the skirt again. annularSnapModel gives the forces and the hoop strain in
5
+ // each part from the Bayer snap-fit design guide's annular joint (a beam on an elastic foundation: P = y d Es X, with
6
+ // X from the tube's proportions), the two parts as springs in series where both give, and the strain held to the
7
+ // plastic's limit by the guide's rule for a brief snap. annularBead is the bead to add to the box's wall, annularGroove
8
+ // the groove (and the skirt's lead-in) to cut from the lid. Units: mm, N, MPa, degrees.
9
+ import { DEFAULTS, printerOf, rest, finding, positive, oneOf, isNum, shown, mm, r3 } from './model.mjs';
10
+ import { lathe } from './draw.mjs';
11
+ import { optionsOf } from './holes.mjs';
12
+ import { materialOf } from './strength.mjs';
13
+
14
+ const n1 = (x) => +x.toFixed(1), n2 = (x) => +x.toFixed(2), n4 = (x) => +x.toFixed(4), pc = (x) => `${mm(n2(x * 100))}%`;
15
+ const tan = (deg) => Math.tan((deg * Math.PI) / 180);
16
+ /** The uses an annular snap is sized for: opened often (a lid, the guide's 60% of the brief-snap strain) or snapped once. */
17
+ export const SNAP_USES = ['often', 'once'];
18
+
19
+ /**
20
+ * The geometric factor of the Bayer guide's annular snap joint for the outer part, a tube (the hub, here the lid's
21
+ * skirt) spread over a rigid shaft: X_N = 0.62 √((k − 1)/(k + 1)) / ((k² + 1)/(k² − 1) + ν), k = d0 / d.
22
+ * @param {number} k the tube's outside diameter over its inside diameter at the joint @param {number} nu Poisson's ratio
23
+ * @returns {number}
24
+ */
25
+ export const hubFactor = (k, nu) => (0.62 * Math.sqrt((k - 1) / (k + 1))) / ((k * k + 1) / (k * k - 1) + nu);
26
+ /**
27
+ * The same for the inner part, a hollow shaft (here the box's wall) squeezed in a rigid tube:
28
+ * X_W = 0.62 √((k − 1)/(k + 1)) / ((k² + 1)/(k² − 1) − ν), k = d / di.
29
+ * @param {number} k the shaft's outside diameter at the joint over its inside diameter @param {number} nu Poisson's ratio
30
+ * @returns {number}
31
+ */
32
+ export const shaftFactor = (k, nu) => (0.62 * Math.sqrt((k - 1) / (k + 1))) / ((k * k + 1) / (k * k - 1) - nu);
33
+
34
+ // The force along the push to make a transverse force P over a face at deg from the axis, with friction mu: the
35
+ // guide's W = P (μ + tan α) / (1 − μ tan α). A square face, or one friction locks, never lets go
36
+ const along = (P, deg, mu) => (deg >= 90 || mu * tan(deg) >= 1 ? Infinity : (P * (mu + tan(deg))) / (1 - mu * tan(deg)));
37
+ const per = (deg, mu) => along(1, deg, mu);
38
+ // How much stiffer a joint is for lying away from its tube's free end: 1 at the end, the guide's 3 once it is at least
39
+ // 1.8 √(d t) in, and straight between (the guide gives only the ends; the line between is an estimate)
40
+ const remote = (end, d, t) => { const far = 1.8 * Math.sqrt(d * t), k = DEFAULTS.snap_remote.value; return { far: n2(far), factor: 1 + (k - 1) * Math.min(1, end / far) }; };
41
+
42
+ // e^(s u) (A cos u + B sin u) and its n-th derivative in u, at u
43
+ const wave = (s, A, B, u, n) => { for (let i = 0; i < n; i++) [A, B] = [s * A + B, s * B - A]; return Math.exp(s * u) * (A * Math.cos(u) + B * Math.sin(u)); };
44
+ const LONG = 12; // a tube this many 1/β long is long: e^-12 of the load is left at its far end
45
+ /**
46
+ * A ring load on a thin tube, as Hetényi's beam on an elastic foundation (the theory the Bayer guide's annular joint is
47
+ * built on): the tube's wall in ξ = βx, with β⁴ = 3 (1 − ν²) / (R² t²), bends as w'''' + 4 w = 0, and a ring load q
48
+ * per mm round it puts a step of q / (D β³) in w''' (D = E t³ / (12 (1 − ν²))). The load is a from one end and b from
49
+ * the other (each in 1/β), and each end is 'free' (no moment, no shear), 'closed' (held by an end wall: no deflection,
50
+ * no slope, the stiffest an end can be) or 'long' (far enough off not to count). Gives the deflection under the load and
51
+ * the curvature w'' at each end, both per q / (D β³). The free-standing checks: a long tube both ways gives w = 1/8,
52
+ * a free end at the load gives 1/2 (Hetényi, Beams on Elastic Foundation, 1946: w = Pβ / 2k and 2Pβ / k).
53
+ * @param {number} a the load's distance from end A, in 1/β @param {number} b from end B
54
+ * @param {{ A?: 'free' | 'closed' | 'long', B?: 'free' | 'closed' | 'long' }} [ends] (default both long)
55
+ * @returns {{ w: number, bendA: number, bendB: number }}
56
+ */
57
+ export function tubeRing(a, b, ends = {}) {
58
+ const what = 'tubeRing', kinds = ['free', 'closed', 'long'];
59
+ for (const [k, v] of [['a', a], ['b', b]]) if (!(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is the load's distance from an end, in 1/β, 0 or more (got ${shown(v)})`);
60
+ if (ends == null || typeof ends !== 'object' || Array.isArray(ends)) throw new Error(`${what}: ends is { A, B }, each free, closed or long (got ${shown(ends)})`);
61
+ // An end more than twice LONG away is long whatever it is: e^-24 of the load reaches it, and its e^u waves would
62
+ // overflow a double past about 709/β (its curvature there is then 0 to that precision)
63
+ const A0 = oneOf(what, 'ends.A', ends.A ?? 'long', kinds), B0 = oneOf(what, 'ends.B', ends.B ?? 'long', kinds);
64
+ const A = a > 2 * LONG ? 'long' : A0, B = b > 2 * LONG ? 'long' : B0, la = A === 'long' ? LONG : a, lb = B === 'long' ? LONG : b;
65
+ // Each side of the load has its own four waves, from its start: e^-u cos u, e^-u sin u, e^u cos u, e^u sin u
66
+ const row = (side, u, n, sign = 1) => { const r = Array(8).fill(0); [[-1, 1, 0], [-1, 0, 1], [1, 1, 0], [1, 0, 1]].forEach(([s, c, si], i) => { r[side * 4 + i] = sign * wave(s, c, si, u, n); }); return r; };
67
+ const end = (side, u, kind) => (kind === 'closed' ? [0, 1] : [2, 3]).map((n) => [row(side, u, n), 0]);
68
+ const eqs = [...end(0, 0, A), ...end(1, lb, B)];
69
+ for (const n of [0, 1, 2, 3]) { const l = row(0, la, n, -1), r = row(1, 0, n); eqs.push([l.map((x, i) => x + r[i]), n === 3 ? 1 : 0]); }
70
+ // Gauss with partial pivoting
71
+ const M = eqs.map(([r, v]) => [...r, v]);
72
+ for (let c = 0; c < 8; c++) {
73
+ let p = c; for (let r = c + 1; r < 8; r++) if (Math.abs(M[r][c]) > Math.abs(M[p][c])) p = r;
74
+ [M[c], M[p]] = [M[p], M[c]];
75
+ for (let r = 0; r < 8; r++) if (r !== c) { const k = M[r][c] / M[c][c]; for (let j = c; j < 9; j++) M[r][j] -= k * M[c][j]; }
76
+ }
77
+ const x = M.map((r, i) => r[8] / r[i]), at = (side, u, n) => row(side, u, n).reduce((t, v, i) => t + v * x[i], 0);
78
+ return { w: at(1, 0, 0), bendA: A === A0 ? at(0, 0, 2) : 0, bendB: B === B0 ? at(1, lb, 2) : 0 };
79
+ }
80
+ // A closed end near the joint: how much stiffer it makes the part (the beam's deflection with the end open over that
81
+ // with it closed, the rest of the tube as it is) and the bending strain at the closed end's root per N of P
82
+ const closedEnd = (free, shut, Rm, t, d, E, nu) => {
83
+ const beta = Math.pow((3 * (1 - nu * nu)) / (Rm * Rm * t * t), 0.25), a = free * beta, b = shut * beta;
84
+ const open = tubeRing(a, LONG, { A: 'free' }), closed = tubeRing(a, b, { A: 'free', B: 'closed' });
85
+ // q = P / (π d) per mm round; M = D w''(x) = w''(ξ) q / β; the strain at the face is 6 M (1 − ν²) / (E t²)
86
+ const perP = (6 * Math.abs(closed.bendB) * (1 - nu * nu)) / (Math.PI * d * beta * E * t * t);
87
+ return { beta, stiffer: open.w / closed.w, perP };
88
+ };
89
+
90
+ /**
91
+ * @typedef {{ diameter: number, inside: number, outside: number, wall: number, end: number, far: number, factor: number,
92
+ * remote: number, X: number, stiffness: number, deflection: number, strain: number, closed: number | null, stiffer?: number, decay?: number, root?: number }} SnapPart
93
+ * one part of the joint: its diameters at the joint, wall, how far the joint is from its free end and the guide's
94
+ * "remote" distance, the stiffening that gives (remote), and with a closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter),
95
+ * how much of the interference it takes (on the diameter) and the hoop strain that leaves in it; with a closed end
96
+ * (closed, its distance from the joint), how much stiffer that end makes it, the length 1/β over which its wall
97
+ * bends, and the bending strain at the end's root
98
+ */
99
+ /**
100
+ * @typedef {{ kind: 'annular snap', diameter: number, wall: number, skirt: number, clearance: number, bead: number, length: number, undercut: number,
101
+ * interference: number, lead: number, back: number, land: number, sized: boolean, uses: 'often' | 'once', material: string,
102
+ * lidMaterial: string, friction: number, permissible: number, box: SnapPart, lid: SnapPart, force: number, insertion: number,
103
+ * removal: number, holds: boolean, pull: number | null, margin: number | null, most: { undercut: number, removal: number },
104
+ * groove: { inner: number, outer: number, depth: number }, rests: object[], findings: object[] }} AnnularSnap
105
+ * diameter: the box's wall outside at the joint; bead: how far the bead stands off it (radial); length: the bead's
106
+ * height along the axis, return face, land and lead face; undercut: the
107
+ * bead less the clearance, the radial overlap the skirt is spread by; interference: the same on the diameter, shared
108
+ * between the parts; force: the transverse force P that takes; insertion and removal: along the push, N;
109
+ * permissible: the hoop strain each part may see; most: the largest undercut that strain allows and the removal
110
+ * force it would give; groove: the groove's radii and depth in the skirt
111
+ */
112
+
113
+ /**
114
+ * An annular snap: a lid with a skirt that clicks over a bead round a round box's rim. Each part is a tube; the
115
+ * interference (the bead less the clearance, on the diameter) is shared between them as two springs in series, each
116
+ * P = y d Es X (Bayer, Snap-Fit Joints for Plastics, the annular snap joint), with Es taken as the material's modulus.
117
+ * The hoop strain in each is its share over its diameter, held to the plastic's limit: about 70% of its yield strain
118
+ * for a brief snap in an amorphous plastic, and 60% of that for a joint opened often (the same guide). Without a bead
119
+ * height, the bead is sized: the smallest the print can hold (fixings.snap_least), or more where pull asks it, up to
120
+ * what the strain allows. Refused by name: a bead no taller than the clearance (it never catches), walls that leave no
121
+ * tube, angles outside 0° to 90°, a lead friction locks, a groove deeper than the skirt. A closed end near the joint
122
+ * (the box's floor, the lid's top) is a beam on an elastic foundation held round there (Hetényi): the part is stiffer,
123
+ * so its mate takes more of the interference, and the bending at that end's root is held to the same limit.
124
+ * @param {{ diameter: number, wall: number, skirt: number, bead?: number, lead?: number, back?: number, land?: number, boxEnd?: number, lidEnd?: number, boxFloor?: number, lidTop?: number }} p
125
+ * diameter: the box's wall outside, at the joint, mm; wall: the box's wall thickness there; skirt: the lid's skirt
126
+ * thickness; bead: how far the bead stands off the wall (default sized); lead: the face the lid pushes over, its
127
+ * angle from the axis (default 30); back: the return face's (default 45: the steepest the box prints without support,
128
+ * as it is the underside of the bead); land: the bead's flat top, along the axis (default two layers); boxEnd: from the
129
+ * bead to the box's rim, its free end; lidEnd: from the groove to the skirt's mouth (each default 0, at the end);
130
+ * boxFloor: from the bead to the box's floor, its closed end; lidTop: from the groove to the underside of the lid's
131
+ * top (each default none: far enough off not to count; each at least its part's wall, the box's wall or the skirt)
132
+ * @param {{ material?: string | object, lidMaterial?: string | object, printer?: object, sets?: object, uses?: 'often' | 'once', friction?: number, pull?: number, push?: number }} [o]
133
+ * material: the box's plastic (default PLA); lidMaterial: the lid's (default the box's); printer: the printer's rule
134
+ * set or values (default the X1C: its fit is the clearance, its overhang the steepest return face); uses: often (the
135
+ * default, a lid) or once; friction: μ between the parts (default fixings.snap_friction); pull: the force along the
136
+ * axis the lid must stay on against, N, held to fixings.load_margin; push: the force it is pushed on with, N (warns
137
+ * where pushing it on square takes more)
138
+ * @returns {AnnularSnap}
139
+ */
140
+ export function annularSnapModel(p, o = {}) {
141
+ const what = 'annularSnapModel';
142
+ if (p == null || typeof p !== 'object' || Array.isArray(p)) throw new Error(`${what}: give the joint's figures ({ diameter: 60, wall: 1.68, skirt: 1.26 }), not ${shown(p)}`);
143
+ optionsOf(what, o, '{ material: \'pla\', pull: 10 }');
144
+ const d = positive(what, 'diameter', p.diameter), t = positive(what, 'wall', p.wall), s = positive(what, 'skirt', p.skirt);
145
+ if (t >= d / 2) throw new Error(`${what}: a wall of ${mm(t)} mm fills a ${mm(d)} mm box: the box's wall is under half its diameter, so it is a tube that gives`);
146
+ const pr = printerOf(what, o.printer), c = pr.n('fit'), layer = pr.n('layer'), overhang = pr.n('overhang');
147
+ const angle = (k, v, dflt) => { const x = v ?? dflt; if (!(isNum(x) && x > 0 && x <= 90)) throw new Error(`${what}: ${k} is an angle from the axis above 0° and at most 90°, in degrees (got ${shown(v)})`); return x; };
148
+ const lead = angle('lead', p.lead, 30), back = angle('back', p.back, 45);
149
+ if (lead >= 90) throw new Error(`${what}: a lead of 90° is a square face the lid cannot be pushed over: give a lead under 90°, 30° to 45° is usual`);
150
+ const land = p.land != null ? positive(what, 'land', p.land) : r3(2 * layer);
151
+ const end = (k) => { const v = p[k] ?? 0; if (!(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is how far the joint is from that part's free end, 0 mm or more (got ${shown(p[k])})`); return v; };
152
+ // A closed end at the joint itself (0 mm) holds the wall rigid there, so it cannot give at all; one nearer than the
153
+ // wall is thick is a solid corner, not a tube's wall that bends, which the beam on an elastic foundation (a thin-shell
154
+ // theory) does not model, and its sums lose their sign to rounding as the distance goes to 0. Both refused
155
+ const shut = (k, what2, wall, wallName) => { if (p[k] == null) return null; const v = p[k]; if (!(isNum(v) && v >= wall - 1e-9)) throw new Error(`${what}: ${k} is how far the joint is from ${what2}, its closed end, at least the ${mm(wall)} mm ${wallName} (got ${shown(v)}): a joint nearer its closed end than that is a solid corner that cannot give, so move it further off`); return v; };
156
+ const boxFloor = shut('boxFloor', 'the box\'s floor', t, 'wall'), lidTop = shut('lidTop', 'the lid\'s top', s, 'skirt');
157
+ const boxEnd = end('boxEnd'), lidEnd = end('lidEnd'), uses = oneOf(what, 'uses', o.uses ?? 'often', SNAP_USES);
158
+ const mu = o.friction ?? DEFAULTS.snap_friction.value;
159
+ if (!(isNum(mu) && mu >= 0 && mu < 1)) throw new Error(`${what}: friction is μ between the parts, 0 or more and under 1 (got ${shown(o.friction)})`);
160
+ if (mu * tan(lead) >= 1 - 1e-9) throw new Error(`${what}: a ${mm(lead)}° lead at friction ${mm(mu)} locks: μ tan α is ${mm(n2(mu * tan(lead)))}, 1 or more, so no push slides the skirt over it. Give a lead under ${mm(n1((Math.atan(1 / mu) * 180) / Math.PI))}° at that friction, 30° to 45° is usual`);
161
+ const pull = o.pull != null ? positive(what, 'pull (along the axis, in N)', o.pull) : null, push = o.push != null ? positive(what, 'push (along the axis, in N)', o.push) : null;
162
+ if (p.bead != null && !(isNum(p.bead) && p.bead > c + 1e-9)) throw new Error(`${what}: a bead of ${shown(p.bead)} mm is no taller than the ${pr.cite('fit')} clearance of ${mm(c)} mm round the skirt, so it never catches: give a bead over ${mm(c)} mm, or leave it out to have it sized`);
163
+ if (p.bead != null && p.bead >= s - 1e-9) throw new Error(`${what}: a bead of ${mm(p.bead)} mm needs a groove as deep in the ${mm(s)} mm skirt, which cuts right through it: give a skirt thicker than the bead, by a print line or more`);
164
+ const box = materialOf(what, o.material ?? 'pla', o.sets), lidMat = materialOf(what, o.lidMaterial ?? o.material ?? 'pla', o.sets);
165
+ for (const m of [box, lidMat]) if (!m.poisson) throw new Error(`${what}: ${m.name} has no poisson in its rule set, which the guide's geometric factor needs`);
166
+ if (box.cls !== 'plastic' || lidMat.cls !== 'plastic') throw new Error(`${what}: an annular snap is two printed plastic parts; ${box.cls !== 'plastic' ? box.name : lidMat.name} is a ${box.cls !== 'plastic' ? box.cls : lidMat.cls}`);
167
+
168
+ // The permissible hoop strain: the guide's share of the yield strain, the yield strain taken as strength over modulus
169
+ // (a straight line to the strength, so below the real yield strain: on the safe side), and 60% of that if opened often
170
+ const brief = DEFAULTS.snap_brief.value, often = uses === 'often' ? DEFAULTS.snap_often.value : 1;
171
+ const limitOf = (m) => (brief * often * m.strength.value) / m.modulus.value, permissible = Math.min(limitOf(box), limitOf(lidMat));
172
+
173
+ // Each part as a spring on the diameter: P = y d Es X, stiffened where the joint lies away from its free end
174
+ const di = d - 2 * t, dh = d + 2 * c, d0 = dh + 2 * s;
175
+ // A closed end (the box's floor, the lid's top) near the joint holds the tube round there: Hetényi's beam on an elastic
176
+ // foundation gives how much stiffer that makes it than the same tube open, and the bending at the closed end's root
177
+ const part = (diameter, inside, outside, wall, endAt, closedAt, X, m) => {
178
+ const r = remote(endAt, diameter, wall), E = m.modulus.value, nu = m.poisson.value;
179
+ const ce = closedAt == null ? null : closedEnd(endAt, closedAt, (inside + outside) / 4, wall, diameter, E, nu), factor = r.factor * (ce ? ce.stiffer : 1);
180
+ return { diameter: r3(diameter), inside: r3(inside), outside: r3(outside), wall, end: endAt, far: r.far, remote: n2(r.factor), factor: n2(factor), X, stiffness: factor * diameter * E * X,
181
+ closed: closedAt, ...(ce ? { stiffer: n2(ce.stiffer), decay: n2(1 / ce.beta), rootPerP: ce.perP } : {}) };
182
+ };
183
+ const B = part(d, di, d, t, boxEnd, boxFloor, shaftFactor(d / di, box.poisson.value), box), L = part(dh, dh, d0, s, lidEnd, lidTop, hubFactor(d0 / dh, lidMat.poisson.value), lidMat);
184
+ const k = 1 / (1 / B.stiffness + 1 / L.stiffness);
185
+ // The most force (and so interference) the strain allows: P = ε k_i d_i in each part
186
+ // The most force (and so interference) the strain allows: P = ε k_i d_i in each part, and at a closed end's root P = ε / (strain per N)
187
+ const Pmost = Math.min(permissible * B.stiffness * B.diameter, permissible * L.stiffness * L.diameter, ...[B, L].filter((q) => q.rootPerP).map((q) => permissible / q.rootPerP)), mostUndercut = Pmost / k / 2;
188
+ // to the thousandth: the sized bead is rounded up to what the pull needs and down to what the strain allows
189
+ const up = (x) => Math.ceil(x * 1000 - 1e-6) / 1000, down = (x) => Math.floor(x * 1000 + 1e-6) / 1000;
190
+ const least = DEFAULTS.snap_least.value, back1 = per(back, mu), want = DEFAULTS.load_margin.value;
191
+ let undercut, sized = false, sizeSays = null;
192
+ if (p.bead != null) undercut = p.bead - c;
193
+ else {
194
+ sized = true;
195
+ const need = pull != null && Number.isFinite(back1) ? (want * pull) / back1 / k / 2 : 0;
196
+ undercut = Math.max(least, up(need));
197
+ sizeSays = need > least ? `sized from the ${mm(pull)} N pull: ${mm(want)} times it over the ${mm(back)}° return face` : `sized as the smallest the print holds, fixings.snap_least ${mm(least)} mm${pull != null ? `, which already holds the ${mm(pull)} N pull ${mm(want)} times over` : ''}`;
198
+ if (undercut > mostUndercut) { sizeSays += `, more than the ${mm(r3(mostUndercut))} mm the strain allows, so held to that`; undercut = Math.max(down(mostUndercut), 0); }
199
+ undercut = r3(undercut);
200
+ }
201
+ const bead = r3(undercut + c), Y = 2 * undercut, P = k * Y, length = r3(bead / tan(back) + land + bead / tan(lead));
202
+ // The strains are judged unrounded (exact, below), and shown to 4 places: a bead held to the strain's limit could round over it
203
+ const exact = new Map();
204
+ for (const q of [B, L]) { const e = { strain: P / q.stiffness / q.diameter, root: q.rootPerP != null ? P * q.rootPerP : null }; exact.set(q, e);
205
+ q.deflection = r3(P / q.stiffness); q.strain = n4(e.strain); if (q.rootPerP != null) { q.root = n4(e.root); delete q.rootPerP; } q.X = +q.X.toPrecision(3); q.stiffness = n1(q.stiffness); }
206
+ const insertion = along(P, lead, mu), removal = along(P, back, mu), holds = !Number.isFinite(removal), most = { undercut: down(mostUndercut), removal: Number.isFinite(back1) ? n1(back1 * Pmost) : Infinity };
207
+
208
+ const out = [], rests = [], cited = (m) => `${m.strength.name} ${mm(m.strength.value)} MPa over ${m.modulus.name} ${mm(m.modulus.value)} MPa`;
209
+ rests.push(pr.rest('fit'), pr.rest('overhang'), rest(box.modulus.name, box.modulus), rest(box.strength.name, box.strength), rest(box.poisson.name, box.poisson),
210
+ rest('fixings.snap_brief', DEFAULTS.snap_brief), ...(uses === 'often' ? [rest('fixings.snap_often', DEFAULTS.snap_often)] : []), rest('fixings.snap_remote', DEFAULTS.snap_remote), pr.rest('line'));
211
+ if (lidMat !== box && lidMat.name !== box.name) rests.push(rest(lidMat.modulus.name, lidMat.modulus), rest(lidMat.strength.name, lidMat.strength), rest(lidMat.poisson.name, lidMat.poisson));
212
+ if (o.friction == null) rests.push(rest('fixings.snap_friction', DEFAULTS.snap_friction));
213
+ if (sized) rests.push(rest('fixings.snap_least', DEFAULTS.snap_least));
214
+ if (pull != null) rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
215
+ out.push(finding('info', `a ${mm(bead)} mm bead round the ${mm(d)} mm box, in a skirt ${mm(c)} mm clear of the wall (${pr.cite('fit')}): ${mm(undercut)} mm of undercut, ${mm(r3(Y))} mm on the diameter, shared by the box's wall (${mm(B.deflection)} mm) and the lid's skirt (${mm(L.deflection)} mm)${sized ? `, ${sizeSays}` : ''}`,
216
+ 'snap.undercut', { values: { bead, undercut, interference: r3(Y), box: B.deflection, lid: L.deflection } }));
217
+ for (const [q, name, m] of [[B, 'the box\'s wall', box], [L, 'the lid\'s skirt', lidMat]]) {
218
+ const ok = exact.get(q).strain <= permissible * (1 + 1e-9);
219
+ out.push(finding(ok ? 'pass' : 'fail', `${name} is ${ok ? '' : 'over its limit: '}${pc(q.strain)} hoop strain (${mm(q.deflection)} mm over ${mm(q.diameter)} mm) where ${m.name} may see ${pc(permissible)}: ${mm(DEFAULTS.snap_brief.value)} of its yield strain, ${cited(m)}${uses === 'often' ? `, and ${mm(DEFAULTS.snap_often.value)} of that since it is opened often` : ''}${ok ? '' : `. The most undercut the strain allows is ${mm(most.undercut)} mm: a smaller bead, a thinner ${q === B ? 'wall' : 'skirt'}, or a bigger box`}`,
220
+ 'snap.strain', { values: { strain: q.strain, permissible: n4(permissible), deflection: q.deflection, diameter: q.diameter }, refs: { part: q === B ? 'box' : 'lid', material: m.name } }));
221
+ }
222
+ for (const [q, name, m, endName] of [[B, 'the box\'s wall', box, 'floor'], [L, 'the lid\'s skirt', lidMat, 'top']]) {
223
+ if (q.closed == null) continue;
224
+ out.push(finding('info', `${name} meets its ${endName} ${mm(n2(q.closed))} mm from the joint, where a tube's wall bends over about 1/β = ${mm(q.decay)} mm: ${q.stiffer >= 1.01 ? `held round there, it is ${mm(q.stiffer)} times as stiff as the same tube open` : 'far enough off to make no difference to its stiffness'} (Hetényi's beam on an elastic foundation, the ${endName} taken as fully closed, the stiffest it can be)`,
225
+ 'snap.closed', { values: { closed: q.closed, decay: q.decay, stiffer: q.stiffer }, refs: { part: q === B ? 'box' : 'lid' } }));
226
+ const ok = exact.get(q).root <= permissible * (1 + 1e-9);
227
+ out.push(finding(ok ? 'pass' : 'fail', `${name} bends where it meets its ${endName}: ${pc(q.root)} strain at the root where ${m.name} may see ${pc(permissible)}${ok ? '' : `. Move the joint further from the ${endName} (the wall bends over about 1/β, ${mm(q.decay)} mm), or a smaller bead: the most undercut the strain allows is ${mm(most.undercut)} mm`}`,
228
+ 'snap.root', { values: { strain: q.root, permissible: n4(permissible), closed: q.closed }, refs: { part: q === B ? 'box' : 'lid', material: m.name } }));
229
+ }
230
+ // The groove is cut the bead's depth into the skirt: what is left behind it must print as a wall of at least one line
231
+ const line = pr.n('line'), left = r3(s - bead), thick = left >= line - 1e-9;
232
+ out.push(finding(thick ? 'pass' : 'fail', `the groove leaves ${mm(left)} mm of the ${mm(s)} mm skirt behind it${thick ? `, at least the ${pr.cite('line')} ${mm(line)} mm line` : `, under the ${pr.cite('line')} ${mm(line)} mm line, so it prints thin or not at all: a thicker skirt, or a smaller bead`}`,
233
+ 'snap.skirt', { values: { left, skirt: s, line } }));
234
+ if (undercut < least - 1e-9) out.push(finding('warn', `an undercut of ${mm(undercut)} mm is under fixings.snap_least, ${mm(least)} mm: the print's own error is that size, so the lid may not catch, or catch only in places`, 'snap.least', { values: { undercut, least } }));
235
+ out.push(finding('info', `${mm(n1(insertion))} N to push the lid on square and ${holds ? 'it holds for good (a square return face)' : `${mm(n1(removal))} N to pull it off square`}: a transverse force of ${mm(n1(P))} N (P = y d Es X, Bayer's annular snap joint, X ${mm(B.X)} for the wall and ${mm(L.X)} for the skirt) through the ${mm(lead)}° lead and ${mm(back)}° return faces at μ ${mm(mu)}. Pressed on at a tilt, a part of the bead at a time, it takes much less, as the guide says of a lid put on by hand`,
236
+ 'snap.forces', { values: { force: n1(P), insertion: n1(insertion), removal: Number.isFinite(removal) ? n1(removal) : null, friction: mu } }));
237
+ if (B.remote > 1 || L.remote > 1) out.push(finding('info', `the joint lies in from a free end (box ${mm(boxEnd)} mm of ${mm(B.far)}, lid ${mm(lidEnd)} mm of ${mm(L.far)}, where 1.8 √(d t) counts as remote), so it is stiffer by ${mm(B.remote)} and ${mm(L.remote)} times: the guide gives 3 at a remote joint, and the line between is an estimate`, 'snap.remote', { values: { box: B.remote, lid: L.remote } }));
238
+ if (push != null) { const ok = insertion <= push; out.push(finding(ok ? 'pass' : 'warn', `pushed with ${mm(push)} N, the lid goes on ${ok ? `square, ${mm(n1(insertion))} N` : `only at a tilt: square it takes ${mm(n1(insertion))} N. A shallower lead or a smaller bead lowers it`}`, 'snap.push', { values: { push, insertion: n1(insertion) } })); }
239
+ const margin = pull != null ? (holds ? Infinity : n2(removal / pull)) : null;
240
+ if (pull != null) out.push(finding(margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail', `pulled with ${mm(pull)} N, the lid stays on ${holds ? 'for good' : `${mm(margin)} times over (${mm(n1(removal))} N)`}${margin >= want ? '' : margin >= 1 ? `, under the ${mm(want)} times fixings.load_margin asks` : ': it comes off'}${margin >= want ? '' : `. The strain allows up to ${mm(most.undercut)} mm of undercut, which would hold ${mm(most.removal)} N`}`,
241
+ 'snap.hold', { values: { pull, removal: Number.isFinite(removal) ? n1(removal) : null, margin: Number.isFinite(margin) ? margin : null, want } }));
242
+ else out.push(finding('info', `give pull, the force the lid must stay on against, to have its hold checked`, 'snap.hold'));
243
+ // Printing: the box stands on its floor, so the bead's return face is an overhang; the lid is printed on its top, so
244
+ // the groove's face nearest the mouth, the return face's mate, is a ceiling at the same angle. The lead face and the
245
+ // skirt's lead-in lean the other way and always print
246
+ const prints = back <= overhang + 1e-9;
247
+ out.push(finding(prints ? 'pass' : 'fail', prints ? `the box printed standing on its floor and the lid on its top print with no support: the bead's ${mm(back)}° return face and the groove's mating face are within ${pr.cite('overhang')} ${mm(overhang)}°, and the ${mm(lead)}° lead face leans the way that always prints`
248
+ : `the ${mm(back)}° return face is past ${pr.cite('overhang')} ${mm(overhang)}°: under the box's bead and over the lid's groove it needs support. Give back ${mm(overhang)}° or less; a steeper face holds harder, so let the bead be taller instead`, 'snap.printable', { values: { back, overhang } }));
249
+ const groove = { inner: r3(dh / 2), outer: r3(dh / 2 + bead), depth: bead };
250
+ return { kind: 'annular snap', diameter: d, wall: t, skirt: s, clearance: c, bead, length, undercut, interference: r3(Y), lead, back, land, sized, uses, material: box.name, lidMaterial: lidMat.name, friction: mu,
251
+ permissible: n4(permissible), box: B, lid: L, force: n1(P), insertion: Number.isFinite(insertion) ? n1(insertion) : Infinity, removal: Number.isFinite(removal) ? n1(removal) : Infinity, holds, pull, margin, most, groove, rests, findings: out };
252
+ }
253
+
254
+ // The bead's outline in [radius, z] from its foot on the wall at z: up the return face, along the land, down the lead
255
+ // face, sunk into the wall by a little so it joins it
256
+ const beadOutline = (m, z, grow = 0) => {
257
+ const R = m.diameter / 2 + grow, h = m.bead, rise = h / tan(m.back), fall = h / tan(m.lead), sink = Math.min(m.wall / 2, 0.3);
258
+ const z0 = z - grow, top = z0 + rise + m.land + 2 * grow + fall;
259
+ return [[R - sink - grow, z0], [R, z0], [R + h, z0 + rise], [R + h, z0 + rise + m.land + 2 * grow], [R, top], [R - sink - grow, top]];
260
+ };
261
+ /**
262
+ * The bead to add to the box: a ring round the wall's outside, its foot (the bottom of the return face) at z = at.
263
+ * Union it with a box whose wall's outside is the model's diameter about the z axis.
264
+ * @param {object | AnnularSnap} p the joint's figures, as annularSnapModel takes them, or its model
265
+ * @param {object} [o] as annularSnapModel, and at: the bead's foot, mm up z (default 0); segments: faces round (default 96)
266
+ * @returns {object} a JSCAD geom3 with .model
267
+ */
268
+ export function annularBead(p, o = {}) {
269
+ const m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o), at = o.at ?? 0, n = o.segments ?? 96;
270
+ if (!isNum(at)) throw new Error(`annularBead: at is the bead's foot up z, in mm (got ${shown(o.at)})`);
271
+ return Object.assign(lathe(beadOutline(m, at), n), { model: m });
272
+ }
273
+ /**
274
+ * The groove to cut from the lid's skirt, in the same place as the bead it takes (at, as annularBead's): the bead's
275
+ * outline grown by the clearance all round, so the seated bead touches nothing, and with mouth, the skirt's mouth's z,
276
+ * a lead-in cone there at the lead angle, as wide as the bead, so the skirt's edge starts over it.
277
+ * @param {object | AnnularSnap} p the joint's figures or its model
278
+ * @param {object} [o] as annularSnapModel, and at: the bead's foot (default 0); mouth: the z of the skirt's open end,
279
+ * below at (default none: no lead-in); segments: faces round (default 96)
280
+ * @returns {object} a JSCAD geom3 to subtract, with .model
281
+ */
282
+ export function annularGroove(p, o = {}) {
283
+ const what = 'annularGroove', m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o), at = o.at ?? 0, n = o.segments ?? 96, c = m.clearance;
284
+ if (!isNum(at)) throw new Error(`${what}: at is the bead's foot up z, in mm (got ${shown(o.at)})`);
285
+ const ring = beadOutline(m, at, c);
286
+ if (o.mouth == null) return Object.assign(lathe(ring, n), { model: m });
287
+ if (!(isNum(o.mouth) && o.mouth < at - c - 1e-9)) throw new Error(`${what}: mouth is the z of the skirt's open end, below the groove's foot at ${mm(at - c)} mm (got ${shown(o.mouth)})`);
288
+ // The lead-in: from the groove's full radius at the mouth up to the skirt's inside, joined to the groove by a band at
289
+ // the skirt's inside so the two are one cutter
290
+ const R = m.diameter / 2 + c, h = m.bead, rise = h / tan(m.lead), z = o.mouth - 0.1, sink = Math.min(m.wall / 2, 0.3) + c;
291
+ const top = Math.min(o.mouth + rise, ring[1][1]);
292
+ return Object.assign(lathe([[R - sink, z], [R + h, z], [R + h, o.mouth], [R + h - (top - o.mouth) * tan(m.lead), top], ...(top < ring[1][1] ? [[R, top], [R, ring[1][1]]] : []), ...ring.slice(1, -1), [R - sink, ring.at(-1)[1]]], n), { model: m });
293
+ }