@altnovatrail/picture-kit 0.0.0-stage → 0.1.1

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 (122) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +7 -0
  3. package/README.md +28 -2
  4. package/lib/emoji.d.ts +16 -0
  5. package/lib/emoji.js +64 -0
  6. package/lib/index.d.ts +9 -0
  7. package/lib/index.js +10 -0
  8. package/lib/kind.d.ts +22 -0
  9. package/lib/kind.js +2 -0
  10. package/lib/kinds/balance.d.ts +34 -0
  11. package/lib/kinds/balance.js +217 -0
  12. package/lib/kinds/branches.d.ts +33 -0
  13. package/lib/kinds/branches.js +473 -0
  14. package/lib/kinds/calendar.d.ts +55 -0
  15. package/lib/kinds/calendar.js +532 -0
  16. package/lib/kinds/chart.d.ts +48 -0
  17. package/lib/kinds/chart.js +645 -0
  18. package/lib/kinds/choices.d.ts +14 -0
  19. package/lib/kinds/choices.js +53 -0
  20. package/lib/kinds/clock.d.ts +36 -0
  21. package/lib/kinds/clock.js +219 -0
  22. package/lib/kinds/coins.d.ts +37 -0
  23. package/lib/kinds/coins.js +550 -0
  24. package/lib/kinds/column.d.ts +37 -0
  25. package/lib/kinds/column.js +410 -0
  26. package/lib/kinds/commands-parts.d.ts +12 -0
  27. package/lib/kinds/commands-parts.js +24 -0
  28. package/lib/kinds/commands.d.ts +66 -0
  29. package/lib/kinds/commands.js +789 -0
  30. package/lib/kinds/containers.d.ts +52 -0
  31. package/lib/kinds/containers.js +758 -0
  32. package/lib/kinds/countfig.d.ts +41 -0
  33. package/lib/kinds/countfig.js +372 -0
  34. package/lib/kinds/cubes.d.ts +70 -0
  35. package/lib/kinds/cubes.js +371 -0
  36. package/lib/kinds/die.d.ts +32 -0
  37. package/lib/kinds/die.js +301 -0
  38. package/lib/kinds/domino.d.ts +37 -0
  39. package/lib/kinds/domino.js +450 -0
  40. package/lib/kinds/dotgrid.d.ts +38 -0
  41. package/lib/kinds/dotgrid.js +411 -0
  42. package/lib/kinds/figure.d.ts +62 -0
  43. package/lib/kinds/figure.js +687 -0
  44. package/lib/kinds/fold-parts.d.ts +73 -0
  45. package/lib/kinds/fold-parts.js +315 -0
  46. package/lib/kinds/fold.d.ts +52 -0
  47. package/lib/kinds/fold.js +650 -0
  48. package/lib/kinds/fraction.d.ts +50 -0
  49. package/lib/kinds/fraction.js +568 -0
  50. package/lib/kinds/gauges.d.ts +53 -0
  51. package/lib/kinds/gauges.js +880 -0
  52. package/lib/kinds/gears.d.ts +40 -0
  53. package/lib/kinds/gears.js +787 -0
  54. package/lib/kinds/grid.d.ts +45 -0
  55. package/lib/kinds/grid.js +591 -0
  56. package/lib/kinds/groups.d.ts +23 -0
  57. package/lib/kinds/groups.js +335 -0
  58. package/lib/kinds/index.d.ts +3 -0
  59. package/lib/kinds/index.js +87 -0
  60. package/lib/kinds/lanes.d.ts +36 -0
  61. package/lib/kinds/lanes.js +220 -0
  62. package/lib/kinds/layers.d.ts +31 -0
  63. package/lib/kinds/layers.js +419 -0
  64. package/lib/kinds/line.d.ts +38 -0
  65. package/lib/kinds/line.js +739 -0
  66. package/lib/kinds/magic-parts.d.ts +72 -0
  67. package/lib/kinds/magic-parts.js +186 -0
  68. package/lib/kinds/magic.d.ts +66 -0
  69. package/lib/kinds/magic.js +664 -0
  70. package/lib/kinds/map.d.ts +32 -0
  71. package/lib/kinds/map.js +370 -0
  72. package/lib/kinds/matchsticks.d.ts +26 -0
  73. package/lib/kinds/matchsticks.js +434 -0
  74. package/lib/kinds/necklace.d.ts +27 -0
  75. package/lib/kinds/necklace.js +342 -0
  76. package/lib/kinds/net.d.ts +47 -0
  77. package/lib/kinds/net.js +241 -0
  78. package/lib/kinds/overlay.d.ts +50 -0
  79. package/lib/kinds/overlay.js +519 -0
  80. package/lib/kinds/pieces.d.ts +41 -0
  81. package/lib/kinds/pieces.js +420 -0
  82. package/lib/kinds/pipes.d.ts +46 -0
  83. package/lib/kinds/pipes.js +657 -0
  84. package/lib/kinds/plane-parts.d.ts +105 -0
  85. package/lib/kinds/plane-parts.js +372 -0
  86. package/lib/kinds/plane.d.ts +35 -0
  87. package/lib/kinds/plane.js +755 -0
  88. package/lib/kinds/pyramid.d.ts +26 -0
  89. package/lib/kinds/pyramid.js +228 -0
  90. package/lib/kinds/ropes.d.ts +30 -0
  91. package/lib/kinds/ropes.js +571 -0
  92. package/lib/kinds/shapes.d.ts +59 -0
  93. package/lib/kinds/shapes.js +490 -0
  94. package/lib/kinds/solids.d.ts +78 -0
  95. package/lib/kinds/solids.js +1058 -0
  96. package/lib/kinds/tangram.d.ts +52 -0
  97. package/lib/kinds/tangram.js +713 -0
  98. package/lib/kinds/target.d.ts +39 -0
  99. package/lib/kinds/target.js +761 -0
  100. package/lib/kinds/tiles.d.ts +55 -0
  101. package/lib/kinds/tiles.js +606 -0
  102. package/lib/kinds/venn.d.ts +38 -0
  103. package/lib/kinds/venn.js +710 -0
  104. package/lib/noto.d.ts +2 -0
  105. package/lib/noto.js +212 -0
  106. package/lib/objects.d.ts +7 -0
  107. package/lib/objects.js +226 -0
  108. package/lib/pen.d.ts +32 -0
  109. package/lib/pen.js +60 -0
  110. package/lib/read.d.ts +9 -0
  111. package/lib/read.js +49 -0
  112. package/lib/render.d.ts +24 -0
  113. package/lib/render.js +68 -0
  114. package/lib/solve/balance.d.ts +46 -0
  115. package/lib/solve/balance.js +118 -0
  116. package/lib/style.d.ts +70 -0
  117. package/lib/style.js +39 -0
  118. package/lib/svg.d.ts +22 -0
  119. package/lib/svg.js +48 -0
  120. package/lib/things.d.ts +40 -0
  121. package/lib/things.js +269 -0
  122. package/package.json +28 -4
