@rangefoundry/svg-drawings 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +22 -2
  3. package/dist/bullet/density.d.ts +65 -0
  4. package/dist/bullet/density.js +91 -0
  5. package/dist/bullet/figure.d.ts +34 -0
  6. package/dist/bullet/figure.js +50 -0
  7. package/dist/bullet/index.d.ts +4 -0
  8. package/dist/bullet/index.js +5 -0
  9. package/dist/bullet/outline.d.ts +144 -0
  10. package/dist/bullet/outline.js +683 -0
  11. package/dist/bullet/profile.d.ts +76 -0
  12. package/dist/bullet/profile.js +257 -0
  13. package/dist/cartridge/callouts.d.ts +18 -0
  14. package/dist/cartridge/callouts.js +153 -0
  15. package/dist/cartridge/detail.d.ts +34 -0
  16. package/dist/cartridge/detail.js +99 -0
  17. package/dist/cartridge/figure.d.ts +59 -0
  18. package/dist/cartridge/figure.js +113 -0
  19. package/dist/cartridge/figures.d.ts +47 -0
  20. package/dist/cartridge/figures.js +54 -0
  21. package/dist/cartridge/focus.d.ts +3 -0
  22. package/dist/cartridge/focus.js +7 -0
  23. package/dist/cartridge/index.d.ts +8 -0
  24. package/dist/cartridge/index.js +8 -0
  25. package/dist/cartridge/profile.d.ts +46 -0
  26. package/dist/cartridge/profile.js +630 -0
  27. package/dist/cartridge/regions.d.ts +28 -0
  28. package/dist/cartridge/regions.js +50 -0
  29. package/dist/core/advances.json +106 -0
  30. package/dist/core/annotate.d.ts +11 -0
  31. package/dist/core/annotate.js +715 -0
  32. package/dist/core/cache.d.ts +4 -0
  33. package/dist/core/cache.js +16 -0
  34. package/dist/core/face.d.ts +56 -0
  35. package/dist/core/face.js +54 -0
  36. package/dist/core/fillet.d.ts +7 -0
  37. package/dist/core/fillet.js +42 -0
  38. package/dist/core/geometry.d.ts +22 -0
  39. package/dist/core/geometry.js +136 -0
  40. package/dist/core/layout.d.ts +46 -0
  41. package/dist/core/layout.js +69 -0
  42. package/dist/core/placer.d.ts +60 -0
  43. package/dist/core/placer.js +291 -0
  44. package/dist/core/section.d.ts +32 -0
  45. package/dist/core/section.js +75 -0
  46. package/dist/core/text.d.ts +19 -0
  47. package/dist/core/text.js +38 -0
  48. package/dist/core/types.d.ts +185 -0
  49. package/dist/core/types.js +2 -0
  50. package/dist/core/units.d.ts +18 -0
  51. package/dist/core/units.js +26 -0
  52. package/dist/core/vector.d.ts +8 -0
  53. package/dist/core/vector.js +23 -0
  54. package/dist/index.d.ts +9 -0
  55. package/dist/index.js +10 -0
  56. package/dist/seating/chamber.d.ts +21 -0
  57. package/dist/seating/chamber.js +23 -0
  58. package/dist/seating/index.d.ts +3 -0
  59. package/dist/seating/index.js +4 -0
  60. package/dist/seating/preview.d.ts +12 -0
  61. package/dist/seating/preview.js +30 -0
  62. package/dist/seating/seating.d.ts +210 -0
  63. package/dist/seating/seating.js +284 -0
  64. package/dist/target/face.d.ts +68 -0
  65. package/dist/target/face.js +50 -0
  66. package/dist/target/index.d.ts +1 -0
  67. package/dist/target/index.js +2 -0
  68. package/package.json +64 -3
