@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,4 @@
|
|
|
1
|
+
import type { Medium } from './layout.ts';
|
|
2
|
+
import type { LengthUnit } from './units.ts';
|
|
3
|
+
/** Per figure object, medium, text size and unit: the screen text size search, the width and the model lay out the same figure at the same size, so once is enough. */
|
|
4
|
+
export declare function layoutCache<F extends object, L>(lay: (figure: F, medium: Medium, em: number, unit: LengthUnit) => L): (figure: F, medium: Medium, em: number, unit: LengthUnit) => L;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Per figure object, medium, text size and unit: the screen text size search, the width and the model lay out the same figure at the same size, so once is enough. */
|
|
2
|
+
export function layoutCache(lay) {
|
|
3
|
+
const laidOut = new WeakMap();
|
|
4
|
+
return (figure, medium, em, unit) => {
|
|
5
|
+
const key = `${medium} ${em} ${unit}`;
|
|
6
|
+
const cache = laidOut.get(figure) ?? new Map();
|
|
7
|
+
laidOut.set(figure, cache);
|
|
8
|
+
const hit = cache.get(key);
|
|
9
|
+
if (hit)
|
|
10
|
+
return hit;
|
|
11
|
+
const laid = lay(figure, medium, em, unit);
|
|
12
|
+
cache.set(key, laid);
|
|
13
|
+
return laid;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Constants of the technical face, in mm; distances marked "at 1.6 em" are the old face's at its 1.6 mm text and scale with the text size (`k = em / 1.6`). */
|
|
2
|
+
/** Filled arrowhead, length and full width. */
|
|
3
|
+
export declare const arrow: {
|
|
4
|
+
length: number;
|
|
5
|
+
width: number;
|
|
6
|
+
};
|
|
7
|
+
/** A span under this many arrow lengths takes its arrows outside, on tails of `arrowTailLengths` arrows. */
|
|
8
|
+
export declare const shortSpan = 3;
|
|
9
|
+
/** Length of the tail of an outside arrow, in arrow lengths. */
|
|
10
|
+
export declare const arrowTailLengths = 2.2;
|
|
11
|
+
/** Gap between a feature and the start of its extension line, mm. */
|
|
12
|
+
export declare const extensionGap = 0.5;
|
|
13
|
+
/** How far an extension line runs past its dimension line, mm. */
|
|
14
|
+
export declare const overrun = 0.9;
|
|
15
|
+
/** Text size the lane distances below are given at, mm. */
|
|
16
|
+
export declare const baseEm = 1.6;
|
|
17
|
+
/** At 1.6 em: distance from the widest radius to the first lane of length dimensions, mm. */
|
|
18
|
+
export declare const firstLaneOffset = 3;
|
|
19
|
+
/** At 1.6 em: the distance between two lanes of length dimensions, mm. */
|
|
20
|
+
export declare const lanePitch = 3.2;
|
|
21
|
+
/** At 1.6 em: the zigzag of a broken rule. */
|
|
22
|
+
export declare const breakLength = 2.4;
|
|
23
|
+
/** At 1.6 em: the amplitude of the zigzag of a broken rule, mm. */
|
|
24
|
+
export declare const breakAmplitude = 0.7;
|
|
25
|
+
/** A length rule that ends beyond zMax times (1 + this value) is drawn broken. */
|
|
26
|
+
export declare const breakAllowance = 0.2;
|
|
27
|
+
/** At 1.6 em: length of a radius leader from its corner to its text, and the step of the callout leader lengths, mm. */
|
|
28
|
+
export declare const radiusLeaderLength = 5;
|
|
29
|
+
/** At 1.6 em: the radius of the delta and i arcs, mm. */
|
|
30
|
+
export declare const smallArc = 4.2;
|
|
31
|
+
/** At 1.6 em: the length of the flanks of the delta and i arcs, mm. */
|
|
32
|
+
export declare const smallFlank = 7.5;
|
|
33
|
+
/** A multiple of the vertex distance from L1, shortened where the flanks would reach the texts of lane 0 or the arc's middle come nearer the head than 0.35 zMax. */
|
|
34
|
+
export declare const alphaArc = 1.6;
|
|
35
|
+
/** In em: the farthest an angle text without a leader sits from its arc. */
|
|
36
|
+
export declare const nearArc = 3;
|
|
37
|
+
/** Space between the annotation box and the figure frame, mm. */
|
|
38
|
+
export declare const frameMargin = 4;
|
|
39
|
+
/** Width of the steel band around the chamber cavity, mm: a drawing convention, not a barrel wall thickness. */
|
|
40
|
+
export declare const steelBandWidth = 3;
|
|
41
|
+
/** Screen: drawing px per mm before the column caps it; the narrowest column (390 px page). */
|
|
42
|
+
export declare const pxPerMm = 8;
|
|
43
|
+
/** Screen: width of the narrowest drawing column, CSS px. */
|
|
44
|
+
export declare const phoneColumn = 358;
|
|
45
|
+
/** Screen: the smallest text size, CSS px. */
|
|
46
|
+
export declare const minTextPx = 11;
|
|
47
|
+
/** The smallest text size (one em) of a screen drawing, mm. */
|
|
48
|
+
export declare const minEm = 1.8;
|
|
49
|
+
/** Print: text size (one em), mm. */
|
|
50
|
+
export declare const printEm = 2.5;
|
|
51
|
+
/** Print: the widest drawing, mm. */
|
|
52
|
+
export declare const printWidth = 190;
|
|
53
|
+
/** Diameter sign before a diameter symbol (U+2205; the font has no U+2300). */
|
|
54
|
+
export declare const diameterSign = "\u2205";
|
|
55
|
+
/** Axis dash pattern, mm. */
|
|
56
|
+
export declare const axisDash: number[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Constants of the technical face, in mm; distances marked "at 1.6 em" are the old face's at its 1.6 mm text and scale with the text size (`k = em / 1.6`). */
|
|
2
|
+
/** Filled arrowhead, length and full width. */
|
|
3
|
+
export const arrow = { length: 1.1, width: 0.7 };
|
|
4
|
+
/** A span under this many arrow lengths takes its arrows outside, on tails of `arrowTailLengths` arrows. */
|
|
5
|
+
export const shortSpan = 3;
|
|
6
|
+
/** Length of the tail of an outside arrow, in arrow lengths. */
|
|
7
|
+
export const arrowTailLengths = 2.2;
|
|
8
|
+
/** Gap between a feature and the start of its extension line, mm. */
|
|
9
|
+
export const extensionGap = 0.5;
|
|
10
|
+
/** How far an extension line runs past its dimension line, mm. */
|
|
11
|
+
export const overrun = 0.9;
|
|
12
|
+
/** Text size the lane distances below are given at, mm. */
|
|
13
|
+
export const baseEm = 1.6;
|
|
14
|
+
/** At 1.6 em: distance from the widest radius to the first lane of length dimensions, mm. */
|
|
15
|
+
export const firstLaneOffset = 3.0;
|
|
16
|
+
/** At 1.6 em: the distance between two lanes of length dimensions, mm. */
|
|
17
|
+
export const lanePitch = 3.2;
|
|
18
|
+
/** At 1.6 em: the zigzag of a broken rule. */
|
|
19
|
+
export const breakLength = 2.4;
|
|
20
|
+
/** At 1.6 em: the amplitude of the zigzag of a broken rule, mm. */
|
|
21
|
+
export const breakAmplitude = 0.7;
|
|
22
|
+
/** A length rule that ends beyond zMax times (1 + this value) is drawn broken. */
|
|
23
|
+
export const breakAllowance = 0.2;
|
|
24
|
+
/** At 1.6 em: length of a radius leader from its corner to its text, and the step of the callout leader lengths, mm. */
|
|
25
|
+
export const radiusLeaderLength = 5;
|
|
26
|
+
/** At 1.6 em: the radius of the delta and i arcs, mm. */
|
|
27
|
+
export const smallArc = 4.2;
|
|
28
|
+
/** At 1.6 em: the length of the flanks of the delta and i arcs, mm. */
|
|
29
|
+
export const smallFlank = 7.5;
|
|
30
|
+
/** A multiple of the vertex distance from L1, shortened where the flanks would reach the texts of lane 0 or the arc's middle come nearer the head than 0.35 zMax. */
|
|
31
|
+
export const alphaArc = 1.6;
|
|
32
|
+
/** In em: the farthest an angle text without a leader sits from its arc. */
|
|
33
|
+
export const nearArc = 3;
|
|
34
|
+
/** Space between the annotation box and the figure frame, mm. */
|
|
35
|
+
export const frameMargin = 4;
|
|
36
|
+
/** Width of the steel band around the chamber cavity, mm: a drawing convention, not a barrel wall thickness. */
|
|
37
|
+
export const steelBandWidth = 3;
|
|
38
|
+
/** Screen: drawing px per mm before the column caps it; the narrowest column (390 px page). */
|
|
39
|
+
export const pxPerMm = 8;
|
|
40
|
+
/** Screen: width of the narrowest drawing column, CSS px. */
|
|
41
|
+
export const phoneColumn = 358;
|
|
42
|
+
/** Screen: the smallest text size, CSS px. */
|
|
43
|
+
export const minTextPx = 11;
|
|
44
|
+
/** The smallest text size (one em) of a screen drawing, mm. */
|
|
45
|
+
export const minEm = 1.8;
|
|
46
|
+
/** Print: text size (one em), mm. */
|
|
47
|
+
export const printEm = 2.5;
|
|
48
|
+
/** Print: the widest drawing, mm. */
|
|
49
|
+
export const printWidth = 190;
|
|
50
|
+
/** Diameter sign before a diameter symbol (U+2205; the font has no U+2300). */
|
|
51
|
+
export const diameterSign = '∅';
|
|
52
|
+
/** Axis dash pattern, mm. */
|
|
53
|
+
export const axisDash = [2, 1, 0.4, 1];
|
|
54
|
+
//# sourceMappingURL=face.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SectionPoint } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Samples n + 1 points of the arc of radius r tangent to the lines a-corner and corner-b, or
|
|
4
|
+
* null when its tangent points do not lie on both segments. Up to 0.1 mm past a segment end the
|
|
5
|
+
* arc is cut to that end: the double-radius shoulders of the records overrun it by rounding.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fillet(a: SectionPoint, corner: SectionPoint, b: SectionPoint, r: number, n?: number): SectionPoint[] | null;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Samples n + 1 points of the arc of radius r tangent to the lines a-corner and corner-b, or
|
|
3
|
+
* null when its tangent points do not lie on both segments. Up to 0.1 mm past a segment end the
|
|
4
|
+
* arc is cut to that end: the double-radius shoulders of the records overrun it by rounding.
|
|
5
|
+
*/
|
|
6
|
+
export function fillet(a, corner, b, r, n = 8) {
|
|
7
|
+
const [cr, cz] = corner;
|
|
8
|
+
const unit = ([pr, pz]) => {
|
|
9
|
+
const l = Math.hypot(pr - cr, pz - cz);
|
|
10
|
+
return [(pr - cr) / l, (pz - cz) / l, l];
|
|
11
|
+
};
|
|
12
|
+
const [ur, uz, la] = unit(a);
|
|
13
|
+
const [wr, wz, lb] = unit(b);
|
|
14
|
+
const half = Math.acos(Math.min(1, Math.max(-1, ur * wr + uz * wz))) / 2;
|
|
15
|
+
const m = Math.hypot(ur + wr, uz + wz);
|
|
16
|
+
// a straight line has no corner to round
|
|
17
|
+
if (m < 1e-12)
|
|
18
|
+
return [corner];
|
|
19
|
+
const t = Math.min(r / Math.tan(half), la, lb);
|
|
20
|
+
if (!(r / Math.tan(half) <= t + 0.1))
|
|
21
|
+
return null;
|
|
22
|
+
const d = t / Math.cos(half);
|
|
23
|
+
const rt = t * Math.tan(half);
|
|
24
|
+
const [or, oz] = [cr + ((ur + wr) / m) * d, cz + ((uz + wz) / m) * d];
|
|
25
|
+
const a0 = Math.atan2(cz + uz * t - oz, cr + ur * t - or);
|
|
26
|
+
let sweep = Math.atan2(cz + wz * t - oz, cr + wr * t - or) - a0;
|
|
27
|
+
if (sweep > Math.PI)
|
|
28
|
+
sweep -= 2 * Math.PI;
|
|
29
|
+
if (sweep < -Math.PI)
|
|
30
|
+
sweep += 2 * Math.PI;
|
|
31
|
+
const arc = Array.from({ length: n + 1 }, (_, k) => {
|
|
32
|
+
const angle = a0 + (sweep * k) / n;
|
|
33
|
+
return [or + rt * Math.cos(angle), oz + rt * Math.sin(angle)];
|
|
34
|
+
});
|
|
35
|
+
// a cut arc ends exactly on the segment end, not a rounding error before it
|
|
36
|
+
if (t === la)
|
|
37
|
+
arc[0] = a;
|
|
38
|
+
if (t === lb)
|
|
39
|
+
arc[n] = b;
|
|
40
|
+
return arc;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=fillet.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PartPoint } from './section.ts';
|
|
2
|
+
import type { Arrowhead, Label } from './types.ts';
|
|
3
|
+
/** Does the segment cross the box (grown by `pad`)? */
|
|
4
|
+
export declare function segHitsBox({ a, b }: {
|
|
5
|
+
a: PartPoint;
|
|
6
|
+
b: PartPoint;
|
|
7
|
+
}, l: Label, pad?: number): boolean;
|
|
8
|
+
/** Do two text boxes (grown by `pad`) overlap? Separating axes of both. */
|
|
9
|
+
export declare function boxesOverlap(l: Label, m: Label, pad?: number): boolean;
|
|
10
|
+
/** Do segments pq and rs cross or touch? */
|
|
11
|
+
export declare function segsCross(p: PartPoint, q: PartPoint, r: PartPoint, s: PartPoint): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The four corners of a label's text box in the part frame, mm, in the order (+w/2, +h/2),
|
|
14
|
+
* (+w/2, -h/2), (-w/2, -h/2), (-w/2, +h/2) from its center, w along its direction, h across it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const labelCorners: (l: Label) => PartPoint[];
|
|
17
|
+
/** The corners of a filled arrowhead: its tip, then the two ends of its base. */
|
|
18
|
+
export declare function arrowheadCorners({ at, dir: [ux, uy] }: Arrowhead): PartPoint[];
|
|
19
|
+
/** Do two convex polygons overlap, or come nearer than `pad`? Separating axes of both. */
|
|
20
|
+
export declare function polygonsOverlap(p: PartPoint[], q: PartPoint[], pad?: number): boolean;
|
|
21
|
+
/** Distance from a point to a text box, 0 inside it. */
|
|
22
|
+
export declare function boxDistance(l: Label, [x, y]: PartPoint): number;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as face from './face.js';
|
|
2
|
+
import { add } from './vector.js';
|
|
3
|
+
/** Is the segment clear of the box's bounding circle's square (the box grown by `pad`)? */
|
|
4
|
+
function clearOfReach(a, b, l, reach) {
|
|
5
|
+
return [0, 1].some((k) => Math.max(a[k], b[k]) < l.c[k] - reach || Math.min(a[k], b[k]) > l.c[k] + reach);
|
|
6
|
+
}
|
|
7
|
+
/** Clips the parameter range `t` against dd * t + ss <= lim; false when the segment is parallel and outside. */
|
|
8
|
+
function clipRange(t, dd, ss, lim) {
|
|
9
|
+
if (Math.abs(dd) < 1e-12)
|
|
10
|
+
return !(ss > lim);
|
|
11
|
+
const at = (lim - ss) / dd;
|
|
12
|
+
if (dd > 0)
|
|
13
|
+
t[1] = Math.min(t[1], at);
|
|
14
|
+
else
|
|
15
|
+
t[0] = Math.max(t[0], at);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
/** Does the segment cross the box (grown by `pad`)? */
|
|
19
|
+
export function segHitsBox({ a, b }, l, pad = 0) {
|
|
20
|
+
// most segments pass far from the box
|
|
21
|
+
const reach = Math.hypot(l.w / 2 + pad, l.h / 2 + pad);
|
|
22
|
+
if (clearOfReach(a, b, l, reach))
|
|
23
|
+
return false;
|
|
24
|
+
const [ux, uy] = l.dir;
|
|
25
|
+
const local = ([x, y]) => {
|
|
26
|
+
const [dx, dy] = [x - l.c[0], y - l.c[1]];
|
|
27
|
+
return [dx * ux + dy * uy, -dx * uy + dy * ux];
|
|
28
|
+
};
|
|
29
|
+
const [p, q] = [local(a), local(b)];
|
|
30
|
+
const [hw, hh] = [l.w / 2 + pad, l.h / 2 + pad];
|
|
31
|
+
const t = [0, 1];
|
|
32
|
+
const axes = [
|
|
33
|
+
[q[0] - p[0], p[0], hw],
|
|
34
|
+
[q[1] - p[1], p[1], hh],
|
|
35
|
+
];
|
|
36
|
+
for (const [d, s, lim] of axes) {
|
|
37
|
+
if (!clipRange(t, d, s, lim) || !clipRange(t, -d, -s, lim))
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return t[0] <= t[1];
|
|
41
|
+
}
|
|
42
|
+
/** Do two text boxes (grown by `pad`) overlap? Separating axes of both. */
|
|
43
|
+
export function boxesOverlap(l, m, pad = 0) {
|
|
44
|
+
const corners = (b) => {
|
|
45
|
+
const [ux, uy] = b.dir;
|
|
46
|
+
const [hw, hh] = [b.w / 2 + pad / 2, b.h / 2 + pad / 2];
|
|
47
|
+
const quad = [
|
|
48
|
+
[hw, hh],
|
|
49
|
+
[hw, -hh],
|
|
50
|
+
[-hw, -hh],
|
|
51
|
+
[-hw, hh],
|
|
52
|
+
];
|
|
53
|
+
return quad.map(([s, t]) => [b.c[0] + s * ux - t * uy, b.c[1] + s * uy + t * ux]);
|
|
54
|
+
};
|
|
55
|
+
const [cl, cm] = [corners(l), corners(m)];
|
|
56
|
+
const axes = [l.dir, [-l.dir[1], l.dir[0]], m.dir, [-m.dir[1], m.dir[0]]];
|
|
57
|
+
for (const [ux, uy] of axes) {
|
|
58
|
+
const proj = (pts) => pts.map(([x, y]) => x * ux + y * uy);
|
|
59
|
+
const [a, b] = [proj(cl), proj(cm)];
|
|
60
|
+
if (Math.max(...a) <= Math.min(...b) || Math.max(...b) <= Math.min(...a))
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
/** Do segments pq and rs cross or touch? */
|
|
66
|
+
export function segsCross(p, q, r, s) {
|
|
67
|
+
if (Math.max(p[0], q[0]) < Math.min(r[0], s[0]) ||
|
|
68
|
+
Math.max(r[0], s[0]) < Math.min(p[0], q[0]) ||
|
|
69
|
+
Math.max(p[1], q[1]) < Math.min(r[1], s[1]) ||
|
|
70
|
+
Math.max(r[1], s[1]) < Math.min(p[1], q[1]))
|
|
71
|
+
return false;
|
|
72
|
+
const d = (q[0] - p[0]) * (s[1] - r[1]) - (q[1] - p[1]) * (s[0] - r[0]);
|
|
73
|
+
if (Math.abs(d) < 1e-12)
|
|
74
|
+
return false;
|
|
75
|
+
const t = ((r[0] - p[0]) * (s[1] - r[1]) - (r[1] - p[1]) * (s[0] - r[0])) / d;
|
|
76
|
+
const u = ((r[0] - p[0]) * (q[1] - p[1]) - (r[1] - p[1]) * (q[0] - p[0])) / d;
|
|
77
|
+
return t >= 0 && t <= 1 && u >= 0 && u <= 1;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The four corners of a label's text box in the part frame, mm, in the order (+w/2, +h/2),
|
|
81
|
+
* (+w/2, -h/2), (-w/2, -h/2), (-w/2, +h/2) from its center, w along its direction, h across it.
|
|
82
|
+
*/
|
|
83
|
+
export const labelCorners = (l) => {
|
|
84
|
+
const signs = [
|
|
85
|
+
[1, 1],
|
|
86
|
+
[1, -1],
|
|
87
|
+
[-1, -1],
|
|
88
|
+
[-1, 1],
|
|
89
|
+
];
|
|
90
|
+
return signs.map(([s, t]) => [
|
|
91
|
+
l.c[0] + (s * l.w * l.dir[0]) / 2 - (t * l.h * l.dir[1]) / 2,
|
|
92
|
+
l.c[1] + (s * l.w * l.dir[1]) / 2 + (t * l.h * l.dir[0]) / 2,
|
|
93
|
+
]);
|
|
94
|
+
};
|
|
95
|
+
/** The corners of a filled arrowhead: its tip, then the two ends of its base. */
|
|
96
|
+
export function arrowheadCorners({ at, dir: [ux, uy] }) {
|
|
97
|
+
const base = add(at, [ux, uy], -face.arrow.length);
|
|
98
|
+
const h = face.arrow.width / 2;
|
|
99
|
+
return [at, [base[0] - uy * h, base[1] + ux * h], [base[0] + uy * h, base[1] - ux * h]];
|
|
100
|
+
}
|
|
101
|
+
/** Do two convex polygons overlap, or come nearer than `pad`? Separating axes of both. */
|
|
102
|
+
export function polygonsOverlap(p, q, pad = 0) {
|
|
103
|
+
const apart = (nx, ny) => {
|
|
104
|
+
let [p0, p1, q0, q1] = [Infinity, -Infinity, Infinity, -Infinity];
|
|
105
|
+
for (const [x, y] of p) {
|
|
106
|
+
const d = x * nx + y * ny;
|
|
107
|
+
p0 = Math.min(p0, d);
|
|
108
|
+
p1 = Math.max(p1, d);
|
|
109
|
+
}
|
|
110
|
+
for (const [x, y] of q) {
|
|
111
|
+
const d = x * nx + y * ny;
|
|
112
|
+
q0 = Math.min(q0, d);
|
|
113
|
+
q1 = Math.max(q1, d);
|
|
114
|
+
}
|
|
115
|
+
return p1 + pad <= q0 || q1 + pad <= p0;
|
|
116
|
+
};
|
|
117
|
+
if (apart(1, 0) || apart(0, 1))
|
|
118
|
+
return false;
|
|
119
|
+
for (const poly of [p, q])
|
|
120
|
+
for (let i = 0; i < poly.length; i++) {
|
|
121
|
+
const [a, b] = [poly[i], poly[(i + 1) % poly.length]];
|
|
122
|
+
if (!a || !b)
|
|
123
|
+
continue;
|
|
124
|
+
const l = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
125
|
+
if (l > 1e-12 && apart((a[1] - b[1]) / l, (b[0] - a[0]) / l))
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
/** Distance from a point to a text box, 0 inside it. */
|
|
131
|
+
export function boxDistance(l, [x, y]) {
|
|
132
|
+
const [dx, dy] = [x - l.c[0], y - l.c[1]];
|
|
133
|
+
const [u, v] = [dx * l.dir[0] + dy * l.dir[1], -dx * l.dir[1] + dy * l.dir[0]];
|
|
134
|
+
return Math.hypot(Math.max(Math.abs(u) - l.w / 2, 0), Math.max(Math.abs(v) - l.h / 2, 0));
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PartPoint } from './section.ts';
|
|
2
|
+
import type { Layout, Profile } from './types.ts';
|
|
3
|
+
import { type LengthUnit } from './units.ts';
|
|
4
|
+
/** The sides of one figure, each with its profile. */
|
|
5
|
+
export type Drawn<Side extends string = string, P extends Profile = Profile> = {
|
|
6
|
+
side: Side;
|
|
7
|
+
p: P;
|
|
8
|
+
}[];
|
|
9
|
+
/** Screen: the part frame turned -90 deg (head at the bottom); print: unturned. */
|
|
10
|
+
export type Medium = 'screen' | 'print';
|
|
11
|
+
/** The part frame direction that reads level on the medium. */
|
|
12
|
+
export declare const readingDirection: (medium: Medium) => PartPoint;
|
|
13
|
+
/**
|
|
14
|
+
* The dash-dot axis of a side: from 1 mm behind the head to 2 mm past the part, or on to the
|
|
15
|
+
* stations dimensioned past it (S, L6 short of the break) plus the overrun.
|
|
16
|
+
*/
|
|
17
|
+
export declare function axisReach(p: Profile): [number, number];
|
|
18
|
+
/** Width of the drawing across the medium's page direction, in mm, with its margins. */
|
|
19
|
+
export declare const frameWidth: (box: Layout['box'], medium: Medium, em: number, unit?: LengthUnit) => number;
|
|
20
|
+
/**
|
|
21
|
+
* The smallest text size of at least 1.8 mm that renders 11 CSS px when the widest figure
|
|
22
|
+
* (`widest(em)`, its frame width in mm) fills the 358 px phone column (8 px per mm at most): the
|
|
23
|
+
* width is near linear in the text size, so two layouts give it in closed form; a last check steps
|
|
24
|
+
* up where it is not.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fitEm(widest: (em: number) => number): number;
|
|
27
|
+
/** The scale bar and the unit note, in the outer frame. */
|
|
28
|
+
export interface ScaleBar {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
/** In mm. */
|
|
32
|
+
length: number;
|
|
33
|
+
/** The bar's text: its length in the unit, "10 mm" or "0.5 in". */
|
|
34
|
+
label: string;
|
|
35
|
+
text: [number, number];
|
|
36
|
+
/** "Dimensions in mm" or "Dimensions in inches". */
|
|
37
|
+
note: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The outer frame (x, y, width, height in mm) around the part-frame box of the layout, at least
|
|
41
|
+
* `across` mm across the medium's page direction, with the scale bar strip below.
|
|
42
|
+
*/
|
|
43
|
+
export declare function figureFrame(box: [number, number, number, number], medium: Medium, em: number, across: number, unit?: LengthUnit): {
|
|
44
|
+
frame: [number, number, number, number];
|
|
45
|
+
scale: ScaleBar;
|
|
46
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as face from './face.js';
|
|
2
|
+
import { textWidth } from './text.js';
|
|
3
|
+
import { perUnit, scaleLength, unitNote } from './units.js';
|
|
4
|
+
/** The part frame direction that reads level on the medium. */
|
|
5
|
+
export const readingDirection = (medium) => medium === 'screen' ? [0, 1] : [1, 0];
|
|
6
|
+
/**
|
|
7
|
+
* The dash-dot axis of a side: from 1 mm behind the head to 2 mm past the part, or on to the
|
|
8
|
+
* stations dimensioned past it (S, L6 short of the break) plus the overrun.
|
|
9
|
+
*/
|
|
10
|
+
export function axisReach(p) {
|
|
11
|
+
const zMax = Math.max(...p.points.map(([, z]) => z));
|
|
12
|
+
const reach = p.annotation.dimensions
|
|
13
|
+
.filter((d) => d.kind !== 'diameter' && d.to <= zMax + face.breakAllowance * zMax)
|
|
14
|
+
.map((d) => d.to);
|
|
15
|
+
return [-1, Math.max(zMax + 2, ...reach.map((z) => z + face.overrun))];
|
|
16
|
+
}
|
|
17
|
+
/** Width of the drawing across the medium's page direction, in mm, with its margins. */
|
|
18
|
+
export const frameWidth = (box, medium, em, unit = 'mm') => Math.max((medium === 'screen' ? box[3] - box[1] : box[2] - box[0]) + 2 * face.frameMargin, textWidth(unitNote(unit), em) + 2 * face.frameMargin);
|
|
19
|
+
/**
|
|
20
|
+
* The smallest text size of at least 1.8 mm that renders 11 CSS px when the widest figure
|
|
21
|
+
* (`widest(em)`, its frame width in mm) fills the 358 px phone column (8 px per mm at most): the
|
|
22
|
+
* width is near linear in the text size, so two layouts give it in closed form; a last check steps
|
|
23
|
+
* up where it is not.
|
|
24
|
+
*/
|
|
25
|
+
export function fitEm(widest) {
|
|
26
|
+
const px = (em, w = widest(em)) => em * Math.min(face.pxPerMm, face.phoneColumn / w);
|
|
27
|
+
const e1 = face.minEm;
|
|
28
|
+
const w1 = widest(e1);
|
|
29
|
+
if (px(e1, w1) >= face.minTextPx)
|
|
30
|
+
return e1;
|
|
31
|
+
// the layout is linear only between label moves: the slope comes from a nearby size
|
|
32
|
+
const e2 = 1.15 * e1;
|
|
33
|
+
const b = (widest(e2) - w1) / (e2 - e1);
|
|
34
|
+
const a = w1 - b * e1;
|
|
35
|
+
const room = face.phoneColumn - face.minTextPx * b;
|
|
36
|
+
let em = Math.ceil(Math.max(e1, room > 0 ? (face.minTextPx * a) / room : e1) * 1000) / 1000;
|
|
37
|
+
for (let n = 0; n < 60 && px(em) < face.minTextPx - 1e-9; n++)
|
|
38
|
+
em = Math.ceil(em * 1020) / 1000;
|
|
39
|
+
return em;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The outer frame (x, y, width, height in mm) around the part-frame box of the layout, at least
|
|
43
|
+
* `across` mm across the medium's page direction, with the scale bar strip below.
|
|
44
|
+
*/
|
|
45
|
+
export function figureFrame(box, medium, em, across, unit = 'mm') {
|
|
46
|
+
const m = face.frameMargin;
|
|
47
|
+
// the outer frame: screen x = part y, screen y = -part x
|
|
48
|
+
let [x0, y0, x1, y1] = medium === 'screen' ? [box[1], -box[2], box[3], -box[0]] : box;
|
|
49
|
+
x0 -= m;
|
|
50
|
+
y0 -= m;
|
|
51
|
+
x1 += m;
|
|
52
|
+
y1 += m;
|
|
53
|
+
const note = unitNote(unit);
|
|
54
|
+
const w = Math.max(x1 - x0, across, textWidth(note, em) + 2 * m);
|
|
55
|
+
const strip = 2.6 * em;
|
|
56
|
+
const bar = scaleLength(w - 2 * m - textWidth(unit === 'mm' ? '00 mm' : '0.0 in', em) - em, unit);
|
|
57
|
+
return {
|
|
58
|
+
frame: [x0, y0, w, y1 - y0 + strip],
|
|
59
|
+
scale: {
|
|
60
|
+
x: x0 + m,
|
|
61
|
+
y: y1 - m / 2 + 0.6 * em,
|
|
62
|
+
length: bar * perUnit[unit],
|
|
63
|
+
label: `${unit === 'mm' ? bar : String(bar).replace(/^0\./, '.')} ${unit}`,
|
|
64
|
+
text: [x0 + m, y1 - m / 2 + 1.9 * em],
|
|
65
|
+
note,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PartPoint } from './section.ts';
|
|
2
|
+
import type { Arc, Arrowhead, Label, Layout, LineSegment, Part } from './types.ts';
|
|
3
|
+
/** One place to try for a text, with the lines, arrowheads, arc and diameter tips it brings. */
|
|
4
|
+
export type Candidate = {
|
|
5
|
+
l: Label;
|
|
6
|
+
segs?: LineSegment[];
|
|
7
|
+
tips?: Arrowhead[];
|
|
8
|
+
arc?: Arc;
|
|
9
|
+
across?: Layout['diameterTips'][number];
|
|
10
|
+
};
|
|
11
|
+
/** What the steps of one layout share: the face at its text size, what is placed, the choice. */
|
|
12
|
+
export type Placer = ReturnType<typeof createPlacer>;
|
|
13
|
+
/** At text size `em` (mm) in the part frame: the face distances at that size, what is placed so far (from the axis line over `axis`) and the count of what a candidate runs into; `keepCorners` makes a diameter arrowhead in a radius corner's room cost a little. */
|
|
14
|
+
export declare function createPlacer(part: Part, em: number, horizontal: PartPoint, axis: [number, number], keepCorners: boolean): {
|
|
15
|
+
part: Part;
|
|
16
|
+
points: import("./types.ts").SectionPoint[];
|
|
17
|
+
annotation: import("./types.ts").Annotation;
|
|
18
|
+
lengthUnit: import("./units.ts").LengthUnit | undefined;
|
|
19
|
+
fixedDecimals: boolean;
|
|
20
|
+
em: number;
|
|
21
|
+
horizontal: PartPoint;
|
|
22
|
+
k: number;
|
|
23
|
+
lane0: number;
|
|
24
|
+
pitch: number;
|
|
25
|
+
arrowLen: number;
|
|
26
|
+
tailLen: number;
|
|
27
|
+
rMax: number;
|
|
28
|
+
zMax: number;
|
|
29
|
+
zBreak: number;
|
|
30
|
+
gap: number;
|
|
31
|
+
leaderLength: number;
|
|
32
|
+
labels: Label[];
|
|
33
|
+
segs: LineSegment[];
|
|
34
|
+
arcs: Arc[];
|
|
35
|
+
tips: Arrowhead[];
|
|
36
|
+
across: {
|
|
37
|
+
owner: string;
|
|
38
|
+
tips: [PartPoint, PartPoint];
|
|
39
|
+
}[];
|
|
40
|
+
spans: {
|
|
41
|
+
owner: string;
|
|
42
|
+
length: number;
|
|
43
|
+
outside: boolean;
|
|
44
|
+
broken: boolean;
|
|
45
|
+
}[];
|
|
46
|
+
placements: {
|
|
47
|
+
candidates: Candidate[];
|
|
48
|
+
chosen: Candidate;
|
|
49
|
+
}[];
|
|
50
|
+
start: (z: number) => number;
|
|
51
|
+
label: (text: string, c: PartPoint, dir: PartPoint, owner: string) => Label;
|
|
52
|
+
textConflicts: ({ l, segs: own, tips: ownTips }: Candidate, limit?: number) => number;
|
|
53
|
+
conflicts: (c: Candidate) => number;
|
|
54
|
+
pick: (candidates: Candidate[]) => Candidate;
|
|
55
|
+
commit: (c: Candidate) => void;
|
|
56
|
+
uncommit: (c: Candidate) => void;
|
|
57
|
+
place: (candidates: Candidate[]) => void;
|
|
58
|
+
rule: (a: PartPoint, b: PartPoint, owner: string, outside: boolean) => void;
|
|
59
|
+
broken: (a: PartPoint, b: PartPoint, owner: string) => void;
|
|
60
|
+
};
|