@@ -0,0 +1,371 @@
1
+ import { margin } from "../kind.js";
2
+ import { textWidth } from "../pen.js";
3
+ import { int, isObj, list, oneOf, only, text } from "../read.js";
4
+ import { colorNames, colors, ink, isColor, outline } from "../style.js";
5
+ import { poly } from "../svg.js";
6
+ import { checkThing, drawThing, wordOf } from "../things.js";
7
+ export const faces = ["top", "front", "right"];
8
+ const most = 30;
9
+ const reach = 9;
10
+ const biggest = 42;
11
+ const smallest = 18;
12
+ const room = 640 - 2 * margin;
13
+ const tallest = 420;
14
+ const gap = 40;
15
+ const across = Math.cos(Math.PI / 6);
16
+ /** The side of the square a sticker on a face is drawn in, before it is laid on the face. */
17
+ export const box = 64;
18
+ function hex(value) {
19
+ return [1, 3, 5].map((i) => Number.parseInt(value.slice(i, i + 2), 16));
20
+ }
21
+ /** mix is a colour between a and b, t of the way to b. */
22
+ export function mix(a, b, t) {
23
+ const [x, y] = [hex(a), hex(b)];
24
+ return `#${x
25
+ .map((v, i) => Math.round(v + (y[i] - v) * t)
26
+ .toString(16)
27
+ .padStart(2, "0"))
28
+ .join("")}`;
29
+ }
30
+ /** tones are the fills of a cube's three faces: lightest on top, darker in front, darkest on the right. */
31
+ export function tones(name) {
32
+ const c = colors[name];
33
+ return { top: mix(c.fill, "#ffffff", 0.2), front: mix(c.fill, c.dark, 0.4), right: c.dark };
34
+ }
35
+ /** cubesOf lists the cubes of a checked structure, each with its colour. */
36
+ export function cubesOf(st) {
37
+ const base = st.color ?? "white";
38
+ if (st.heights) {
39
+ const out = [];
40
+ st.heights.forEach((row, y) => {
41
+ row.forEach((h, x) => {
42
+ for (let z = 0; z < h; z++)
43
+ out.push({ x, y, z, color: base });
44
+ });
45
+ });
46
+ return out;
47
+ }
48
+ return (st.cubes ?? []).map((item) => {
49
+ const [x, y, z] = Array.isArray(item) ? item : item.at;
50
+ const color = Array.isArray(item) ? base : (item.color ?? base);
51
+ return { x, y, z, color };
52
+ });
53
+ }
54
+ export function projector(s, ox, oy) {
55
+ return (x, y, z) => ({ x: ox + (x - y) * across * s, y: oy + ((x + y - 2 * z) * s) / 2 });
56
+ }
57
+ /**
58
+ * cornersOf are the corners of a face of the cube at x, y, z, in the order a
59
+ * sticker on it reads: top left, top right, bottom right, bottom left.
60
+ */
61
+ export function cornersOf(c, face, at) {
62
+ const { x, y, z } = c;
63
+ if (face === "top")
64
+ return [at(x, y, z + 1), at(x + 1, y, z + 1), at(x + 1, y + 1, z + 1), at(x, y + 1, z + 1)];
65
+ if (face === "front")
66
+ return [at(x, y + 1, z + 1), at(x + 1, y + 1, z + 1), at(x + 1, y + 1, z), at(x, y + 1, z)];
67
+ return [at(x + 1, y + 1, z + 1), at(x + 1, y, z + 1), at(x + 1, y, z), at(x + 1, y + 1, z)];
68
+ }
69
+ /** onFace is the transform that lays a box × box square on a face given by its corners. */
70
+ export function onFace(corners) {
71
+ const [tl, tr, , bl] = corners;
72
+ const f = (v) => (Math.round(v * 10000) / 10000).toString();
73
+ return `matrix(${f((tr.x - tl.x) / box)} ${f((tr.y - tl.y) / box)} ${f((bl.x - tl.x) / box)} ${f((bl.y - tl.y) / box)} ${f(tl.x)} ${f(tl.y)})`;
74
+ }
75
+ /**
76
+ * The picture is a grid of small triangles, and each face of a cube covers
77
+ * two of them. triangles names them; a triangle shows the face of the cube
78
+ * nearest the eye, the one whose x + y + z is greatest.
79
+ */
80
+ function triangles(c, face) {
81
+ const u = 3 * (c.x - c.y);
82
+ const v = c.x + c.y - 2 * c.z;
83
+ if (face === "top")
84
+ return [`${u - 1},${v - 1}`, `${u + 1},${v - 1}`];
85
+ if (face === "front")
86
+ return [`${u - 1},${v + 1}`, `${u - 2},${v}`];
87
+ return [`${u + 1},${v + 1}`, `${u + 2},${v}`];
88
+ }
89
+ /** sight says, for each cube and face, how many of its two triangles are in sight. */
90
+ export function sight(cubes) {
91
+ const owner = new Map();
92
+ const depth = (c) => c.x + c.y + c.z;
93
+ cubes.forEach((c, i) => {
94
+ for (const face of faces)
95
+ for (const t of triangles(c, face)) {
96
+ const was = owner.get(t);
97
+ if (was === undefined || depth(cubes[was]) < depth(c))
98
+ owner.set(t, i);
99
+ }
100
+ });
101
+ return cubes.map((c, i) => {
102
+ const seen = { top: 0, front: 0, right: 0 };
103
+ for (const face of faces)
104
+ seen[face] = triangles(c, face).filter((t) => owner.get(t) === i).length;
105
+ return seen;
106
+ });
107
+ }
108
+ function boundsOf(cubes) {
109
+ return {
110
+ uMin: Math.min(...cubes.map((c) => c.x - c.y - 1)),
111
+ uMax: Math.max(...cubes.map((c) => c.x - c.y + 1)),
112
+ vMin: Math.min(...cubes.map((c) => c.x + c.y - 2 * c.z - 2)),
113
+ vMax: Math.max(...cubes.map((c) => c.x + c.y - 2 * c.z + 2)),
114
+ };
115
+ }
116
+ /** edgeOf is the edge of a cube in pixels that fits every structure side by side. */
117
+ function edgeOf(all) {
118
+ const bounds = all.map(boundsOf);
119
+ const wide = bounds.reduce((sum, b) => sum + b.uMax - b.uMin, 0) * across;
120
+ const high = Math.max(...bounds.map((b) => b.vMax - b.vMin)) / 2;
121
+ return Math.min(biggest, (room - gap * (all.length - 1)) / wide, tallest / high);
122
+ }
123
+ function same(a, b) {
124
+ return a[0] === b.x && a[1] === b.y && a[2] === b.z;
125
+ }
126
+ function checkAt(value, path, problems) {
127
+ if (!Array.isArray(value) || value.length !== 3) {
128
+ problems.push(`${path}: must be [x, y, z], three whole numbers from 0 to ${reach}`);
129
+ return undefined;
130
+ }
131
+ const before = problems.length;
132
+ const at = value.map((v, i) => int(v, `${path}[${i}]`, problems, 0, reach));
133
+ return problems.length === before ? at : undefined;
134
+ }
135
+ function checkStructure(st, path, problems) {
136
+ only(st, ["cubes", "heights", "color", "marks", "label"], path, problems);
137
+ if (st.color !== undefined && !isColor(st.color))
138
+ problems.push(`${path}.color: must be a colour: ${colorNames.join(", ")}`);
139
+ if (st.label !== undefined)
140
+ text(st.label, `${path}.label`, problems, 10);
141
+ if ((st.cubes === undefined) === (st.heights === undefined)) {
142
+ problems.push(`${path}: must give either cubes or heights`);
143
+ return;
144
+ }
145
+ const before = problems.length;
146
+ // where each cube was given, for a path in a problem
147
+ const named = [];
148
+ if (st.cubes !== undefined) {
149
+ list(st.cubes, `${path}.cubes`, problems, 1, most).forEach((item, j) => {
150
+ const p = `${path}.cubes[${j}]`;
151
+ if (isObj(item)) {
152
+ only(item, ["at", "color"], p, problems);
153
+ checkAt(item.at, `${p}.at`, problems);
154
+ if (item.color !== undefined && !isColor(item.color))
155
+ problems.push(`${p}.color: must be a colour: ${colorNames.join(", ")}`);
156
+ }
157
+ else
158
+ checkAt(item, p, problems);
159
+ named.push(p);
160
+ });
161
+ }
162
+ else {
163
+ let total = 0;
164
+ list(st.heights, `${path}.heights`, problems, 1, reach + 1).forEach((row, y) => {
165
+ list(row, `${path}.heights[${y}]`, problems, 1, reach + 1).forEach((h, x) => {
166
+ const k = int(h, `${path}.heights[${y}][${x}]`, problems, 0, reach + 1);
167
+ for (let z = 0; z < k; z++)
168
+ named.push(`${path}.heights[${y}][${x}]`);
169
+ total += k;
170
+ });
171
+ });
172
+ if (problems.length === before && total === 0)
173
+ problems.push(`${path}.heights: must hold at least 1 cube`);
174
+ if (total > most)
175
+ problems.push(`${path}.heights: at most ${most} cubes in a structure`);
176
+ }
177
+ if (problems.length > before)
178
+ return;
179
+ const cubes = cubesOf(st);
180
+ for (let j = 0; j < cubes.length; j++)
181
+ for (let i = 0; i < j; i++)
182
+ if (same([cubes[i].x, cubes[i].y, cubes[i].z], cubes[j]))
183
+ problems.push(`${named[j]}: the same place as ${named[i]}`);
184
+ if (problems.length > before)
185
+ return;
186
+ if (!cubes.some((c) => c.z === 0))
187
+ problems.push(`${path}.cubes: the lowest cube must stand on the table, at z 0`);
188
+ const reached = new Set([0]);
189
+ for (let grew = true; grew;) {
190
+ grew = false;
191
+ cubes.forEach((c, j) => {
192
+ if (reached.has(j))
193
+ return;
194
+ const touches = [...reached].some((i) => {
195
+ const o = cubes[i];
196
+ return Math.abs(o.x - c.x) + Math.abs(o.y - c.y) + Math.abs(o.z - c.z) === 1;
197
+ });
198
+ if (touches) {
199
+ reached.add(j);
200
+ grew = true;
201
+ }
202
+ });
203
+ }
204
+ const apart = cubes.findIndex((_, j) => !reached.has(j));
205
+ if (apart >= 0)
206
+ problems.push(`${named[apart]}: the cubes of a structure must hold together face to face; this one is apart`);
207
+ if (st.marks === undefined)
208
+ return;
209
+ const seen = sight(cubes);
210
+ const taken = new Set();
211
+ list(st.marks, `${path}.marks`, problems, 1, 6).forEach((m, j) => {
212
+ const p = `${path}.marks[${j}]`;
213
+ if (!isObj(m)) {
214
+ problems.push(`${p}: must be a cube, a face and a thing`);
215
+ return;
216
+ }
217
+ only(m, ["cube", "face", "thing"], p, problems);
218
+ const at = checkAt(m.cube, `${p}.cube`, problems);
219
+ const face = oneOf(m.face, faces, `${p}.face`, problems);
220
+ checkThing(m.thing, `${p}.thing`, problems);
221
+ if (!at)
222
+ return;
223
+ const i = cubes.findIndex((c) => same(at, c));
224
+ if (i < 0) {
225
+ problems.push(`${p}.cube: no cube of the structure at [${at.join(", ")}]`);
226
+ return;
227
+ }
228
+ if (seen[i][face] < 2)
229
+ problems.push(`${p}.face: the ${face} face of the cube at [${at.join(", ")}] is not wholly in sight; marks go on a face no cube covers`);
230
+ const key = `${at.join(",")} ${face}`;
231
+ if (taken.has(key))
232
+ problems.push(`${p}: another mark is on the same face`);
233
+ taken.add(key);
234
+ });
235
+ }
236
+ function drawStructure(pen, st, cubes, at) {
237
+ const seen = sight(cubes);
238
+ const order = cubes
239
+ .map((_, i) => i)
240
+ .sort((a, b) => {
241
+ const [p, q] = [cubes[a], cubes[b]];
242
+ return p.x + p.y + p.z - (q.x + q.y + q.z) || p.z - q.z || p.x - q.x || p.y - q.y;
243
+ });
244
+ for (const i of order) {
245
+ const c = cubes[i];
246
+ const fill = tones(c.color);
247
+ for (const face of faces) {
248
+ if (seen[i][face] === 0)
249
+ continue;
250
+ const corners = cornersOf(c, face, at);
251
+ pen.el("path", {
252
+ d: poly(corners),
253
+ fill: fill[face],
254
+ stroke: ink,
255
+ "stroke-width": outline,
256
+ "stroke-linejoin": "round",
257
+ });
258
+ const mark = st.marks?.find((m) => same(m.cube, c) && m.face === face);
259
+ if (mark) {
260
+ const sub = pen.sub();
261
+ drawThing(sub, mark.thing, box / 2, box / 2, box * 0.8);
262
+ pen.add(`<g transform="${onFace(corners)}">${sub.markup()}</g>`);
263
+ }
264
+ }
265
+ }
266
+ }
267
+ const ordinal = (k) => String(k + 1);
268
+ /** article is "a" or "an" before a word. */
269
+ export function article(word) {
270
+ return /^[aeiou]/i.test(word) ? `an ${word}` : `a ${word}`;
271
+ }
272
+ function where(c, o) {
273
+ return `row ${ordinal(c.y - o.y)}, place ${ordinal(c.x - o.x)}, level ${ordinal(c.z)}`;
274
+ }
275
+ function sayStructure(st) {
276
+ const cubes = cubesOf(st);
277
+ const o = { x: Math.min(...cubes.map((c) => c.x)), y: Math.min(...cubes.map((c) => c.y)) };
278
+ const rows = Math.max(...cubes.map((c) => c.y)) - o.y + 1;
279
+ const places = Math.max(...cubes.map((c) => c.x)) - o.x + 1;
280
+ const stack = (x, y) => cubes.filter((c) => c.x === x + o.x && c.y === y + o.y).sort((a, b) => a.z - b.z);
281
+ const upright = cubes.every((c) => c.z === 0 || stack(c.x - o.x, c.y - o.y)[c.z - 1]?.z === c.z - 1);
282
+ const used = colorNames.filter((name) => cubes.some((c) => c.color === name));
283
+ const one = used.length === 1;
284
+ const plural = (k, w) => `${k} ${w}${k === 1 ? "" : "s"}`;
285
+ let out;
286
+ if (upright && rows === 1 && places === 1) {
287
+ out = `one stack of ${cubes.length} cubes; from the bottom up: ${cubes
288
+ .sort((a, b) => a.z - b.z)
289
+ .map((c) => colors[c.color].word)
290
+ .join(", ")}`;
291
+ }
292
+ else if (upright) {
293
+ const lines = Array.from({ length: rows }, (_, y) => Array.from({ length: places }, (_, x) => {
294
+ const s = stack(x, y);
295
+ return one || s.length === 0
296
+ ? String(s.length)
297
+ : `${s.length} (${s.map((c) => colors[c.color].word).join(", ")})`;
298
+ }).join(", "));
299
+ out = `stacks of ${one ? `${colors[used[0]].word} ` : ""}cubes on ${plural(rows, "row")} of ${plural(places, "place")}; seen from above, from the back row to the front row and from left to right, the number of cubes in each place${one ? "" : " (their colours from the bottom up)"}: ${lines.join("; ")}`;
300
+ }
301
+ else {
302
+ const levels = Math.max(...cubes.map((c) => c.z)) + 1;
303
+ const say = Array.from({ length: levels }, (_, z) => {
304
+ const rowsAt = Array.from({ length: rows }, (_, y) => {
305
+ const here = cubes
306
+ .filter((c) => c.z === z && c.y - o.y === y)
307
+ .sort((a, b) => a.x - b.x)
308
+ .map((c) => `${ordinal(c.x - o.x)}${one ? "" : ` ${colors[c.color].word}`}`);
309
+ return here.length
310
+ ? `row ${ordinal(y)}: ${plural(here.length, "cube")} at place ${here.join(", ")}`
311
+ : "";
312
+ }).filter(Boolean);
313
+ return `level ${ordinal(z)} — ${rowsAt.join("; ")}`;
314
+ });
315
+ out = `${one ? `${colors[used[0]].word} ` : ""}cubes on ${plural(levels, "level")} from the table up, rows from the back to the front, places from left to right: ${say.join(". ")}`;
316
+ }
317
+ if (!one)
318
+ out += `. In all, ${used.map((name) => plural(cubes.filter((c) => c.color === name).length, `${colors[name].word} cube`)).join(" and ")}`;
319
+ for (const m of st.marks ?? [])
320
+ out += `. On the ${m.face} face of the cube at ${where({ x: m.cube[0], y: m.cube[1], z: m.cube[2] }, o)}: ${typeof m.thing === "object" && "ask" in m.thing ? "a question mark" : article(wordOf(m.thing))}`;
321
+ return `${out}.`;
322
+ }
323
+ export const cubes = {
324
+ kind: "cubes",
325
+ members: ["kind", "structures"],
326
+ check(scene, problems) {
327
+ only(scene, this.members, "scene", problems);
328
+ const structures = list(scene.structures, "structures", problems, 1, 4);
329
+ structures.forEach((st, i) => {
330
+ if (!isObj(st))
331
+ problems.push(`structures[${i}]: must be a structure`);
332
+ else
333
+ checkStructure(st, `structures[${i}]`, problems);
334
+ });
335
+ if (problems.length > 0)
336
+ return;
337
+ const all = scene.structures.map(cubesOf);
338
+ if (edgeOf(all) < smallest)
339
+ problems.push(`structures: too big to draw side by side with cubes of at least ${smallest} pixels; use fewer structures, or narrower or lower ones`);
340
+ },
341
+ draw(scene, pen) {
342
+ const sts = scene.structures;
343
+ const all = sts.map(cubesOf);
344
+ const s = edgeOf(all);
345
+ const bounds = all.map(boundsOf);
346
+ const high = Math.max(...bounds.map((b) => ((b.vMax - b.vMin) * s) / 2));
347
+ const labelled = sts.some((st) => st.label);
348
+ let x = margin;
349
+ sts.forEach((st, i) => {
350
+ const b = bounds[i];
351
+ const w = (b.uMax - b.uMin) * across * s;
352
+ const bw = Math.max(w, st.label ? textWidth(st.label, 18) : 0);
353
+ const at = projector(s, x + (bw - w) / 2 - b.uMin * across * s, margin + high - (b.vMax * s) / 2);
354
+ drawStructure(pen, st, all[i], at);
355
+ if (st.label)
356
+ pen.text(x + bw / 2, margin + high + 24, st.label, { size: 18 });
357
+ x += bw + gap;
358
+ });
359
+ return { width: x - gap + margin, height: margin + high + (labelled ? 40 : 0) + margin };
360
+ },
361
+ describe(scene) {
362
+ const sts = scene.structures;
363
+ if (sts.length === 1) {
364
+ const said = sayStructure(sts[0]);
365
+ return `A structure of cubes: ${said}`;
366
+ }
367
+ return `${sts.length} structures of cubes, side by side. ${sts
368
+ .map((st, i) => `Structure ${st.label ?? i + 1}: ${sayStructure(st)}`)
369
+ .join(" ")}`;
370
+ },
371
+ };
@@ -0,0 +1,32 @@
1
+ import type { Kind } from "../kind.ts";
2
+ /**
3
+ * Die: one to six dice in a row, each seen from above, the front and the
4
+ * right, its three faces showing their pips, or one face of a die laid flat.
5
+ * A "?" stands where the question asks. A die has each of 1 to 6 once, so the
6
+ * three faces of a view show three different values. With standard, every
7
+ * die is a standard one, opposite faces adding up to 7, so no two faces that
8
+ * add up to 7 show together; with same, the views are all of one and the
9
+ * same die, and the check proves that one die can show them all.
10
+ */
11
+ export type Value = number | "?";
12
+ export type View = {
13
+ top: Value;
14
+ front: Value;
15
+ right: Value;
16
+ label?: string;
17
+ };
18
+ export type Flat = {
19
+ face: Value;
20
+ label?: string;
21
+ };
22
+ export type Die = View | Flat;
23
+ export type DieScene = {
24
+ kind: "die";
25
+ dice: Die[];
26
+ standard?: boolean;
27
+ same?: boolean;
28
+ arrows?: boolean;
29
+ };
30
+ /** pips are the places of the pips of each value on a box × box face. */
31
+ export declare const pips: Record<number, [number, number][]>;
32
+ export declare const die: Kind;