@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,683 @@
|
|
|
1
|
+
import { deg, lengthText } from '../core/units.js';
|
|
2
|
+
import { closedEdges, pairs } from '../core/vector.js';
|
|
3
|
+
/** Assumed boat-tail half angle, degrees, when the bullet gives only the tail length. */
|
|
4
|
+
export const assumedBoatTailAngle = 8;
|
|
5
|
+
const isHollow = (type) => type === 'conical-hollow-base' || type === 'rounded-hollow-base';
|
|
6
|
+
const flatTips = new Set(['hollow-point', 'open-meplat', 'soft-point']);
|
|
7
|
+
const forms = new Set(['tangent', 'secant', 'hybrid', 'round-nose', 'flat-nose']);
|
|
8
|
+
/** Curved parts are sampled in this many steps (z steps for arcs, angle steps for a round nose). */
|
|
9
|
+
const steps = 24;
|
|
10
|
+
/** Allowed misfit of tail + bearing + nose against the length: three values rounded to 0.001 in. */
|
|
11
|
+
const lengthTolerance = 0.05;
|
|
12
|
+
const angleTolerance = 0.5;
|
|
13
|
+
const ratioTolerance = 0.01;
|
|
14
|
+
const worst = (...tags) => tags.includes('approximate')
|
|
15
|
+
? 'approximate'
|
|
16
|
+
: tags.includes('derived')
|
|
17
|
+
? 'derived'
|
|
18
|
+
: (tags[0] ?? 'derived');
|
|
19
|
+
const mm = (x) => `${+x.toFixed(3)} mm`;
|
|
20
|
+
/** A length in mm written in `unit`: mm to 3 decimals, inches as the figure labels write them. */
|
|
21
|
+
const inUnit = (unit) => unit === 'mm' ? mm : (x) => `${lengthText(x, 'in')} in`;
|
|
22
|
+
/** Twice the signed area of the triangle p, q, s. */
|
|
23
|
+
export const triangleArea2 = (p, q, s) => (q[0] - p[0]) * (s[1] - p[1]) - (q[1] - p[1]) * (s[0] - p[0]);
|
|
24
|
+
const within = (p, q, s) => Math.min(p[0], q[0]) - 1e-12 <= s[0] &&
|
|
25
|
+
s[0] <= Math.max(p[0], q[0]) + 1e-12 &&
|
|
26
|
+
Math.min(p[1], q[1]) - 1e-12 <= s[1] &&
|
|
27
|
+
s[1] <= Math.max(p[1], q[1]) + 1e-12;
|
|
28
|
+
/** Whether two closed segments meet. */
|
|
29
|
+
function meet(p1, p2, p3, p4) {
|
|
30
|
+
const eps = 1e-12;
|
|
31
|
+
const [d1, d2, d3, d4] = [
|
|
32
|
+
triangleArea2(p3, p4, p1),
|
|
33
|
+
triangleArea2(p3, p4, p2),
|
|
34
|
+
triangleArea2(p1, p2, p3),
|
|
35
|
+
triangleArea2(p1, p2, p4),
|
|
36
|
+
];
|
|
37
|
+
if (((d1 > eps && d2 < -eps) || (d1 < -eps && d2 > eps)) &&
|
|
38
|
+
((d3 > eps && d4 < -eps) || (d3 < -eps && d4 > eps)))
|
|
39
|
+
return true;
|
|
40
|
+
return ((Math.abs(d1) <= eps && within(p3, p4, p1)) ||
|
|
41
|
+
(Math.abs(d2) <= eps && within(p3, p4, p2)) ||
|
|
42
|
+
(Math.abs(d3) <= eps && within(p1, p2, p3)) ||
|
|
43
|
+
(Math.abs(d4) <= eps && within(p1, p2, p4)));
|
|
44
|
+
}
|
|
45
|
+
/** Whether the half profile, closed along the axis, crosses or touches itself away from shared corners. */
|
|
46
|
+
export function profileCrossesItself(points) {
|
|
47
|
+
const edges = closedEdges(points);
|
|
48
|
+
for (const [i, ei] of edges.entries())
|
|
49
|
+
for (const [j, ej] of edges.entries()) {
|
|
50
|
+
if (j < i + 2 || (i === 0 && j === edges.length - 1))
|
|
51
|
+
continue;
|
|
52
|
+
if (meet(...ei, ...ej))
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Bullet outline from the given dimensions; stated proportions stand in for missing ones and
|
|
59
|
+
* are named in the notes. Input that cannot form an outline returns a reason. Ogive radius and
|
|
60
|
+
* Rt/R as defined by McCoy, ARBRL-TR-02293, 1981, PDF p. 13. A refusal and the notes write their
|
|
61
|
+
* lengths in `unit`.
|
|
62
|
+
*/
|
|
63
|
+
export function bulletOutline(b, given = 'sourced', unit = 'mm') {
|
|
64
|
+
const o = outlineOf(b, given, inUnit(unit));
|
|
65
|
+
return 'reason' in o ? { reason: o.reason(inUnit(unit)), fields: o.fields } : o;
|
|
66
|
+
}
|
|
67
|
+
/** The outline of `bulletOutline` with its notes in `length`, or a refusal not yet written in a length unit. */
|
|
68
|
+
function outlineOf(b, given, length) {
|
|
69
|
+
const { diameter: d, length: L } = b;
|
|
70
|
+
if (!(d > 0) || !(L > 0))
|
|
71
|
+
return fail('The diameter and the length must be positive.', ...(d > 0 ? [] : ['diameter']), ...(L > 0 ? [] : ['length']));
|
|
72
|
+
const notes = [];
|
|
73
|
+
const front = noseFront(b, given, notes);
|
|
74
|
+
if ('reason' in front)
|
|
75
|
+
return front;
|
|
76
|
+
const { base, n, nTag, z0, m, mTag, curve, noseTag } = front;
|
|
77
|
+
const tip = tipSplit(b, n, noseTag, notes);
|
|
78
|
+
if (tip && 'reason' in tip)
|
|
79
|
+
return tip;
|
|
80
|
+
const mouth = hollowPointMouth(b, m, given, notes);
|
|
81
|
+
if ('reason' in mouth)
|
|
82
|
+
return mouth;
|
|
83
|
+
const groove = cannelureGeometry(b, base.t, z0, notes);
|
|
84
|
+
if (groove && 'reason' in groove)
|
|
85
|
+
return groove;
|
|
86
|
+
const cavity = cavityGeometry(b, base.rb, notes);
|
|
87
|
+
if (cavity && 'reason' in cavity)
|
|
88
|
+
return cavity;
|
|
89
|
+
const assembled = assemblePoints({
|
|
90
|
+
given,
|
|
91
|
+
a: d / 2,
|
|
92
|
+
L,
|
|
93
|
+
base,
|
|
94
|
+
cavity,
|
|
95
|
+
groove,
|
|
96
|
+
z0,
|
|
97
|
+
nTag,
|
|
98
|
+
noseTag,
|
|
99
|
+
samples: noseSamples(curve, noseTag, tip),
|
|
100
|
+
rAt: curve.rAt,
|
|
101
|
+
m,
|
|
102
|
+
mTag,
|
|
103
|
+
...mouth,
|
|
104
|
+
});
|
|
105
|
+
return closeOutline(assembled, {
|
|
106
|
+
cavity,
|
|
107
|
+
tip,
|
|
108
|
+
n,
|
|
109
|
+
nTag,
|
|
110
|
+
bearingLength: z0 - base.t,
|
|
111
|
+
L,
|
|
112
|
+
notes: notes.map((n) => (typeof n === 'string' ? n : n(length))),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** The base, nose length, meplat and nose curve of a bullet: everything up to the tip and the groove. */
|
|
116
|
+
function noseFront(b, given, notes) {
|
|
117
|
+
const base = baseGeometry(b, given, notes);
|
|
118
|
+
if ('reason' in base)
|
|
119
|
+
return base;
|
|
120
|
+
const nose = noseLengthOf(b, base, notes);
|
|
121
|
+
if ('reason' in nose)
|
|
122
|
+
return nose;
|
|
123
|
+
const { n, nTag } = nose;
|
|
124
|
+
const form = b.ogive?.form;
|
|
125
|
+
if (form !== undefined && !forms.has(form))
|
|
126
|
+
return fail(`Unknown nose form ${form}.`, 'ogive.form');
|
|
127
|
+
const meplat = meplatRadius(b, given, notes);
|
|
128
|
+
if ('reason' in meplat)
|
|
129
|
+
return meplat;
|
|
130
|
+
const { m, mTag } = meplat;
|
|
131
|
+
const curve = noseCurve(b, n, m, notes);
|
|
132
|
+
if ('reason' in curve)
|
|
133
|
+
return curve;
|
|
134
|
+
const noseTag = worst(nTag, mTag, curve.formTag);
|
|
135
|
+
return { base, n, nTag, z0: b.length - n, m, mTag, curve, noseTag };
|
|
136
|
+
}
|
|
137
|
+
/** The nose sample z values with their tags: the curve's, its extra ones and the tip start. */
|
|
138
|
+
function noseSamples(curve, noseTag, tip) {
|
|
139
|
+
const samples = new Map(curve.zs.map((z) => [z, noseTag]));
|
|
140
|
+
for (const [z, tag] of [...curve.extra, ...(tip ? [[tip.tipStart, tip.tag]] : [])])
|
|
141
|
+
samples.set(z, tag);
|
|
142
|
+
return samples;
|
|
143
|
+
}
|
|
144
|
+
/** The outline from its assembled points, or a refusal when the section crosses itself. */
|
|
145
|
+
function closeOutline({ points, tags, segments, approximate, baseEdge }, { cavity, tip, n, nTag, bearingLength, L, notes, }) {
|
|
146
|
+
// section polygon closed along the axis; the full section mirrors it
|
|
147
|
+
if (profileCrossesItself(points))
|
|
148
|
+
return fail('The outline crosses itself: check the nose, tail, groove and tip lengths.', 'noseLength', 'base.length', 'cannelure.start', 'tip.length');
|
|
149
|
+
const { area, areaCentreZ } = sectionProperties(points);
|
|
150
|
+
return {
|
|
151
|
+
points,
|
|
152
|
+
tags,
|
|
153
|
+
segments,
|
|
154
|
+
approximate,
|
|
155
|
+
baseEdge,
|
|
156
|
+
...(cavity && {
|
|
157
|
+
cavity: { radius: cavity.radius, depth: cavity.depth, typed: cavity.typed },
|
|
158
|
+
}),
|
|
159
|
+
noseLength: n,
|
|
160
|
+
noseAssumed: nTag === 'approximate',
|
|
161
|
+
bearingLength,
|
|
162
|
+
volume: revolutionVolume(points, L),
|
|
163
|
+
area,
|
|
164
|
+
areaCentreZ,
|
|
165
|
+
...(tip && { tipStart: tip.tipStart }),
|
|
166
|
+
notes,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const fail = (reason, ...fields) => ({
|
|
170
|
+
reason: typeof reason === 'string' ? () => reason : reason,
|
|
171
|
+
fields,
|
|
172
|
+
});
|
|
173
|
+
const tan = (x) => Math.tan(x * deg);
|
|
174
|
+
const noBoatTail = (gd) => fail((l) => `The base diameter ${l(gd)} leaves no boat tail.`, 'base.diameter', 'diameter');
|
|
175
|
+
/** Length and diameter given; the angle, if given too, must agree with them. */
|
|
176
|
+
function tailFromLengthDiameter({ ga, ac, given, start }, gl, gd) {
|
|
177
|
+
const rb = gd / 2;
|
|
178
|
+
if (!(rb < ac))
|
|
179
|
+
return noBoatTail(gd);
|
|
180
|
+
const implied = Math.atan((ac - rb) / gl) / deg;
|
|
181
|
+
if (ga !== undefined && Math.abs(implied - ga) > angleTolerance)
|
|
182
|
+
return fail((l) => `The base length ${l(gl)}, base diameter ${l(gd)} and angle ${ga} degrees disagree: length and diameter give ${implied.toFixed(2)} degrees.`, 'base.angle', 'base.length', 'base.diameter');
|
|
183
|
+
return { ...start, t: gl, rb, rbTag: given };
|
|
184
|
+
}
|
|
185
|
+
function tailFromLengthAngle({ ac, start }, gl, ga) {
|
|
186
|
+
const rb = ac - gl * tan(ga);
|
|
187
|
+
if (!(rb > 0))
|
|
188
|
+
return fail((l) => `The base length ${l(gl)} at ${ga} degrees leaves no base.`, 'base.length', 'base.angle');
|
|
189
|
+
return { ...start, t: gl, rb, rbTag: 'derived' };
|
|
190
|
+
}
|
|
191
|
+
function tailFromDiameterAngle({ ac, given, start }, gd, ga) {
|
|
192
|
+
const rb = gd / 2;
|
|
193
|
+
if (!(rb < ac))
|
|
194
|
+
return noBoatTail(gd);
|
|
195
|
+
return { ...start, rb, rbTag: given, t: (ac - rb) / tan(ga), tTag: 'derived' };
|
|
196
|
+
}
|
|
197
|
+
function tailFromLength({ ac, start }, gl, a, notes) {
|
|
198
|
+
notes.push(`Boat tail drawn at an assumed ${assumedBoatTailAngle} degree angle.`);
|
|
199
|
+
return { ...start, t: gl, rb: Math.max(ac - gl * tan(assumedBoatTailAngle), 0.5 * a) };
|
|
200
|
+
}
|
|
201
|
+
function tailFromDiameter({ ac, given, start }, gd, notes) {
|
|
202
|
+
const rb = gd / 2;
|
|
203
|
+
if (!(rb < ac))
|
|
204
|
+
return noBoatTail(gd);
|
|
205
|
+
notes.push(`The boat tail length is drawn from the base diameter at an assumed ${assumedBoatTailAngle} degree angle.`);
|
|
206
|
+
return {
|
|
207
|
+
...start,
|
|
208
|
+
rb,
|
|
209
|
+
rbTag: given,
|
|
210
|
+
t: (ac - rb) / tan(assumedBoatTailAngle),
|
|
211
|
+
tTag: 'approximate',
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/** The boat tail from the given length, diameter and angle; assumed values are named in `notes`. */
|
|
215
|
+
function boatTail(c, a, notes) {
|
|
216
|
+
const { gl, gd, ga } = c;
|
|
217
|
+
if (gl !== undefined && gd !== undefined)
|
|
218
|
+
return tailFromLengthDiameter(c, gl, gd);
|
|
219
|
+
if (gl !== undefined && ga !== undefined)
|
|
220
|
+
return tailFromLengthAngle(c, gl, ga);
|
|
221
|
+
if (gd !== undefined && ga !== undefined)
|
|
222
|
+
return tailFromDiameterAngle(c, gd, ga);
|
|
223
|
+
if (gl !== undefined)
|
|
224
|
+
return tailFromLength(c, gl, a, notes);
|
|
225
|
+
if (gd !== undefined)
|
|
226
|
+
return tailFromDiameter(c, gd, notes);
|
|
227
|
+
notes.push('The record has no boat tail length: the base is drawn flat.');
|
|
228
|
+
return c.start;
|
|
229
|
+
}
|
|
230
|
+
/** Refusal of a base length, diameter or angle outside what a base can have. */
|
|
231
|
+
function baseInputRefusal(d, gl, gd, ga) {
|
|
232
|
+
if (gd !== undefined && !(gd > 0 && gd < d))
|
|
233
|
+
return fail((l) => `The base diameter ${l(gd)} is not between 0 and the diameter ${l(d)}.`, 'base.diameter', 'diameter');
|
|
234
|
+
if (ga !== undefined && !(ga > 0 && ga < 90))
|
|
235
|
+
return fail(`The boat-tail angle ${ga} degrees is not between 0 and 90.`, 'base.angle');
|
|
236
|
+
if (gl !== undefined && !(gl >= 0))
|
|
237
|
+
return fail('The base length must not be negative.', 'base.length');
|
|
238
|
+
}
|
|
239
|
+
/** A boat tail or a flat face: a hollow base takes the boat-tail dimensions where it gives any. */
|
|
240
|
+
function baseKinds(type, gl, gd, ga) {
|
|
241
|
+
const tailType = type === 'boat-tail' ||
|
|
242
|
+
type === 'rebated-boat-tail' ||
|
|
243
|
+
(isHollow(type) && (gl !== undefined || gd !== undefined || ga !== undefined));
|
|
244
|
+
const flatFaced = type === 'flat' || (isHollow(type) && !tailType);
|
|
245
|
+
return { tailType, flatFaced };
|
|
246
|
+
}
|
|
247
|
+
/** The boat tail of a base type with one, with a rebate's depth where the type has it. */
|
|
248
|
+
function shapedTail(b, given, start, notes) {
|
|
249
|
+
let s = 0;
|
|
250
|
+
if (b.base?.type === 'rebated-boat-tail') {
|
|
251
|
+
s = 0.015 * b.diameter;
|
|
252
|
+
notes.push((l) => `The rebate depth is assumed: 0.015 d, ${l(s)}.`);
|
|
253
|
+
}
|
|
254
|
+
const { length: gl, diameter: gd, angle: ga } = b.base ?? {};
|
|
255
|
+
const a = b.diameter / 2;
|
|
256
|
+
const shaped = boatTail({ gl, gd, ga, ac: a - s, given, start: { ...start, s } }, a, notes);
|
|
257
|
+
if ('reason' in shaped)
|
|
258
|
+
return shaped;
|
|
259
|
+
return shaped.t === 0 ? { ...shaped, rb: a, s: 0 } : shaped;
|
|
260
|
+
}
|
|
261
|
+
/** A base without a boat tail: flat, with a note where the record names no flat base. */
|
|
262
|
+
function unshapedTail(start, flatFaced, gl, notes) {
|
|
263
|
+
if (!flatFaced)
|
|
264
|
+
notes.push(gl === undefined
|
|
265
|
+
? 'The record has no base type: the base is drawn flat.'
|
|
266
|
+
: (l) => `The record gives a base length of ${l(gl)} without a base type: the base is drawn flat.`);
|
|
267
|
+
return start;
|
|
268
|
+
}
|
|
269
|
+
/** The base from the base type, length, diameter and angle; assumed values are named in `notes`. */
|
|
270
|
+
function baseGeometry(b, given, notes) {
|
|
271
|
+
const { diameter: d, length: L } = b;
|
|
272
|
+
const a = d / 2;
|
|
273
|
+
// base: tail length t, base edge radius rb, cone top radius ac (below a for a rebate)
|
|
274
|
+
const type = b.base?.type;
|
|
275
|
+
const gl = b.base?.length;
|
|
276
|
+
const gd = b.base?.diameter;
|
|
277
|
+
const ga = b.base?.angle;
|
|
278
|
+
const { tailType, flatFaced } = baseKinds(type, gl, gd, ga);
|
|
279
|
+
const refusal = baseInputRefusal(d, gl, gd, ga);
|
|
280
|
+
if (refusal)
|
|
281
|
+
return refusal;
|
|
282
|
+
const start = { t: 0, rb: a, s: 0, tTag: given, rbTag: flatFaced ? given : 'approximate' };
|
|
283
|
+
const tail = tailType
|
|
284
|
+
? shapedTail(b, given, start, notes)
|
|
285
|
+
: unshapedTail(start, flatFaced, gl, notes);
|
|
286
|
+
if ('reason' in tail)
|
|
287
|
+
return tail;
|
|
288
|
+
const { t, rb, s, tTag, rbTag } = tail;
|
|
289
|
+
if (!(t < L))
|
|
290
|
+
return fail((l) => `The boat tail ${l(t)} is not shorter than the length ${l(L)}.`, 'base.length', 'length');
|
|
291
|
+
const tailKnown = flatFaced || (tailType && t > 0 && tTag !== 'approximate');
|
|
292
|
+
const baseKnown = tailKnown && rbTag !== 'approximate' && s === 0;
|
|
293
|
+
return { t, rb, s, tTag, rbTag, tailKnown, baseKnown };
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The bracket of the depth of a cavity whose depth is not given, as multiples of its radius: half
|
|
297
|
+
* to three times the assumed depth. An assumption without a source (no maker publishes a depth).
|
|
298
|
+
*/
|
|
299
|
+
export const cavityDepthBracket = Object.freeze({ low: 0.5, high: 3 });
|
|
300
|
+
/** The cavity of a hollow base type with a cavity diameter; none otherwise. */
|
|
301
|
+
function cavityGeometry(b, rb, notes) {
|
|
302
|
+
const type = b.base?.type;
|
|
303
|
+
if (!isHollow(type))
|
|
304
|
+
return;
|
|
305
|
+
const cd = b.base?.cavityDiameter;
|
|
306
|
+
if (cd === undefined) {
|
|
307
|
+
notes.push('The record has no cavity diameter: the base is drawn without a cavity.');
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const r = cd / 2;
|
|
311
|
+
if (!(r > 0 && r < rb))
|
|
312
|
+
return fail((l) => `The cavity diameter ${l(cd)} is not between 0 and the base diameter ${l(2 * rb)}.`, 'base.cavityDiameter', 'base.diameter', 'diameter');
|
|
313
|
+
const typed = b.base?.cavityDepth;
|
|
314
|
+
if (typed !== undefined && !(typed > 0))
|
|
315
|
+
return fail('The cavity depth must be positive.', 'base.cavityDepth');
|
|
316
|
+
const h = typed ?? r;
|
|
317
|
+
if (!(h < b.length))
|
|
318
|
+
return fail((l) => `The cavity depth ${l(h)} is not below the length ${l(b.length)}.`, typed === undefined ? 'base.cavityDiameter' : 'base.cavityDepth', 'length');
|
|
319
|
+
const cone = type === 'conical-hollow-base';
|
|
320
|
+
if (typed === undefined)
|
|
321
|
+
notes.push((l) => `The cavity depth is assumed: a ${cone ? 'cone' : 'hemisphere'} as deep as its opening is wide at its radius, ${l(r)}.`);
|
|
322
|
+
else
|
|
323
|
+
notes.push((l) => `The cavity depth is typed: ${l(h)}.`);
|
|
324
|
+
const points = cone
|
|
325
|
+
? [
|
|
326
|
+
[0, h],
|
|
327
|
+
[r, 0],
|
|
328
|
+
]
|
|
329
|
+
: Array.from({ length: steps + 1 }, (_, j) => j === steps
|
|
330
|
+
? [r, 0]
|
|
331
|
+
: [r * Math.sin(((j / steps) * Math.PI) / 2), h * Math.cos(((j / steps) * Math.PI) / 2)]);
|
|
332
|
+
return { radius: r, depth: h, typed: typed !== undefined, points };
|
|
333
|
+
}
|
|
334
|
+
/** The nose length n: given, else the length less tail and bearing, else assumed. */
|
|
335
|
+
function noseLengthOf(b, { t, tailKnown }, notes) {
|
|
336
|
+
const { diameter: d, length: L } = b;
|
|
337
|
+
const bearing = b.bearingLength;
|
|
338
|
+
if (b.noseLength !== undefined) {
|
|
339
|
+
const n = b.noseLength;
|
|
340
|
+
if (!(n > 0))
|
|
341
|
+
return fail('The nose length must be positive.', 'noseLength');
|
|
342
|
+
if (n > L - t + 1e-9)
|
|
343
|
+
return fail((l) => `The nose length ${l(n)} is above the length less the boat tail, ${l(L - t)}.`, 'noseLength', 'length', 'base.length');
|
|
344
|
+
if (bearing !== undefined && tailKnown && Math.abs(t + bearing + n - L) > lengthTolerance)
|
|
345
|
+
return fail((l) => `Boat tail ${l(t)}, bearing ${l(bearing)} and nose ${l(n)} do not add up to the length ${l(L)}.`, 'noseLength', 'bearingLength', 'length', 'base.length');
|
|
346
|
+
return { n, nTag: 'derived' };
|
|
347
|
+
}
|
|
348
|
+
if (bearing !== undefined && tailKnown) {
|
|
349
|
+
const n = L - t - bearing;
|
|
350
|
+
if (!(n > 0))
|
|
351
|
+
return fail((l) => `Boat tail ${l(t)} and bearing ${l(bearing)} leave no nose of the length ${l(L)}.`, 'bearingLength', 'length', 'base.length');
|
|
352
|
+
return { n, nTag: 'derived' };
|
|
353
|
+
}
|
|
354
|
+
const n = Math.min(Math.min(2 * d, 0.6 * L), L - t);
|
|
355
|
+
notes.push((l) => `The record has no nose length: an assumed nose of ${l(n)} is drawn and no jump is given.`);
|
|
356
|
+
return { n, nTag: 'approximate' };
|
|
357
|
+
}
|
|
358
|
+
/** The meplat radius m: given, else a share of the diameter for a flat nose or a flat tip. */
|
|
359
|
+
function meplatRadius(b, given, notes) {
|
|
360
|
+
const d = b.diameter;
|
|
361
|
+
const form = b.ogive?.form;
|
|
362
|
+
const tipType = b.tip?.type ?? '';
|
|
363
|
+
const md = b.meplatDiameter;
|
|
364
|
+
if (md !== undefined) {
|
|
365
|
+
if (!(md >= 0 && md < d))
|
|
366
|
+
return fail((l) => `The meplat diameter ${l(md)} is not below the diameter ${l(d)}.`, 'meplatDiameter', 'diameter');
|
|
367
|
+
return { m: md / 2, mTag: given };
|
|
368
|
+
}
|
|
369
|
+
const share = form === 'flat-nose' ? 0.6 : flatTips.has(tipType) ? 0.15 : 0;
|
|
370
|
+
if (share)
|
|
371
|
+
notes.push(`The meplat is assumed: ${share} d.`);
|
|
372
|
+
return { m: (share * d) / 2, mTag: 'approximate' };
|
|
373
|
+
}
|
|
374
|
+
/** Refusal of an ogive radius or Rt/R that is out of range or disagrees with the other. */
|
|
375
|
+
function ogiveInputRefusal(radius, ratio, fromRadius) {
|
|
376
|
+
if (radius !== undefined && !(radius > 0))
|
|
377
|
+
return fail('The ogive radius must be positive.', 'ogive.radius');
|
|
378
|
+
if (ratio !== undefined && !(ratio >= 0 && ratio <= 1))
|
|
379
|
+
return fail(`Rt/R ${ratio} is not between 0 and 1.`, 'ogive.radiusRatio');
|
|
380
|
+
if (ratio !== undefined &&
|
|
381
|
+
fromRadius !== undefined &&
|
|
382
|
+
Math.abs(ratio - fromRadius) > ratioTolerance)
|
|
383
|
+
return fail((l) => `The ogive radius ${l(radius)} gives Rt/R ${fromRadius.toFixed(3)}, not the given ${ratio}.`, 'ogive.radiusRatio', 'ogive.radius');
|
|
384
|
+
}
|
|
385
|
+
/** At most 1 (1 a tangent ogive), with the tag of its form; assumed values are named in `notes`. */
|
|
386
|
+
function ogiveRatio(form, given, { n, k, rt }, notes) {
|
|
387
|
+
let q = given;
|
|
388
|
+
let formTag = 'derived';
|
|
389
|
+
if (q !== undefined && q > 1 + ratioTolerance)
|
|
390
|
+
return fail((l) => `The ogive radius is below the tangent radius ${l(rt)}: the nose would rise above the shank.`, 'ogive.radius', 'ogive.radiusRatio', 'noseLength');
|
|
391
|
+
if (form === 'tangent' && q !== undefined && Math.abs(q - 1) > ratioTolerance)
|
|
392
|
+
return fail(`A tangent ogive has Rt/R 1, not ${q.toFixed(3)}.`, 'ogive.radiusRatio', 'ogive.radius', 'ogive.form');
|
|
393
|
+
if (form === undefined && q === undefined) {
|
|
394
|
+
formTag = 'approximate';
|
|
395
|
+
notes.push('The nose is drawn as an assumed tangent ogive.');
|
|
396
|
+
}
|
|
397
|
+
if ((form === 'secant' || form === 'hybrid') && q === undefined) {
|
|
398
|
+
q = 0.5;
|
|
399
|
+
formTag = 'approximate';
|
|
400
|
+
notes.push(`The ${form} ogive radius is assumed: Rt/R 0.5.`);
|
|
401
|
+
}
|
|
402
|
+
q = Math.min(q ?? 1, 1);
|
|
403
|
+
if (q > 0 && n < k - 1e-9)
|
|
404
|
+
return fail((l) => `The nose length ${l(n)} is below its radial drop ${l(k)}: no ogive reaches the meplat.`, 'noseLength', 'meplatDiameter');
|
|
405
|
+
return { used: q, formTag };
|
|
406
|
+
}
|
|
407
|
+
/** The circle arc through `o` of radius `r` as r(z). */
|
|
408
|
+
const arcAt = (o, r) => (z) => o[0] + Math.sqrt(Math.max(r ** 2 - (z - o[1]) ** 2, 0));
|
|
409
|
+
/** A blend arc tangent to the shank, then a secant arc of radius R tangent to it through the meplat edge. */
|
|
410
|
+
function hybridNose({ L, a, z0, m, rt, R }, zSteps, formTag, notes) {
|
|
411
|
+
const r1 = rt / 2;
|
|
412
|
+
const c1 = [a - r1, z0];
|
|
413
|
+
const D = [m - c1[0], L - c1[1]];
|
|
414
|
+
const dl = Math.hypot(...D);
|
|
415
|
+
const delta = R - r1;
|
|
416
|
+
const g = (R ** 2 - delta ** 2 - dl ** 2) / (2 * delta);
|
|
417
|
+
const theta = Math.atan2(D[1], D[0]) - Math.acos(g / dl);
|
|
418
|
+
const c2 = [c1[0] - delta * Math.cos(theta), c1[1] - delta * Math.sin(theta)];
|
|
419
|
+
const tz = z0 + r1 * Math.sin(theta);
|
|
420
|
+
if (!(Math.abs(g) <= dl && theta > 0 && theta < Math.PI / 2 && tz < L && m >= c2[0] - 1e-9))
|
|
421
|
+
return fail('No hybrid nose joins the blend arc and the secant arc before the meplat.', 'ogive.radius', 'ogive.radiusRatio', 'noseLength');
|
|
422
|
+
const blend = arcAt(c1, r1);
|
|
423
|
+
const secant = arcAt(c2, R);
|
|
424
|
+
notes.push('The hybrid blend radius is assumed: half the tangent radius.');
|
|
425
|
+
return {
|
|
426
|
+
rAt: (z) => (z <= tz ? blend(z) : secant(z)),
|
|
427
|
+
zs: zSteps,
|
|
428
|
+
extra: [[tz, 'approximate']],
|
|
429
|
+
formTag,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
/** From the shank end at z0 = L - n to the meplat edge at radius m: a round nose, a cone, a secant or tangent ogive of radius R = Rt / (Rt/R), or a hybrid of a blend arc and a secant arc. */
|
|
433
|
+
function noseCurve(b, n, m, notes) {
|
|
434
|
+
const L = b.length;
|
|
435
|
+
const a = b.diameter / 2;
|
|
436
|
+
const z0 = L - n;
|
|
437
|
+
const form = b.ogive?.form;
|
|
438
|
+
const k = a - m;
|
|
439
|
+
const rt = (n ** 2 + k ** 2) / (2 * k);
|
|
440
|
+
const radius = b.ogive?.radius;
|
|
441
|
+
const ratio = b.ogive?.radiusRatio;
|
|
442
|
+
const fromRadius = radius === undefined ? undefined : rt / radius;
|
|
443
|
+
const refusal = ogiveInputRefusal(radius, ratio, fromRadius);
|
|
444
|
+
if (refusal)
|
|
445
|
+
return refusal;
|
|
446
|
+
const q = ratio ?? fromRadius;
|
|
447
|
+
if (form === 'round-nose' || form === 'flat-nose') {
|
|
448
|
+
if (q !== undefined)
|
|
449
|
+
notes.push(`A ${form} reads no ogive radius or Rt/R.`);
|
|
450
|
+
return {
|
|
451
|
+
rAt: (z) => m + k * Math.sqrt(Math.max(1 - ((z - z0) / n) ** 2, 0)),
|
|
452
|
+
zs: Array.from({ length: steps }, (_, j) => z0 + n * Math.sin(((j + 1) * Math.PI) / 2 / steps)),
|
|
453
|
+
extra: [],
|
|
454
|
+
formTag: 'derived',
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
const ogive = ogiveRatio(form, q, { n, k, rt }, notes);
|
|
458
|
+
if ('reason' in ogive)
|
|
459
|
+
return ogive;
|
|
460
|
+
const { used, formTag } = ogive;
|
|
461
|
+
const zSteps = Array.from({ length: steps }, (_, j) => z0 + (n * (j + 1)) / steps);
|
|
462
|
+
// a vanishing Rt/R is the cone; a secant circle of radius near 1e12 mm loses precision
|
|
463
|
+
if (used < 1e-6)
|
|
464
|
+
return { rAt: (z) => a - (k * (z - z0)) / n, zs: zSteps, extra: [], formTag };
|
|
465
|
+
// circle of radius R through the shank end and the meplat edge, center on the axis side
|
|
466
|
+
const R = rt / used;
|
|
467
|
+
if (form === 'hybrid')
|
|
468
|
+
return hybridNose({ L, a, z0, m, rt, R }, zSteps, formTag, notes);
|
|
469
|
+
const c = Math.hypot(k, n);
|
|
470
|
+
const h = Math.sqrt(Math.max(R ** 2 - c ** 2 / 4, 0));
|
|
471
|
+
const centre = [a - k / 2 - (h * n) / c, z0 + n / 2 - (h * k) / c];
|
|
472
|
+
return { rAt: arcAt(centre, R), zs: zSteps, extra: [], formTag };
|
|
473
|
+
}
|
|
474
|
+
/** Where a polymer tip leaves the jacket, with the tag of that sample; none without a polymer tip. */
|
|
475
|
+
function tipSplit(b, n, noseTag, notes) {
|
|
476
|
+
if (b.tip?.type !== 'polymer-tip')
|
|
477
|
+
return;
|
|
478
|
+
const tl = b.tip.length ?? 0.2 * n;
|
|
479
|
+
if (!(tl > 0 && tl < n))
|
|
480
|
+
return fail((l) => `The polymer tip length ${l(tl)} is not below the nose length ${l(n)}.`, 'tip.length', 'noseLength');
|
|
481
|
+
if (b.tip.length === undefined)
|
|
482
|
+
notes.push('The polymer tip length is assumed: 0.2 nose length.');
|
|
483
|
+
return { tipStart: b.length - tl, tag: b.tip.length === undefined ? 'approximate' : noseTag };
|
|
484
|
+
}
|
|
485
|
+
/** The hollow-point mouth radius on the meplat line, 0 without a hollow point. */
|
|
486
|
+
function hollowPointMouth(b, m, given, notes) {
|
|
487
|
+
let mouth = 0;
|
|
488
|
+
let mouthTag = given;
|
|
489
|
+
if (b.tip?.type === 'hollow-point') {
|
|
490
|
+
if (b.tip.mouthDiameter !== undefined)
|
|
491
|
+
mouth = b.tip.mouthDiameter / 2;
|
|
492
|
+
else {
|
|
493
|
+
mouth = 0.5 * m;
|
|
494
|
+
mouthTag = 'approximate';
|
|
495
|
+
if (m > 0)
|
|
496
|
+
notes.push('The hollow-point mouth is assumed: 0.5 meplat.');
|
|
497
|
+
}
|
|
498
|
+
if (mouth > m + 1e-9)
|
|
499
|
+
return fail((l) => `The hollow-point mouth ${l(2 * mouth)} is wider than the meplat ${l(2 * m)}.`, 'tip.mouthDiameter', 'meplatDiameter');
|
|
500
|
+
}
|
|
501
|
+
return { mouth, mouthTag };
|
|
502
|
+
}
|
|
503
|
+
/** The cannelure, which must lie on the shank between t and z0; none without one. */
|
|
504
|
+
function cannelureGeometry(b, t, z0, notes) {
|
|
505
|
+
const cn = b.cannelure;
|
|
506
|
+
if (!cn)
|
|
507
|
+
return;
|
|
508
|
+
const groove = {
|
|
509
|
+
start: cn.start,
|
|
510
|
+
width: cn.width,
|
|
511
|
+
depth: cn.depth ?? 0.02 * b.diameter,
|
|
512
|
+
assumed: cn.depth === undefined,
|
|
513
|
+
};
|
|
514
|
+
if (!(groove.width > 0 && groove.depth > 0 && groove.depth < b.diameter / 2))
|
|
515
|
+
return fail('The cannelure needs a positive width and a depth below the radius.', 'cannelure.width', 'cannelure.depth');
|
|
516
|
+
if (groove.start < t + 1e-9 || groove.start + groove.width > z0 + 1e-9)
|
|
517
|
+
return fail((l) => `The cannelure is not on the shank between ${l(t)} and ${l(z0)}.`, 'cannelure.start', 'cannelure.width');
|
|
518
|
+
if (groove.assumed)
|
|
519
|
+
notes.push('The cannelure depth is assumed: 0.02 d.');
|
|
520
|
+
return groove;
|
|
521
|
+
}
|
|
522
|
+
/** A cavity's wall runs down from its apex to the base face: the profile starts on the axis at the apex. */
|
|
523
|
+
function addBottom({ given, cavity }, add) {
|
|
524
|
+
if (!cavity) {
|
|
525
|
+
add([0, 0], given, false);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const wall = cavity.typed ? given : 'approximate';
|
|
529
|
+
for (const [j, p] of cavity.points.entries())
|
|
530
|
+
add(p, j === cavity.points.length - 1 ? given : wall, !cavity.typed && j > 0);
|
|
531
|
+
}
|
|
532
|
+
/** The base edge and, past it, the boat tail's end and a rebate's step. */
|
|
533
|
+
function addTail({ a, base }, add) {
|
|
534
|
+
const { t, rb, s, tTag, rbTag } = base;
|
|
535
|
+
const baseApprox = !base.baseKnown;
|
|
536
|
+
add([rb, 0], rbTag, baseApprox);
|
|
537
|
+
if (t <= 0)
|
|
538
|
+
return;
|
|
539
|
+
add([a - s, t], s > 0 ? 'approximate' : tTag, baseApprox);
|
|
540
|
+
if (s > 0)
|
|
541
|
+
add([a, t], tTag, baseApprox);
|
|
542
|
+
}
|
|
543
|
+
function addGroove({ given, a, groove }, add) {
|
|
544
|
+
if (!groove)
|
|
545
|
+
return;
|
|
546
|
+
const gTag = groove.assumed ? 'approximate' : given;
|
|
547
|
+
const z1 = groove.start + groove.width;
|
|
548
|
+
add([a, groove.start], given, false);
|
|
549
|
+
add([a - groove.depth, groove.start], gTag, gTag === 'approximate');
|
|
550
|
+
add([a - groove.depth, z1], gTag, gTag === 'approximate');
|
|
551
|
+
add([a, z1], given, gTag === 'approximate');
|
|
552
|
+
}
|
|
553
|
+
/** The nose samples up to the tip. */
|
|
554
|
+
function addNose({ L, z0, noseTag, samples, rAt, m, mTag }, add) {
|
|
555
|
+
const noseApprox = noseTag === 'approximate';
|
|
556
|
+
for (const z of [...samples.keys()].sort((x, y) => x - y)) {
|
|
557
|
+
if (z <= z0)
|
|
558
|
+
continue;
|
|
559
|
+
const atTip = z >= L - 1e-12;
|
|
560
|
+
add(atTip ? [m, L] : [rAt(z), z], atTip ? mTag : samples.get(z), noseApprox);
|
|
561
|
+
if (atTip)
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/** The hollow-point mouth and the meplat's center on the meplat line. */
|
|
566
|
+
function addMeplat({ L, given, m, mTag, mouth, mouthTag }, add) {
|
|
567
|
+
if (mouth > 0 && mouth < m)
|
|
568
|
+
add([mouth, L], mouthTag, mTag === 'approximate' || mouthTag === 'approximate');
|
|
569
|
+
if (m > 0)
|
|
570
|
+
add([0, L], given, mTag === 'approximate');
|
|
571
|
+
}
|
|
572
|
+
/** Stroked runs of the points: consecutive edges of the same kind share one run. */
|
|
573
|
+
function strokedRuns(points, edges) {
|
|
574
|
+
const segments = [];
|
|
575
|
+
for (const [k, [prev, p]] of pairs(points).entries()) {
|
|
576
|
+
const approximate = edges[k + 1] ?? false;
|
|
577
|
+
const last = segments[segments.length - 1];
|
|
578
|
+
if (last && last.approximate === approximate)
|
|
579
|
+
last.points.push(p);
|
|
580
|
+
else
|
|
581
|
+
segments.push({ points: [prev, p], approximate });
|
|
582
|
+
}
|
|
583
|
+
return segments;
|
|
584
|
+
}
|
|
585
|
+
/** From the base center (or the apex of the cavity) to the tip on the axis, each with its tag and whether the edge reaching it is approximate, plus the stroked runs, the z ranges drawn from an assumed shape and the index of the base face's edge. */
|
|
586
|
+
function assemblePoints(parts) {
|
|
587
|
+
const { a, L, base, groove, z0, nTag, noseTag } = parts;
|
|
588
|
+
const { t } = base;
|
|
589
|
+
const points = [];
|
|
590
|
+
const tags = [];
|
|
591
|
+
const edges = [];
|
|
592
|
+
const add = (p, tag, approx) => {
|
|
593
|
+
points.push(p);
|
|
594
|
+
tags.push(tag);
|
|
595
|
+
edges.push(approx);
|
|
596
|
+
};
|
|
597
|
+
const baseApprox = !base.baseKnown;
|
|
598
|
+
addBottom(parts, add);
|
|
599
|
+
const baseEdge = points.length;
|
|
600
|
+
addTail(parts, add);
|
|
601
|
+
addGroove(parts, add);
|
|
602
|
+
const tip = points[points.length - 1];
|
|
603
|
+
if (tip && (tip[1] < z0 || tip[0] < a))
|
|
604
|
+
add([a, z0], nTag === 'approximate' ? 'approximate' : 'derived', false);
|
|
605
|
+
addNose(parts, add);
|
|
606
|
+
addMeplat(parts, add);
|
|
607
|
+
const segments = strokedRuns(points, edges);
|
|
608
|
+
const noseApprox = noseTag === 'approximate';
|
|
609
|
+
// an assumed base stands in for an unknown base shape, so it taints the shank up to the nose
|
|
610
|
+
const approximate = [
|
|
611
|
+
...(baseApprox ? [[0, t || z0]] : []),
|
|
612
|
+
...(groove?.assumed ? [[groove.start, groove.start + groove.width]] : []),
|
|
613
|
+
...(noseApprox ? [[z0, L]] : []),
|
|
614
|
+
];
|
|
615
|
+
return { points, tags, segments, approximate, baseEdge };
|
|
616
|
+
}
|
|
617
|
+
/** Area of the full axial section, mm², and the z of its center, mm, of a half profile closed along the axis. */
|
|
618
|
+
function sectionProperties(points) {
|
|
619
|
+
let half = 0;
|
|
620
|
+
let moment = 0;
|
|
621
|
+
for (const [[r0, za], [r1, zb]] of closedEdges(points)) {
|
|
622
|
+
const cross = za * r1 - zb * r0;
|
|
623
|
+
half += cross / 2;
|
|
624
|
+
moment += ((za + zb) * cross) / 6;
|
|
625
|
+
}
|
|
626
|
+
return { area: 2 * Math.abs(half), areaCentreZ: moment / half };
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Volume of the solid of revolution of a half profile closed along the axis, from z = 0 to `cut`,
|
|
630
|
+
* mm³: each segment adds its frustum going up and takes it off going down, so the wall of a
|
|
631
|
+
* cavity subtracts.
|
|
632
|
+
*/
|
|
633
|
+
export function revolutionVolume(points, cut) {
|
|
634
|
+
let v = 0;
|
|
635
|
+
for (const [p, q] of pairs(points)) {
|
|
636
|
+
const up = p[1] < q[1];
|
|
637
|
+
const [[r0, z0], [r1, z1]] = up ? [p, q] : [q, p];
|
|
638
|
+
if (z1 <= z0 || z0 >= cut)
|
|
639
|
+
continue;
|
|
640
|
+
const z = Math.min(z1, cut);
|
|
641
|
+
const r = r0 + ((r1 - r0) * (z - z0)) / (z1 - z0);
|
|
642
|
+
v += ((up ? 1 : -1) * (Math.PI * (z - z0) * (r0 ** 2 + r0 * r + r ** 2))) / 3;
|
|
643
|
+
}
|
|
644
|
+
return v;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* The bullet volume below `cut` mm, mm³, with the cavity of a hollow base at the ends of
|
|
648
|
+
* {@link cavityDepthBracket}: `low` with the deepest cavity, `high` with the shallowest. Undefined
|
|
649
|
+
* without a cavity of assumed depth, with nothing below the cut, or when a bracket depth gives no
|
|
650
|
+
* outline. A deepest cavity that would reach the length is held just below it; one that would cut
|
|
651
|
+
* through the wall (a boat tail, a short shank) is made shallower, to the deepest depth whose
|
|
652
|
+
* outline holds (bisection down to the assumed depth).
|
|
653
|
+
*/
|
|
654
|
+
export function cavityVolumeBracket(b, cut) {
|
|
655
|
+
const o = bulletOutline(b);
|
|
656
|
+
if ('reason' in o || !o.cavity || o.cavity.typed || !(cut > 0))
|
|
657
|
+
return;
|
|
658
|
+
const r = o.cavity.radius;
|
|
659
|
+
const below = (depth) => {
|
|
660
|
+
const at = bulletOutline({ ...b, base: { ...b.base, cavityDepth: depth } });
|
|
661
|
+
return 'reason' in at ? undefined : revolutionVolume(at.points, Math.min(cut, b.length));
|
|
662
|
+
};
|
|
663
|
+
// the deepest depth up to the bracket's end whose outline holds: bisection from the assumed depth
|
|
664
|
+
let ok = r;
|
|
665
|
+
let bad = Math.min(cavityDepthBracket.high * r, 0.999 * b.length);
|
|
666
|
+
if (below(bad) !== undefined)
|
|
667
|
+
ok = bad;
|
|
668
|
+
else
|
|
669
|
+
for (let i = 0; i < 30 && bad - ok > 1e-6 * r; i++) {
|
|
670
|
+
const mid = (ok + bad) / 2;
|
|
671
|
+
if (below(mid) === undefined)
|
|
672
|
+
bad = mid;
|
|
673
|
+
else
|
|
674
|
+
ok = mid;
|
|
675
|
+
}
|
|
676
|
+
const low = below(ok);
|
|
677
|
+
const high = below(cavityDepthBracket.low * r);
|
|
678
|
+
return low === undefined || high === undefined ? undefined : { low, high };
|
|
679
|
+
}
|
|
680
|
+
/** Whether the bullet below `cut` mm rests on an assumed shape: an assumed range or a cavity of assumed depth. */
|
|
681
|
+
export const assumedBelow = (o, cut) => (o.cavity !== undefined && !o.cavity.typed && cut > 0) ||
|
|
682
|
+
o.approximate.some(([z0, z1]) => z1 > z0 && z0 < cut);
|
|
683
|
+
//# sourceMappingURL=outline.js.map
|