@@ -0,0 +1,630 @@
1
+ import { fillet } from '../core/fillet.js';
2
+ import { deg } from '../core/units.js';
3
+ /**
4
+ * CIP tables whose symbol meanings were checked against the geometry and
5
+ * that `cipProfile` draws; table VII is drawn by `shotshellProfile`.
6
+ */
7
+ export const drawnTables = new Set(['I', 'II', 'III', 'IV', 'V', 'VIII', 'IX', 'X']);
8
+ const baseSymbols = ['R1', 'R', 'P1', 'L3', 'H2'];
9
+ const mm = (x) => Number(x.toFixed(3));
10
+ // the callers run after `missing` found the base symbols, or after the check of the symbol itself
11
+ const stored = (v, ...symbols) => symbols.map((s) => v(s));
12
+ /**
13
+ * The value of a symbol on a side as drawn: with a value, of `variant` when given and stored,
14
+ * else without a variant.
15
+ */
16
+ export const storedValue = (values, side, symbol, variant) => {
17
+ const of = (want) => values.find((v) => v.side === side &&
18
+ v.symbol === symbol &&
19
+ (want === undefined ? !v.variant : v.variant === want) &&
20
+ v.value !== undefined);
21
+ return (variant === undefined ? undefined : of(variant)) ?? of(undefined);
22
+ };
23
+ /** A stored cone angle more than 1 degree off the angle the drawn lengths give. */
24
+ const angleOff = (angle, drawn) => angle !== undefined && Math.abs(drawn - angle) > 1;
25
+ /**
26
+ * Names a cartridge whose L3 lies over 0.3 mm past chamber L3 + h, or whose L6 is below its own
27
+ * L3: its front is closed or crimped (blanks, shot), so the cartridge side is not drawn.
28
+ */
29
+ export function closedFront(values) {
30
+ const [L3, chamberL3] = [
31
+ storedValue(values, 'cartridge', 'L3')?.value,
32
+ storedValue(values, 'chamber', 'L3')?.value,
33
+ ];
34
+ if (L3 === undefined)
35
+ return undefined;
36
+ const front = chamberL3 === undefined
37
+ ? undefined
38
+ : chamberL3 + (storedValue(values, 'chamber', 'h')?.value ?? 0);
39
+ if (front !== undefined && L3 > front + 0.3)
40
+ return {
41
+ code: 'closedFront',
42
+ symbols: ['L3', 'h'],
43
+ text: `Cartridge L3 ${L3} mm lies ${mm(L3 - front)} mm past chamber L3 + h ${mm(front)} mm: its front is closed or crimped, so the cartridge is not drawn.`,
44
+ };
45
+ const L6 = storedValue(values, 'cartridge', 'L6')?.value;
46
+ if (L6 !== undefined && L6 < L3)
47
+ return {
48
+ code: 'closedFront',
49
+ symbols: ['L3', 'L6'],
50
+ text: `Cartridge L6 ${L6} mm is below its L3 ${L3} mm: its front is closed or crimped, so the cartridge is not drawn.`,
51
+ };
52
+ return undefined;
53
+ }
54
+ /**
55
+ * Simplified half-section outline of one side of a CIP record: lengths draw, angles
56
+ * check, and each disagreement becomes a note. Values with a variant are ignored.
57
+ * The chamber recess ends at the chamber's own E, else its own R, else the cartridge R; it is
58
+ * never narrower than P1.
59
+ */
60
+ export function cipProfile(values, side, table) {
61
+ const find = (symbol, s = side) => storedValue(values, s, symbol);
62
+ const v = (symbol) => find(symbol)?.value;
63
+ const E = v('E');
64
+ const rim = side === 'chamber' ? (E ?? v('R') ?? find('R', 'cartridge')?.value) : v('R');
65
+ const missing = baseSymbols.filter((s) => (s === 'R' ? rim : v(s)) === undefined);
66
+ if (missing.length)
67
+ return { missing };
68
+ const R = rim;
69
+ const d = draft(side, find);
70
+ const groove = grooveDepth(d, R, table);
71
+ headProfile(d, R);
72
+ const zP1 = grooveAndBelt(d, R, groove, table);
73
+ const { points, marks } = d;
74
+ const [P1, L3] = stored(v, 'P1', 'L3');
75
+ points.push([P1 / 2, zP1]);
76
+ marks.diameter('P1', zP1, { toward: 1 });
77
+ const [P0, L0] = [v('P0'), v('L0')];
78
+ if (P0 !== undefined && L0 !== undefined && zP1 < L0 && L0 < (v('L1') ?? L3)) {
79
+ points.push([P0 / 2, L0]);
80
+ marks.diameter('P0', L0, { toward: 1 });
81
+ marks.length('L0', 0);
82
+ marks.edge(L0);
83
+ }
84
+ const shoulder = shoulderProfile(d, zP1);
85
+ neckProfile(d, shoulder);
86
+ if (side === 'chamber') {
87
+ const zG1 = chamberMouth(d);
88
+ if (zG1 !== undefined)
89
+ chamberThroat(d, zG1);
90
+ }
91
+ const { derivedE } = groove;
92
+ return {
93
+ points,
94
+ notes: d.notes,
95
+ annotation: marks.done(points),
96
+ ...(derivedE === undefined ? {} : { derivedE: mm(derivedE) }),
97
+ };
98
+ }
99
+ /** An empty outline of a side that reads its stored values with `find`. */
100
+ function draft(side, find) {
101
+ const notes = [];
102
+ return {
103
+ side,
104
+ find,
105
+ v: (symbol) => find(symbol)?.value,
106
+ points: [],
107
+ notes,
108
+ note: (code, symbols, text, at) => {
109
+ notes.push({ code, symbols, text, at });
110
+ },
111
+ marks: annotationBuilder(find),
112
+ name: side === 'chamber' ? 'Chamber' : 'Cartridge',
113
+ };
114
+ }
115
+ /** The stored e, else outside table III (where delta is the belt cone) one cone from E1 at R to P1 at E (grooveDerivedE), drawn as 0 when negative. */
116
+ function grooveDepth({ side, v }, R, table) {
117
+ const [P1, E, E1, storedE, delta] = [v('P1'), v('E'), v('E1'), v('e'), v('delta')];
118
+ const validDelta = delta !== undefined && delta > 0 && delta < 90;
119
+ const derivedE = side === 'cartridge' &&
120
+ storedE === undefined &&
121
+ table !== 'III' &&
122
+ validDelta &&
123
+ E !== undefined &&
124
+ E1 !== undefined
125
+ ? E - R - (P1 - E1) / 2 / Math.tan(delta * deg)
126
+ : undefined;
127
+ const e = storedE ?? (derivedE === undefined ? undefined : Math.max(0, derivedE));
128
+ return { e, derivedE };
129
+ }
130
+ /** The head from the axis: the rim corner, the head face and the rim (cartridge) or recess (chamber) to R. */
131
+ function headProfile(d, R) {
132
+ const { side, v, marks, note, points } = d;
133
+ const [R1, P1] = stored(v, 'R1', 'P1');
134
+ const E = v('E');
135
+ if (side === 'chamber' && E === undefined && v('R') === undefined)
136
+ note('cartridgeR', ['R'], `The chamber has no E or R: its recess is drawn to the cartridge R ${R} mm.`, [Math.max(R1, v('R3') ?? 0, P1) / 2, R]);
137
+ const R3 = v('R3');
138
+ // a table III chamber recess takes the belt; a case body cannot pass a recess narrower than P1
139
+ const head = side === 'chamber' ? Math.max(R1, R3 ?? 0, P1) : R1;
140
+ if (side === 'chamber' && Math.max(R1, R3 ?? 0) < P1)
141
+ note('headBelowP1', ['R1', 'P1'], `Chamber R1 ${R1} mm is below P1 ${P1} mm: the head is drawn at P1.`, [head / 2, 0]);
142
+ points.push([0, 0], ...rimCorner(d, head, R), [head / 2, R]);
143
+ marks.diameter('R1', 0, { behindHeadFace: true });
144
+ if (side === 'chamber') {
145
+ marks.diameter('R3', 0, { behindHeadFace: true });
146
+ // the recess depth: the chamber's own E, else its own R; the cartridge R is not dimensioned
147
+ marks.length(E === undefined ? 'R' : 'E', 0, undefined, { behindHeadFace: true });
148
+ }
149
+ else
150
+ marks.length('R', 0, undefined, { behindHeadFace: true });
151
+ marks.edge(R);
152
+ }
153
+ /** The groove's points and marks, the belt where there is one, and the notes on e and delta. */
154
+ function drawGroove({ v, marks, note, points }, c) {
155
+ const { R, e, derivedE, E, E1, R3, delta, validDelta, belt, zBelt } = c;
156
+ const P1 = v('P1');
157
+ points.push([E1 / 2, R], [E1 / 2, R + e]);
158
+ marks.diameter('E1', 0, { behindHeadFace: true });
159
+ marks.length('E', 0, undefined, { behindHeadFace: true });
160
+ // a derived e is shown in the table and the description only
161
+ if (v('e') !== undefined)
162
+ marks.length('e', R, undefined, { behindHeadFace: true });
163
+ marks.edge(R + e, E);
164
+ const cone = belt ? [R3 / 2, zBelt] : [P1 / 2, E];
165
+ if (validDelta)
166
+ marks.angle('delta', [E1 / 2, R + e], [[E1 / 2, R + e + (cone[1] - R - e)], cone]);
167
+ if (derivedE !== undefined)
168
+ note('grooveDerivedE', ['e', 'delta'], `Cartridge e is not published: delta ${delta} degrees from E1 at R to P1 at E gives e ${mm(derivedE)} mm${derivedE < 0 ? ', drawn as 0' : ''}.`, [E1 / 2, R + e]);
169
+ if (belt) {
170
+ points.push([R3 / 2, zBelt], [R3 / 2, E]);
171
+ marks.diameter('R3', 0, { behindHeadFace: true });
172
+ marks.edge(zBelt);
173
+ }
174
+ else if (delta !== undefined) {
175
+ const angle = Math.atan2((P1 - E1) / 2, E - R - e) / deg;
176
+ if (Math.abs(angle - delta) > 1)
177
+ note('grooveAngle', ['delta', 'E'], `Cartridge delta ${delta} degrees differs from the ${mm(angle)} degrees of the groove from E1 at R + e to P1 at E; the lengths are drawn.`, [(E1 + P1) / 4, (R + e + E) / 2]);
178
+ }
179
+ }
180
+ /** From E1 at R + e to P1 at E, through the belt from R3 to E where table III gives one; returns the station of P1, E after a groove, else R. */
181
+ function grooveAndBelt(d, R, { e, derivedE }, table) {
182
+ const { side, v, note } = d;
183
+ const R1 = v('R1');
184
+ const [E, E1, delta, R3] = [v('E'), v('E1'), v('delta'), v('R3')];
185
+ const validDelta = delta !== undefined && delta > 0 && delta < 90;
186
+ const groove = side === 'cartridge' && E !== undefined && E1 !== undefined && e !== undefined && R + e < E;
187
+ // the belt front is the only length drawn from an angle: delta, from the axis, up to R3
188
+ const zBelt = groove && R3 !== undefined && R3 > E1 && validDelta
189
+ ? R + e + (R3 - E1) / 2 / Math.tan(delta * deg)
190
+ : undefined;
191
+ const belt = zBelt !== undefined && zBelt <= E;
192
+ // in table III, E ends the belt, so without the belt the groove has no end
193
+ if (side === 'cartridge' && table === 'III' && !belt)
194
+ note('beltSkipped', ['E1', 'e', 'E', 'R3', 'delta'], `Cartridge ${['E1', 'e', 'E', 'R3', 'delta'].map((s) => `${s} ${v(s) ?? 'missing'}`).join(', ')} (mm, delta in degrees) give no belt ending by E: the outline steps to P1 at R.`, [R1 / 2, R]);
195
+ if (!(groove && (table !== 'III' || belt)))
196
+ return R;
197
+ drawGroove(d, { R, e, derivedE, E, E1, R3, delta, validDelta, belt, zBelt });
198
+ return E;
199
+ }
200
+ /** One shoulder corner, r1 at P2 or r2 at H1: its fillet arc where one fits, else sharp. */
201
+ function shoulderCorner({ v, marks, note, points, name }, symbol, corner, next, [L1, L2]) {
202
+ const r = v(symbol);
203
+ const prev = points.at(-1);
204
+ const arc = r === undefined || !prev ? null : fillet(prev, corner, next, r);
205
+ const [arcStart, arcEnd] = [arc?.[0], arc?.at(-1)];
206
+ // P2 is dimensioned before the r1 arc, H1 after the r2 arc, on the straight lines
207
+ if (symbol === 'r1')
208
+ marks.diameter('P2', arcStart ? arcStart[1] : L1, { toward: -1 });
209
+ else
210
+ marks.diameter('H1', arcEnd ? arcEnd[1] : L2, { toward: 1 });
211
+ if (arc) {
212
+ points.push(...arc);
213
+ marks.radius(symbol, corner);
214
+ return;
215
+ }
216
+ if (r !== undefined)
217
+ note('filletSkipped', [symbol], `${name} ${symbol} ${r} mm does not fit the corner at ${symbol === 'r1' ? 'P2 at L1' : 'H1 at L2'}: the corner is drawn sharp.`, corner);
218
+ points.push(corner);
219
+ }
220
+ /** The drawn shoulder: its lengths, the cone angle, the corners with their fillets. */
221
+ function drawShoulder(d, [P2, L1, L2, H1]) {
222
+ const { v, marks, note, name } = d;
223
+ const [L3, H2] = stored(v, 'L3', 'H2');
224
+ marks.length('L1', 0);
225
+ marks.length('L2', 0);
226
+ marks.length('S', 0, undefined, { far: true });
227
+ marks.edge(L1, L2);
228
+ // where the cone through P2 at L1 and H1 at L2 meets the axis
229
+ if (H1 < P2) {
230
+ const vertex = L1 + ((L2 - L1) * P2) / (P2 - H1);
231
+ marks.angle('alpha', [0, vertex], [
232
+ [P2 / 2, L1],
233
+ [-P2 / 2, L1],
234
+ ]);
235
+ }
236
+ const alpha = v('alpha');
237
+ const cone = (2 * Math.atan2((P2 - H1) / 2, L2 - L1)) / deg;
238
+ if (angleOff(alpha, cone))
239
+ note('shoulderAngle', ['alpha', 'L1', 'L2'], `${name} alpha ${alpha} degrees differs from the ${mm(cone)} degrees of the shoulder from P2 at L1 to H1 at L2; the lengths are drawn.`, [(P2 + H1) / 4, (L1 + L2) / 2]);
240
+ const corners = [
241
+ ['r1', [P2 / 2, L1], [H1 / 2, L2]],
242
+ ['r2', [H1 / 2, L2], [H2 / 2, L3]],
243
+ ];
244
+ // r2 starts where the r1 arc leaves the shoulder, so the two never overlap
245
+ for (const [symbol, corner, next] of corners)
246
+ shoulderCorner(d, symbol, corner, next, [L1, L2]);
247
+ }
248
+ /** The note on a shoulder with only some of P2, L1, L2 and H1 stored. */
249
+ function noteShoulderPartial({ v, note, name }, zP1) {
250
+ const [P1, L3, H2] = stored(v, 'P1', 'L3', 'H2');
251
+ const shoulderSet = ['P2', 'L1', 'L2', 'H1'];
252
+ const shoulderStored = shoulderSet.filter((s) => v(s) !== undefined);
253
+ if (!shoulderStored.length || shoulderStored.length >= 4)
254
+ return;
255
+ const fillets = ['r1', 'r2'].filter((s) => v(s) !== undefined);
256
+ note('shoulderPartial', shoulderSet, `${name} ${shoulderStored.map((s) => `${s} ${v(s)}`).join(', ')} mm without ${shoulderSet.filter((s) => v(s) === undefined).join(', ')}: no shoulder is drawn, the wall runs straight from P1 to H2${fillets.length ? `, ${fillets.join(' and ')} not drawn` : ''}.`, [(P1 + H2) / 4, (zP1 + L3) / 2]);
257
+ }
258
+ /** From P2 at L1 to H1 at L2 with its fillets r1 and r2, where all four are stored and in order; whether it is drawn. */
259
+ function shoulderProfile(d, zP1) {
260
+ const { v, note, name } = d;
261
+ const [P1, L3, H2] = stored(v, 'P1', 'L3', 'H2');
262
+ const [P2, L1, L2, H1] = [v('P2'), v('L1'), v('L2'), v('H1')];
263
+ noteShoulderPartial(d, zP1);
264
+ if (P2 === undefined || L1 === undefined || L2 === undefined || H1 === undefined)
265
+ return false;
266
+ if (!(zP1 < L1 && L1 < L2 && L2 <= L3 && H1 <= P2)) {
267
+ note('shoulderOrder', ['L1', 'L2', 'L3', 'P2', 'H1'], `${name} L1 ${L1}, L2 ${L2} and L3 ${L3} mm past the P1 station ${zP1} mm, or H1 ${H1} and P2 ${P2} mm, are out of order: no shoulder is drawn.`, [(P1 + H2) / 4, (zP1 + L3) / 2]);
268
+ return false;
269
+ }
270
+ drawShoulder(d, [P2, L1, L2, H1]);
271
+ return true;
272
+ }
273
+ /** The neck to H2 at L3; on the cartridge L6, G1 past the mouth and the neck length L3 - L2. */
274
+ function neckProfile(d, shoulder) {
275
+ const { side, v, marks, points } = d;
276
+ const [L3, H2] = stored(v, 'L3', 'H2');
277
+ const L2 = v('L2');
278
+ points.push([H2 / 2, L3]);
279
+ marks.diameter('H2', L3, { toward: -1 });
280
+ marks.length('L3', 0);
281
+ if (side === 'cartridge') {
282
+ marks.length('L6', 0);
283
+ marks.diameter('G1', L3, { front: true });
284
+ // L2 = L3: a shoulder with no neck
285
+ if (shoulder && L3 - L2 > 1e-6)
286
+ marks.chain('L3−L2', L3 - L2, L2, L3);
287
+ }
288
+ }
289
+ /** The mouth cone's length from its included angle alpha1; 180 degrees is a step; none without an angle. */
290
+ function mouthConeLength(alpha1, H2, G1) {
291
+ if (alpha1 === undefined || !(alpha1 > 0))
292
+ return;
293
+ return alpha1 >= 180 ? 0 : Math.max(0, (H2 - G1) / 2 / Math.tan((alpha1 / 2) * deg));
294
+ }
295
+ /** From H2 at L3 to G1, by h or the alpha1 cone; returns the station of G1, none without G1. */
296
+ function chamberMouth(d) {
297
+ const { v, marks, note, points } = d;
298
+ const [L3, H2] = stored(v, 'L3', 'H2');
299
+ const [G1, h, alpha1] = [v('G1'), v('h'), v('alpha1')];
300
+ const throat = ['G', 'F', 'h', 's'].filter((symbol) => v(symbol) !== undefined);
301
+ if (G1 === undefined) {
302
+ if (throat.length)
303
+ note('noG1', ['G1', ...throat], `Chamber has no G1: the outline ends at H2 at L3, ${throat.map((symbol) => `${symbol} ${v(symbol)}`).join(', ')} mm not drawn.`, [H2 / 2, L3]);
304
+ return;
305
+ }
306
+ const hCone = mouthConeLength(alpha1, H2, G1);
307
+ if (h !== undefined && hCone !== undefined && Math.abs(h - hCone) > 0.05)
308
+ note('mouthCone', ['h', 'alpha1'], `Chamber h ${h} mm differs from the ${mm(hCone)} mm the alpha1 cone of ${alpha1} degrees gives; h is drawn.`, [(H2 + G1) / 4, L3 + h / 2]);
309
+ if (h === undefined && hCone === undefined && H2 !== G1)
310
+ note('mouthStep', ['h', 'alpha1'], `Chamber ${alpha1 === undefined ? 'has no h or alpha1' : `has no h and alpha1 ${alpha1} is not a cone angle`}: the mouth is drawn as a step from H2 ${H2} to G1 ${G1} mm at L3.`, [(H2 + G1) / 4, L3]);
311
+ const zG1 = L3 + (h ?? hCone ?? 0);
312
+ points.push([G1 / 2, zG1]);
313
+ marks.edge(L3, zG1);
314
+ marks.length('h', L3);
315
+ if (alpha1 !== undefined && zG1 > L3 && H2 > G1)
316
+ marks.angle('alpha1', [0, L3 + ((zG1 - L3) * H2) / (H2 - G1)], [
317
+ [H2 / 2, L3],
318
+ [-H2 / 2, L3],
319
+ ]);
320
+ return zG1;
321
+ }
322
+ /** From G1 at `zG1`: the leade to F at L3 + G and a bore stub, or a G1 stub without G or F. */
323
+ function chamberThroat(d, zG1) {
324
+ const { v, find, marks, note, points } = d;
325
+ const [L3, G1] = stored(v, 'L3', 'G1');
326
+ const [G, F] = [v('G'), v('F')];
327
+ if (G === undefined || F === undefined) {
328
+ points.push([G1 / 2, zG1 + 0.1 * L3]);
329
+ marks.diameter('G1', zG1, { toward: 1 });
330
+ marks.convention('g1Stub', G1 / 2, zG1, zG1 + 0.1 * L3);
331
+ return;
332
+ }
333
+ // h, s and G share chamber L3 as datum; the stored L3+G mostly adds G to the cartridge L3
334
+ const [sum, cartridgeL3] = [find('L3+G', 'cartridge')?.value, find('L3', 'cartridge')?.value];
335
+ const off = (base) => base === undefined || Math.abs(sum - base - G) > 0.015;
336
+ if (sum !== undefined && off(L3) && off(cartridgeL3))
337
+ note('throatDatum', ['L3+G', 'L3', 'G'], `Cartridge L3+G ${sum} mm is ${cartridgeL3 === undefined ? 'not' : 'neither'} chamber L3 + G ${mm(L3 + G)} mm, where the leade ends${cartridgeL3 === undefined ? '' : `, nor cartridge L3 + G ${mm(cartridgeL3 + G)} mm`}.`, [F / 2, L3 + G]);
338
+ const zEnd = Math.max(L3 + G, zG1);
339
+ marks.length('G', L3);
340
+ const free = leadeProfile(d, zG1, zEnd);
341
+ marks.diameter('G1', (zG1 + free) / 2, { toward: 1 });
342
+ points.push([F / 2, zEnd], [F / 2, zEnd + 0.1 * L3]);
343
+ marks.diameter('F', zEnd);
344
+ marks.edge(zEnd);
345
+ marks.convention('boreStub', F / 2, zEnd, zEnd + 0.1 * L3);
346
+ }
347
+ /** From G1 to F at `zEnd`, at the angle i from s or back from L3 + G, a step without a leade; returns where the free bore at G1 ends. */
348
+ function leadeProfile(d, zG1, zEnd) {
349
+ const { v, marks, note, points } = d;
350
+ const [L3, G1, G, F] = stored(v, 'L3', 'G1', 'G', 'F');
351
+ const [i, s] = [v('i'), v('s')];
352
+ if (G1 <= F) {
353
+ note('noLeade', ['G1', 'F'], `Chamber G1 ${G1} mm is not above F ${F} mm: no leade, a step at L3 + G.`, [G1 / 2, zEnd]);
354
+ points.push([G1 / 2, zEnd]);
355
+ return zEnd;
356
+ }
357
+ if (!(i !== undefined && i > 0 && i < 90)) {
358
+ note('iInvalid', ['i'], `Chamber i ${i ?? 'missing'} is not an angle between 0 and 90 degrees: the leade is drawn straight from G1 to F.`, [(G1 + F) / 4, (zG1 + zEnd) / 2]);
359
+ return zG1;
360
+ }
361
+ const leade = (G1 - F) / 2 / Math.tan(i * deg);
362
+ const start = s === undefined ? L3 + G - leade : L3 + s;
363
+ const drawn = Math.min(zEnd, Math.max(zG1, start));
364
+ if (s !== undefined && Math.abs(G - s - leade) > 0.1)
365
+ note('leadeAngle', ['s', 'i'], `Chamber s ${s} mm and i ${mm(i)} degrees disagree: G - s is ${mm(G - s)} mm, the leade at i ${mm(leade)} mm; the leade is drawn from ${mm(drawn - L3)} mm past L3.`, [G1 / 2, drawn]);
366
+ // within 0.1 mm the start is the rounding of the stored values and is clamped silently
367
+ if (start < zG1 - 0.1)
368
+ note('leadeStartBelowH', s === undefined ? ['G', 'i', 'h'] : ['s', 'h'], `The chamber leade starts ${mm(start - L3)} mm past L3 (${s === undefined ? 'from G and i' : 's'}), before h ${mm(zG1 - L3)} mm; it is drawn from L3 + h.`, [G1 / 2, drawn]);
369
+ // only s can pass G: a start from i lies before L3 + G
370
+ if (start > zEnd + 0.1)
371
+ note('leadeStartPastG', ['s', 'G'], `Chamber s ${s} mm lies beyond the leade end at L3 + ${mm(zEnd - L3)} mm (G ${G} mm): the leade is drawn as a step there.`, [G1 / 2, drawn]);
372
+ points.push([G1 / 2, drawn]);
373
+ if (s !== undefined)
374
+ marks.length('s', L3);
375
+ marks.edge(drawn);
376
+ if (drawn < zEnd)
377
+ marks.angle('i', [G1 / 2, drawn], [
378
+ [G1 / 2, zEnd],
379
+ [F / 2, zEnd],
380
+ ]);
381
+ return drawn;
382
+ }
383
+ /** From the head face to the rim side at r: a chamfer where f and beta are stored (beta from the head face line, f along the axis, so the face ends f / tan(beta) inside the rim), else a round of r0 where stored, else the sharp corner. */
384
+ function rimCorner({ side, v, marks, note }, head, R) {
385
+ const corner = [head / 2, 0];
386
+ if (side !== 'cartridge')
387
+ return [corner];
388
+ const [f, beta, r0] = [v('f'), v('beta'), v('r0')];
389
+ let chamfer = false;
390
+ if (f !== undefined && beta !== undefined) {
391
+ const inset = f / Math.tan(beta * deg);
392
+ if (beta > 0 && beta < 90 && f > 0 && f < R && inset < head / 2)
393
+ chamfer = true;
394
+ else
395
+ note('chamferSkipped', ['f', 'beta'], `Cartridge f ${f} mm and beta ${beta} degrees give no chamfer inside the rim (R ${R} mm): the rim corner is drawn sharp.`, corner);
396
+ if (chamfer) {
397
+ const foot = [head / 2 - inset, 0];
398
+ const top = [head / 2, f];
399
+ marks.angle('beta', foot, [corner, top]);
400
+ marks.length('f', 0, undefined, { behindHeadFace: true });
401
+ if (r0 !== undefined)
402
+ note('filletSkipped', ['r0'], `Cartridge r0 ${r0} mm is not drawn beside the chamfer: no sheet shows which corner it rounds.`, corner);
403
+ return [foot, top];
404
+ }
405
+ }
406
+ if (r0 === undefined)
407
+ return [corner];
408
+ const arc = fillet([0, 0], corner, [head / 2, R], r0);
409
+ if (!arc) {
410
+ note('filletSkipped', ['r0'], `Cartridge r0 ${r0} mm does not fit the rim corner at the head face: the corner is drawn sharp.`, corner);
411
+ return [corner];
412
+ }
413
+ marks.radius('r0', corner);
414
+ return arc;
415
+ }
416
+ /** Collects the annotation of one side; `find` gives the stored value of a symbol. */
417
+ function annotationBuilder(find) {
418
+ const dimensions = [];
419
+ const angles = [];
420
+ const radii = [];
421
+ const stations = [];
422
+ const conventions = [];
423
+ const value = (symbol) => {
424
+ const stored = find(symbol);
425
+ return stored === undefined ? undefined : { stored, value: stored.value };
426
+ };
427
+ return {
428
+ /** A stored length from `from`, to `from` plus its value unless `to` is given. */
429
+ length(symbol, from, to, extra = {}) {
430
+ const v = value(symbol);
431
+ if (v)
432
+ dimensions.push({
433
+ kind: from === 0 ? 'length' : 'chain',
434
+ symbol,
435
+ ...v,
436
+ from,
437
+ to: to ?? from + v.value,
438
+ ...extra,
439
+ });
440
+ },
441
+ chain(symbol, derived, from, to) {
442
+ dimensions.push({
443
+ kind: 'chain',
444
+ symbol,
445
+ value: Number(derived.toFixed(3)),
446
+ derived: true,
447
+ from,
448
+ to,
449
+ });
450
+ },
451
+ diameter(symbol, z, extra = {}) {
452
+ const v = value(symbol);
453
+ if (v)
454
+ dimensions.push({
455
+ kind: 'diameter',
456
+ symbol,
457
+ ...v,
458
+ from: z,
459
+ to: z,
460
+ radius: v.value / 2,
461
+ ...extra,
462
+ });
463
+ },
464
+ angle(symbol, vertex, flanks) {
465
+ const v = value(symbol);
466
+ if (v)
467
+ angles.push({ kind: 'angle', symbol, ...v, vertex, flanks });
468
+ },
469
+ radius(symbol, corner) {
470
+ const v = value(symbol);
471
+ if (v) {
472
+ radii.push({ kind: 'radius', symbol, ...v, corner });
473
+ stations.push(corner[1]);
474
+ }
475
+ },
476
+ edge(...z) {
477
+ stations.push(...z);
478
+ },
479
+ convention(kind, r, from, to) {
480
+ conventions.push({ kind, r, from, to });
481
+ },
482
+ /** The annotation, with the edges at the stations where the outline turns or steps. */
483
+ done(points) {
484
+ return {
485
+ dimensions,
486
+ angles,
487
+ radii,
488
+ edges: edgeStations(points, stations, radii),
489
+ conventions,
490
+ };
491
+ },
492
+ };
493
+ }
494
+ /** The stations past the head where the outline turns or steps, or a radius rounds a corner, rising. */
495
+ function edgeStations(points, stations, radii) {
496
+ const corners = new Set(radii.map((c) => c.corner[1]));
497
+ return [...new Set(stations)]
498
+ .filter((z) => z > 0 && (corners.has(z) || turns(points, z)))
499
+ .sort((a, b) => a - b);
500
+ }
501
+ /** Whether the outline changes direction or steps at the station z. */
502
+ function turns(points, z) {
503
+ const at = points.flatMap((p, k) => (Math.abs(p[1] - z) < 1e-9 ? [{ k, p }] : []));
504
+ const [first, last] = [at[0], at[at.length - 1]];
505
+ if (!first || !last)
506
+ return false;
507
+ // the directions into and out of the station, skipping repeated points
508
+ const before = points.slice(0, first.k).findLast(([r, pz]) => r !== first.p[0] || pz !== z);
509
+ const after = points.slice(last.k + 1).find(([r, pz]) => r !== last.p[0] || pz !== z);
510
+ if (!before || !after)
511
+ return false;
512
+ if (first.p[0] !== last.p[0])
513
+ return true;
514
+ const [r, pz] = first.p;
515
+ const a = Math.atan2(r - before[0], pz - before[1]);
516
+ const b = Math.atan2(after[0] - r, after[1] - pz);
517
+ return Math.abs(a - b) > 1e-6;
518
+ }
519
+ /** Variants of the cartridge l of a table VII record, or [undefined] when l has none. */
520
+ export function shotshellVariants(values) {
521
+ const variants = values.flatMap((v) => v.side === 'cartridge' && v.symbol === 'l' && v.variant ? [v.variant] : []);
522
+ return variants.length ? [...new Set(variants)] : [undefined];
523
+ }
524
+ /**
525
+ * Half section of one side of a CIP table VII record (shotshell): rim g to t, then the body from d
526
+ * at t to h at l (chamber G, T, D, H, L); with l1 and l2 a cone from d at l1 to d2 at l2 (chamber
527
+ * D1 to B). The chamber goes on with the forcing cone from H at L to the bore B at the included
528
+ * angle alpha1, a max limit, so the shortest cone. l and L take the value of the variant, the
529
+ * other symbols their value without one. No head height or crimp: no value gives them.
530
+ */
531
+ export function shotshellProfile(values, side, variant) {
532
+ const chamber = side === 'chamber';
533
+ const names = chamber ? shotshellNames.chamber : shotshellNames.cartridge;
534
+ const [gS, tS, dS, hS, lS] = names;
535
+ // only the case and chamber lengths are published per variant
536
+ const outline = draft(side, (symbol) => storedValue(values, side, symbol, symbol === lS ? variant : undefined));
537
+ const { v, points, marks } = outline;
538
+ const missing = [gS, tS, dS, hS, lS, ...(chamber ? ['B'] : [])].filter((s) => v(s) === undefined);
539
+ if (missing.length)
540
+ return { missing };
541
+ const [g, t, d, h, l] = stored(v, gS, tS, dS, hS, lS);
542
+ points.push([0, 0], [g / 2, 0], [g / 2, t], [d / 2, t]);
543
+ marks.diameter(gS, 0, { behindHeadFace: true });
544
+ marks.diameter(dS, 0, { behindHeadFace: true });
545
+ marks.length(tS, 0, undefined, { behindHeadFace: true });
546
+ marks.length(lS, 0);
547
+ marks.diameter(hS, l, { toward: -1 });
548
+ marks.edge(t);
549
+ const drawCone = shotshellCone(outline, names);
550
+ points.push([h / 2, l]);
551
+ if (chamber)
552
+ forcingCone(outline, names, drawCone);
553
+ return { points, notes: outline.notes, annotation: marks.done(points) };
554
+ }
555
+ /** In the order rim, rim length, body start, body end, length, cone start, cone end, cone start length, cone end length, cone angle. */
556
+ const shotshellNames = {
557
+ chamber: ['G', 'T', 'D', 'H', 'L', 'D1', 'B', 'L1', 'L2', 'alpha1'],
558
+ cartridge: ['g', 't', 'd', 'h', 'l', 'd', 'd2', 'l1', 'l2', 'alpha'],
559
+ };
560
+ /** From the start diameter at l1 to the end diameter at l2, where both are stored and in order; whether it is drawn. */
561
+ function shotshellCone(o, names) {
562
+ const { side, v, points, marks, note, name } = o;
563
+ const chamber = side === 'chamber';
564
+ const [, tS, dS, hS, lS, startS, endS, l1S, l2S, angleS] = names;
565
+ const [t, d, h, l] = stored(v, tS, dS, hS, lS);
566
+ const [start, end, l1, l2, angle] = [v(startS), v(endS), v(l1S), v(l2S), v(angleS)];
567
+ // the cone set without B, which every chamber stores for the bore
568
+ const set = [chamber ? startS : endS, l1S, l2S];
569
+ const cone = set.filter((s) => v(s) !== undefined);
570
+ const drawCone = start !== undefined &&
571
+ end !== undefined &&
572
+ l1 !== undefined &&
573
+ l2 !== undefined &&
574
+ t < l1 &&
575
+ l1 < l2 &&
576
+ l2 < l;
577
+ if (drawCone) {
578
+ points.push([start / 2, l1], [end / 2, l2]);
579
+ marks.length(l1S, 0);
580
+ marks.length(l2S, 0);
581
+ marks.diameter(chamber ? startS : endS, chamber ? l1 : l2, { toward: chamber ? -1 : 1 });
582
+ marks.edge(l1, l2);
583
+ if (start > end)
584
+ marks.angle(angleS, [0, l1 + ((l2 - l1) * start) / (start - end)], [
585
+ [start / 2, l1],
586
+ [-start / 2, l1],
587
+ ]);
588
+ const drawn = (2 * Math.atan2((start - end) / 2, l2 - l1)) / deg;
589
+ if (angleOff(angle, drawn))
590
+ note('shoulderAngle', [angleS, l1S, l2S], `${name} ${angleS} ${angle} degrees differs from the ${mm(drawn)} degrees of the cone from ${startS} at ${l1S} to ${endS} at ${l2S}; the lengths are drawn.`, [(start + end) / 4, (l1 + l2) / 2]);
591
+ }
592
+ else if (cone.length)
593
+ note('shoulderPartial', set, `${name} ${cone.map((s) => `${s} ${v(s)}`).join(', ')} mm are incomplete or out of order: no cone is drawn, the body runs straight from ${dS} to ${hS}.`, [(d + h) / 4, (t + l) / 2]);
594
+ return drawCone;
595
+ }
596
+ /** The chamber forcing cone from H at L to the bore B, and a bore stub. */
597
+ function forcingCone(o, names, drawCone) {
598
+ const { v, points, marks, note } = o;
599
+ const [, , , hS, lS, , , , , angleS] = names;
600
+ const [h, l] = stored(v, hS, lS);
601
+ const angle = v(angleS);
602
+ const B = v('B');
603
+ // alpha1 is the included angle of the forcing cone; 180 degrees is a step
604
+ const valid = angle !== undefined && angle > 0 && angle <= 180;
605
+ if (h > B && !valid)
606
+ note('mouthStep', ['alpha1'], `Chamber alpha1 ${angle ?? 'missing'} is not a cone angle: the forcing cone is drawn as a step from H ${h} to B ${B} mm at L.`, [(h + B) / 4, l]);
607
+ const zB = l + (h > B && valid && angle < 180 ? (h - B) / 2 / Math.tan((angle / 2) * deg) : 0);
608
+ // H = B (9 C.F. Mori): the bore goes on from H at L
609
+ if (B !== h) {
610
+ points.push([B / 2, zB]);
611
+ marks.diameter('B', zB);
612
+ marks.edge(l, zB);
613
+ if (!drawCone && zB > l)
614
+ marks.angle(angleS, [0, l + ((zB - l) * h) / (h - B)], [
615
+ [h / 2, l],
616
+ [-h / 2, l],
617
+ ]);
618
+ }
619
+ points.push([B / 2, zB + 0.1 * l]);
620
+ marks.convention('boreStub', B / 2, zB, zB + 0.1 * l);
621
+ }
622
+ /** Symbol, stored value, then tolerance (signed) or limit, as the description gives them. */
623
+ export function valueParts(value) {
624
+ const t = value.tolerance;
625
+ const tolerance = [t?.lower, t?.upper === undefined ? undefined : `+${t.upper}`]
626
+ .filter((x) => x !== undefined)
627
+ .join(' ');
628
+ return [value.symbol, String(value.value), tolerance, value.limit ?? ''].filter((x) => x);
629
+ }
630
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1,28 @@
1
+ import type { SpecValue } from '../core/types.ts';
2
+ import { type LengthUnit } from '../core/units.ts';
3
+ /** The regions of the case in which chamber and cartridge dimensions are compared. */
4
+ export type RegionName = 'head' | 'body' | 'shoulder' | 'neck';
5
+ /** A region and, per symbol both sides publish, the chamber minimum minus the cartridge maximum in mm. */
6
+ export interface Region {
7
+ name: RegionName;
8
+ values: {
9
+ symbol: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ /** The symbols compared in each region: the stored values whose difference `regions` gives. */
14
+ export declare const regionSymbols: Record<RegionName, string[]>;
15
+ /** Caption text naming a region difference: the chamber minimum less the cartridge maximum, signed. */
16
+ export declare const differenceWording = "nominal minimum difference of published dimensions";
17
+ /** The wording that names a negative region difference (chamber minimum below cartridge maximum). */
18
+ export declare const conflictWording = "data conflict between published cartridge maximum and chamber minimum (check source)";
19
+ /**
20
+ * The regions of a record with their differences, from stored values only: head R1, R3 and R,
21
+ * body P1, shoulder P2 and H1, neck H2. A chamber E is the recess depth, so the chamber R is
22
+ * compared only where the chamber stores no E. None behind a closed front.
23
+ */
24
+ export declare function regions(values: SpecValue[]): Region[];
25
+ /** A difference with its sign; a negative one is a conflict. */
26
+ export declare const signedLengthText: (value: number, unit?: LengthUnit) => string;
27
+ /** The callout text of a region, placed at it: "P2 +0.03, H1 +0.07"; a conflict marked. */
28
+ export declare const regionText: ({ values }: Region, unit?: LengthUnit) => string;