@logomarks/generate 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README.md +41 -2
  4. package/package.json +29 -4
  5. package/src/controls.js +34 -0
  6. package/src/draw.js +60 -0
  7. package/src/finish.js +172 -0
  8. package/src/generate.js +194 -0
  9. package/src/guard.js +66 -0
  10. package/src/index.d.ts +96 -0
  11. package/src/index.js +9 -0
  12. package/src/presets.js +26 -0
  13. package/src/random.js +23 -0
  14. package/src/raster.js +52 -0
  15. package/src/recipes/arcs.js +83 -0
  16. package/src/recipes/bands.js +90 -0
  17. package/src/recipes/bars.js +106 -0
  18. package/src/recipes/blobs.js +74 -0
  19. package/src/recipes/bloom.js +53 -0
  20. package/src/recipes/burst.js +44 -0
  21. package/src/recipes/chevrons.js +45 -0
  22. package/src/recipes/cut.js +80 -0
  23. package/src/recipes/dashes.js +61 -0
  24. package/src/recipes/dots.js +47 -0
  25. package/src/recipes/fan.js +73 -0
  26. package/src/recipes/fold.js +66 -0
  27. package/src/recipes/hex.js +58 -0
  28. package/src/recipes/horizon.js +51 -0
  29. package/src/recipes/index.js +79 -0
  30. package/src/recipes/iso.js +35 -0
  31. package/src/recipes/letter.js +204 -0
  32. package/src/recipes/line.js +142 -0
  33. package/src/recipes/links.js +63 -0
  34. package/src/recipes/orbit.js +50 -0
  35. package/src/recipes/pixel.js +38 -0
  36. package/src/recipes/rings.js +82 -0
  37. package/src/recipes/route.js +107 -0
  38. package/src/recipes/shear.js +61 -0
  39. package/src/recipes/spiral.js +42 -0
  40. package/src/recipes/split.js +54 -0
  41. package/src/recipes/stack.js +71 -0
  42. package/src/recipes/steps.js +35 -0
  43. package/src/recipes/stripes.js +66 -0
  44. package/src/recipes/tiles.js +60 -0
  45. package/src/recipes/tri.js +126 -0
  46. package/src/recipes/turns.js +41 -0
  47. package/src/recipes/twin.js +64 -0
  48. package/src/recipes/venn.js +54 -0
  49. package/src/recipes/waves.js +40 -0
  50. package/src/shapes.js +54 -0
