@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,76 @@
|
|
|
1
|
+
import type { Profile } from '../core/types.ts';
|
|
2
|
+
import type { LengthUnit } from '../core/units.ts';
|
|
3
|
+
import { type BaseType, type BulletDimensions, type Outline, type Refusal } from './outline.ts';
|
|
4
|
+
/** A stored quantity: the value in the stored unit and the text as printed. */
|
|
5
|
+
interface StoredQuantity {
|
|
6
|
+
value: number;
|
|
7
|
+
raw?: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
/** The bullet record fields the drawing reads; the API type of a bullet record is assignable to it. */
|
|
10
|
+
export interface BulletValues {
|
|
11
|
+
diameter?: StoredQuantity | undefined;
|
|
12
|
+
length?: StoredQuantity | undefined;
|
|
13
|
+
noseLength?: StoredQuantity | undefined;
|
|
14
|
+
baseToOgive?: StoredQuantity | undefined;
|
|
15
|
+
bearingLength?: StoredQuantity | undefined;
|
|
16
|
+
meplatDiameter?: StoredQuantity | undefined;
|
|
17
|
+
base?: {
|
|
18
|
+
type?: BaseType | undefined;
|
|
19
|
+
length?: StoredQuantity | undefined;
|
|
20
|
+
diameter?: StoredQuantity | undefined;
|
|
21
|
+
angle?: StoredQuantity | undefined;
|
|
22
|
+
cavityDiameter?: StoredQuantity | undefined;
|
|
23
|
+
cavityDepth?: StoredQuantity | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
ogive?: {
|
|
26
|
+
form?: string | undefined;
|
|
27
|
+
radius?: StoredQuantity | undefined;
|
|
28
|
+
radiusRatio?: StoredQuantity | undefined;
|
|
29
|
+
} | undefined;
|
|
30
|
+
cannelure?: {
|
|
31
|
+
start: StoredQuantity;
|
|
32
|
+
width: StoredQuantity;
|
|
33
|
+
depth?: StoredQuantity | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
tip?: {
|
|
36
|
+
type: string;
|
|
37
|
+
length?: StoredQuantity | undefined;
|
|
38
|
+
mouthDiameter?: StoredQuantity | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
provenance?: {
|
|
41
|
+
sources: {
|
|
42
|
+
title?: string | undefined;
|
|
43
|
+
fields?: string[] | undefined;
|
|
44
|
+
}[];
|
|
45
|
+
} | undefined;
|
|
46
|
+
}
|
|
47
|
+
/** A dimensioned field of a bullet drawing. */
|
|
48
|
+
interface BulletSymbol {
|
|
49
|
+
/** Drawing symbol, such as `L` or `BTO`. */
|
|
50
|
+
symbol: string;
|
|
51
|
+
/** Dot path of the field in the bullet record. */
|
|
52
|
+
path: string;
|
|
53
|
+
/** Name of the field in labels. */
|
|
54
|
+
name: string;
|
|
55
|
+
}
|
|
56
|
+
/** The drawing symbol of each dimensioned field, its record path and its name. */
|
|
57
|
+
export declare const bulletSymbols: readonly BulletSymbol[];
|
|
58
|
+
/** The shape `bulletOutline` reads, in mm and degrees; undefined without a length or a diameter. */
|
|
59
|
+
export declare function bulletDimensions(r: BulletValues): BulletDimensions | undefined;
|
|
60
|
+
/** The title of the source that covers a field: one without `fields` covers the whole record; none without provenance. */
|
|
61
|
+
export declare const sourceTitle: (r: BulletValues, field: string) => string | undefined;
|
|
62
|
+
/** The profile of a bullet in mm and degrees, with its outline and the fields left undimensioned. */
|
|
63
|
+
export interface BulletProfile extends Profile {
|
|
64
|
+
outline: Outline;
|
|
65
|
+
/** Names of the stored fields that are not dimensioned. */
|
|
66
|
+
undimensioned: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The outline of a bullet and the dimensions of the values `sourced` covers that the drawn
|
|
70
|
+
* outline follows: a value the outline replaced, assumed or derived is never dimensioned. A
|
|
71
|
+
* refusal writes its lengths in `unit`.
|
|
72
|
+
*/
|
|
73
|
+
export declare function bulletProfile(shape: BulletDimensions, sourced: (field: string) => boolean, given?: 'sourced' | 'entered', unit?: LengthUnit): BulletProfile | Refusal;
|
|
74
|
+
/** The profile of a record: its shape, with the fields its sources cover. */
|
|
75
|
+
export declare function recordProfile(r: BulletValues): BulletProfile | Refusal;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { bulletOutline, } from './outline.js';
|
|
2
|
+
/** The drawing symbol of each dimensioned field, its record path and its name. */
|
|
3
|
+
export const bulletSymbols = [
|
|
4
|
+
{ symbol: 'L', path: 'length', name: 'length' },
|
|
5
|
+
{ symbol: 'd', path: 'diameter', name: 'diameter' },
|
|
6
|
+
{ symbol: 'n', path: 'noseLength', name: 'nose length' },
|
|
7
|
+
{ symbol: 'b', path: 'bearingLength', name: 'bearing length' },
|
|
8
|
+
{ symbol: 't', path: 'base.length', name: 'boat-tail length' },
|
|
9
|
+
{ symbol: 'db', path: 'base.diameter', name: 'base diameter' },
|
|
10
|
+
{ symbol: 'dc', path: 'base.cavityDiameter', name: 'cavity diameter' },
|
|
11
|
+
{ symbol: 'dm', path: 'meplatDiameter', name: 'meplat diameter' },
|
|
12
|
+
{ symbol: 'dh', path: 'tip.mouthDiameter', name: 'hollow-point mouth diameter' },
|
|
13
|
+
{ symbol: 'R', path: 'ogive.radius', name: 'ogive radius' },
|
|
14
|
+
{ symbol: 'Rt/R', path: 'ogive.radiusRatio', name: 'ogive radius ratio' },
|
|
15
|
+
{ symbol: 'lt', path: 'tip.length', name: 'tip length' },
|
|
16
|
+
{ symbol: 'BTO', path: 'baseToOgive', name: 'base to ogive' },
|
|
17
|
+
{ symbol: 'c', path: 'cannelure.start', name: 'cannelure start' },
|
|
18
|
+
{ symbol: 'w', path: 'cannelure.width', name: 'cannelure width' },
|
|
19
|
+
];
|
|
20
|
+
/** Stored fields the drawing reads but never dimensions. */
|
|
21
|
+
const undimensionable = [
|
|
22
|
+
{ path: 'base.angle', name: 'boat-tail angle' },
|
|
23
|
+
{ path: 'base.cavityDepth', name: 'cavity depth' },
|
|
24
|
+
];
|
|
25
|
+
const baseDimensions = (base) => ({
|
|
26
|
+
...(base.type && { type: base.type }),
|
|
27
|
+
...(base.length && { length: base.length.value }),
|
|
28
|
+
...(base.diameter && { diameter: base.diameter.value }),
|
|
29
|
+
...(base.angle && { angle: base.angle.value }),
|
|
30
|
+
...(base.cavityDiameter && { cavityDiameter: base.cavityDiameter.value }),
|
|
31
|
+
...(base.cavityDepth && { cavityDepth: base.cavityDepth.value }),
|
|
32
|
+
});
|
|
33
|
+
const ogiveDimensions = (ogive) => ({
|
|
34
|
+
...(ogive.form && { form: ogive.form }),
|
|
35
|
+
...(ogive.radius && { radius: ogive.radius.value }),
|
|
36
|
+
...(ogive.radiusRatio && { radiusRatio: ogive.radiusRatio.value }),
|
|
37
|
+
});
|
|
38
|
+
const cannelureDimensions = (cannelure) => ({
|
|
39
|
+
start: cannelure.start.value,
|
|
40
|
+
width: cannelure.width.value,
|
|
41
|
+
...(cannelure.depth && { depth: cannelure.depth.value }),
|
|
42
|
+
});
|
|
43
|
+
const tipDimensions = (tip) => ({
|
|
44
|
+
type: tip.type,
|
|
45
|
+
...(tip.length && { length: tip.length.value }),
|
|
46
|
+
...(tip.mouthDiameter && { mouthDiameter: tip.mouthDiameter.value }),
|
|
47
|
+
});
|
|
48
|
+
/** The shape `bulletOutline` reads, in mm and degrees; undefined without a length or a diameter. */
|
|
49
|
+
export function bulletDimensions(r) {
|
|
50
|
+
if (!r.length || !r.diameter)
|
|
51
|
+
return;
|
|
52
|
+
const base = r.base && baseDimensions(r.base);
|
|
53
|
+
const ogive = r.ogive && ogiveDimensions(r.ogive);
|
|
54
|
+
const cannelure = r.cannelure && cannelureDimensions(r.cannelure);
|
|
55
|
+
const tip = r.tip && tipDimensions(r.tip);
|
|
56
|
+
return {
|
|
57
|
+
diameter: r.diameter.value,
|
|
58
|
+
length: r.length.value,
|
|
59
|
+
...(r.noseLength && { noseLength: r.noseLength.value }),
|
|
60
|
+
...(r.baseToOgive && { baseToOgive: r.baseToOgive.value }),
|
|
61
|
+
...(r.bearingLength && { bearingLength: r.bearingLength.value }),
|
|
62
|
+
...(r.meplatDiameter && { meplatDiameter: r.meplatDiameter.value }),
|
|
63
|
+
...(base && { base }),
|
|
64
|
+
...(ogive && { ogive }),
|
|
65
|
+
...(cannelure && { cannelure }),
|
|
66
|
+
...(tip && { tip }),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** The title of the source that covers a field: one without `fields` covers the whole record; none without provenance. */
|
|
70
|
+
export const sourceTitle = (r, field) => r.provenance?.sources.find((s) => !s.fields || s.fields.some((f) => field === f || field.startsWith(`${f}.`)))?.title;
|
|
71
|
+
/** A field's stored quantity by its dot path. */
|
|
72
|
+
const at = (r, field) => field.split('.').reduce((o, k) => o?.[k], r);
|
|
73
|
+
/**
|
|
74
|
+
* The outline of a bullet and the dimensions of the values `sourced` covers that the drawn
|
|
75
|
+
* outline follows: a value the outline replaced, assumed or derived is never dimensioned. A
|
|
76
|
+
* refusal writes its lengths in `unit`.
|
|
77
|
+
*/
|
|
78
|
+
export function bulletProfile(shape, sourced, given = 'sourced', unit = 'mm') {
|
|
79
|
+
const o = bulletOutline(shape, given, unit);
|
|
80
|
+
if ('reason' in o)
|
|
81
|
+
return o;
|
|
82
|
+
const L = shape.length;
|
|
83
|
+
const z0 = L - o.noseLength;
|
|
84
|
+
const t = z0 - o.bearingLength;
|
|
85
|
+
const groove = shape.cannelure;
|
|
86
|
+
const dimensions = dimensionsOf(shape, o, sourced);
|
|
87
|
+
const radii = ogiveRadii(shape, o, sourced);
|
|
88
|
+
const undimensioned = undimensionedFields(shape, [...dimensions, ...radii]);
|
|
89
|
+
const edges = [
|
|
90
|
+
...(t > 0 ? [t] : []),
|
|
91
|
+
...(z0 > t && z0 < L ? [z0] : []),
|
|
92
|
+
...(groove ? [groove.start, groove.start + groove.width] : []),
|
|
93
|
+
...(o.tipStart === undefined ? [] : [o.tipStart]),
|
|
94
|
+
].sort((x, y) => x - y);
|
|
95
|
+
return {
|
|
96
|
+
points: o.points,
|
|
97
|
+
notes: [],
|
|
98
|
+
annotation: { dimensions, angles: [], radii, edges, conventions: [] },
|
|
99
|
+
outline: o,
|
|
100
|
+
undimensioned,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** The middle of the longest shank run, off the cannelure: where the diameter goes. */
|
|
104
|
+
function shankStation(t, z0, groove) {
|
|
105
|
+
const runs = groove
|
|
106
|
+
? [
|
|
107
|
+
[t, groove.start],
|
|
108
|
+
[groove.start + groove.width, z0],
|
|
109
|
+
]
|
|
110
|
+
: [[t, z0]];
|
|
111
|
+
const [s0, s1] = runs.reduce((p, c) => (c[1] - c[0] > p[1] - p[0] ? c : p), runs[0]);
|
|
112
|
+
return (s0 + s1) / 2;
|
|
113
|
+
}
|
|
114
|
+
/** Radius of the point the base face's edge reaches. */
|
|
115
|
+
function baseRadius(o) {
|
|
116
|
+
const corner = o.points[o.baseEdge];
|
|
117
|
+
if (!corner)
|
|
118
|
+
throw new Error('The outline has no base edge point.');
|
|
119
|
+
return corner[0];
|
|
120
|
+
}
|
|
121
|
+
/** The base dimensions behind station `t`: boat-tail length, base diameter and cavity. */
|
|
122
|
+
function tailDimensions(shape, o, t, add) {
|
|
123
|
+
const rb = baseRadius(o);
|
|
124
|
+
const tail = t > 0;
|
|
125
|
+
const gl = shape.base?.length;
|
|
126
|
+
add('t', gl, tail && gl !== undefined && Math.abs(t - gl) < 1e-9, {
|
|
127
|
+
kind: 'length',
|
|
128
|
+
from: 0,
|
|
129
|
+
to: t,
|
|
130
|
+
});
|
|
131
|
+
const gd = shape.base?.diameter;
|
|
132
|
+
add('db', gd, tail && gd !== undefined && Math.abs(2 * rb - gd) < 1e-9, {
|
|
133
|
+
kind: 'diameter',
|
|
134
|
+
from: 0,
|
|
135
|
+
to: 0,
|
|
136
|
+
radius: rb,
|
|
137
|
+
behindHeadFace: true,
|
|
138
|
+
});
|
|
139
|
+
const cavityDiameter = shape.base?.cavityDiameter;
|
|
140
|
+
add('dc', cavityDiameter, o.cavity !== undefined &&
|
|
141
|
+
cavityDiameter !== undefined &&
|
|
142
|
+
Math.abs(2 * o.cavity.radius - cavityDiameter) < 1e-9, { kind: 'diameter', from: 0, to: 0, radius: o.cavity?.radius, behindHeadFace: true });
|
|
143
|
+
}
|
|
144
|
+
/** The front dimensions on the meplat line: meplat, hollow-point mouth and polymer tip. */
|
|
145
|
+
function frontDimensions(shape, o, add) {
|
|
146
|
+
const L = shape.length;
|
|
147
|
+
const tip = shape.tip?.type;
|
|
148
|
+
const meplat = shape.meplatDiameter;
|
|
149
|
+
add('dm', meplat, (meplat ?? 0) > 0, {
|
|
150
|
+
kind: 'diameter',
|
|
151
|
+
from: L,
|
|
152
|
+
to: L,
|
|
153
|
+
radius: (meplat ?? 0) / 2,
|
|
154
|
+
front: true,
|
|
155
|
+
});
|
|
156
|
+
const mouth = shape.tip?.mouthDiameter;
|
|
157
|
+
// the outline draws the mouth on the meplat line only inside it
|
|
158
|
+
const meplatR = Math.max(...o.points.filter(([, z]) => z === L).map(([r]) => r));
|
|
159
|
+
add('dh', mouth, tip === 'hollow-point' && (mouth ?? 0) > 0 && (mouth ?? 0) / 2 < meplatR, {
|
|
160
|
+
kind: 'diameter',
|
|
161
|
+
from: L,
|
|
162
|
+
to: L,
|
|
163
|
+
radius: (mouth ?? 0) / 2,
|
|
164
|
+
front: true,
|
|
165
|
+
});
|
|
166
|
+
add('lt', shape.tip?.length, tip === 'polymer-tip' && o.tipStart !== undefined, {
|
|
167
|
+
kind: 'chain',
|
|
168
|
+
from: o.tipStart ?? 0,
|
|
169
|
+
to: L,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** The dimensions of the stored values `sourced` covers that the drawn outline `o` follows. */
|
|
173
|
+
function dimensionsOf(shape, o, sourced) {
|
|
174
|
+
const { length: L, diameter } = shape;
|
|
175
|
+
const a = diameter / 2;
|
|
176
|
+
const z0 = L - o.noseLength;
|
|
177
|
+
const t = z0 - o.bearingLength;
|
|
178
|
+
const groove = shape.cannelure;
|
|
179
|
+
const dimensions = [];
|
|
180
|
+
const add = (symbol, value, ok, d) => {
|
|
181
|
+
const field = bulletSymbols.find((s) => s.symbol === symbol)?.path;
|
|
182
|
+
if (value !== undefined && ok && sourced(field))
|
|
183
|
+
dimensions.push({ symbol, value, stored: { symbol, value }, ...d });
|
|
184
|
+
};
|
|
185
|
+
const station = shankStation(t, z0, groove);
|
|
186
|
+
add('L', L, true, { kind: 'length', from: 0, to: L });
|
|
187
|
+
add('d', diameter, true, { kind: 'diameter', from: station, to: station, radius: a });
|
|
188
|
+
add('n', shape.noseLength, !o.noseAssumed, { kind: 'chain', from: z0, to: L });
|
|
189
|
+
const bearing = shape.bearingLength;
|
|
190
|
+
add('b', bearing, bearing !== undefined && Math.abs(o.bearingLength - bearing) <= 0.05, {
|
|
191
|
+
kind: 'chain',
|
|
192
|
+
from: t,
|
|
193
|
+
to: z0,
|
|
194
|
+
});
|
|
195
|
+
tailDimensions(shape, o, t, add);
|
|
196
|
+
frontDimensions(shape, o, add);
|
|
197
|
+
const bto = shape.baseToOgive;
|
|
198
|
+
add('BTO', bto, bto !== undefined && bto > 0 && bto < L, {
|
|
199
|
+
kind: 'length',
|
|
200
|
+
from: 0,
|
|
201
|
+
to: bto ?? 0,
|
|
202
|
+
});
|
|
203
|
+
if (groove) {
|
|
204
|
+
add('c', groove.start, true, { kind: 'length', from: 0, to: groove.start });
|
|
205
|
+
add('w', groove.width, true, {
|
|
206
|
+
kind: 'chain',
|
|
207
|
+
from: groove.start,
|
|
208
|
+
to: groove.start + groove.width,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return dimensions;
|
|
212
|
+
}
|
|
213
|
+
/** The nose callouts on the drawn nose, R at its middle and Rt/R further forward; none on a round nose. */
|
|
214
|
+
function ogiveRadii(shape, o, sourced) {
|
|
215
|
+
const L = shape.length;
|
|
216
|
+
const z0 = L - o.noseLength;
|
|
217
|
+
const radii = [];
|
|
218
|
+
const round = shape.ogive?.form === 'round-nose' || shape.ogive?.form === 'flat-nose';
|
|
219
|
+
const nosePoint = (share) => {
|
|
220
|
+
const z = z0 + share * o.noseLength;
|
|
221
|
+
const nose = o.points.filter(([, pz]) => pz > z0 && pz < L);
|
|
222
|
+
const first = nose[0];
|
|
223
|
+
return first && nose.reduce((p, c) => (Math.abs(c[1] - z) < Math.abs(p[1] - z) ? c : p), first);
|
|
224
|
+
};
|
|
225
|
+
for (const [symbol, value, share] of [
|
|
226
|
+
['R', shape.ogive?.radius, 0.5],
|
|
227
|
+
['Rt/R', shape.ogive?.radiusRatio, 0.75],
|
|
228
|
+
]) {
|
|
229
|
+
if (value === undefined ||
|
|
230
|
+
round ||
|
|
231
|
+
!sourced(symbol === 'R' ? 'ogive.radius' : 'ogive.radiusRatio'))
|
|
232
|
+
continue;
|
|
233
|
+
const corner = nosePoint(share);
|
|
234
|
+
if (corner)
|
|
235
|
+
radii.push({ kind: 'radius', symbol, value, stored: { symbol, value }, corner });
|
|
236
|
+
}
|
|
237
|
+
return radii;
|
|
238
|
+
}
|
|
239
|
+
/** Names of the fields the shape gives that no mark in `drawn` dimensions. */
|
|
240
|
+
function undimensionedFields(shape, drawn) {
|
|
241
|
+
const symbols = new Set(drawn.map((d) => d.symbol));
|
|
242
|
+
const stored = (field) => at(shape, field) !== undefined;
|
|
243
|
+
return [
|
|
244
|
+
...bulletSymbols.filter((s) => !symbols.has(s.symbol) && stored(s.path)),
|
|
245
|
+
...undimensionable.filter((s) => stored(s.path)),
|
|
246
|
+
].map((s) => s.name);
|
|
247
|
+
}
|
|
248
|
+
/** The profile of a record: its shape, with the fields its sources cover. */
|
|
249
|
+
export function recordProfile(r) {
|
|
250
|
+
const shape = bulletDimensions(r);
|
|
251
|
+
if (!shape) {
|
|
252
|
+
const field = r.length ? 'diameter' : 'length';
|
|
253
|
+
return { reason: `The record has no ${field}.`, fields: [field] };
|
|
254
|
+
}
|
|
255
|
+
return bulletProfile(shape, (field) => at(r, field) !== undefined && sourceTitle(r, field) !== undefined);
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Layout } from '../core/types.ts';
|
|
2
|
+
import type { LengthUnit } from '../core/units.ts';
|
|
3
|
+
import type { Profile } from './profile.ts';
|
|
4
|
+
import { type Region, type RegionName } from './regions.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Where each region is called out along the axis, from the cartridge diameters: the head in the
|
|
7
|
+
* rim, the body, shoulder and neck between the stations of P1, P2, H1 and H2 (a wall without a
|
|
8
|
+
* drawn shoulder split in quarters).
|
|
9
|
+
*/
|
|
10
|
+
export declare function regionStations({ points, annotation }: Profile): Record<RegionName, number>;
|
|
11
|
+
/**
|
|
12
|
+
* The Combined layer: one callout per region, a leader from the chamber wall at its station
|
|
13
|
+
* straight out past the steel band to a lane, the text along the axis a gap past the leader's end.
|
|
14
|
+
* Lanes as in the length stack: the innermost where the text clears the texts and leaders there
|
|
15
|
+
* and the leader clears the texts of the lanes it crosses, +r before -r, inside `box` (the frame
|
|
16
|
+
* of the other layers) where any lane is free there, so switching views keeps the frame.
|
|
17
|
+
*/
|
|
18
|
+
export declare function regionCallouts(cartridge: Profile, chamber: Profile, list: Region[], em: number, box: [number, number, number, number], unit?: LengthUnit): Layout;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import * as face from '../core/face.js';
|
|
2
|
+
import { labelCorners } from '../core/geometry.js';
|
|
3
|
+
import { radiusAt, steelRadius } from '../core/section.js';
|
|
4
|
+
import { textWidth } from '../core/text.js';
|
|
5
|
+
import { regionText } from './regions.js';
|
|
6
|
+
/**
|
|
7
|
+
* Where each region is called out along the axis, from the cartridge diameters: the head in the
|
|
8
|
+
* rim, the body, shoulder and neck between the stations of P1, P2, H1 and H2 (a wall without a
|
|
9
|
+
* drawn shoulder split in quarters).
|
|
10
|
+
*/
|
|
11
|
+
export function regionStations({ points, annotation }) {
|
|
12
|
+
const at = (symbol) => annotation.dimensions.find((d) => d.kind === 'diameter' && d.symbol === symbol)?.from;
|
|
13
|
+
const zMax = Math.max(...points.map(([, z]) => z));
|
|
14
|
+
// the rim length R, not a point index: a chamfer or r0 adds points before the rim top
|
|
15
|
+
const rim = annotation.dimensions.find((d) => d.kind === 'length' && d.symbol === 'R')?.to ?? points[2]?.[1];
|
|
16
|
+
if (rim === undefined)
|
|
17
|
+
throw new Error('The rim length R is not dimensioned and the outline has no rim point.');
|
|
18
|
+
const start = at('P1') ?? rim;
|
|
19
|
+
const end = at('H2') ?? zMax;
|
|
20
|
+
const [p2, h1] = [at('P2'), at('H1')];
|
|
21
|
+
const shoulder = p2 !== undefined && h1 !== undefined;
|
|
22
|
+
return {
|
|
23
|
+
head: rim / 2,
|
|
24
|
+
body: shoulder ? (start + p2) / 2 : start + 0.25 * (end - start),
|
|
25
|
+
shoulder: shoulder ? (p2 + h1) / 2 : start + 0.5 * (end - start),
|
|
26
|
+
neck: shoulder ? (h1 + end) / 2 : start + 0.75 * (end - start),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The Combined layer: one callout per region, a leader from the chamber wall at its station
|
|
31
|
+
* straight out past the steel band to a lane, the text along the axis a gap past the leader's end.
|
|
32
|
+
* Lanes as in the length stack: the innermost where the text clears the texts and leaders there
|
|
33
|
+
* and the leader clears the texts of the lanes it crosses, +r before -r, inside `box` (the frame
|
|
34
|
+
* of the other layers) where any lane is free there, so switching views keeps the frame.
|
|
35
|
+
*/
|
|
36
|
+
export function regionCallouts(cartridge, chamber, list, em, box, unit = 'mm') {
|
|
37
|
+
const k = em / face.baseEm;
|
|
38
|
+
const [lane0, pitch, gap] = [face.firstLaneOffset * k, face.lanePitch * k, 0.12 * em];
|
|
39
|
+
const outer = steelRadius(chamber.points);
|
|
40
|
+
const lanes = {
|
|
41
|
+
stations: regionStations(cartridge),
|
|
42
|
+
laneR: (n) => outer + lane0 + n * pitch,
|
|
43
|
+
gap,
|
|
44
|
+
em,
|
|
45
|
+
box,
|
|
46
|
+
unit,
|
|
47
|
+
};
|
|
48
|
+
return calloutLayout(bestPlacement(list, lanes), chamber, outer, lanes);
|
|
49
|
+
}
|
|
50
|
+
/** The first of `spans` that fits lane n+1 on the side `sign` and leaves the lanes it crosses free at `z`. */
|
|
51
|
+
function fittingSpan(spans, { within, n, sign, z }, { gap, box }, free) {
|
|
52
|
+
return spans.find(([a, b]) => (!within || (a >= box[0] && b <= box[2])) &&
|
|
53
|
+
free(sign * (n + 1), [a, b]) &&
|
|
54
|
+
Array.from({ length: n }, (_, m) => sign * (m + 1)).every((lane) => free(lane, [z - gap, z + gap])));
|
|
55
|
+
}
|
|
56
|
+
/** Does a text of height em centered at radius r reach past the box's top or bottom? */
|
|
57
|
+
const outsideBox = (r, em, box) => r + em / 2 > box[3] || r - em / 2 < box[1];
|
|
58
|
+
/** The innermost lane that fits a callout, inside the box first, +r before -r; undefined when none does. */
|
|
59
|
+
function searchLanes({ region, z, text, w }, spans, lanes, free) {
|
|
60
|
+
const { laneR, em, box } = lanes;
|
|
61
|
+
for (const within of [true, false])
|
|
62
|
+
for (let n = 0; n < 40; n++)
|
|
63
|
+
for (const sign of [1, -1]) {
|
|
64
|
+
const r = sign * laneR(n);
|
|
65
|
+
if (within && outsideBox(r, em, box))
|
|
66
|
+
continue;
|
|
67
|
+
const span = fittingSpan(spans, { within, n, sign, z }, lanes, free);
|
|
68
|
+
if (span)
|
|
69
|
+
return { place: { region, z, text, w, sign, n, span }, within };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Places the callouts in this order; the ones outside `box` counted. */
|
|
73
|
+
function placeInLanes(order, before, lanes) {
|
|
74
|
+
const { stations, gap, em, unit } = lanes;
|
|
75
|
+
const taken = new Map();
|
|
76
|
+
const free = (lane, [a, b]) => (taken.get(lane) ?? []).every(([c, d]) => b + gap <= c || d + gap <= a);
|
|
77
|
+
const take = (lane, span) => taken.set(lane, [...(taken.get(lane) ?? []), span]);
|
|
78
|
+
const placed = [];
|
|
79
|
+
let outside = 0;
|
|
80
|
+
for (const region of order) {
|
|
81
|
+
const z = stations[region.name];
|
|
82
|
+
const text = regionText(region, unit);
|
|
83
|
+
const w = textWidth(text, em);
|
|
84
|
+
const after = [z + gap, z + gap + w];
|
|
85
|
+
const spans = before ? [[z - gap - w, z - gap], after] : [after, [z - gap - w, z - gap]];
|
|
86
|
+
const found = searchLanes({ region, z, text, w }, spans, lanes, free);
|
|
87
|
+
// a station covered on both sides in every lane: this order fails
|
|
88
|
+
if (!found)
|
|
89
|
+
return { placed, outside: Infinity };
|
|
90
|
+
const { place } = found;
|
|
91
|
+
if (!found.within)
|
|
92
|
+
outside++;
|
|
93
|
+
take(place.sign * (place.n + 1), place.span);
|
|
94
|
+
for (let m = 0; m < place.n; m++)
|
|
95
|
+
take(place.sign * (m + 1), [z - gap, z + gap]);
|
|
96
|
+
placed.push(place);
|
|
97
|
+
}
|
|
98
|
+
return { placed, outside };
|
|
99
|
+
}
|
|
100
|
+
/** The placement with the fewest callouts outside `box`: by station first, then every order. */
|
|
101
|
+
function bestPlacement(list, lanes) {
|
|
102
|
+
// a text covering another station must lie outside that callout's lane: try every order
|
|
103
|
+
const orders = (list) => list.length < 2
|
|
104
|
+
? [list]
|
|
105
|
+
: list.flatMap((x, k) => orders(list.filter((_, j) => j !== k)).map((o) => [x, ...o]));
|
|
106
|
+
const byStation = [...list].sort((a, b) => lanes.stations[a.name] - lanes.stations[b.name]);
|
|
107
|
+
let best = placeInLanes(byStation, false, lanes);
|
|
108
|
+
for (const before of [false, true])
|
|
109
|
+
for (const order of orders(byStation)) {
|
|
110
|
+
if (best.outside === 0)
|
|
111
|
+
break;
|
|
112
|
+
const next = placeInLanes(order, before, lanes);
|
|
113
|
+
if (next.outside < best.outside)
|
|
114
|
+
best = next;
|
|
115
|
+
}
|
|
116
|
+
return best.placed;
|
|
117
|
+
}
|
|
118
|
+
/** The leaders and texts of the placed callouts, in a box grown from `box` to take them. */
|
|
119
|
+
function calloutLayout(placed, chamber, outer, lanes) {
|
|
120
|
+
const { laneR, em, box } = lanes;
|
|
121
|
+
const layout = {
|
|
122
|
+
labels: [],
|
|
123
|
+
segs: [],
|
|
124
|
+
arcs: [],
|
|
125
|
+
arrowheads: [],
|
|
126
|
+
box,
|
|
127
|
+
diameterTips: [],
|
|
128
|
+
spans: [],
|
|
129
|
+
};
|
|
130
|
+
for (const { region, z, text, w, sign, n, span } of placed) {
|
|
131
|
+
const wall = radiusAt(chamber.points, z) ?? outer;
|
|
132
|
+
const r = sign * laneR(n);
|
|
133
|
+
layout.arrowheads.push({ at: [z, sign * wall], dir: [0, -sign], owner: region.name });
|
|
134
|
+
layout.segs.push({ a: [z, sign * wall], b: [z, r], kind: 'thin', owner: region.name });
|
|
135
|
+
layout.labels.push({
|
|
136
|
+
text,
|
|
137
|
+
c: [(span[0] + span[1]) / 2, r],
|
|
138
|
+
dir: [1, 0],
|
|
139
|
+
w,
|
|
140
|
+
h: em,
|
|
141
|
+
owner: region.name,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const pts = [...layout.labels.flatMap(labelCorners), ...layout.segs.map((s) => s.b)];
|
|
145
|
+
layout.box = [
|
|
146
|
+
Math.min(box[0], ...pts.map((p) => p[0])),
|
|
147
|
+
Math.min(box[1], ...pts.map((p) => p[1])),
|
|
148
|
+
Math.max(box[2], ...pts.map((p) => p[0])),
|
|
149
|
+
Math.max(box[3], ...pts.map((p) => p[1])),
|
|
150
|
+
];
|
|
151
|
+
return layout;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=callouts.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SectionPoint } from '../core/types.ts';
|
|
2
|
+
import type { Side } from './figures.ts';
|
|
3
|
+
import type { Profile } from './profile.ts';
|
|
4
|
+
/** A detail view of one side: A the head (rim, groove, belt, recess), B the chamber throat. */
|
|
5
|
+
export interface DetailSpec {
|
|
6
|
+
letter: 'A' | 'B';
|
|
7
|
+
side: Side;
|
|
8
|
+
/** The feature region in the half section, mm: r0, z0, r1, z1. */
|
|
9
|
+
region: [number, number, number, number];
|
|
10
|
+
/** The point the main view's letter marks and a cut window keeps. */
|
|
11
|
+
anchor: SectionPoint;
|
|
12
|
+
/** The outline segments of the region that must reach a size in px: mm and px wanted. */
|
|
13
|
+
sizes: {
|
|
14
|
+
mm: number;
|
|
15
|
+
px: number;
|
|
16
|
+
}[];
|
|
17
|
+
}
|
|
18
|
+
/** Room around the region at the detail scale, mm. */
|
|
19
|
+
export declare const detailMargin = 3;
|
|
20
|
+
/**
|
|
21
|
+
* The details of a side, each only where the side stores its values: A where E, e, R, E1 or delta
|
|
22
|
+
* is dimensioned, B on the chamber where G1 is, with F and i or with h or s.
|
|
23
|
+
*/
|
|
24
|
+
export declare function detailSpecs(side: Side, p: Profile): DetailSpec[];
|
|
25
|
+
/**
|
|
26
|
+
* The scale k of a detail and its window at that scale (mm, the half section times k: r0, z0, r1,
|
|
27
|
+
* z1): the largest k at which the region with its margin fits the cap, raised to the smallest k
|
|
28
|
+
* at which every size reaches its px at `pxPerMm` of the main view; a window over the cap is cut
|
|
29
|
+
* about the anchor.
|
|
30
|
+
*/
|
|
31
|
+
export declare function detailWindow(spec: DetailSpec, pxPerMm: number, across?: number): {
|
|
32
|
+
scale: number;
|
|
33
|
+
window: [number, number, number, number];
|
|
34
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { pairs } from '../core/vector.js';
|
|
2
|
+
/** Allowed enlargement factors of a detail view over the main view. */
|
|
3
|
+
const detailScales = [2, 5, 10, 20, 50];
|
|
4
|
+
/** The largest window at the detail scale, mm: along the axis and across it. */
|
|
5
|
+
const detailWindowCap = { along: 32, across: 20 };
|
|
6
|
+
/** Room around the region at the detail scale, mm. */
|
|
7
|
+
export const detailMargin = 3;
|
|
8
|
+
const symbolsOf = ({ annotation: a }) => new Set([...a.dimensions, ...a.angles].map((d) => d.symbol));
|
|
9
|
+
/**
|
|
10
|
+
* The details of a side, each only where the side stores its values: A where E, e, R, E1 or delta
|
|
11
|
+
* is dimensioned, B on the chamber where G1 is, with F and i or with h or s.
|
|
12
|
+
*/
|
|
13
|
+
export function detailSpecs(side, p) {
|
|
14
|
+
const has = symbolsOf(p);
|
|
15
|
+
const at = (symbol) => p.annotation.dimensions.find((d) => d.symbol === symbol);
|
|
16
|
+
return [headDetail(side, p, has, at), throatDetail(side, p, has, at)].filter((d) => d !== undefined);
|
|
17
|
+
}
|
|
18
|
+
/** Detail A, the head, where E, e, R, E1 or delta is dimensioned. */
|
|
19
|
+
function headDetail(side, p, has, at) {
|
|
20
|
+
const zP1 = at('P1')?.from;
|
|
21
|
+
if (!['E', 'e', 'R', 'E1', 'delta'].some((s) => has.has(s)) || zP1 === undefined)
|
|
22
|
+
return;
|
|
23
|
+
const head = p.points.slice(1).filter(([, z]) => z <= zP1 + 1e-9);
|
|
24
|
+
const sizes = segments(head);
|
|
25
|
+
const r = (symbol) => at(symbol)?.radius;
|
|
26
|
+
const [R1, E1, R3, P1] = ['R1', 'E1', 'R3', 'P1'].map(r);
|
|
27
|
+
const [R, E] = ['R', 'E'].map((s) => at(s)?.to);
|
|
28
|
+
// grooves and belts at least 6 px: the groove depth and its length to E, the belt step and length
|
|
29
|
+
if (side === 'cartridge' && [R1, E1, R, E].every((x) => x !== undefined)) {
|
|
30
|
+
sizes.push({
|
|
31
|
+
mm: Math.min(R1 - E1, E - R),
|
|
32
|
+
px: 6,
|
|
33
|
+
});
|
|
34
|
+
const belt = head.find(([pr]) => R3 !== undefined && Math.abs(pr - R3) < 1e-9);
|
|
35
|
+
if (belt && P1 !== undefined)
|
|
36
|
+
sizes.push({ mm: Math.min(R3 - P1, E - belt[1]), px: 6 });
|
|
37
|
+
}
|
|
38
|
+
// the chamber recess step to P1 at its depth, else the head corner
|
|
39
|
+
const step = side === 'chamber' ? head.findLast(([, z]) => z > 0) : undefined;
|
|
40
|
+
const anchor = step ?? head[Math.floor(head.length / 2)];
|
|
41
|
+
if (!anchor)
|
|
42
|
+
return;
|
|
43
|
+
return { letter: 'A', side, region: box(head), anchor, sizes };
|
|
44
|
+
}
|
|
45
|
+
/** Detail B, the chamber throat, where G1 is dimensioned with F and i or with h or s. */
|
|
46
|
+
function throatDetail(side, p, has, at) {
|
|
47
|
+
const { angles, conventions } = p.annotation;
|
|
48
|
+
const throat = has.has('F') && has.has('i');
|
|
49
|
+
if (side !== 'chamber' || !at('G1') || !(throat || has.has('h') || has.has('s')))
|
|
50
|
+
return;
|
|
51
|
+
const L3 = at('H2')?.from;
|
|
52
|
+
// from H2 at L3 to the leade start (or the G1 stub, or the step at the leade end)
|
|
53
|
+
const z1 = angles.find((a) => a.symbol === 'i')?.vertex[1] ??
|
|
54
|
+
conventions.find((c) => c.kind === 'g1Stub')?.from ??
|
|
55
|
+
at('F')?.from ??
|
|
56
|
+
L3;
|
|
57
|
+
const part = p.points.filter(([, z]) => z >= L3 - 1e-9 && z <= z1 + 1e-9);
|
|
58
|
+
const anchor = part[0];
|
|
59
|
+
if (!anchor)
|
|
60
|
+
return;
|
|
61
|
+
return { letter: 'B', side, region: box(part), anchor, sizes: segments(part) };
|
|
62
|
+
}
|
|
63
|
+
const box = (points) => [
|
|
64
|
+
Math.min(...points.map(([r]) => r)),
|
|
65
|
+
Math.min(...points.map(([, z]) => z)),
|
|
66
|
+
Math.max(...points.map(([r]) => r)),
|
|
67
|
+
Math.max(...points.map(([, z]) => z)),
|
|
68
|
+
];
|
|
69
|
+
/** Every outline segment of at least 0.01 mm at 1 px; shorter ones are the rounding of the values. */
|
|
70
|
+
const segments = (points) => pairs(points)
|
|
71
|
+
.map(([[pr, pz], [r, z]]) => Math.hypot(r - pr, z - pz))
|
|
72
|
+
.filter((mm) => mm >= 0.01 - 1e-9)
|
|
73
|
+
.map((mm) => ({ mm, px: 1 }));
|
|
74
|
+
/**
|
|
75
|
+
* The scale k of a detail and its window at that scale (mm, the half section times k: r0, z0, r1,
|
|
76
|
+
* z1): the largest k at which the region with its margin fits the cap, raised to the smallest k
|
|
77
|
+
* at which every size reaches its px at `pxPerMm` of the main view; a window over the cap is cut
|
|
78
|
+
* about the anchor.
|
|
79
|
+
*/
|
|
80
|
+
export function detailWindow(spec, pxPerMm, across = detailWindowCap.across) {
|
|
81
|
+
const [r0, z0, r1, z1] = spec.region;
|
|
82
|
+
const fits = (k) => (z1 - z0) * k + 2 * detailMargin <= detailWindowCap.along &&
|
|
83
|
+
(r1 - r0) * k + 2 * detailMargin <= across;
|
|
84
|
+
const kFit = detailScales.findLast(fits) ?? Math.min(...detailScales);
|
|
85
|
+
const kNeed = detailScales.find((k) => spec.sizes.every(({ mm, px }) => mm * k * pxPerMm >= px)) ??
|
|
86
|
+
Math.max(...detailScales);
|
|
87
|
+
const k = Math.max(kFit, kNeed);
|
|
88
|
+
const cut = (lo, hi, at, room) => {
|
|
89
|
+
const [a, b] = [lo * k - detailMargin, hi * k + detailMargin];
|
|
90
|
+
if (b - a <= room)
|
|
91
|
+
return [a, b];
|
|
92
|
+
const from = Math.min(Math.max(at * k - room / 2, a), b - room);
|
|
93
|
+
return [from, from + room];
|
|
94
|
+
};
|
|
95
|
+
const [wr0, wr1] = cut(r0, r1, spec.anchor[0], across);
|
|
96
|
+
const [wz0, wz1] = cut(z0, z1, spec.anchor[1], detailWindowCap.along);
|
|
97
|
+
return { scale: k, window: [wr0, wz0, wr1, wz1] };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=detail.js.map
|