@rangefoundry/svg-drawings 0.0.0 → 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 +21 -1
  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 +60 -4
@@ -0,0 +1,26 @@
1
+ /** Radians per degree. */
2
+ export const deg = Math.PI / 180;
3
+ /** mm per unit. */
4
+ export const perUnit = { mm: 1, in: 25.4 };
5
+ /**
6
+ * A stored mm value as a label prints it: mm as stored; inches to 4 decimals (the web app's inch
7
+ * digits), without a zero before the point below 1 in, as inch drawings print them.
8
+ */
9
+ export const lengthText = (mm, unit = 'mm') => unit === 'mm' ? String(mm) : (mm / perUnit.in).toFixed(4).replace(/^0\./, '.');
10
+ /**
11
+ * The longest 1, 2 or 5 times a power of ten of the unit that fits `room` mm, at least 1 mm or
12
+ * 0.1 in; in the unit.
13
+ */
14
+ export function scaleLength(room, unit = 'mm') {
15
+ const k = perUnit[unit];
16
+ const e0 = unit === 'mm' ? 0 : -1;
17
+ let best = 10 ** e0;
18
+ for (let e = e0; e <= 3; e++)
19
+ for (const s of [1, 2, 5])
20
+ if (s * 10 ** e * k <= room * 0.5)
21
+ best = s * 10 ** e;
22
+ return Number(best.toPrecision(1));
23
+ }
24
+ /** The note that names the unit of a figure's length texts, "Dimensions in mm" or "inches". */
25
+ export const unitNote = (unit = 'mm') => `Dimensions in ${unit === 'mm' ? 'mm' : 'inches'}`;
26
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1,8 @@
1
+ import type { PartPoint } from './section.ts';
2
+ export declare const add: (a: PartPoint, b: PartPoint, s?: number) => PartPoint;
3
+ export declare const unit: (a: PartPoint, b: PartPoint) => PartPoint;
4
+ /** The consecutive pairs of a list: (0, 1), (1, 2), and so on. */
5
+ export declare const pairs: <T>(list: T[]) => [T, T][];
6
+ /** The edges of a closed polygon: the consecutive pairs, then the last point back to the first. */
7
+ export declare const closedEdges: <T>(list: T[]) => [T, T][];
8
+ export declare const polar: (c: PartPoint, r: number, a: number) => PartPoint;
@@ -0,0 +1,23 @@
1
+ export const add = (a, b, s = 1) => [
2
+ a[0] + b[0] * s,
3
+ a[1] + b[1] * s,
4
+ ];
5
+ export const unit = (a, b) => {
6
+ const l = Math.hypot(b[0] - a[0], b[1] - a[1]);
7
+ return l > 1e-12 ? [(b[0] - a[0]) / l, (b[1] - a[1]) / l] : [1, 0];
8
+ };
9
+ /** The consecutive pairs of a list: (0, 1), (1, 2), and so on. */
10
+ export const pairs = (list) => list.slice(1).flatMap((b, n) => {
11
+ const a = list[n];
12
+ return a === undefined ? [] : [[a, b]];
13
+ });
14
+ /** The edges of a closed polygon: the consecutive pairs, then the last point back to the first. */
15
+ export const closedEdges = (list) => {
16
+ const [first, last] = [list[0], list[list.length - 1]];
17
+ return first === undefined || last === undefined ? [] : [...pairs(list), [last, first]];
18
+ };
19
+ export const polar = (c, r, a) => [
20
+ c[0] + r * Math.cos(a),
21
+ c[1] + r * Math.sin(a),
22
+ ];
23
+ //# sourceMappingURL=vector.js.map
@@ -0,0 +1,9 @@
1
+ export * from './core/annotate.ts';
2
+ export * as face from './core/face.ts';
3
+ export * from './core/fillet.ts';
4
+ export * from './core/geometry.ts';
5
+ export * from './core/layout.ts';
6
+ export * from './core/section.ts';
7
+ export * from './core/text.ts';
8
+ export * from './core/types.ts';
9
+ export { type LengthUnit, lengthText, scaleLength, unitNote } from './core/units.ts';
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from './core/annotate.js';
2
+ export * as face from './core/face.js';
3
+ export * from './core/fillet.js';
4
+ export * from './core/geometry.js';
5
+ export * from './core/layout.js';
6
+ export * from './core/section.js';
7
+ export * from './core/text.js';
8
+ export * from './core/types.js';
9
+ export { lengthText, scaleLength, unitNote } from './core/units.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ import type { SpecValue } from '../core/types.ts';
2
+ /** The values of a CIP record the preview reads: the cartridge L3 (case length) and L6, the chamber throat. */
3
+ export interface SeatingValues {
4
+ caseLength: number;
5
+ cartridgeL6?: number | undefined;
6
+ /** Chamber L3, mm. */
7
+ chamberL3?: number | undefined;
8
+ G1?: number | undefined;
9
+ F?: number | undefined;
10
+ /** Chamber G: the leade end past chamber L3, mm. */
11
+ leadeEnd?: number | undefined;
12
+ /** Chamber s: the leade start past chamber L3, mm. */
13
+ leadeStart?: number | undefined;
14
+ /** Chamber i: the leade angle to the axis, degrees. */
15
+ leadeAngle?: number | undefined;
16
+ }
17
+ /**
18
+ * The chamber values the preview reads, in mm and degrees, from stored values: the cartridge L3
19
+ * as `caseLength` and L6, the chamber L3, G1, F, G, s and i. Undefined without a cartridge L3.
20
+ */
21
+ export declare function chamberOf(values: SpecValue[]): SeatingValues | undefined;
@@ -0,0 +1,23 @@
1
+ import { storedValue } from '../cartridge/profile.js';
2
+ /**
3
+ * The chamber values the preview reads, in mm and degrees, from stored values: the cartridge L3
4
+ * as `caseLength` and L6, the chamber L3, G1, F, G, s and i. Undefined without a cartridge L3.
5
+ */
6
+ export function chamberOf(values) {
7
+ const c = (symbol) => storedValue(values, 'cartridge', symbol)?.value;
8
+ const ch = (symbol) => storedValue(values, 'chamber', symbol)?.value;
9
+ const caseLength = c('L3');
10
+ if (caseLength === undefined)
11
+ return;
12
+ return {
13
+ caseLength,
14
+ cartridgeL6: c('L6'),
15
+ chamberL3: ch('L3'),
16
+ G1: ch('G1'),
17
+ F: ch('F'),
18
+ leadeEnd: ch('G'),
19
+ leadeStart: ch('s'),
20
+ leadeAngle: ch('i'),
21
+ };
22
+ }
23
+ //# sourceMappingURL=chamber.js.map
@@ -0,0 +1,3 @@
1
+ export * from './chamber.ts';
2
+ export * from './preview.ts';
3
+ export * from './seating.ts';
@@ -0,0 +1,4 @@
1
+ export * from './chamber.js';
2
+ export * from './preview.js';
3
+ export * from './seating.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ import type { Side } from '../cartridge/figures.ts';
2
+ import { type Profile } from '../cartridge/profile.ts';
3
+ import type { Drawn } from '../core/layout.ts';
4
+ import type { SpecValue } from '../core/types.ts';
5
+ /**
6
+ * The cartridge (CIP maximum) and the chamber (CIP minimum) of a record for the preview: outlines
7
+ * without dimensions, the chamber's last bore point run out to at least `tip` mm, so the bullet
8
+ * stays inside the drawn bore. Missing values of either side are named.
9
+ */
10
+ export declare function previewDrawn(values: SpecValue[], table: string | undefined, tip: number): Drawn<Side, Profile> | {
11
+ missing: string[];
12
+ };
@@ -0,0 +1,30 @@
1
+ import { cipProfile } from '../cartridge/profile.js';
2
+ /** A profile without dimensions, angles, radii and conventions: the outline and its edge lines only. */
3
+ const bare = (p) => ({
4
+ ...p,
5
+ annotation: { dimensions: [], angles: [], radii: [], conventions: [], edges: p.annotation.edges },
6
+ });
7
+ /**
8
+ * The cartridge (CIP maximum) and the chamber (CIP minimum) of a record for the preview: outlines
9
+ * without dimensions, the chamber's last bore point run out to at least `tip` mm, so the bullet
10
+ * stays inside the drawn bore. Missing values of either side are named.
11
+ */
12
+ export function previewDrawn(values, table, tip) {
13
+ const cartridge = cipProfile(values, 'cartridge', table);
14
+ const chamber = cipProfile(values, 'chamber', table);
15
+ const missing = [
16
+ ...('missing' in cartridge ? cartridge.missing.map((m) => `cartridge ${m}`) : []),
17
+ ...('missing' in chamber ? chamber.missing.map((m) => `chamber ${m}`) : []),
18
+ ];
19
+ if ('missing' in cartridge || 'missing' in chamber)
20
+ return { missing };
21
+ const points = [...chamber.points];
22
+ const last = points.pop();
23
+ if (last)
24
+ points.push([last[0], Math.max(last[1], tip)]);
25
+ return [
26
+ { side: 'cartridge', p: bare(cartridge) },
27
+ { side: 'chamber', p: bare({ ...chamber, points }) },
28
+ ];
29
+ }
30
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1,210 @@
1
+ import { type BulletDimensions, type Outline, type Tag } from '../bullet/outline.ts';
2
+ import { type LengthUnit } from '../core/units.ts';
3
+ import type { SeatingValues } from './chamber.ts';
4
+ export { assumedBoatTailAngle, type BulletDimensions, bulletOutline, revolutionVolume, } from '../bullet/outline.ts';
5
+ /** A computed value with the tag that tells where it comes from. */
6
+ export interface Tagged {
7
+ value: number;
8
+ /**
9
+ * `entered`: typed or slid by the user; `sourced`: taken from a record as stored; `derived`:
10
+ * computed from those; `approximate`: resting on an assumed shape.
11
+ */
12
+ tag: Tag;
13
+ }
14
+ /**
15
+ * Where the bullet's diameter d meets the leade, from the head: chamber L3 + s + (G1 - d) / 2 /
16
+ * tan(i). Without s the leade starts at L3 + G - (G1 - F) / 2 / tan(i), as the outline draws it.
17
+ * Own derivation, not a CIP value and not checked against a measurement. The notes write their
18
+ * lengths in `unit`.
19
+ */
20
+ export declare function leadeContact(ch: SeatingValues, d: number, unit?: LengthUnit): {
21
+ z: number;
22
+ note?: string | undefined;
23
+ } | {
24
+ missing: string[];
25
+ } | {
26
+ none: string;
27
+ };
28
+ /** Water capacity (g), water density (g/cm³), barrel length (mm) and the seating length as COAL or CBTO (mm), with the bullet dimensions and the chamber and case values. */
29
+ interface SeatInput {
30
+ bullet: BulletDimensions;
31
+ chamber: SeatingValues;
32
+ /** Water capacity, g. */
33
+ waterCapacity?: number | undefined;
34
+ /** Water density, g/cm³: turns the water capacity into a volume (the caller passes core's value). */
35
+ waterDensity: number;
36
+ /** Barrel length, mm: from the breech face, or from the forcing cone for a revolver `cylinder` that says so. */
37
+ barrelLength?: number | undefined;
38
+ /** A revolver's cylinder: the gap between cylinder face and barrel (mm, 0 where not given) and whether `barrelLength` is measured from the forcing cone. */
39
+ cylinder?: RevolverCylinder | undefined;
40
+ by: {
41
+ kind: 'overallLength' | 'baseToOgive';
42
+ value: number;
43
+ };
44
+ /** The firearm's measured lands contact of this bullet: it replaces the chamber-derived jump. */
45
+ lands?: LandsContact | undefined;
46
+ /** The page's length unit: the outline's notes write their lengths in it (mm by default). */
47
+ unit?: LengthUnit | undefined;
48
+ }
49
+ /**
50
+ * The cartridge length at which this bullet touched the lands in a firearm, mm, measured as CBTO
51
+ * and/or COAL. The CBTO is used when the bullet has a base-to-ogive, else the COAL.
52
+ */
53
+ export interface LandsContact {
54
+ baseToOgive?: number | undefined;
55
+ overallLength?: number | undefined;
56
+ }
57
+ /** A revolver's cylinder as the seating takes it. */
58
+ export interface RevolverCylinder {
59
+ /** Gap between cylinder face and barrel, mm. */
60
+ gap: number;
61
+ /** The barrel length is measured from the forcing cone, so the travel adds the cylinder run. */
62
+ fromForcingCone: boolean;
63
+ }
64
+ /** The seated bullet: its outline, lengths, volumes and jump, each with its tag, and notes. */
65
+ export interface Seating {
66
+ outline: Outline;
67
+ /** z of the bullet base from the head, mm. */
68
+ basePosition: number;
69
+ /** Cartridge overall length (COAL), mm. */
70
+ coal: Tagged;
71
+ /** Cartridge base to ogive (CBTO), mm; none without the bullet base-to-ogive. */
72
+ cbto?: Tagged | undefined;
73
+ /** Seating depth: case length (cartridge L3) less the base position, mm. */
74
+ depth: Tagged;
75
+ /** Case volume to the mouth and volume behind the bullet, cm³. */
76
+ caseVolume?: Tagged;
77
+ volumeBehindBullet?: Tagged;
78
+ /**
79
+ * Bounds of `volumeBehindBullet` over the depth bracket of a cavity of assumed depth below the
80
+ * mouth (`cavityVolumeBracket`), cm³; none without such a cavity.
81
+ */
82
+ cavityRange?: {
83
+ low: number;
84
+ high: number;
85
+ };
86
+ travel?: Tagged;
87
+ /**
88
+ * A revolver's cylinder, mm: its `face` from the head, the larger of the cartridge's L6 (`from`
89
+ * `L6`) and the COAL (`COAL`), since the cylinder holds the whole round; `exit`, the travel at
90
+ * which the bullet base passes the face; with a barrel from the forcing cone, `run` (face plus
91
+ * gap), which the travel includes.
92
+ */
93
+ cylinder?: {
94
+ face: number;
95
+ from: 'L6' | 'COAL';
96
+ gap: number;
97
+ exit: number;
98
+ run?: number;
99
+ };
100
+ /** Leade contact from the head, approximate. */
101
+ leade?: number | undefined;
102
+ /** COAL at which the jump is 0. */
103
+ contactCoal?: number;
104
+ /** Value undefined where a jump cannot be given; missing names what a derived value lacks. */
105
+ jump: {
106
+ value?: number | undefined;
107
+ tag: 'derived' | 'approximate';
108
+ missing: string[];
109
+ /** `lands`: from the firearm's measured lands contact; `chamber`: from the C.I.P. chamber values. */
110
+ source: 'lands' | 'chamber';
111
+ };
112
+ /** The bullet touches the lands: a jump of 0 or less. */
113
+ contact: boolean;
114
+ /** COAL above the CIP maximum L6. */
115
+ aboveL6: boolean;
116
+ notes: string[];
117
+ }
118
+ /**
119
+ * The bullet seated by COAL (base = COAL - length) or by CBTO (base = CBTO - bullet
120
+ * base-to-ogive): seating depth = case length (cartridge L3) - base; volume behind the bullet =
121
+ * water capacity / water density - the bullet volume below the mouth; travel = barrel - base, plus
122
+ * the cylinder run (the larger of L6 and COAL, plus the gap) for a revolver barrel from the forcing
123
+ * cone; jump = leade contact - (base + length - nose length). With a measured lands contact the bullet
124
+ * base at contact is its CBTO less the bullet base-to-ogive (else its COAL less the length) and
125
+ * jump = contact base - base.
126
+ */
127
+ export declare function seat({ bullet, chamber, waterCapacity, waterDensity, barrelLength, cylinder, by, lands, unit, }: SeatInput): Seating;
128
+ /** COAL at which the bullet touches the lands for a measured contact, mm; none without a usable one. */
129
+ export declare function landsContactCoal(bullet: BulletDimensions, lands: LandsContact | undefined): number | undefined;
130
+ /**
131
+ * Assumed bullet length uncertainty: `measured` absolute (mm), `estimated` relative to the length.
132
+ * Unverified; the estimated one follows an input finding.
133
+ */
134
+ export declare const bulletLengthTolerance: Readonly<{
135
+ measured: 0.05;
136
+ estimated: 0.15;
137
+ }>;
138
+ /** Case length to the mouth (mm), cartridge overall length COAL (mm) and whether the bullet length is measured or estimated, with the bullet dimensions. */
139
+ interface IntrusionInput {
140
+ bullet: BulletDimensions;
141
+ /** Case length to the mouth, mm: the water capacity is taken to the mouth. */
142
+ caseLength: number;
143
+ coal: number;
144
+ /** Required, so no length counts as measured by default. */
145
+ lengthSource: 'measured' | 'estimated';
146
+ /** The page's length unit: the outline's notes write their lengths in it (mm by default). */
147
+ unit?: LengthUnit | undefined;
148
+ }
149
+ /** The bullet volume below the case mouth with bounds from the length tolerance. */
150
+ interface Intrusion {
151
+ /** Seating depth, mm. */
152
+ depth: number;
153
+ /** Bullet volume below the case mouth, cm³. */
154
+ volume: Tagged;
155
+ /** Bounds of `volume` for the length tolerance of the source, cm³. */
156
+ low: number;
157
+ high: number;
158
+ notes: string[];
159
+ }
160
+ /**
161
+ * The bullet volume inside the case (`apps/docs/docs/models/case-capacity.md`, "Bullet volume below
162
+ * the mouth"): base = COAL - length, so at fixed COAL a length error dL moves the depth by dL and
163
+ * the volume by at most pi d^2 / 4 dL, which gives the bounds (the lower one clamped at 0).
164
+ */
165
+ export declare function intrusion({ bullet, caseLength, coal, lengthSource, unit, }: IntrusionInput): Intrusion;
166
+ /**
167
+ * An effective bullet density, g/cm³: the mass over the volume of a cylinder of the bullet's diameter
168
+ * and length, so the shape of the nose and base is in it, with the relative error of the length it
169
+ * gives (the 90th percentile of the records it was taken from).
170
+ */
171
+ export interface EffectiveDensity {
172
+ value: number;
173
+ /** Relative to the true length, 1: the estimated length is within this fraction of it for 90 % of the records. */
174
+ error: number;
175
+ }
176
+ /** Input of `estimateIntrusion`: diameter (mm), mass (g), density and the case and cartridge lengths (mm). */
177
+ interface EstimateInput {
178
+ diameter: number;
179
+ mass: number;
180
+ density: EffectiveDensity;
181
+ /** Case length to the mouth, mm. */
182
+ caseLength: number;
183
+ coal: number;
184
+ }
185
+ /** The bullet volume below the mouth of a bullet known by diameter and mass only. */
186
+ interface IntrusionEstimate {
187
+ /** Estimated bullet length, mm. */
188
+ length: number;
189
+ /** Bullet volume below the mouth, cm³, always `approximate`. */
190
+ volume: Tagged;
191
+ /** Bounds of `volume` for the length error, cm³. */
192
+ low: number;
193
+ high: number;
194
+ notes: string[];
195
+ }
196
+ /**
197
+ * The bullet volume below the mouth without a bullet length (`apps/docs/docs/models/case-capacity.md`,
198
+ * "Bullet without a length"): the length is mass / (effective density * cylinder area), then
199
+ * `intrusion` at the given COAL with the outline of assumed proportions. The bounds are the volumes
200
+ * at the lengths the density error allows, length / (1 + error) and length / (1 - error); a longer
201
+ * bullet takes more of the case.
202
+ */
203
+ export declare function estimateIntrusion(i: EstimateInput): IntrusionEstimate;
204
+ /** The basis line of the jump row: what is missing first when no jump can be given. */
205
+ export declare function jumpNote(jump: Seating['jump']): string;
206
+ /**
207
+ * Slider range of COAL, mm: from a quarter of the bullet out of the case to a tenth of the bullet
208
+ * length past the larger of L6 and the COAL of leade contact (mouth plus bullet length without L6).
209
+ */
210
+ export declare function coalRange(chamber: SeatingValues, bullet: BulletDimensions, contactCoal?: number): [number, number];