package/src/guard.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The quality guard: what makes a generated mark unusable at small sizes, read from its geometry before fitting.
3
+ * A mark fails on a speck (a piece much smaller than the rest), a sliver (a piece thinner than about half the house
4
+ * gap on average), hairline holes (the counters an opening of radius 1 px wipes out, past `maxThinHoles`), thin parts (spikes, pinched necks or slivers that an opening of a small bitmap wipes out, past
5
+ * `maxThinShare` of the ink), too many pieces to read at 32 px, too plain (one solid convex shape with no hole: a bare
6
+ * square, disc or quarter disc is not a mark), or too sparse (the ink under `minInkShare` of its own bounding box).
7
+ */
8
+ import { signedArea, perimeter } from '@logomarks/core/geometry';
9
+ import { fill, thinShareBits } from './raster.js';
10
+
11
+ /** The limits, in units of the 448 box. */
12
+ export const GUARD = { minPieceShare: 0.012, minMeanWidth: 14, maxPieces: 26, raster: 128, neck: 2, maxThinShare: 0.035, plainSolidity: 0.96, minInkShare: 0.14, maxThinHoles: 0.45 };
13
+
14
+ /** Each piece of a shape (a polygon: its outer ring and holes) with its area and mean width (2 × area / perimeter). */
15
+ export function pieces(shape) {
16
+ const polys = !shape || !shape.length ? [] : typeof shape[0][0][0] === 'number' ? [shape] : shape; // a lone polygon too
17
+ return polys.map((poly) => {
18
+ const a = Math.abs(signedArea(poly[0])) - poly.slice(1).reduce((s, h) => s + Math.abs(signedArea(h)), 0);
19
+ const per = poly.reduce((s, ring) => s + perimeter(ring), 0);
20
+ return { area: a, width: (2 * a) / Math.max(per, 1e-9) };
21
+ });
22
+ }
23
+
24
+ /** What is wrong with a shape, in plain words; empty when it passes. `limits` overrides GUARD's for a recipe. */
25
+ export function problems(shape, limits = {}) {
26
+ const L = { ...GUARD, ...limits };
27
+ const ps = pieces(shape).filter((p) => p.area > 1e-6), out = [];
28
+ if (!ps.length) return ['nothing drawn'];
29
+ const total = ps.reduce((s, p) => s + p.area, 0);
30
+ if (ps.length > L.maxPieces) out.push(`${ps.length} pieces, too busy`);
31
+ if (ps.some((p) => p.area < L.minPieceShare * total)) out.push('a speck');
32
+ if (ps.some((p) => p.width < L.minMeanWidth)) out.push('a sliver');
33
+ if (!out.length && thinShare(shape) > L.maxThinShare) out.push('thin parts');
34
+ const polys = typeof shape[0][0][0] === 'number' ? [shape] : shape;
35
+ // the holes read too: a knocked-out mark (a badge, an outline) whose holes are hairlines is unreadable at 32 px
36
+ const holes = polys.flatMap((poly) => poly.slice(1).map((h) => [h]));
37
+ const holeArea = holes.reduce((t, h) => t + Math.abs(signedArea(h[0])), 0);
38
+ if (!out.length && holeArea > 0.03 * total && thinShareBits(fill(holes, GUARD.raster), GUARD.raster, 1) > L.maxThinHoles) out.push('hairline holes');
39
+ if (polys.length === 1 && polys[0].length === 1 && total / hullArea(polys[0][0]) > L.plainSolidity) out.push('too plain');
40
+ const [x0, y0, x1, y1] = box(polys);
41
+ if (total / Math.max(1, (x1 - x0) * (y1 - y0)) < L.minInkShare) out.push('too sparse');
42
+ return out;
43
+ }
44
+
45
+ /** The share of the ink in parts thinner than about twice `neck` pixels of a `raster`-wide bitmap (4 units a pixel at
46
+ * 128): what an opening (erode, then dilate) wipes out. */
47
+ export function thinShare(shape) {
48
+ return thinShareBits(fill(shape, GUARD.raster), GUARD.raster, GUARD.neck);
49
+ }
50
+
51
+ /** The bounding box of polygons: [x0, y0, x1, y1]. */
52
+ function box(polys) {
53
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
54
+ for (const poly of polys) for (const [x, y] of poly[0]) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }
55
+ return [x0, y0, x1, y1];
56
+ }
57
+
58
+ /** The area of a ring's convex hull (monotone chain). */
59
+ function hullArea(ring) {
60
+ const pts = [...ring].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
61
+ const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
62
+ const lower = [], upper = [];
63
+ for (const p of pts) { while (lower.length >= 2 && cross(lower.at(-2), lower.at(-1), p) <= 0) lower.pop(); lower.push(p); }
64
+ for (const p of pts.reverse()) { while (upper.length >= 2 && cross(upper.at(-2), upper.at(-1), p) <= 0) upper.pop(); upper.push(p); }
65
+ return Math.abs(signedArea([...lower.slice(0, -1), ...upper.slice(0, -1)]));
66
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,96 @@
1
+ /** A control a recipe exposes. */
2
+ export type Control = (
3
+ | { key: string; label: string; type: 'range'; min: number; max: number; step: number; value: number }
4
+ | { key: string; label: string; type: 'choice'; options: string[]; value: string }
5
+ | { key: string; label: string; type: 'toggle'; value: boolean }
6
+ ) & {
7
+ /** 'finish' for the shared finish controls (turn, mirror, round, outline); none for the recipe's own. */
8
+ group?: 'finish';
9
+ };
10
+
11
+ /** Param values by control key. */
12
+ export type Params = Record<string, number | string | boolean>;
13
+
14
+ /** A recipe: a construction and its controls. */
15
+ export interface Recipe {
16
+ id: string;
17
+ /** Its name in a picker ("Bars"). */
18
+ name: string;
19
+ /** One plain line about it. */
20
+ line: string;
21
+ controls: Control[];
22
+ /** The mark for resolved params, unfitted, as a core Shape. */
23
+ build(params: Params): unknown;
24
+ /** The guard's limits this recipe overrides (dots and pixels are many pieces by design). */
25
+ guard: Partial<{ minPieceShare: number; minMeanWidth: number; maxPieces: number; maxThinShare: number; plainSolidity: number; minInkShare: number }>;
26
+ }
27
+
28
+ /** A generated mark. */
29
+ export interface Generated {
30
+ recipe: string;
31
+ /** The params it was drawn with, resolved (every control, clamped). */
32
+ params: Params;
33
+ /** The fitted SVG: 512 canvas, longest side 448, centred, currentColor. */
34
+ svg: string;
35
+ /** The fitted mark's pieces as SVG path data, one per piece (its outline and holes, even-odd), in reading order. */
36
+ pieces: string[];
37
+ /** What the guard found wrong (a speck, a sliver, too busy); empty when it passes. */
38
+ problems: string[];
39
+ /** The seed its params were drawn from, for a variation. */
40
+ seed?: number;
41
+ }
42
+
43
+ /** Every recipe, by id: bars, bands, twin, stack, shear, turns, burst, tiles, route, arcs, rings, stripes, dots, pixel,
44
+ * chevrons, waves. */
45
+ export const RECIPES: Record<string, Recipe>;
46
+ /** A recipe by id; throws for an unknown one. */
47
+ export function recipe(id: string): Recipe;
48
+ /** A mark from a recipe and its params (defaults for missing ones, clamped), fitted to the standard. */
49
+ export function generate(id: string, params?: Params): Generated;
50
+ /** Random params from a seed, keeping `locked` keys at `base`. */
51
+ export function randomParams(id: string, seed: number | string, o?: { base?: Params; locked?: string[]; finish?: boolean }): Params;
52
+ /** `count` marks from consecutive seeds, `locked` controls held at `base`; failed draws are skipped. */
53
+ export function variations(id: string, o?: { count?: number; seed?: number | string; base?: Params; locked?: string[]; finish?: boolean }): Generated[];
54
+ /** Params close to `params`: ranges nudged by up to `amount` of their span, a choice swapped now and then; toggles, the
55
+ * finish and `locked` keys kept. */
56
+ export function nearby(id: string, params: Params, o?: { seed?: number | string; amount?: number; locked?: string[] }): Params;
57
+ /** `count` marks close to `params`, failed draws skipped, none repeated. */
58
+ export function similar(id: string, params: Params, o?: { count?: number; seed?: number | string; amount?: number; locked?: string[] }): Generated[];
59
+ /** `count` marks from any recipe (picked per seed from `ids`), random params, failed draws skipped: a bulk random mix. */
60
+ export function mix(o?: { count?: number; seed?: number | string; ids?: string[] }): Generated[];
61
+ /** Every control's default. */
62
+ export function defaults(controls: Control[]): Params;
63
+ /** Every control's value from params, clamped, defaults for missing ones. */
64
+ export function resolve(controls: Control[], params?: Params): Params;
65
+ /** One value fitted to its control. */
66
+ export function clampTo(control: Control, v: unknown): number | string | boolean;
67
+ /** A random value for a control. */
68
+ export function randomValue(control: Control, r: () => number): number | string | boolean;
69
+ /** A random function in [0, 1) from a seed (mulberry32). */
70
+ export function rng(seed: number | string): () => number;
71
+ /** A seed from a number or a string, as an unsigned 32-bit integer. */
72
+ export function seedOf(seed: number | string): number;
73
+ /** The guard's limits, in units of the 448 box. */
74
+ export const GUARD: { minPieceShare: number; minMeanWidth: number; maxPieces: number };
75
+ /** What is wrong with an unfitted shape, in plain words; empty when it passes. */
76
+ export function problems(shape: unknown, limits?: Record<string, number>): string[];
77
+ /** A preset: a recipe and its settings, a one-click starting point. */
78
+ export interface Preset {
79
+ id: string;
80
+ name: string;
81
+ recipe: string;
82
+ params: Params;
83
+ /** One plain line about it. */
84
+ note: string;
85
+ }
86
+ /** The combinations the references use most, each drawing and passing the guard. */
87
+ export const PRESETS: Preset[];
88
+ /** An unfitted shape's pieces as SVG path data in the fitted 512 canvas (longest side 448, centred), in reading order. */
89
+ export function piecesOf(shape: unknown): string[];
90
+ /**
91
+ * An SVG of pieces in two colours: `colors` [base, accent] (default currentColor and #c8ff00); `pattern` alternate (every
92
+ * other piece in the accent), first (the first piece), rows (every other row) or size (the biggest piece).
93
+ */
94
+ export function svgOf(pieces: string[], o?: { colors?: [string, string]; pattern?: 'alternate' | 'first' | 'last' | 'rows' | 'size' | 'smallest' | 'inner' | 'outer' | 'left' | 'top' | 'gradient' }): string;
95
+ /** The colour patterns `svgOf` knows, in a picker's order. */
96
+ export const PATTERNS: readonly string[];
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @logomarks/generate: abstract logomarks from rules and controls, no AI.
3
+ */
4
+ export { RECIPES } from './recipes/index.js';
5
+ export { recipe, generate, randomParams, variations, nearby, similar, mix, piecesOf, svgOf, PATTERNS } from './generate.js';
6
+ export { defaults, resolve, clampTo, randomValue } from './controls.js';
7
+ export { rng, seedOf } from './random.js';
8
+ export { GUARD, problems } from './guard.js';
9
+ export { PRESETS } from './presets.js';
package/src/presets.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Presets: the combinations the owner's references use most (generator-study.md, "Combinations"), each a recipe and its
3
+ * settings, so a page can offer them as one-click starting points. Every one draws and passes the guard (tested).
4
+ */
5
+
6
+ /** @type {import('./index.js').Preset[]} */
7
+ export const PRESETS = [
8
+ { id: 'speed-bands', name: 'Speed bands', recipe: 'bands', params: { count: 3, join: 'slant', joinWidth: 0.2, ends: 'square', extra: 'both' }, note: 'Three bands climbing through a slanted step.' },
9
+ { id: 'corner-arrow', name: 'Corner arrow', recipe: 'arcs', params: { sweep: 'quarter', count: 2, legs: 0.35, move: 'arrow', corner: 'square' }, note: 'Nested corner bands cut by a diagonal arrow.' },
10
+ { id: 'slab-pair', name: 'Slab pair', recipe: 'shear', params: { rows: 2, cols: 2, lean: 'same', angle: 30, lengths: 'alternate', slide: 0.25 }, note: 'Four slanted slabs, long and short, slid a row.' },
11
+ { id: 'cut-h', name: 'Cut H', recipe: 'bars', params: { count: 3, cut: 'middle', cutSize: 0.18, cutAngle: 35 }, note: 'Three bars, the middle one cut on a slant.' },
12
+ { id: 'skyline', name: 'Skyline', recipe: 'bars', params: { count: 4, cut: 'none', lengths: 'arch', ends: 'square', weight: 0.72 }, note: 'Four towers, tallest in the middle.' },
13
+ { id: 'half-pills', name: 'Half pills', recipe: 'bars', params: { count: 3, cut: 'none', level: true, lengths: 'rising', round: 40, roundWhich: 'each-right' }, note: 'Stacked bars, flat on the left and round on the right.' },
14
+ { id: 'twin-slant', name: 'Twin slant', recipe: 'twin', params: { piece: 'L', slant: 20, corner: 'cut', ends: 'angled' }, note: 'Two Ls turned about the centre, leaning.' },
15
+ { id: 'six-ray', name: 'Six-ray asterisk', recipe: 'burst', params: { rays: 6, ray: 'bar', inner: 0.12, width: 0.13, move: 'none' }, note: 'Six heavy bars round an open centre.' },
16
+ { id: 'striped-disc', name: 'Striped disc', recipe: 'stripes', params: { shape: 'circle', angle: 45, move: 'shift' }, note: 'A disc of diagonal stripes, every other one slid.' },
17
+ { id: 'diagonal-slot', name: 'Diagonal slot', recipe: 'cut', params: { body: 'square', cut: 'slot', angle: '45' }, note: 'A square with one slot run in from the corner.' },
18
+ { id: 'split-diamond', name: 'Split diamond', recipe: 'split', params: { shape: 'diamond', cuts: 2, slide: 0.2 }, note: 'A diamond in three slid parts.' },
19
+ { id: 'soft-steps', name: 'Soft steps', recipe: 'tiles', params: { round: 20, roundWhich: 'alternate' }, note: 'A grid of tiles, every other one softened.' },
20
+ { id: 'arrow-stack', name: 'Arrow stack', recipe: 'chevrons', params: { count: 3, point: 'right', grow: 0, tip: 'flat' }, note: 'Three flat-tipped chevrons pointing right.' },
21
+ { id: 'facing-halves', name: 'Facing halves', recipe: 'stack', params: { layout: 'row', count: 2, shapeA: 'half', shapeB: 'half', turnA: '90', turnB: '270', combine: 'gap' }, note: 'Two half discs back to back.' },
22
+ { id: 'round-meander', name: 'Round meander', recipe: 'route', params: { frame: 'open', turns: 'round', diagonals: false, node: 'none', ends: 'square', tracks: 1, steps: 3 }, note: 'One band meandering inside an open frame, soft turns.' },
23
+ { id: 'three-chevrons', name: 'Three chevrons', recipe: 'turns', params: { unit: 'chevron', count: '3', join: 'gap', face: '180', size: 0.44, radius: 0.1 }, note: 'Three chevrons pointing in round the centre.' },
24
+ { id: 'dash-columns', name: 'Dash columns', recipe: 'dashes', params: { rows: 3, rhythm: 'halves', align: 'left' }, note: 'Three rows of paired dashes.' },
25
+ { id: 'outlined-frames', name: 'Outlined frames', recipe: 'stack', params: { layout: 'nest', count: 3, shapeA: 'square', shapeB: 'square', combine: 'over', outline: 30 }, note: 'Nested squares drawn as outlines.' },
26
+ ];
package/src/random.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Seeded random numbers: the same seed always draws the same mark.
3
+ */
4
+
5
+ /** A seed from a number or any string (FNV-1a), as an unsigned 32-bit integer. */
6
+ export function seedOf(seed) {
7
+ if (typeof seed === 'number' && Number.isFinite(seed)) return seed >>> 0;
8
+ let h = 2166136261;
9
+ for (const ch of String(seed)) h = Math.imul(h ^ ch.codePointAt(0), 16777619);
10
+ return h >>> 0;
11
+ }
12
+
13
+ /** A random function in [0, 1) from a seed (mulberry32). */
14
+ export function rng(seed) {
15
+ let a = seedOf(seed);
16
+ return () => {
17
+ a = (a + 0x6d2b79f5) >>> 0;
18
+ let t = a;
19
+ t = Math.imul(t ^ (t >>> 15), t | 1);
20
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
21
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
22
+ };
23
+ }
package/src/raster.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A small bitmap of a shape, and opening it (erode, then dilate): the guard's fast test for thin parts.
3
+ */
4
+
5
+ /** The shape filled into an N × N bitmap of the 512 canvas (even-odd, sampled at pixel centres). */
6
+ export function fill(shape, N = 128) {
7
+ const bits = new Uint8Array(N * N), k = 512 / N, edges = [];
8
+ for (const poly of shape) for (const ring of poly) for (let i = 0; i < ring.length; i++) {
9
+ const a = ring[i], b = ring[(i + 1) % ring.length];
10
+ if (a[1] !== b[1]) edges.push(a[1] < b[1] ? [a[0], a[1], b[0], b[1]] : [b[0], b[1], a[0], a[1]]);
11
+ }
12
+ for (let row = 0; row < N; row++) {
13
+ const y = (row + 0.5) * k, xs = [];
14
+ for (const [x0, y0, x1, y1] of edges) if (y >= y0 && y < y1) xs.push(x0 + ((y - y0) * (x1 - x0)) / (y1 - y0));
15
+ xs.sort((p, q) => p - q);
16
+ for (let i = 0; i + 1 < xs.length; i += 2) {
17
+ const c0 = Math.max(0, Math.ceil(xs[i] / k - 0.5)), c1 = Math.min(N - 1, Math.floor(xs[i + 1] / k - 0.5));
18
+ for (let c = c0; c <= c1; c++) bits[row * N + c] = 1;
19
+ }
20
+ }
21
+ return bits;
22
+ }
23
+
24
+ /** The offsets of a disc of radius r pixels. */
25
+ function disc(r) {
26
+ const out = [];
27
+ for (let dy = -r; dy <= r; dy++) for (let dx = -r; dx <= r; dx++) if (dx * dx + dy * dy <= r * r + r) out.push([dx, dy]);
28
+ return out;
29
+ }
30
+
31
+ /** One pass of erosion (`all` true: kept where the whole disc is set) or dilation (set where any of it is). */
32
+ function morph(bits, N, r, all) {
33
+ const out = new Uint8Array(N * N), d = disc(r);
34
+ for (let y = 0; y < N; y++) for (let x = 0; x < N; x++) {
35
+ let v = all ? 1 : 0;
36
+ for (const [dx, dy] of d) {
37
+ const X = x + dx, Y = y + dy, b = X >= 0 && Y >= 0 && X < N && Y < N ? bits[Y * N + X] : 0;
38
+ if (all && !b) { v = 0; break; }
39
+ if (!all && b) { v = 1; break; }
40
+ }
41
+ out[y * N + x] = v;
42
+ }
43
+ return out;
44
+ }
45
+
46
+ /** The share of set pixels an opening of radius r wipes out (parts thinner than about 2r pixels). */
47
+ export function thinShareBits(bits, N, r) {
48
+ const opened = morph(morph(bits, N, r, true), N, r, false);
49
+ let ink = 0, kept = 0;
50
+ for (let i = 0; i < bits.length; i++) { ink += bits[i]; kept += bits[i] & opened[i]; }
51
+ return ink ? (ink - kept) / ink : 0;
52
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Arcs: nested quarter or half rings from a corner or an edge, the house gap between them, round a core (a quarter disc,
3
+ * a square or nothing), with ONE move: an arrow cut along the diagonal, a slot, or the group mirrored into a pair. After
4
+ * nested arches, stepped arcs and corner bands. The default is arches on legs: a quarter of rings round a disc in a
5
+ * corner is the RSS or Wi-Fi icon. `corner` squares or chamfers the bands into nested L-bands (the corporate-modernist
6
+ * corner marks), `slant` shears the group, and a `quarter` core fills the innermost corner in the bands' own corner style
7
+ * (only on legs: a bare quarter round a corner core is the RSS icon again).
8
+ */
9
+ import { U, D, I, rect, circle, poly, arcBand, sector, mapPts } from '@logomarks/core/geometry';
10
+ import { BOX, GAP, tidy, shear } from '../draw.js';
11
+
12
+ /** @type {import('../index.js').Control[]} */
13
+ export const controls = [
14
+ { key: 'count', label: 'Rings', type: 'range', min: 1, max: 5, step: 1, value: 3 },
15
+ { key: 'sweep', label: 'Sweep', type: 'choice', options: ['half', 'quarter'], value: 'half' },
16
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.85, step: 0.01, value: 0.6 },
17
+ { key: 'core', label: 'Core', type: 'choice', options: ['none', 'disc', 'square', 'quarter'], value: 'none' },
18
+ { key: 'legs', label: 'Legs', type: 'range', min: 0, max: 0.6, step: 0.01, value: 0.3 },
19
+ { key: 'move', label: 'Move', type: 'choice', options: ['none', 'arrow', 'slot', 'pair'], value: 'none' },
20
+ { key: 'corner', label: 'Corner', type: 'choice', options: ['round', 'square', 'chamfer'], value: 'round' },
21
+ { key: 'chamfer', label: 'Chamfer', type: 'range', min: 0.3, max: 0.6, step: 0.01, value: 0.4 },
22
+ { key: 'slant', label: 'Slant', type: 'range', min: -25, max: 25, step: 1, value: 0 },
23
+ ];
24
+
25
+ /**
26
+ * The outer outline of a band at radius `ro` in a corner style: a quarter (opening up-right from (cx, cy)) or a half
27
+ * (opening up), square or chamfered (`c` the chamfer as a share of ro).
28
+ */
29
+ function frame(cx, cy, ro, half, style, c) {
30
+ const k = c * ro;
31
+ if (half) return style === 'square' ? rect(cx - ro, cy - ro, 2 * ro, ro) : poly([[cx - ro, cy], [cx - ro, cy - ro + k], [cx - ro + k, cy - ro], [cx + ro - k, cy - ro], [cx + ro, cy - ro + k], [cx + ro, cy]]);
32
+ return style === 'square' ? rect(cx, cy - ro, ro, ro) : poly([[cx, cy], [cx, cy - ro], [cx + ro - k, cy - ro], [cx + ro, cy - ro + k], [cx + ro, cy]]);
33
+ }
34
+
35
+ /** A band of width t at radius r in a corner style; round is the arc band. */
36
+ function band(cx, cy, r, t, half, p) {
37
+ if (p.corner === 'round') return arcBand(cx, cy, r, t, half ? 180 : 270, 360);
38
+ const ro = r + t / 2, ri = r - t / 2, c = p.chamfer;
39
+ // the inner outline's chamfer is shortened so the band keeps its width round the cut corner
40
+ const ci = ri > 0 ? Math.max(0, (c * ro - t * 0.414) / ri) : 0;
41
+ return ri > 0 ? D(frame(cx, cy, ro, half, p.corner, c), frame(cx, cy, ri, half, p.corner, ci)) : frame(cx, cy, ro, half, p.corner, c);
42
+ }
43
+
44
+ /** One group: rings round a centre at (cx, cy), opening up-right (quarter) or up (half), radius R. */
45
+ function group(p, cx, cy, R, half) {
46
+ const n = p.count, gap = Math.max(GAP, ((1 - p.weight) * R) / (n + 1)), t = (R - n * gap) / (n + 1), parts = [];
47
+ const a0 = half ? 180 : 270, a1 = 360;
48
+ if (p.core === 'disc') parts.push(sector(cx, cy, t, a0, a1, 64));
49
+ if (p.core === 'square') parts.push(I(rect(cx - t, cy - t, half ? 2 * t : t, t), rect(cx - (half ? t : 0), cy - t, half ? 2 * t : t, t)));
50
+ if (p.core === 'quarter') parts.push(p.corner === 'round' ? sector(cx, cy, t, a0, a1, 64) : frame(cx, cy, t, half, p.corner, p.chamfer));
51
+ for (let k = 1; k <= n; k++) {
52
+ const r = t + k * (gap + t) - t / 2;
53
+ parts.push(p.corner === 'round' ? arcBand(cx, cy, r, t, a0, a1) : band(cx, cy, r, t, half, p));
54
+ if (p.legs > 0) { const l = p.legs * R; parts.push(rect(cx + r - t / 2, cy, t, l)); if (half) parts.push(rect(cx - r - t / 2, cy, t, l)); }
55
+ }
56
+ return U(...parts);
57
+ }
58
+
59
+ /** The mark for resolved params. */
60
+ export function build(params) {
61
+ const p = { ...params };
62
+ // a quarter core is for square or chamfered corners only, and on legs: round rings round a corner core are the RSS icon
63
+ if (p.core === 'quarter' && p.corner === 'round') p.core = 'none';
64
+ if (p.core === 'quarter' && p.legs < 0.2) p.legs = 0.25;
65
+ const half = p.sweep === 'half', { x0, y1, cx, size } = BOX;
66
+ let s;
67
+ if (p.move === 'pair') {
68
+ const R = half ? size / 4 : size / 2;
69
+ const one = half ? group(p, cx, BOX.y0 + R, R, true) : group(p, x0, BOX.y0 + R, R, false);
70
+ s = U(one, mapPts(one, ([x, y]) => [2 * BOX.cx - x, 2 * BOX.cy - y]));
71
+ } else {
72
+ s = half ? group(p, cx, y1 - (p.legs * size) / 2, size / 2, true) : group(p, x0, y1, size, false);
73
+ }
74
+ if (p.move === 'arrow') {
75
+ // a slot along the diagonal from the centre corner, ending in an arrowhead out at the far corner
76
+ const w = GAP * 1.6, ox = half ? cx : x0, oy = half ? y1 : y1, L = size * (half ? 0.55 : 1.25), a = half ? -90 : -45;
77
+ const dx = Math.cos((a * Math.PI) / 180), dy = Math.sin((a * Math.PI) / 180), nx = -dy, ny = dx;
78
+ const tip = [ox + dx * L, oy + dy * L];
79
+ s = D(s, poly([[ox + nx * w, oy + ny * w], [tip[0] + nx * w, tip[1] + ny * w], [tip[0] - nx * w, tip[1] - ny * w], [ox - nx * w, oy - ny * w]]));
80
+ }
81
+ if (p.move === 'slot') s = D(s, rect(half ? cx - GAP : x0 - 5, half ? BOX.y0 - 5 : y1 - size * 0.55 - GAP, half ? GAP * 2 : size + 10, half ? size + 10 : GAP * 2));
82
+ return tidy(p.slant ? shear(s, p.slant) : s);
83
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Bands: two to four level bands stacked down the square, each rising one row part way along through ONE kind of
3
+ * join (an S-curve, a slant or a step), every band cleared from the ones above it by the house gap. An optional short
4
+ * piece fills the free end of the bottom row (a tail) or the top row (a cap). After marks of stacked bars climbing
5
+ * through a smooth bend.
6
+ */
7
+ import { U, poly, mapPts, circle } from '@logomarks/core/geometry';
8
+ import { BOX, GAP, clear, shear, level } from '../draw.js';
9
+
10
+ /** @type {import('../index.js').Control[]} */
11
+ export const controls = [
12
+ { key: 'count', label: 'Bands', type: 'range', min: 2, max: 4, step: 1, value: 2 },
13
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.4, max: 0.85, step: 0.01, value: 0.66 },
14
+ { key: 'join', label: 'Join', type: 'choice', options: ['curve', 'slant', 'step'], value: 'curve' },
15
+ { key: 'joinAt', label: 'Join position', type: 'range', min: 0.2, max: 0.7, step: 0.01, value: 0.4 },
16
+ { key: 'joinWidth', label: 'Join width', type: 'range', min: 0.08, max: 0.35, step: 0.01, value: 0.16 },
17
+ { key: 'extra', label: 'Extra piece', type: 'choice', options: ['none', 'tail', 'cap', 'both'], value: 'tail' },
18
+ { key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'round', 'angled'], value: 'square' },
19
+ { key: 'slant', label: 'Slant', type: 'range', min: -25, max: 25, step: 1, value: 0 },
20
+ { key: 'flip', label: 'Mirror', type: 'toggle', value: false },
21
+ ];
22
+
23
+ /** How far along a join the centre line has risen (0 → 1), for a join kind, at t from 0 to 1. */
24
+ function rise(join, t) {
25
+ if (join === 'slant') return t;
26
+ return t * t * (3 - 2 * t); // smoothstep: an S-curve
27
+ }
28
+
29
+ /** One band from the left edge to the right, its left part centred at yL and its right part at yR, `th` thick. */
30
+ function band(p, yL, yR, th, xj, jw) {
31
+ const { x0, x1 } = BOX;
32
+ if (p.join === 'step') {
33
+ // a Z of three straight parts: the left run, an upright the join wide, the right run
34
+ return U(level(x0, xj + jw, yL - th / 2, th, 'square'), level(xj, x1, yR - th / 2, th, 'square'), poly([[xj, yR - th / 2], [xj + jw, yR - th / 2], [xj + jw, yL + th / 2], [xj, yL + th / 2]]));
35
+ }
36
+ const steps = 48, top = [], bottom = [];
37
+ const yc = (x) => (x <= xj ? yL : x >= xj + jw ? yR : yL + (yR - yL) * rise(p.join, (x - xj) / jw));
38
+ const xs = [x0, ...Array.from({ length: steps + 1 }, (_, i) => xj + (jw * i) / steps), x1];
39
+ for (const x of xs) { top.push([x, yc(x) - th / 2]); bottom.push([x, yc(x) + th / 2]); }
40
+ return poly([...top, ...bottom.reverse()]);
41
+ }
42
+
43
+ /** Round or angle a band's two free ends by trimming it with its end caps. */
44
+ function ends(shape, p, yL, yR, th) {
45
+ if (p.ends === 'square') return shape;
46
+ const { x0, x1 } = BOX;
47
+ if (p.ends === 'round') {
48
+ const trim = poly([[x0 - 1, yL - th], [x0 + th / 2, yL - th], [x0 + th / 2, yL + th], [x0 - 1, yL + th]]);
49
+ const trimR = poly([[x1 - th / 2, yR - th], [x1 + 1, yR - th], [x1 + 1, yR + th], [x1 - th / 2, yR + th]]);
50
+ return U(clearExact(shape, U(trim, trimR)), circle(x0 + th / 2, yL, th / 2, 64), circle(x1 - th / 2, yR, th / 2, 64));
51
+ }
52
+ // angled: both ends cut at 45°, parallel
53
+ const cutL = poly([[x0 - 1, yL - th / 2 - 1], [x0 + th, yL - th / 2 - 1], [x0, yL + th / 2 + 1], [x0 - 1, yL + th / 2 + 1]]);
54
+ const cutR = poly([[x1, yR - th / 2 - 1], [x1 + 1, yR - th / 2 - 1], [x1 + 1, yR + th / 2 + 1], [x1 - th, yR + th / 2 + 1]]);
55
+ return clearExact(shape, U(cutL, cutR));
56
+ }
57
+
58
+ /** A level piece centred at y from x0 to x1, only its `side` end shaped (round, or square for anything else). */
59
+ function endOnly(x0, x1, y, th, shape, side) {
60
+ if (shape !== 'round' || x1 - x0 < th * 1.5) return level(x0, x1, y - th / 2, th, 'square');
61
+ return side === 'right'
62
+ ? U(level(x0, x1 - th / 2, y - th / 2, th, 'square'), circle(x1 - th / 2, y, th / 2, 64))
63
+ : U(level(x0 + th / 2, x1, y - th / 2, th, 'square'), circle(x0 + th / 2, y, th / 2, 64));
64
+ }
65
+
66
+ /** `a` without `b` (no gap). */
67
+ function clearExact(a, b) { return clear(a, b, 0.0001); }
68
+
69
+ /** The mark for resolved params. */
70
+ export function build(params) {
71
+ // a step join is three straight runs: its ends stay square, or the caps land on the upright
72
+ const p = params.join === 'step' ? { ...params, ends: 'square' } : params;
73
+ const rows = p.count + 1;
74
+ const gap = Math.max(GAP, ((1 - p.weight) * BOX.size) / rows);
75
+ const th = (BOX.size - (rows - 1) * gap) / rows;
76
+ const yOf = (r) => BOX.y0 + r * (th + gap) + th / 2;
77
+ const xj = BOX.x0 + p.joinAt * BOX.size, jw = Math.max(p.join === 'step' ? th : th * 0.5, p.joinWidth * BOX.size);
78
+ const placed = [];
79
+ for (let k = 0; k < p.count; k++) {
80
+ let b = ends(band(p, yOf(k + 1), yOf(k), th, xj, jw), p, yOf(k + 1), yOf(k), th);
81
+ if (placed.length) b = clear(b, U(...placed));
82
+ placed.push(b);
83
+ }
84
+ // the extra pieces: square where they meet the bands (that end is carved), shaped like the bands at their free end
85
+ if (p.extra === 'tail' || p.extra === 'both') placed.push(clear(endOnly(xj, BOX.x1, yOf(rows - 1), th, p.ends, 'right'), U(...placed)));
86
+ if (p.extra === 'cap' || p.extra === 'both') placed.push(clear(endOnly(BOX.x0, xj + jw, yOf(0), th, p.ends, 'left'), U(...placed)));
87
+ let mark = shear(U(...placed), p.slant);
88
+ if (p.flip) mark = mapPts(mark, ([x, y]) => [2 * BOX.cx - x, y]);
89
+ return mark;
90
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Bars: two to six upright bars across the square, the house gap or more between them, with ONE move: a cut through
3
+ * some of them (the middle one, every other one, a stair of cuts), lengths that rise or fall, round or angled ends, a
4
+ * slant. After marks like a three-bar H with its middle bar cut, or slanted slashes. `spine` joins the bars with one
5
+ * crossbar (comb and barcode letters), `widths` makes them uneven, `cutAngle` slants the cut and a `notch` cut bites a V
6
+ * into the outer bars' inner edges. Banned reads: three bars on a bottom spine with the middle longest is a trident;
7
+ * rising bars on a common foot with gaps are the signal-bars icon (slanted or cut too; on a bottom spine, a bar chart),
8
+ * so rising bars always hang from a top spine.
9
+ */
10
+ import { U, D, rect, poly, rot } from '@logomarks/core/geometry';
11
+ import { BOX, GAP, upright, shear, quarterTurn, tidy } from '../draw.js';
12
+ import { rng } from '../random.js';
13
+
14
+ /** @type {import('../index.js').Control[]} */
15
+ export const controls = [
16
+ { key: 'count', label: 'Bars', type: 'range', min: 2, max: 6, step: 1, value: 3 },
17
+ { key: 'weight', label: 'Weight', type: 'range', min: 0.35, max: 0.85, step: 0.01, value: 0.6 },
18
+ { key: 'cut', label: 'Cut', type: 'choice', options: ['none', 'middle', 'alternate', 'stair', 'outer', 'notch'], value: 'middle' },
19
+ { key: 'cutSize', label: 'Cut size', type: 'range', min: 0.05, max: 0.3, step: 0.01, value: 0.12 },
20
+ { key: 'cutAt', label: 'Cut height', type: 'range', min: 0.2, max: 0.8, step: 0.01, value: 0.5 },
21
+ { key: 'lengths', label: 'Lengths', type: 'choice', options: ['equal', 'arch', 'valley', 'rising'], value: 'equal' },
22
+ { key: 'ends', label: 'Ends', type: 'choice', options: ['square', 'round', 'angled'], value: 'square' },
23
+ { key: 'slant', label: 'Slant', type: 'range', min: -35, max: 35, step: 1, value: 0 },
24
+ { key: 'level', label: 'Lie flat', type: 'toggle', value: false },
25
+ { key: 'cutAngle', label: 'Cut angle', type: 'range', min: -45, max: 45, step: 1, value: 0 },
26
+ { key: 'spine', label: 'Spine', type: 'choice', options: ['none', 'top', 'bottom', 'middle', 'half'], value: 'none' },
27
+ { key: 'spineWeight', label: 'Spine weight', type: 'range', min: 0.6, max: 1, step: 0.01, value: 0.8 },
28
+ { key: 'widths', label: 'Widths', type: 'choice', options: ['equal', 'growing', 'thin-thick', 'random'], value: 'equal' },
29
+ ];
30
+
31
+ /** Each bar's width: shares of the room left after the gaps, by a widths setting. */
32
+ function widthsOf(kind, n, room) {
33
+ const rand = rng(`bars:${n}`);
34
+ const k = Array.from({ length: n }, (_, i) => (kind === 'growing' ? 0.6 + (0.8 * i) / Math.max(1, n - 1) : kind === 'thin-thick' ? (i % 2 ? 1.4 : 0.6) : kind === 'random' ? 0.55 + rand() * 0.9 : 1));
35
+ const sum = k.reduce((a, b) => a + b, 0);
36
+ // never a bar under 34 wide (a hairline at 32 px): the thin ones take from the rest
37
+ const ws = k.map((v) => (room * v) / sum), floor = Math.min(34, room / n);
38
+ const short = ws.reduce((t, x) => t + Math.max(0, floor - x), 0), over = ws.reduce((t, x) => t + Math.max(0, x - floor), 0);
39
+ return ws.map((x) => (x < floor ? floor : x - (over ? ((x - floor) / over) * short : 0)));
40
+ }
41
+
42
+ /** How tall bar `i` of `n` is, as a share of the box, for a lengths setting. */
43
+ function heightOf(lengths, i, n) {
44
+ const t = n === 1 ? 0 : i / (n - 1), mid = 1 - Math.abs(2 * t - 1);
45
+ if (lengths === 'arch') return 0.55 + 0.45 * mid;
46
+ if (lengths === 'valley') return 1 - 0.45 * mid;
47
+ if (lengths === 'rising') return 0.45 + 0.55 * t;
48
+ return 1;
49
+ }
50
+
51
+ /** Whether bar `i` of `n` is cut, and where along it (0 bottom … 1 top), for a cut setting. */
52
+ function cutOf(cut, i, n, at) {
53
+ const middle = n % 2 ? i === (n - 1) / 2 : i === n / 2 - 1 || i === n / 2;
54
+ if (cut === 'middle') return middle ? at : null;
55
+ if (cut === 'alternate') return i % 2 === 1 ? at : null;
56
+ if (cut === 'outer') return i === 0 || i === n - 1 ? at : null;
57
+ if (cut === 'stair') return 0.2 + (0.6 * i) / Math.max(1, n - 1);
58
+ if (cut === 'notch') return i === 0 || i === n - 1 ? at : null;
59
+ return null;
60
+ }
61
+
62
+ /** The mark for resolved params. */
63
+ export function build(params) {
64
+ const p = { ...params }, n = p.count;
65
+ if (p.spine === 'bottom' && n === 3 && p.lengths === 'arch') p.lengths = 'equal'; // a trident
66
+ // rising bars on one foot are the signal-strength icon (slanted too), and on a bottom spine a bar chart: they hang
67
+ // from a top spine instead, a stepped comb, whatever their cut or slant
68
+ if (p.lengths === 'rising' && (p.spine === 'none' || p.spine === 'bottom') && !p.level) p.spine = 'top';
69
+ const gap = Math.max(GAP, ((1 - p.weight) * BOX.size) / n);
70
+ const ws = widthsOf(p.widths || 'equal', n, BOX.size - (n - 1) * gap);
71
+ const cutH = Math.max(GAP, p.cutSize * BOX.size);
72
+ const parts = [];
73
+ let x = BOX.x0;
74
+ for (let i = 0; i < n; i++) {
75
+ const w = ws[i], h = heightOf(p.lengths, i, n) * BOX.size;
76
+ // bars meet a spine: hung from a top spine, standing on a bottom one
77
+ const top = p.spine === 'top' || p.spine === 'half';
78
+ const y0 = top ? BOX.y0 : p.lengths === 'rising' || p.spine === 'bottom' ? BOX.y1 - h : BOX.cy - h / 2, y1 = y0 + h;
79
+ const at = cutOf(p.cut, i, n, p.cutAt);
80
+ const bx = x;
81
+ x += w + gap;
82
+ if (at === null || (p.cut !== 'notch' && h < cutH + 2 * w)) { parts.push(upright(bx, y0, y1, w, p.ends)); continue; }
83
+ const yc = y1 - at * h;
84
+ if (p.cut === 'notch') {
85
+ // a V bitten from the bar's inner edge (the side facing the middle)
86
+ const depth = w * Math.min(0.45, 0.15 + p.cutSize), inner = i === 0 ? bx + w : bx, s = i === 0 ? -1 : 1;
87
+ parts.push(D(upright(bx, y0, y1, w, p.ends), poly([[inner + 1 * -s, yc - cutH], [inner + s * depth, yc], [inner + 1 * -s, yc + cutH]])));
88
+ continue;
89
+ }
90
+ if (p.cutAngle) {
91
+ // a slanted cut: a band the cut's height turned about the bar's middle at that height
92
+ const band = rot(rect(bx - w, yc - cutH / 2, 3 * w, cutH), p.cutAngle, bx + w / 2, yc);
93
+ parts.push(D(upright(bx, y0, y1, w, p.ends), band));
94
+ continue;
95
+ }
96
+ const a = Math.max(y0 + w, yc - cutH / 2), b = Math.min(y1 - w, yc + cutH / 2);
97
+ parts.push(upright(bx, y0, a, w, p.ends), upright(bx, b, y1, w, p.ends));
98
+ }
99
+ if (p.spine !== 'none') {
100
+ const t = (ws.reduce((a, b) => a + b, 0) / n) * p.spineWeight, x1 = p.spine === 'half' ? BOX.x0 + (x - gap - BOX.x0) / 2 : x - gap;
101
+ const y = p.spine === 'bottom' ? BOX.y1 - t : p.spine === 'middle' ? BOX.cy - t / 2 : BOX.y0;
102
+ parts.push(rect(BOX.x0, y, x1 - BOX.x0, t));
103
+ }
104
+ const mark = shear(p.cutAngle || p.cut === 'notch' || p.widths !== 'equal' ? tidy(U(...parts)) : U(...parts), p.slant);
105
+ return p.level ? quarterTurn(mark) : mark;
106
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Blobs: two to five discs of different sizes fused by soft necks (a metaball bridge between each pair of neighbours:
3
+ * the quad between the two circles' tangent points with two fillet circles, tangent to both, taken out of its sides),
4
+ * in a row, an arc or a cluster laid out by a number. Organic, never a
5
+ * face: the sizes always differ, so no two equal discs sit side by side over a third.
6
+ */
7
+ import { U, D, poly, circle } from '@logomarks/core/geometry';
8
+ import { BOX } from '../draw.js';
9
+ import { rng } from '../random.js';
10
+
11
+ /** @type {import('../index.js').Control[]} */
12
+ export const controls = [
13
+ { key: 'count', label: 'Blobs', type: 'range', min: 2, max: 5, step: 1, value: 3 },
14
+ { key: 'layout', label: 'Layout', type: 'choice', options: ['row', 'arc', 'cluster'], value: 'cluster' },
15
+ { key: 'shape', label: 'Layout no.', type: 'range', min: 1, max: 999, step: 1, value: 8 },
16
+ { key: 'spread', label: 'Size spread', type: 'range', min: 0.2, max: 0.7, step: 0.01, value: 0.45 },
17
+ { key: 'neck', label: 'Neck', type: 'range', min: 10, max: 90, step: 1, value: 40 },
18
+ { key: 'apart', label: 'Apart', type: 'range', min: 0.75, max: 1.15, step: 0.01, value: 0.95 },
19
+ ];
20
+
21
+ /** The discs: [x, y, r], each touching (or nearly) the one before, sizes all different. */
22
+ function discs(p) {
23
+ const rand = rng(`blobs:${p.shape}:${p.count}`), n = p.count, out = [];
24
+ // radii: a falling run, shuffled a little, so no two are equal
25
+ const radii = Array.from({ length: n }, (_, k) => 100 * (1 - p.spread * (k / Math.max(1, n - 1))) * (0.92 + rand() * 0.16));
26
+ if (p.layout !== 'row') radii.sort(() => rand() - 0.5);
27
+ let a = rand() * Math.PI * 2;
28
+ for (let k = 0; k < n; k++) {
29
+ const r = radii[k];
30
+ if (!k) { out.push([0, 0, r]); continue; }
31
+ const prev = out[k - 1], d = (prev[2] + r) * p.apart;
32
+ if (p.layout === 'row') a = 0;
33
+ else if (p.layout === 'arc') a += 0.75;
34
+ else {
35
+ // cluster: try angles until the new disc keeps clear of all but the one it hangs on
36
+ let best = a, score = -Infinity;
37
+ for (let t = 0; t < 12; t++) {
38
+ const cand = rand() * Math.PI * 2, x = prev[0] + d * Math.cos(cand), y = prev[1] + d * Math.sin(cand);
39
+ const s = Math.min(...out.slice(0, -1).map(([ox, oy, or]) => Math.hypot(x - ox, y - oy) - or - r), 999);
40
+ if (s > score) { score = s; best = cand; }
41
+ }
42
+ a = best;
43
+ }
44
+ out.push([prev[0] + d * Math.cos(a), prev[1] + d * Math.sin(a), r]);
45
+ }
46
+ return out;
47
+ }
48
+
49
+ /**
50
+ * The soft neck between two discs: two fillet circles of radius f, each tangent to both discs, and the quad between
51
+ * their tangent points with the fillets taken out. Null when the discs are too far apart for a fillet of that size.
52
+ */
53
+ function bridge([x1, y1, r1], [x2, y2, r2], f) {
54
+ const d = Math.hypot(x2 - x1, y2 - y1), a1 = r1 + f, a2 = r2 + f;
55
+ if (d >= a1 + a2 || d <= Math.abs(a1 - a2)) return null;
56
+ const ux = (x2 - x1) / d, uy = (y2 - y1) / d, cos = (a1 * a1 + d * d - a2 * a2) / (2 * a1 * d), sin = Math.sqrt(Math.max(0, 1 - cos * cos));
57
+ const pts = [], cuts = [];
58
+ for (const s of [1, -1]) {
59
+ const fx = x1 + a1 * (ux * cos - uy * sin * s), fy = y1 + a1 * (uy * cos + ux * sin * s);
60
+ pts.push([[x1 + ((fx - x1) * r1) / a1, y1 + ((fy - y1) * r1) / a1], [x2 + ((fx - x2) * r2) / a2, y2 + ((fy - y2) * r2) / a2]]);
61
+ cuts.push(circle(fx, fy, f, 64));
62
+ }
63
+ return D(poly([pts[0][0], pts[0][1], pts[1][1], pts[1][0]]), U(...cuts));
64
+ }
65
+
66
+ /** The mark for resolved params. */
67
+ export function build(p) {
68
+ const ds = discs(p).map(([x, y, r]) => [BOX.cx + x, BOX.cy + y, r]), parts = ds.map(([x, y, r]) => circle(x, y, r, 96));
69
+ for (let i = 0; i < ds.length; i++) for (let j = i + 1; j < ds.length; j++) {
70
+ const b = bridge(ds[i], ds[j], p.neck);
71
+ if (b) parts.push(b);
72
+ }
73
+ return U(...parts);
74
+ }