@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.
- package/LICENSE +661 -0
- package/README.md +21 -1
- package/dist/bullet/density.d.ts +65 -0
- package/dist/bullet/density.js +91 -0
- package/dist/bullet/figure.d.ts +34 -0
- package/dist/bullet/figure.js +50 -0
- package/dist/bullet/index.d.ts +4 -0
- package/dist/bullet/index.js +5 -0
- package/dist/bullet/outline.d.ts +144 -0
- package/dist/bullet/outline.js +683 -0
- package/dist/bullet/profile.d.ts +76 -0
- package/dist/bullet/profile.js +257 -0
- package/dist/cartridge/callouts.d.ts +18 -0
- package/dist/cartridge/callouts.js +153 -0
- package/dist/cartridge/detail.d.ts +34 -0
- package/dist/cartridge/detail.js +99 -0
- package/dist/cartridge/figure.d.ts +59 -0
- package/dist/cartridge/figure.js +113 -0
- package/dist/cartridge/figures.d.ts +47 -0
- package/dist/cartridge/figures.js +54 -0
- package/dist/cartridge/focus.d.ts +3 -0
- package/dist/cartridge/focus.js +7 -0
- package/dist/cartridge/index.d.ts +8 -0
- package/dist/cartridge/index.js +8 -0
- package/dist/cartridge/profile.d.ts +46 -0
- package/dist/cartridge/profile.js +630 -0
- package/dist/cartridge/regions.d.ts +28 -0
- package/dist/cartridge/regions.js +50 -0
- package/dist/core/advances.json +106 -0
- package/dist/core/annotate.d.ts +11 -0
- package/dist/core/annotate.js +715 -0
- package/dist/core/cache.d.ts +4 -0
- package/dist/core/cache.js +16 -0
- package/dist/core/face.d.ts +56 -0
- package/dist/core/face.js +54 -0
- package/dist/core/fillet.d.ts +7 -0
- package/dist/core/fillet.js +42 -0
- package/dist/core/geometry.d.ts +22 -0
- package/dist/core/geometry.js +136 -0
- package/dist/core/layout.d.ts +46 -0
- package/dist/core/layout.js +69 -0
- package/dist/core/placer.d.ts +60 -0
- package/dist/core/placer.js +291 -0
- package/dist/core/section.d.ts +32 -0
- package/dist/core/section.js +75 -0
- package/dist/core/text.d.ts +19 -0
- package/dist/core/text.js +38 -0
- package/dist/core/types.d.ts +185 -0
- package/dist/core/types.js +2 -0
- package/dist/core/units.d.ts +18 -0
- package/dist/core/units.js +26 -0
- package/dist/core/vector.d.ts +8 -0
- package/dist/core/vector.js +23 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/seating/chamber.d.ts +21 -0
- package/dist/seating/chamber.js +23 -0
- package/dist/seating/index.d.ts +3 -0
- package/dist/seating/index.js +4 -0
- package/dist/seating/preview.d.ts +12 -0
- package/dist/seating/preview.js +30 -0
- package/dist/seating/seating.d.ts +210 -0
- package/dist/seating/seating.js +284 -0
- package/dist/target/face.d.ts +68 -0
- package/dist/target/face.js +50 -0
- package/dist/target/index.d.ts +1 -0
- package/dist/target/index.js +2 -0
- package/package.json +60 -4
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { assumedBelow, bulletOutline, cavityVolumeBracket, revolutionVolume, } from '../bullet/outline.js';
|
|
2
|
+
import { deg, lengthText } from '../core/units.js';
|
|
3
|
+
export { assumedBoatTailAngle, bulletOutline, revolutionVolume, } from '../bullet/outline.js';
|
|
4
|
+
/**
|
|
5
|
+
* Where the bullet's diameter d meets the leade, from the head: chamber L3 + s + (G1 - d) / 2 /
|
|
6
|
+
* tan(i). Without s the leade starts at L3 + G - (G1 - F) / 2 / tan(i), as the outline draws it.
|
|
7
|
+
* Own derivation, not a CIP value and not checked against a measurement. The notes write their
|
|
8
|
+
* lengths in `unit`.
|
|
9
|
+
*/
|
|
10
|
+
export function leadeContact(ch, d, unit = 'mm') {
|
|
11
|
+
const { chamberL3: L3, G1, F, leadeEnd: G, leadeStart: s, leadeAngle: i } = ch;
|
|
12
|
+
const missing = [
|
|
13
|
+
...(L3 === undefined ? ['L3'] : []),
|
|
14
|
+
...(G1 === undefined ? ['G1'] : []),
|
|
15
|
+
...(F === undefined ? ['F'] : []),
|
|
16
|
+
...(s === undefined && G === undefined ? ['s or G'] : []),
|
|
17
|
+
...(i === undefined || !(i > 0 && i < 90) ? ['i'] : []),
|
|
18
|
+
];
|
|
19
|
+
if (missing.length)
|
|
20
|
+
return { missing };
|
|
21
|
+
// `missing` names every one of them that is undefined
|
|
22
|
+
const [l3, g1, f, angle] = [L3, G1, F, i];
|
|
23
|
+
const t = Math.tan(angle * deg);
|
|
24
|
+
// a length as the notes write it: as given in mm, as the figure labels write it in inches
|
|
25
|
+
const l = (x) => (unit === 'mm' ? `${x} mm` : `${lengthText(x, 'in')} in`);
|
|
26
|
+
if (d <= f)
|
|
27
|
+
return { none: `The bullet diameter ${l(d)} is not above F ${l(f)}: no land contact.` };
|
|
28
|
+
const start = l3 + (s ?? G - (g1 - f) / 2 / t);
|
|
29
|
+
if (d >= g1)
|
|
30
|
+
return {
|
|
31
|
+
z: start,
|
|
32
|
+
note: `The bullet diameter ${l(d)} is not below G1 ${l(g1)}: contact taken at the leade start.`,
|
|
33
|
+
};
|
|
34
|
+
return { z: start + (g1 - d) / 2 / t };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The bullet seated by COAL (base = COAL - length) or by CBTO (base = CBTO - bullet
|
|
38
|
+
* base-to-ogive): seating depth = case length (cartridge L3) - base; volume behind the bullet =
|
|
39
|
+
* water capacity / water density - the bullet volume below the mouth; travel = barrel - base, plus
|
|
40
|
+
* the cylinder run (the larger of L6 and COAL, plus the gap) for a revolver barrel from the forcing
|
|
41
|
+
* cone; jump = leade contact - (base + length - nose length). With a measured lands contact the bullet
|
|
42
|
+
* base at contact is its CBTO less the bullet base-to-ogive (else its COAL less the length) and
|
|
43
|
+
* jump = contact base - base.
|
|
44
|
+
*/
|
|
45
|
+
export function seat({ bullet, chamber, waterCapacity, waterDensity, barrelLength, cylinder, by, lands, unit = 'mm', }) {
|
|
46
|
+
const outline = bulletOutline(bullet, 'sourced', unit);
|
|
47
|
+
if ('reason' in outline)
|
|
48
|
+
throw new RangeError(outline.reason);
|
|
49
|
+
const notes = [...outline.notes];
|
|
50
|
+
const { base, coal, cbto } = seatLengths(bullet, by);
|
|
51
|
+
const depthValue = chamber.caseLength - base;
|
|
52
|
+
if (depthValue < 0)
|
|
53
|
+
notes.push('The bullet base is in front of the case mouth: not seated.');
|
|
54
|
+
if (depthValue > bullet.length)
|
|
55
|
+
notes.push('The whole bullet is below the case mouth.');
|
|
56
|
+
const cut = Math.min(Math.max(depthValue, 0), bullet.length);
|
|
57
|
+
const { caseVolume, volume } = seatVolumes(outline, cut, waterCapacity, waterDensity);
|
|
58
|
+
const behind = volumeBehind(volume, depthValue > chamber.caseLength, notes);
|
|
59
|
+
const bracket = behind && caseVolume && cavityVolumeBracket(bullet, cut);
|
|
60
|
+
const byCbto = by.kind === 'baseToOgive';
|
|
61
|
+
const contact = landContact(chamber, bullet, outline, byCbto, unit);
|
|
62
|
+
notes.push(...contact.notes);
|
|
63
|
+
const { leade, missing } = contact;
|
|
64
|
+
const { jump, contactCoal } = jumpOf({
|
|
65
|
+
bullet,
|
|
66
|
+
outline,
|
|
67
|
+
base,
|
|
68
|
+
byCbto,
|
|
69
|
+
leade,
|
|
70
|
+
missing,
|
|
71
|
+
touchBase: landsBase(bullet, lands),
|
|
72
|
+
});
|
|
73
|
+
const cyl = cylinderOf(cylinder, chamber.cartridgeL6, coal.value, base);
|
|
74
|
+
return {
|
|
75
|
+
outline,
|
|
76
|
+
basePosition: base,
|
|
77
|
+
coal,
|
|
78
|
+
...(cbto && { cbto }),
|
|
79
|
+
depth: { value: depthValue, tag: 'derived' },
|
|
80
|
+
...(caseVolume && { caseVolume }),
|
|
81
|
+
...(behind && { volumeBehindBullet: behind }),
|
|
82
|
+
...(bracket &&
|
|
83
|
+
caseVolume && {
|
|
84
|
+
cavityRange: {
|
|
85
|
+
low: Math.max(caseVolume.value - bracket.high / 1000, 0),
|
|
86
|
+
high: caseVolume.value - bracket.low / 1000,
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
...(barrelLength !== undefined && {
|
|
90
|
+
travel: { value: barrelLength + runOf(cyl) - base, tag: 'derived' },
|
|
91
|
+
}),
|
|
92
|
+
...(cyl && { cylinder: cyl }),
|
|
93
|
+
...(leade !== undefined && { leade }),
|
|
94
|
+
...(contactCoal !== undefined && { contactCoal }),
|
|
95
|
+
jump,
|
|
96
|
+
contact: jump.value !== undefined && jump.value <= 0,
|
|
97
|
+
aboveL6: chamber.cartridgeL6 !== undefined && coal.value > chamber.cartridgeL6 + 1e-9,
|
|
98
|
+
notes,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** The cylinder face lies at least at L6 and at the seated COAL: a shorter cylinder could not hold the round. */
|
|
102
|
+
function cylinderOf(cylinder, l6, coal, base) {
|
|
103
|
+
if (!cylinder)
|
|
104
|
+
return undefined;
|
|
105
|
+
const { gap, fromForcingCone } = cylinder;
|
|
106
|
+
const atL6 = l6 !== undefined && l6 >= coal;
|
|
107
|
+
const face = atL6 ? l6 : coal;
|
|
108
|
+
const from = atL6 ? 'L6' : 'COAL';
|
|
109
|
+
return { face, from, gap, exit: face - base, ...(fromForcingCone && { run: face + gap }) };
|
|
110
|
+
}
|
|
111
|
+
/** The cylinder run a barrel measured from the forcing cone adds to the travel, mm. */
|
|
112
|
+
function runOf(cylinder) {
|
|
113
|
+
return cylinder?.run ?? 0;
|
|
114
|
+
}
|
|
115
|
+
/** From the measured lands contact (`touchBase`, the base position at contact) when there is one, else from the leade contact of the chamber. */
|
|
116
|
+
function jumpOf(o) {
|
|
117
|
+
const { bullet, outline, base, byCbto, leade, missing, touchBase } = o;
|
|
118
|
+
if (touchBase !== undefined)
|
|
119
|
+
return {
|
|
120
|
+
jump: { value: touchBase - base, tag: 'derived', missing: [], source: 'lands' },
|
|
121
|
+
contactCoal: touchBase + bullet.length,
|
|
122
|
+
};
|
|
123
|
+
const canJump = leade !== undefined && !outline.noseAssumed;
|
|
124
|
+
return {
|
|
125
|
+
jump: {
|
|
126
|
+
value: canJump ? leade - (base + bullet.length - outline.noseLength) : undefined,
|
|
127
|
+
tag: byCbto ? 'derived' : 'approximate',
|
|
128
|
+
missing,
|
|
129
|
+
source: 'chamber',
|
|
130
|
+
},
|
|
131
|
+
...(canJump && { contactCoal: leade + outline.noseLength }),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** The bullet base position from the head at the measured lands contact, mm; none without a usable one. */
|
|
135
|
+
function landsBase(bullet, lands) {
|
|
136
|
+
if (lands?.baseToOgive !== undefined && bullet.baseToOgive !== undefined)
|
|
137
|
+
return lands.baseToOgive - bullet.baseToOgive;
|
|
138
|
+
if (lands?.overallLength !== undefined)
|
|
139
|
+
return lands.overallLength - bullet.length;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
/** COAL at which the bullet touches the lands for a measured contact, mm; none without a usable one. */
|
|
143
|
+
export function landsContactCoal(bullet, lands) {
|
|
144
|
+
const base = landsBase(bullet, lands);
|
|
145
|
+
return base === undefined ? undefined : base + bullet.length;
|
|
146
|
+
}
|
|
147
|
+
/** The bullet base position from the head, COAL and CBTO for the length entered, mm. */
|
|
148
|
+
function seatLengths(bullet, by) {
|
|
149
|
+
const bto = bullet.baseToOgive;
|
|
150
|
+
if (by.kind === 'baseToOgive' && bto === undefined)
|
|
151
|
+
throw new RangeError('CBTO needs the bullet base-to-ogive');
|
|
152
|
+
const base = by.kind === 'overallLength' ? by.value - bullet.length : by.value - bto;
|
|
153
|
+
const coal = {
|
|
154
|
+
value: base + bullet.length,
|
|
155
|
+
tag: by.kind === 'overallLength' ? 'entered' : 'derived',
|
|
156
|
+
};
|
|
157
|
+
const cbto = bto === undefined
|
|
158
|
+
? undefined
|
|
159
|
+
: { value: base + bto, tag: by.kind === 'baseToOgive' ? 'entered' : 'derived' };
|
|
160
|
+
return { base, coal, cbto };
|
|
161
|
+
}
|
|
162
|
+
/** Case volume and volume behind the bullet, cm³, with the bullet `cut` mm below the mouth; none without a water capacity. */
|
|
163
|
+
function seatVolumes(outline, cut, water, waterDensity) {
|
|
164
|
+
const caseVolume = water === undefined ? undefined : { value: water / waterDensity, tag: 'derived' };
|
|
165
|
+
const volume = caseVolume && {
|
|
166
|
+
value: caseVolume.value - revolutionVolume(outline.points, cut) / 1000,
|
|
167
|
+
tag: assumedBelow(outline, cut) ? 'approximate' : 'derived',
|
|
168
|
+
};
|
|
169
|
+
return { caseVolume, volume };
|
|
170
|
+
}
|
|
171
|
+
/** The volume behind the bullet, none with a note for a base behind the case head or a volume at or below 0. */
|
|
172
|
+
function volumeBehind(volume, behindHead, notes) {
|
|
173
|
+
if (behindHead)
|
|
174
|
+
notes.push('The bullet base is behind the case head: the seating depth is above the case length. No volume behind the bullet is given.');
|
|
175
|
+
else if (volume && volume.value <= 0)
|
|
176
|
+
notes.push('The bullet below the mouth takes the whole case volume: no volume behind the bullet is given.');
|
|
177
|
+
return volume && !behindHead && volume.value > 0 ? volume : undefined;
|
|
178
|
+
}
|
|
179
|
+
/** The leade contact of the bullet from the head, what a derived jump lacks, and the notes on the contact. */
|
|
180
|
+
function landContact(chamber, bullet, outline, byCbto, unit) {
|
|
181
|
+
const notes = [];
|
|
182
|
+
const contactAt = leadeContact(chamber, bullet.diameter, unit);
|
|
183
|
+
if ('note' in contactAt && contactAt.note)
|
|
184
|
+
notes.push(contactAt.note);
|
|
185
|
+
if ('none' in contactAt)
|
|
186
|
+
notes.push(contactAt.none);
|
|
187
|
+
const leade = 'z' in contactAt ? contactAt.z : undefined;
|
|
188
|
+
// Without land contact no input gives a jump, so nothing is named as missing.
|
|
189
|
+
const missing = byCbto || 'none' in contactAt
|
|
190
|
+
? []
|
|
191
|
+
: [
|
|
192
|
+
'a measured CBTO',
|
|
193
|
+
...(bullet.baseToOgive === undefined ? ['the bullet base-to-ogive'] : []),
|
|
194
|
+
];
|
|
195
|
+
if (outline.noseAssumed && !('none' in contactAt))
|
|
196
|
+
missing.push('the bullet nose length');
|
|
197
|
+
if ('missing' in contactAt)
|
|
198
|
+
missing.push(`chamber ${contactAt.missing.join(', ')}`);
|
|
199
|
+
return { leade, missing, notes };
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Assumed bullet length uncertainty: `measured` absolute (mm), `estimated` relative to the length.
|
|
203
|
+
* Unverified; the estimated one follows an input finding.
|
|
204
|
+
*/
|
|
205
|
+
export const bulletLengthTolerance = Object.freeze({ measured: 0.05, estimated: 0.15 });
|
|
206
|
+
/**
|
|
207
|
+
* The bullet volume inside the case (`apps/docs/docs/models/case-capacity.md`, "Bullet volume below
|
|
208
|
+
* the mouth"): base = COAL - length, so at fixed COAL a length error dL moves the depth by dL and
|
|
209
|
+
* the volume by at most pi d^2 / 4 dL, which gives the bounds (the lower one clamped at 0).
|
|
210
|
+
*/
|
|
211
|
+
export function intrusion({ bullet, caseLength, coal, lengthSource, unit = 'mm', }) {
|
|
212
|
+
const outline = bulletOutline(bullet, 'sourced', unit);
|
|
213
|
+
if ('reason' in outline)
|
|
214
|
+
throw new RangeError(outline.reason);
|
|
215
|
+
const notes = [...outline.notes];
|
|
216
|
+
const depth = caseLength - (coal - bullet.length);
|
|
217
|
+
if (depth < 0)
|
|
218
|
+
notes.push('The bullet base is in front of the case mouth: not seated.');
|
|
219
|
+
if (depth > bullet.length)
|
|
220
|
+
notes.push('The whole bullet is below the case mouth.');
|
|
221
|
+
const cut = Math.min(Math.max(depth, 0), bullet.length);
|
|
222
|
+
const estimated = lengthSource === 'estimated';
|
|
223
|
+
if (estimated)
|
|
224
|
+
notes.push('The bullet length is estimated: measure it for the volume.');
|
|
225
|
+
const assumed = assumedBelow(outline, cut);
|
|
226
|
+
const value = revolutionVolume(outline.points, cut) / 1000;
|
|
227
|
+
const dL = estimated
|
|
228
|
+
? bulletLengthTolerance.estimated * bullet.length
|
|
229
|
+
: bulletLengthTolerance.measured;
|
|
230
|
+
const band = ((Math.PI / 4) * bullet.diameter ** 2 * dL) / 1000;
|
|
231
|
+
return {
|
|
232
|
+
depth,
|
|
233
|
+
volume: { value, tag: estimated || assumed ? 'approximate' : 'derived' },
|
|
234
|
+
low: Math.max(value - band, 0),
|
|
235
|
+
high: value + band,
|
|
236
|
+
notes,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The bullet volume below the mouth without a bullet length (`apps/docs/docs/models/case-capacity.md`,
|
|
241
|
+
* "Bullet without a length"): the length is mass / (effective density * cylinder area), then
|
|
242
|
+
* `intrusion` at the given COAL with the outline of assumed proportions. The bounds are the volumes
|
|
243
|
+
* at the lengths the density error allows, length / (1 + error) and length / (1 - error); a longer
|
|
244
|
+
* bullet takes more of the case.
|
|
245
|
+
*/
|
|
246
|
+
export function estimateIntrusion(i) {
|
|
247
|
+
const { diameter, mass, density, caseLength, coal } = i;
|
|
248
|
+
const length = ((mass / density.value) * 1000) / ((Math.PI / 4) * diameter ** 2);
|
|
249
|
+
const at = (l) => intrusion({ bullet: { diameter, length: l }, caseLength, coal, lengthSource: 'estimated' });
|
|
250
|
+
const [mid, short, long] = [
|
|
251
|
+
at(length),
|
|
252
|
+
at(length / (1 + density.error)),
|
|
253
|
+
at(length / (1 - density.error)),
|
|
254
|
+
];
|
|
255
|
+
return {
|
|
256
|
+
length,
|
|
257
|
+
volume: { value: mid.volume.value, tag: 'approximate' },
|
|
258
|
+
low: short.volume.value,
|
|
259
|
+
high: long.volume.value,
|
|
260
|
+
notes: mid.notes,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/** The basis line of the jump row: what is missing first when no jump can be given. */
|
|
264
|
+
export function jumpNote(jump) {
|
|
265
|
+
if (jump.value === undefined)
|
|
266
|
+
return jump.missing.length
|
|
267
|
+
? `not given: missing ${jump.missing.join(', ')}`
|
|
268
|
+
: 'not given: the bullet does not reach the lands (see the notes)';
|
|
269
|
+
if (jump.source === 'lands')
|
|
270
|
+
return 'derived: from the measured lands contact of the firearm and the entered length';
|
|
271
|
+
return jump.tag === 'derived'
|
|
272
|
+
? 'derived: from the entered CBTO and the bullet base-to-ogive against the CIP minimum chamber, assuming the same comparator'
|
|
273
|
+
: `approximate: from COAL and the bullet length; missing: ${jump.missing.join(', ')}`;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Slider range of COAL, mm: from a quarter of the bullet out of the case to a tenth of the bullet
|
|
277
|
+
* length past the larger of L6 and the COAL of leade contact (mouth plus bullet length without L6).
|
|
278
|
+
*/
|
|
279
|
+
export function coalRange(chamber, bullet, contactCoal) {
|
|
280
|
+
const lo = chamber.caseLength + 0.25 * bullet.length;
|
|
281
|
+
const top = Math.max(chamber.cartridgeL6 ?? chamber.caseLength + bullet.length, contactCoal ?? 0);
|
|
282
|
+
return [Math.floor(lo * 10) / 10, Math.ceil((top + 0.1 * bullet.length) * 10) / 10];
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=seating.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** A length in mm, as the quantity objects of a target face record carry it. */
|
|
2
|
+
export interface FaceLength {
|
|
3
|
+
value: number;
|
|
4
|
+
}
|
|
5
|
+
/** The ring fields the face figure reads; a `TargetFace` record fits. */
|
|
6
|
+
export interface FaceRing {
|
|
7
|
+
value: number;
|
|
8
|
+
diameter: FaceLength;
|
|
9
|
+
/** Height of an oval ring; absent: a circle. */
|
|
10
|
+
height?: FaceLength | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* `square`: a square of edge `diameter`; `stadium`: straight sides and half circle ends of the
|
|
13
|
+
* radius `diameter / 2`; absent or `circle`: a circle or oval.
|
|
14
|
+
*/
|
|
15
|
+
shape?: 'circle' | 'square' | 'stadium' | undefined;
|
|
16
|
+
fill?: string | undefined;
|
|
17
|
+
line?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The fields of a target face the figure reads; a `TargetFace` record fits. */
|
|
20
|
+
export interface FaceShape {
|
|
21
|
+
/** Outer to inner. */
|
|
22
|
+
rings: FaceRing[];
|
|
23
|
+
innerTen?: {
|
|
24
|
+
diameter: FaceLength;
|
|
25
|
+
height?: FaceLength | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
blackDiameter: FaceLength;
|
|
28
|
+
blackHeight?: FaceLength | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* An ellipse, or a rectangle when `square`, or a stadium when `stadium`, centered on the scoring
|
|
32
|
+
* center, radii in mm.
|
|
33
|
+
*/
|
|
34
|
+
export interface FaceEllipse {
|
|
35
|
+
rx: number;
|
|
36
|
+
ry: number;
|
|
37
|
+
/** The shape is a rectangle of half-width `rx` and half-height `ry`, not an ellipse. */
|
|
38
|
+
square?: true;
|
|
39
|
+
/** The shape is a rectangle of half-width `rx` and half-height `ry` with half circle ends of the radius `rx`. */
|
|
40
|
+
stadium?: true;
|
|
41
|
+
/** Ring value of the ring the ellipse is drawn for; absent for the paper, the black area and the inner ten. */
|
|
42
|
+
ring?: number;
|
|
43
|
+
/** A color name of the face record, or `white` and `black`. */
|
|
44
|
+
colour: string;
|
|
45
|
+
}
|
|
46
|
+
/** The face as ellipses in drawing order, with the frame around it. */
|
|
47
|
+
export interface FaceFigure {
|
|
48
|
+
/** Frame in mm: the outer ring and a margin. */
|
|
49
|
+
frame: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
};
|
|
55
|
+
/** Paper inside the outer ring, then the colored zones (or the black area), filled. */
|
|
56
|
+
zones: FaceEllipse[];
|
|
57
|
+
/** Ring lines outer to inner, then the inner ten, stroked. */
|
|
58
|
+
lines: FaceEllipse[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A target face laid out from its record: the paper inside the outer ring, the zones in their
|
|
62
|
+
* recorded colors (else the black area), the ring lines and the inner ten. Radii are the half
|
|
63
|
+
* of the recorded diameters and heights. A ring line on a black zone is white, else black or the
|
|
64
|
+
* ring's own line color.
|
|
65
|
+
* shortcut: one scoring center and no sheet; a record with `bulls` or `paper` draws its first
|
|
66
|
+
* bull only, draw the sheet once a record has one.
|
|
67
|
+
*/
|
|
68
|
+
export declare function targetFaceFigure(face: FaceShape): FaceFigure;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const ellipse = (d, height, colour, ring, shape) => ({
|
|
2
|
+
rx: d / 2,
|
|
3
|
+
ry: (height ?? d) / 2,
|
|
4
|
+
colour,
|
|
5
|
+
...(ring !== undefined && { ring }),
|
|
6
|
+
...(shape === 'square' && { square: true }),
|
|
7
|
+
...(shape === 'stadium' && { stadium: true }),
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* A target face laid out from its record: the paper inside the outer ring, the zones in their
|
|
11
|
+
* recorded colors (else the black area), the ring lines and the inner ten. Radii are the half
|
|
12
|
+
* of the recorded diameters and heights. A ring line on a black zone is white, else black or the
|
|
13
|
+
* ring's own line color.
|
|
14
|
+
* shortcut: one scoring center and no sheet; a record with `bulls` or `paper` draws its first
|
|
15
|
+
* bull only, draw the sheet once a record has one.
|
|
16
|
+
*/
|
|
17
|
+
export function targetFaceFigure(face) {
|
|
18
|
+
const outer = face.rings[0];
|
|
19
|
+
if (!outer)
|
|
20
|
+
throw new Error('A target face needs at least one ring.');
|
|
21
|
+
const w = outer.diameter.value;
|
|
22
|
+
const h = outer.height?.value ?? w;
|
|
23
|
+
const pad = w * 0.02;
|
|
24
|
+
const black = face.blackDiameter.value;
|
|
25
|
+
const fills = face.rings.some((r) => r.fill);
|
|
26
|
+
// white on the black zone outside the line
|
|
27
|
+
const onBlack = (i, d) => fills ? face.rings[i - 1]?.fill === 'black' : d <= black;
|
|
28
|
+
const line = (i, d, colour) => colour ?? (onBlack(i, d) ? 'white' : 'black');
|
|
29
|
+
const inner = face.innerTen;
|
|
30
|
+
// the black area and the inner ten take the shape of a stadium face
|
|
31
|
+
const stadium = outer.shape === 'stadium' ? 'stadium' : undefined;
|
|
32
|
+
return {
|
|
33
|
+
frame: { x: -w / 2 - pad, y: -h / 2 - pad, width: w + 2 * pad, height: h + 2 * pad },
|
|
34
|
+
zones: [
|
|
35
|
+
ellipse(w, outer.height?.value, 'white', undefined, outer.shape),
|
|
36
|
+
...(fills
|
|
37
|
+
? face.rings.map((r) => ellipse(r.diameter.value, r.height?.value, r.fill ?? 'white', r.value, r.shape))
|
|
38
|
+
: [ellipse(black, face.blackHeight?.value, 'black', undefined, stadium)]),
|
|
39
|
+
],
|
|
40
|
+
lines: [
|
|
41
|
+
...face.rings.map((r, i) => ellipse(r.diameter.value, r.height?.value, line(i, r.diameter.value, r.line), r.value, r.shape)),
|
|
42
|
+
...(inner
|
|
43
|
+
? [
|
|
44
|
+
ellipse(inner.diameter.value, inner.height?.value, line(face.rings.length, inner.diameter.value), undefined, stadium),
|
|
45
|
+
]
|
|
46
|
+
: []),
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=face.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './face.ts';
|
package/package.json
CHANGED
|
@@ -1,11 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rangefoundry/svg-drawings",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Figure models of cartridges, bullets, seating and target faces, without a renderer.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"reloading",
|
|
7
|
+
"ballistics",
|
|
8
|
+
"cartridge",
|
|
9
|
+
"drawing",
|
|
10
|
+
"svg"
|
|
11
|
+
],
|
|
12
|
+
"license": "AGPL-3.0-or-later",
|
|
13
|
+
"homepage": "https://rangefoundry.github.io/workbench/docs/libraries/drawing/",
|
|
5
14
|
"repository": {
|
|
6
15
|
"type": "git",
|
|
7
16
|
"url": "git+https://github.com/RangeFoundry/workbench.git",
|
|
8
17
|
"directory": "packages/svg-drawings"
|
|
9
18
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"main": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./cartridge": {
|
|
34
|
+
"types": "./dist/cartridge/index.d.ts",
|
|
35
|
+
"default": "./dist/cartridge/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./bullet": {
|
|
38
|
+
"types": "./dist/bullet/index.d.ts",
|
|
39
|
+
"default": "./dist/bullet/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./seating": {
|
|
42
|
+
"types": "./dist/seating/index.d.ts",
|
|
43
|
+
"default": "./dist/seating/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./target": {
|
|
46
|
+
"types": "./dist/target/index.d.ts",
|
|
47
|
+
"default": "./dist/target/index.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"!dist/**/*.map",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
],
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@rangefoundry/catalog": "0.1.0",
|
|
57
|
+
"@types/node": "26.6.6",
|
|
58
|
+
"@vitest/coverage-v8": "5.1.1",
|
|
59
|
+
"typescript": "7.0.2",
|
|
60
|
+
"vitest": "5.1.1"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsc -p tsconfig.build.json",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "vitest run --coverage"
|
|
66
|
+
}
|
|
67
|
+
}
|