@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.
- package/LICENSE +201 -0
- package/NOTICE +7 -0
- package/README.md +28 -2
- package/lib/emoji.d.ts +16 -0
- package/lib/emoji.js +64 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +10 -0
- package/lib/kind.d.ts +22 -0
- package/lib/kind.js +2 -0
- package/lib/kinds/balance.d.ts +34 -0
- package/lib/kinds/balance.js +217 -0
- package/lib/kinds/branches.d.ts +33 -0
- package/lib/kinds/branches.js +473 -0
- package/lib/kinds/calendar.d.ts +55 -0
- package/lib/kinds/calendar.js +532 -0
- package/lib/kinds/chart.d.ts +48 -0
- package/lib/kinds/chart.js +645 -0
- package/lib/kinds/choices.d.ts +14 -0
- package/lib/kinds/choices.js +53 -0
- package/lib/kinds/clock.d.ts +36 -0
- package/lib/kinds/clock.js +219 -0
- package/lib/kinds/coins.d.ts +37 -0
- package/lib/kinds/coins.js +550 -0
- package/lib/kinds/column.d.ts +37 -0
- package/lib/kinds/column.js +410 -0
- package/lib/kinds/commands-parts.d.ts +12 -0
- package/lib/kinds/commands-parts.js +24 -0
- package/lib/kinds/commands.d.ts +66 -0
- package/lib/kinds/commands.js +789 -0
- package/lib/kinds/containers.d.ts +52 -0
- package/lib/kinds/containers.js +758 -0
- package/lib/kinds/countfig.d.ts +41 -0
- package/lib/kinds/countfig.js +372 -0
- package/lib/kinds/cubes.d.ts +70 -0
- package/lib/kinds/cubes.js +371 -0
- package/lib/kinds/die.d.ts +32 -0
- package/lib/kinds/die.js +301 -0
- package/lib/kinds/domino.d.ts +37 -0
- package/lib/kinds/domino.js +450 -0
- package/lib/kinds/dotgrid.d.ts +38 -0
- package/lib/kinds/dotgrid.js +411 -0
- package/lib/kinds/figure.d.ts +62 -0
- package/lib/kinds/figure.js +687 -0
- package/lib/kinds/fold-parts.d.ts +73 -0
- package/lib/kinds/fold-parts.js +315 -0
- package/lib/kinds/fold.d.ts +52 -0
- package/lib/kinds/fold.js +650 -0
- package/lib/kinds/fraction.d.ts +50 -0
- package/lib/kinds/fraction.js +568 -0
- package/lib/kinds/gauges.d.ts +53 -0
- package/lib/kinds/gauges.js +880 -0
- package/lib/kinds/gears.d.ts +40 -0
- package/lib/kinds/gears.js +787 -0
- package/lib/kinds/grid.d.ts +45 -0
- package/lib/kinds/grid.js +591 -0
- package/lib/kinds/groups.d.ts +23 -0
- package/lib/kinds/groups.js +335 -0
- package/lib/kinds/index.d.ts +3 -0
- package/lib/kinds/index.js +87 -0
- package/lib/kinds/lanes.d.ts +36 -0
- package/lib/kinds/lanes.js +220 -0
- package/lib/kinds/layers.d.ts +31 -0
- package/lib/kinds/layers.js +419 -0
- package/lib/kinds/line.d.ts +38 -0
- package/lib/kinds/line.js +739 -0
- package/lib/kinds/magic-parts.d.ts +72 -0
- package/lib/kinds/magic-parts.js +186 -0
- package/lib/kinds/magic.d.ts +66 -0
- package/lib/kinds/magic.js +664 -0
- package/lib/kinds/map.d.ts +32 -0
- package/lib/kinds/map.js +370 -0
- package/lib/kinds/matchsticks.d.ts +26 -0
- package/lib/kinds/matchsticks.js +434 -0
- package/lib/kinds/necklace.d.ts +27 -0
- package/lib/kinds/necklace.js +342 -0
- package/lib/kinds/net.d.ts +47 -0
- package/lib/kinds/net.js +241 -0
- package/lib/kinds/overlay.d.ts +50 -0
- package/lib/kinds/overlay.js +519 -0
- package/lib/kinds/pieces.d.ts +41 -0
- package/lib/kinds/pieces.js +420 -0
- package/lib/kinds/pipes.d.ts +46 -0
- package/lib/kinds/pipes.js +657 -0
- package/lib/kinds/plane-parts.d.ts +105 -0
- package/lib/kinds/plane-parts.js +372 -0
- package/lib/kinds/plane.d.ts +35 -0
- package/lib/kinds/plane.js +755 -0
- package/lib/kinds/pyramid.d.ts +26 -0
- package/lib/kinds/pyramid.js +228 -0
- package/lib/kinds/ropes.d.ts +30 -0
- package/lib/kinds/ropes.js +571 -0
- package/lib/kinds/shapes.d.ts +59 -0
- package/lib/kinds/shapes.js +490 -0
- package/lib/kinds/solids.d.ts +78 -0
- package/lib/kinds/solids.js +1058 -0
- package/lib/kinds/tangram.d.ts +52 -0
- package/lib/kinds/tangram.js +713 -0
- package/lib/kinds/target.d.ts +39 -0
- package/lib/kinds/target.js +761 -0
- package/lib/kinds/tiles.d.ts +55 -0
- package/lib/kinds/tiles.js +606 -0
- package/lib/kinds/venn.d.ts +38 -0
- package/lib/kinds/venn.js +710 -0
- package/lib/noto.d.ts +2 -0
- package/lib/noto.js +212 -0
- package/lib/objects.d.ts +7 -0
- package/lib/objects.js +226 -0
- package/lib/pen.d.ts +32 -0
- package/lib/pen.js +60 -0
- package/lib/read.d.ts +9 -0
- package/lib/read.js +49 -0
- package/lib/render.d.ts +24 -0
- package/lib/render.js +68 -0
- package/lib/solve/balance.d.ts +46 -0
- package/lib/solve/balance.js +118 -0
- package/lib/style.d.ts +70 -0
- package/lib/style.js +39 -0
- package/lib/svg.d.ts +22 -0
- package/lib/svg.js +48 -0
- package/lib/things.d.ts +40 -0
- package/lib/things.js +269 -0
- package/package.json +28 -4
|
@@ -0,0 +1,1058 @@
|
|
|
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, faint, ink, isColor, outline } from "../style.js";
|
|
5
|
+
import { n, poly } from "../svg.js";
|
|
6
|
+
import { article, mix, tones } from "./cubes.js";
|
|
7
|
+
/**
|
|
8
|
+
* Solids: one to five solids on a table — cubes, cuboids, cylinders, cones,
|
|
9
|
+
* pyramids, prisms and spheres — in oblique projection: the front true to
|
|
10
|
+
* size, depth running up and to the right at half scale. A solid stands on
|
|
11
|
+
* the table, to the right of the one before, or, by `on`, in the middle of the
|
|
12
|
+
* top of a cube, a cuboid or an upright cylinder, so solids stand in towers.
|
|
13
|
+
* Under them, a row of panels may show the solids from the front, back, left,
|
|
14
|
+
* right or top, computed from the solids, or a flat outline given by name;
|
|
15
|
+
* drawn as views, coloured with their edges, or as shadows, flat and gray.
|
|
16
|
+
*/
|
|
17
|
+
export const solidShapes = [
|
|
18
|
+
"cube",
|
|
19
|
+
"cuboid",
|
|
20
|
+
"cylinder",
|
|
21
|
+
"cone",
|
|
22
|
+
"pyramid",
|
|
23
|
+
"prism",
|
|
24
|
+
"sphere",
|
|
25
|
+
];
|
|
26
|
+
export const directions = ["front", "back", "left", "right", "top"];
|
|
27
|
+
export const outlines = [
|
|
28
|
+
"circle",
|
|
29
|
+
"square",
|
|
30
|
+
"rectangle",
|
|
31
|
+
"triangle",
|
|
32
|
+
"semicircle",
|
|
33
|
+
"oval",
|
|
34
|
+
"ring",
|
|
35
|
+
"rhombus",
|
|
36
|
+
"trapezoid",
|
|
37
|
+
"pentagon",
|
|
38
|
+
"hexagon",
|
|
39
|
+
];
|
|
40
|
+
/** q is how far one unit of depth runs to the right, and up, on the page. */
|
|
41
|
+
const q = Math.SQRT1_2 / 2;
|
|
42
|
+
const room = 640 - 2 * margin;
|
|
43
|
+
const biggest = 56;
|
|
44
|
+
const smallest = 20;
|
|
45
|
+
const tallest = 300;
|
|
46
|
+
const pad = 12;
|
|
47
|
+
const panelGap = 16;
|
|
48
|
+
const gapBelow = 30;
|
|
49
|
+
const line = { stroke: ink, "stroke-width": outline, "stroke-linejoin": "round" };
|
|
50
|
+
const shadowFill = colors.gray.fill;
|
|
51
|
+
const outlineFill = mix(colors.gray.fill, "#ffffff", 0.55);
|
|
52
|
+
const defaults = {
|
|
53
|
+
cube: { size: 2, color: "red" },
|
|
54
|
+
cuboid: { size: [3, 2, 2], color: "orange" },
|
|
55
|
+
cylinder: { size: [2, 3], color: "blue" },
|
|
56
|
+
cone: { size: [2, 3], color: "yellow" },
|
|
57
|
+
pyramid: { size: [2, 3], color: "green" },
|
|
58
|
+
prism: { size: [2, 3], color: "purple" },
|
|
59
|
+
sphere: { size: 2, color: "pink" },
|
|
60
|
+
};
|
|
61
|
+
const carriers = ["cube", "cuboid", "cylinder"];
|
|
62
|
+
const polygonNames = ["", "", "", "triangle", "square", "pentagon", "hexagon"];
|
|
63
|
+
const baseNames = ["", "", "", "triangular", "square", "pentagonal", "hexagonal"];
|
|
64
|
+
/**
|
|
65
|
+
* ngon is a regular polygon of n sides, w wide, a side flat at the bottom,
|
|
66
|
+
* counterclockwise from its bottom left corner, b running from 0 up; middle is
|
|
67
|
+
* the height of its centre.
|
|
68
|
+
*/
|
|
69
|
+
export function ngon(sides, w) {
|
|
70
|
+
const raw = Array.from({ length: sides }, (_, k) => {
|
|
71
|
+
const t = -Math.PI / 2 - Math.PI / sides + (2 * Math.PI * k) / sides;
|
|
72
|
+
return { a: Math.cos(t), b: Math.sin(t) };
|
|
73
|
+
});
|
|
74
|
+
const f = w / (Math.max(...raw.map((p) => p.a)) - Math.min(...raw.map((p) => p.a)));
|
|
75
|
+
const low = Math.min(...raw.map((p) => p.b));
|
|
76
|
+
const clean = (v) => Math.round(v * 1e9) / 1e9;
|
|
77
|
+
return {
|
|
78
|
+
pts: raw.map((p) => ({ a: clean(p.a * f), b: clean((p.b - low) * f) })),
|
|
79
|
+
middle: clean(-low * f),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function sizeOf(sol) {
|
|
83
|
+
const size = sol.size ?? defaults[sol.shape].size;
|
|
84
|
+
return typeof size === "number" ? [size] : size;
|
|
85
|
+
}
|
|
86
|
+
function measure(sol) {
|
|
87
|
+
const lying = sol.lying === true;
|
|
88
|
+
const [p = 1, r = 1, t = 1] = sizeOf(sol);
|
|
89
|
+
const box = (w, d, h) => ({
|
|
90
|
+
w,
|
|
91
|
+
d,
|
|
92
|
+
h,
|
|
93
|
+
r: 0,
|
|
94
|
+
pts: [
|
|
95
|
+
{ a: -w / 2, b: 0 },
|
|
96
|
+
{ a: w / 2, b: 0 },
|
|
97
|
+
{ a: w / 2, b: d },
|
|
98
|
+
{ a: -w / 2, b: d },
|
|
99
|
+
],
|
|
100
|
+
middle: d / 2,
|
|
101
|
+
sides: 4,
|
|
102
|
+
lying: false,
|
|
103
|
+
});
|
|
104
|
+
switch (sol.shape) {
|
|
105
|
+
case "cube":
|
|
106
|
+
return box(p, p, p);
|
|
107
|
+
case "cuboid":
|
|
108
|
+
return box(p, r, t);
|
|
109
|
+
case "sphere":
|
|
110
|
+
return { w: p, d: p, h: p, r: p / 2, pts: [], middle: p / 2, sides: 0, lying: false };
|
|
111
|
+
case "cylinder":
|
|
112
|
+
case "cone":
|
|
113
|
+
return lying
|
|
114
|
+
? { w: p, d: r, h: p, r: p / 2, pts: [], middle: p / 2, sides: 0, lying }
|
|
115
|
+
: { w: p, d: p, h: r, r: p / 2, pts: [], middle: p / 2, sides: 0, lying };
|
|
116
|
+
default: {
|
|
117
|
+
const sides = sol.sides ?? (sol.shape === "pyramid" ? 4 : 3);
|
|
118
|
+
const g = ngon(sides, p);
|
|
119
|
+
const depth = Math.max(...g.pts.map((v) => v.b));
|
|
120
|
+
if (lying)
|
|
121
|
+
return { w: p, d: r, h: depth, r: 0, pts: g.pts, middle: g.middle, sides, lying };
|
|
122
|
+
// Upright, a polygon of an odd number of sides turns a corner to the front, so two sides show.
|
|
123
|
+
const odd = sides % 2 === 1;
|
|
124
|
+
const pts = odd ? g.pts.map((v) => ({ a: v.a, b: depth - v.b })).reverse() : g.pts;
|
|
125
|
+
const middle = odd ? depth - g.middle : g.middle;
|
|
126
|
+
return { w: p, d: depth, h: r, r: 0, pts, middle, sides, lying };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** place stands each solid on the table, right of the tower before, or on the solid it names. */
|
|
131
|
+
export function place(s) {
|
|
132
|
+
const out = [];
|
|
133
|
+
let towers = 0;
|
|
134
|
+
s.solids.forEach((sol, i) => {
|
|
135
|
+
const m = measure(sol);
|
|
136
|
+
const color = sol.color ?? defaults[sol.shape].color;
|
|
137
|
+
const lo = sol.on === undefined ? undefined : out[sol.on - 1];
|
|
138
|
+
if (lo) {
|
|
139
|
+
out.push({
|
|
140
|
+
...m,
|
|
141
|
+
i,
|
|
142
|
+
tower: lo.tower,
|
|
143
|
+
shape: sol.shape,
|
|
144
|
+
color,
|
|
145
|
+
cx: lo.cx,
|
|
146
|
+
y0: lo.y0 + (lo.d - m.d) / 2,
|
|
147
|
+
z0: lo.z0 + lo.h,
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
// A tower stands clear of the one before it, whose depth runs to the right.
|
|
152
|
+
const before = out.filter((p) => p.tower === towers - 1);
|
|
153
|
+
const x0 = before.length === 0
|
|
154
|
+
? 0
|
|
155
|
+
: Math.max(...before.map((p) => p.cx + p.w / 2 + 1), ...before.map((p) => p.cx + p.w / 2 + q * (p.y0 + p.d) + 0.4));
|
|
156
|
+
out.push({ ...m, i, tower: towers, shape: sol.shape, color, cx: x0 + m.w / 2, y0: 0, z0: 0 });
|
|
157
|
+
towers += 1;
|
|
158
|
+
});
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
/** corners lists where a solid reaches on the page, in units: X to the right, Y up. */
|
|
162
|
+
function reachOf(p) {
|
|
163
|
+
const cy = p.y0 + p.d / 2;
|
|
164
|
+
const z1 = p.z0 + p.h;
|
|
165
|
+
const at = (x, y, z, r = 0) => ({ x: x + q * y, y: z + q * y, r });
|
|
166
|
+
switch (p.shape) {
|
|
167
|
+
case "sphere":
|
|
168
|
+
return [at(p.cx, cy, p.z0 + p.r, p.r)];
|
|
169
|
+
case "cylinder":
|
|
170
|
+
if (p.lying)
|
|
171
|
+
return [at(p.cx, p.y0, p.z0 + p.r, p.r), at(p.cx, p.y0 + p.d, p.z0 + p.r, p.r)];
|
|
172
|
+
return [-1, 1].flatMap((side) => [
|
|
173
|
+
at(p.cx + side * p.r, cy, p.z0),
|
|
174
|
+
at(p.cx + side * p.r, cy, z1),
|
|
175
|
+
at(p.cx, cy + side * p.r, p.z0),
|
|
176
|
+
at(p.cx, cy + side * p.r, z1),
|
|
177
|
+
]);
|
|
178
|
+
case "cone":
|
|
179
|
+
return [
|
|
180
|
+
at(p.cx - p.r, cy, p.z0),
|
|
181
|
+
at(p.cx + p.r, cy, p.z0),
|
|
182
|
+
at(p.cx, cy - p.r, p.z0),
|
|
183
|
+
at(p.cx, cy, z1),
|
|
184
|
+
];
|
|
185
|
+
case "pyramid":
|
|
186
|
+
return [...p.pts.map((v) => at(p.cx + v.a, p.y0 + v.b, p.z0)), at(p.cx, p.y0 + p.middle, z1)];
|
|
187
|
+
default:
|
|
188
|
+
if (p.lying)
|
|
189
|
+
return p.pts.flatMap((v) => [
|
|
190
|
+
at(p.cx + v.a, p.y0, p.z0 + v.b),
|
|
191
|
+
at(p.cx + v.a, p.y0 + p.d, p.z0 + v.b),
|
|
192
|
+
]);
|
|
193
|
+
return p.pts.flatMap((v) => [
|
|
194
|
+
at(p.cx + v.a, p.y0 + v.b, p.z0),
|
|
195
|
+
at(p.cx + v.a, p.y0 + v.b, z1),
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const num = (v) => {
|
|
200
|
+
const r = Math.round(v * 1e6) / 1e6;
|
|
201
|
+
return Number.isInteger(r) ? String(r) : `about ${Math.round(v * 10) / 10}`;
|
|
202
|
+
};
|
|
203
|
+
const plural = (k, word) => `${k} ${word}${k === 1 ? "" : "s"}`;
|
|
204
|
+
function rectWords(w, h) {
|
|
205
|
+
return Math.abs(w - h) < 1e-6
|
|
206
|
+
? `square of side ${num(w)}`
|
|
207
|
+
: `rectangle ${num(w)} wide and ${num(h)} high`;
|
|
208
|
+
}
|
|
209
|
+
function ngonWords(sides, w) {
|
|
210
|
+
if (sides === 4)
|
|
211
|
+
return `square of side ${num(w)}`;
|
|
212
|
+
if (sides === 3)
|
|
213
|
+
return `triangle with equal sides, ${num(w)} wide`;
|
|
214
|
+
return `regular ${polygonNames[sides]} ${num(w)} wide`;
|
|
215
|
+
}
|
|
216
|
+
/** seen gives the corners of a counterclockwise polygon that one looking from toward sees. */
|
|
217
|
+
function seen(pts, toward) {
|
|
218
|
+
const k = pts.length;
|
|
219
|
+
const facing = pts.map((p, i) => {
|
|
220
|
+
const w = pts[(i + 1) % k];
|
|
221
|
+
return (w.b - p.b) * toward.a - (w.a - p.a) * toward.b > 1e-9;
|
|
222
|
+
});
|
|
223
|
+
return pts.flatMap((_, i) => (facing[i] || facing[(i - 1 + k) % k] ? [i] : []));
|
|
224
|
+
}
|
|
225
|
+
const rect = (a0, a1, b0, b1) => ({
|
|
226
|
+
type: "poly",
|
|
227
|
+
pts: [
|
|
228
|
+
{ a: a0, b: b0 },
|
|
229
|
+
{ a: a1, b: b0 },
|
|
230
|
+
{ a: a1, b: b1 },
|
|
231
|
+
{ a: a0, b: b1 },
|
|
232
|
+
],
|
|
233
|
+
});
|
|
234
|
+
function pieceOf(p, dir) {
|
|
235
|
+
const x0 = p.cx - p.w / 2;
|
|
236
|
+
const x1 = p.cx + p.w / 2;
|
|
237
|
+
const y1 = p.y0 + p.d;
|
|
238
|
+
const z1 = p.z0 + p.h;
|
|
239
|
+
const cy = p.y0 + p.d / 2;
|
|
240
|
+
const piece = (form, words, lines = [], detail = "", dot) => ({
|
|
241
|
+
i: p.i,
|
|
242
|
+
tower: p.tower,
|
|
243
|
+
color: p.color,
|
|
244
|
+
form,
|
|
245
|
+
lines,
|
|
246
|
+
...(dot ? { dot } : {}),
|
|
247
|
+
order: dir === "top" ? z1 * 100 + p.i : p.i,
|
|
248
|
+
words,
|
|
249
|
+
detail,
|
|
250
|
+
});
|
|
251
|
+
const inside = (v, lo, hi) => v > lo + 1e-6 && v < hi - 1e-6;
|
|
252
|
+
if (dir === "top") {
|
|
253
|
+
if (p.shape === "sphere" || p.shape === "cone" || (p.shape === "cylinder" && !p.lying)) {
|
|
254
|
+
const c = { a: p.cx, b: cy };
|
|
255
|
+
const words = `circle ${num(2 * p.r)} across`;
|
|
256
|
+
return p.shape === "cone"
|
|
257
|
+
? piece({ type: "circle", c, r: p.r }, words, [], ", with a dot in its middle", c)
|
|
258
|
+
: piece({ type: "circle", c, r: p.r }, words);
|
|
259
|
+
}
|
|
260
|
+
if (p.lying) {
|
|
261
|
+
const lines = seen(p.pts, { a: 0, b: 1 })
|
|
262
|
+
.map((k) => p.cx + p.pts[k].a)
|
|
263
|
+
.filter((a) => inside(a, x0, x1))
|
|
264
|
+
.map((a) => [
|
|
265
|
+
{ a, b: p.y0 },
|
|
266
|
+
{ a, b: y1 },
|
|
267
|
+
]);
|
|
268
|
+
const detail = lines.length ? `, split by ${plural(lines.length, "upright line")}` : "";
|
|
269
|
+
return piece(rect(x0, x1, p.y0, y1), rectWords(p.w, p.d), lines, detail);
|
|
270
|
+
}
|
|
271
|
+
const pts = p.pts.map((v) => ({ a: p.cx + v.a, b: p.y0 + v.b }));
|
|
272
|
+
if (p.shape === "cube" || p.shape === "cuboid")
|
|
273
|
+
return piece({ type: "poly", pts }, rectWords(p.w, p.d));
|
|
274
|
+
if (p.shape === "pyramid") {
|
|
275
|
+
const apex = { a: p.cx, b: p.y0 + p.middle };
|
|
276
|
+
return piece({ type: "poly", pts }, ngonWords(p.sides, p.w), pts.map((v) => [v, apex]), ", with lines from its corners to its middle");
|
|
277
|
+
}
|
|
278
|
+
return piece({ type: "poly", pts }, ngonWords(p.sides, p.w));
|
|
279
|
+
}
|
|
280
|
+
const across = dir === "front" || dir === "back";
|
|
281
|
+
const flip = dir === "back" || dir === "left";
|
|
282
|
+
const u = (x, y) => (across ? x : y) * (flip ? -1 : 1);
|
|
283
|
+
const toward = {
|
|
284
|
+
front: { a: 0, b: -1 },
|
|
285
|
+
back: { a: 0, b: 1 },
|
|
286
|
+
right: { a: 1, b: 0 },
|
|
287
|
+
left: { a: -1, b: 0 },
|
|
288
|
+
}[dir];
|
|
289
|
+
const [lo, hi] = [u(x0, p.y0), u(x1, y1)].sort((m, k) => m - k);
|
|
290
|
+
const uc = u(p.cx, cy);
|
|
291
|
+
switch (p.shape) {
|
|
292
|
+
case "sphere":
|
|
293
|
+
return piece({ type: "circle", c: { a: uc, b: p.z0 + p.r }, r: p.r }, `circle ${num(2 * p.r)} across`);
|
|
294
|
+
case "cone":
|
|
295
|
+
return piece({
|
|
296
|
+
type: "poly",
|
|
297
|
+
pts: [
|
|
298
|
+
{ a: uc - p.r, b: p.z0 },
|
|
299
|
+
{ a: uc + p.r, b: p.z0 },
|
|
300
|
+
{ a: uc, b: z1 },
|
|
301
|
+
],
|
|
302
|
+
}, `triangle ${num(2 * p.r)} wide and ${num(p.h)} high`);
|
|
303
|
+
case "cylinder":
|
|
304
|
+
if (p.lying && across)
|
|
305
|
+
return piece({ type: "circle", c: { a: uc, b: p.z0 + p.r }, r: p.r }, `circle ${num(2 * p.r)} across`);
|
|
306
|
+
return piece(rect(lo, hi, p.z0, z1), rectWords(hi - lo, p.h));
|
|
307
|
+
case "pyramid": {
|
|
308
|
+
const apex = { a: u(p.cx, p.y0 + p.middle), b: z1 };
|
|
309
|
+
const lines = seen(p.pts, toward)
|
|
310
|
+
.map((k) => u(p.cx + p.pts[k].a, p.y0 + p.pts[k].b))
|
|
311
|
+
.filter((a) => inside(a, lo, hi))
|
|
312
|
+
.map((a) => [{ a, b: p.z0 }, apex]);
|
|
313
|
+
const words = `triangle ${num(hi - lo)} wide and ${num(p.h)} high`;
|
|
314
|
+
const detail = lines.length
|
|
315
|
+
? `, with ${plural(lines.length, "line")} from its top corner down to its base`
|
|
316
|
+
: "";
|
|
317
|
+
return piece({
|
|
318
|
+
type: "poly",
|
|
319
|
+
pts: [{ a: lo, b: p.z0 }, { a: hi, b: p.z0 }, apex],
|
|
320
|
+
}, words, lines, detail);
|
|
321
|
+
}
|
|
322
|
+
default: {
|
|
323
|
+
if (p.lying) {
|
|
324
|
+
if (across) {
|
|
325
|
+
const pts = p.pts.map((v) => ({ a: u(p.cx + v.a, 0), b: p.z0 + v.b }));
|
|
326
|
+
if (flip)
|
|
327
|
+
pts.reverse();
|
|
328
|
+
return piece({ type: "poly", pts }, ngonWords(p.sides, p.w));
|
|
329
|
+
}
|
|
330
|
+
const lines = seen(p.pts, { a: toward.a, b: 0 })
|
|
331
|
+
.map((k) => p.z0 + p.pts[k].b)
|
|
332
|
+
.filter((b) => inside(b, p.z0, z1))
|
|
333
|
+
.map((b) => [
|
|
334
|
+
{ a: lo, b },
|
|
335
|
+
{ a: hi, b },
|
|
336
|
+
]);
|
|
337
|
+
const detail = lines.length ? `, split by ${plural(lines.length, "level line")}` : "";
|
|
338
|
+
return piece(rect(lo, hi, p.z0, z1), rectWords(hi - lo, p.h), lines, detail);
|
|
339
|
+
}
|
|
340
|
+
const lines = seen(p.pts, toward)
|
|
341
|
+
.map((k) => u(p.cx + p.pts[k].a, p.y0 + p.pts[k].b))
|
|
342
|
+
.filter((a) => inside(a, lo, hi))
|
|
343
|
+
.map((a) => [
|
|
344
|
+
{ a, b: p.z0 },
|
|
345
|
+
{ a, b: z1 },
|
|
346
|
+
]);
|
|
347
|
+
const detail = lines.length ? `, split by ${plural(lines.length, "upright line")}` : "";
|
|
348
|
+
return piece(rect(lo, hi, p.z0, z1), rectWords(hi - lo, p.h), lines, detail);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function viewOf(placed, dir) {
|
|
353
|
+
return placed.map((p) => pieceOf(p, dir)).sort((m, k) => m.order - k.order);
|
|
354
|
+
}
|
|
355
|
+
function boundsOf(forms) {
|
|
356
|
+
const as = [];
|
|
357
|
+
const bs = [];
|
|
358
|
+
for (const f of forms)
|
|
359
|
+
if (f.type === "circle") {
|
|
360
|
+
as.push(f.c.a - f.r, f.c.a + f.r);
|
|
361
|
+
bs.push(f.c.b - f.r, f.c.b + f.r);
|
|
362
|
+
}
|
|
363
|
+
else
|
|
364
|
+
for (const v of f.pts) {
|
|
365
|
+
as.push(v.a);
|
|
366
|
+
bs.push(v.b);
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
lo: { a: Math.min(...as), b: Math.min(...bs) },
|
|
370
|
+
hi: { a: Math.max(...as), b: Math.max(...bs) },
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/** within says whether a point lies in a form, its edge included. */
|
|
374
|
+
function within(f, v) {
|
|
375
|
+
if (f.type === "circle")
|
|
376
|
+
return Math.hypot(v.a - f.c.a, v.b - f.c.b) <= f.r + 1e-6;
|
|
377
|
+
return f.pts.every((p, i) => {
|
|
378
|
+
const w = f.pts[(i + 1) % f.pts.length];
|
|
379
|
+
return (w.a - p.a) * (v.b - p.b) - (w.b - p.b) * (v.a - p.a) >= -1e-6;
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/** covers says whether one form hides all of another, seen from above. */
|
|
383
|
+
function covers(up, low) {
|
|
384
|
+
const edge = low.type === "circle"
|
|
385
|
+
? Array.from({ length: 48 }, (_, k) => ({
|
|
386
|
+
a: low.c.a + low.r * Math.cos((k * Math.PI) / 24),
|
|
387
|
+
b: low.c.b + low.r * Math.sin((k * Math.PI) / 24),
|
|
388
|
+
}))
|
|
389
|
+
: low.pts;
|
|
390
|
+
return edge.every((v) => within(up, v));
|
|
391
|
+
}
|
|
392
|
+
/** sayView puts a view in words, tower by tower from the left of the panel. */
|
|
393
|
+
function sayView(pieces, dir, colour) {
|
|
394
|
+
const left = (g) => Math.min(...g.map((p) => boundsOf([p.form]).lo.a));
|
|
395
|
+
const groups = [...new Set(pieces.map((p) => p.tower))]
|
|
396
|
+
.map((t) => pieces.filter((p) => p.tower === t).sort((m, k) => m.i - k.i))
|
|
397
|
+
.sort((m, k) => left(m) - left(k));
|
|
398
|
+
const said = groups.map((g) => {
|
|
399
|
+
const shown = dir === "top" ? g.filter((p, k) => !g.slice(k + 1).some((up) => covers(up.form, p.form))) : g;
|
|
400
|
+
const words = shown.map((p) => colour ? article(`${colors[p.color].word} ${p.words}${p.detail}`) : article(p.words));
|
|
401
|
+
const [on, more] = dir === "top" ? ["inside it", "inside that"] : ["on top of it", "on top of that"];
|
|
402
|
+
return words
|
|
403
|
+
.map((w, k) => (k === 0 ? w : k === 1 ? `, ${on} ${w}` : `, and ${more} ${w}`))
|
|
404
|
+
.join("");
|
|
405
|
+
});
|
|
406
|
+
return said.length === 1 ? said[0] : `from left to right, ${said.join("; ")}`;
|
|
407
|
+
}
|
|
408
|
+
// --- outlines given by name ---------------------------------------------------------------
|
|
409
|
+
/** shapeOf gives an outline's size in units and its path, drawn from its bottom left at x, y. */
|
|
410
|
+
function shapeOf(o) {
|
|
411
|
+
const polygon = (w, h, pts, words) => ({
|
|
412
|
+
w,
|
|
413
|
+
h,
|
|
414
|
+
words,
|
|
415
|
+
path: (x, y, s) => poly(pts.map((v) => ({ x: x + v.a * s, y: y - v.b * s }))),
|
|
416
|
+
});
|
|
417
|
+
const round = (rx, ry, half, hole, words) => ({
|
|
418
|
+
w: 2 * rx,
|
|
419
|
+
h: half ? ry : 2 * ry,
|
|
420
|
+
words,
|
|
421
|
+
path: (x, y, s) => {
|
|
422
|
+
const [a, b] = [rx * s, ry * s];
|
|
423
|
+
const cy = half ? y : y - b;
|
|
424
|
+
const arc = (r1, r2) => `M${n(x + rx * s - r1)} ${n(cy)}A${n(r1)} ${n(r2)} 0 1 0 ${n(x + rx * s + r1)} ${n(cy)}A${n(r1)} ${n(r2)} 0 1 0 ${n(x + rx * s - r1)} ${n(cy)}Z`;
|
|
425
|
+
if (half)
|
|
426
|
+
return `M${n(x)} ${n(y)}H${n(x + 2 * a)}A${n(a)} ${n(b)} 0 0 0 ${n(x)} ${n(y)}Z`;
|
|
427
|
+
return hole > 0 ? `${arc(a, b)}${arc(hole * s, hole * s)}` : arc(a, b);
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
switch (o) {
|
|
431
|
+
case "circle":
|
|
432
|
+
return round(1, 1, false, 0, "circle 2 across");
|
|
433
|
+
case "oval":
|
|
434
|
+
return round(1.5, 1, false, 0, "oval 3 wide and 2 high");
|
|
435
|
+
case "semicircle":
|
|
436
|
+
return round(1, 1, true, 0, "half circle 2 wide and 1 high");
|
|
437
|
+
case "ring":
|
|
438
|
+
return round(1, 1, false, 0.5, "ring 2 across with a hole 1 across");
|
|
439
|
+
case "square":
|
|
440
|
+
return polygon(2, 2, square(2, 2), "square of side 2");
|
|
441
|
+
case "rectangle":
|
|
442
|
+
return polygon(3, 2, square(3, 2), "rectangle 3 wide and 2 high");
|
|
443
|
+
case "triangle":
|
|
444
|
+
return polygon(2, 2, [
|
|
445
|
+
{ a: 0, b: 0 },
|
|
446
|
+
{ a: 2, b: 0 },
|
|
447
|
+
{ a: 1, b: 2 },
|
|
448
|
+
], "triangle 2 wide and 2 high");
|
|
449
|
+
case "rhombus":
|
|
450
|
+
return polygon(2, 3, [
|
|
451
|
+
{ a: 1, b: 0 },
|
|
452
|
+
{ a: 2, b: 1.5 },
|
|
453
|
+
{ a: 1, b: 3 },
|
|
454
|
+
{ a: 0, b: 1.5 },
|
|
455
|
+
], "rhombus 2 wide and 3 high");
|
|
456
|
+
case "trapezoid":
|
|
457
|
+
return polygon(3, 2, [
|
|
458
|
+
{ a: 0, b: 0 },
|
|
459
|
+
{ a: 3, b: 0 },
|
|
460
|
+
{ a: 2, b: 2 },
|
|
461
|
+
{ a: 1, b: 2 },
|
|
462
|
+
], "trapezoid 3 wide at the bottom, 1 wide at the top and 2 high");
|
|
463
|
+
default: {
|
|
464
|
+
const g = ngon(o === "pentagon" ? 5 : 6, 2);
|
|
465
|
+
const h = Math.max(...g.pts.map((v) => v.b));
|
|
466
|
+
return polygon(2, h, g.pts.map((v) => ({ a: v.a + 1, b: v.b })), ngonWords(o === "pentagon" ? 5 : 6, 2));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function square(w, h) {
|
|
471
|
+
return [
|
|
472
|
+
{ a: 0, b: 0 },
|
|
473
|
+
{ a: w, b: 0 },
|
|
474
|
+
{ a: w, b: h },
|
|
475
|
+
{ a: 0, b: h },
|
|
476
|
+
];
|
|
477
|
+
}
|
|
478
|
+
function captionOf(v) {
|
|
479
|
+
return v.label ?? v.from ?? "";
|
|
480
|
+
}
|
|
481
|
+
function layout(sc) {
|
|
482
|
+
const placed = place(sc);
|
|
483
|
+
const reach = placed.flatMap(reachOf);
|
|
484
|
+
const left = Math.min(...reach.map((c) => c.x - c.r));
|
|
485
|
+
const right = Math.max(...reach.map((c) => c.x + c.r));
|
|
486
|
+
const low = Math.min(0, ...reach.map((c) => c.y - c.r));
|
|
487
|
+
const high = Math.max(...reach.map((c) => c.y + c.r));
|
|
488
|
+
const panels = (sc.views ?? []).map((v) => {
|
|
489
|
+
if (v.from) {
|
|
490
|
+
const pieces = viewOf(placed, v.from);
|
|
491
|
+
return {
|
|
492
|
+
panel: v,
|
|
493
|
+
pieces,
|
|
494
|
+
bounds: boundsOf(pieces.map((p) => p.form)),
|
|
495
|
+
caption: captionOf(v),
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
const o = v.shape ? shapeOf(v.shape) : { w: 2, h: 2 };
|
|
499
|
+
return {
|
|
500
|
+
panel: v,
|
|
501
|
+
pieces: [],
|
|
502
|
+
bounds: { lo: { a: 0, b: 0 }, hi: { a: o.w, b: o.h } },
|
|
503
|
+
caption: captionOf(v),
|
|
504
|
+
};
|
|
505
|
+
});
|
|
506
|
+
const k = panels.length;
|
|
507
|
+
const across = panels.reduce((m, p) => m + p.bounds.hi.a - p.bounds.lo.a, 0);
|
|
508
|
+
const up = Math.max(0, ...panels.map((p) => p.bounds.hi.b - p.bounds.lo.b));
|
|
509
|
+
const forSolids = Math.min(room / (right - left), tallest / (high - low));
|
|
510
|
+
const forViews = k === 0 ? biggest : Math.min((room - 2 * pad * k - panelGap * (k - 1)) / across, 200 / up);
|
|
511
|
+
const s = Math.min(biggest, forSolids, forViews);
|
|
512
|
+
const tight = s >= smallest ? undefined : forSolids < forViews ? "solids" : "views";
|
|
513
|
+
const widths = panels.map((p) => Math.max((p.bounds.hi.a - p.bounds.lo.a) * s + 2 * pad, p.caption ? textWidth(p.caption, 15) + 12 : 0));
|
|
514
|
+
const row = widths.reduce((m, w) => m + w, 0) + panelGap * Math.max(0, k - 1);
|
|
515
|
+
const inner = Math.max((right - left) * s, row);
|
|
516
|
+
const ox = margin + (inner - (right - left) * s) / 2 - left * s;
|
|
517
|
+
const oy = margin + high * s;
|
|
518
|
+
const py = oy - low * s + gapBelow;
|
|
519
|
+
const ph = up * s + 2 * pad;
|
|
520
|
+
let x = margin + (inner - row) / 2;
|
|
521
|
+
const laid = panels.map((p, j) => {
|
|
522
|
+
const at = { ...p, x, w: widths[j] };
|
|
523
|
+
x += widths[j] + panelGap;
|
|
524
|
+
return at;
|
|
525
|
+
});
|
|
526
|
+
const captions = panels.some((p) => p.caption);
|
|
527
|
+
const height = k === 0 ? oy - low * s + 6 + margin : py + ph + (captions ? 30 : 4) + margin;
|
|
528
|
+
return {
|
|
529
|
+
placed,
|
|
530
|
+
s,
|
|
531
|
+
ox,
|
|
532
|
+
oy,
|
|
533
|
+
left,
|
|
534
|
+
right,
|
|
535
|
+
panels: laid,
|
|
536
|
+
py,
|
|
537
|
+
ph,
|
|
538
|
+
width: inner + 2 * margin,
|
|
539
|
+
height,
|
|
540
|
+
...(tight ? { tight } : {}),
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function sideTone(t, nx, ny) {
|
|
544
|
+
const l = Math.hypot(nx, ny) || 1;
|
|
545
|
+
if (nx / l > 0.5)
|
|
546
|
+
return t.right;
|
|
547
|
+
if (nx / l < -0.5)
|
|
548
|
+
return mix(t.front, t.top, 0.5);
|
|
549
|
+
return t.front;
|
|
550
|
+
}
|
|
551
|
+
function drawSolid(pen, p, at, s, hidden) {
|
|
552
|
+
const t = tones(p.color);
|
|
553
|
+
const y1 = p.y0 + p.d;
|
|
554
|
+
const z1 = p.z0 + p.h;
|
|
555
|
+
const cy = p.y0 + p.d / 2;
|
|
556
|
+
const face = (pts, fill) => pen.el("path", { d: poly(pts), fill, ...line, class: "face" });
|
|
557
|
+
const round = (d, fill) => pen.el("path", { d, fill, ...line, class: "round" });
|
|
558
|
+
// A label goes in the middle of the largest side in sight.
|
|
559
|
+
let spot;
|
|
560
|
+
let most = 0;
|
|
561
|
+
const side = (pts, fill) => {
|
|
562
|
+
face(pts, fill);
|
|
563
|
+
const area = Math.abs(pts.reduce((m, v, i) => {
|
|
564
|
+
const w = pts[(i + 1) % pts.length];
|
|
565
|
+
return m + v.x * w.y - w.x * v.y;
|
|
566
|
+
}, 0) / 2);
|
|
567
|
+
if (area > most + 1e-6) {
|
|
568
|
+
most = area;
|
|
569
|
+
spot = {
|
|
570
|
+
x: pts.reduce((m, v) => m + v.x, 0) / pts.length,
|
|
571
|
+
y: pts.reduce((m, v) => m + v.y, 0) / pts.length,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
const dash = (d) => {
|
|
576
|
+
if (hidden)
|
|
577
|
+
pen.el("path", {
|
|
578
|
+
d,
|
|
579
|
+
fill: "none",
|
|
580
|
+
stroke: ink,
|
|
581
|
+
"stroke-width": 1.8,
|
|
582
|
+
"stroke-dasharray": "5 4",
|
|
583
|
+
"stroke-linecap": "round",
|
|
584
|
+
class: "hidden",
|
|
585
|
+
});
|
|
586
|
+
};
|
|
587
|
+
const rx = p.r * s;
|
|
588
|
+
const ry = q * p.r * s;
|
|
589
|
+
if (p.shape === "sphere") {
|
|
590
|
+
const c = at(p.cx, cy, p.z0 + p.r);
|
|
591
|
+
pen.el("circle", { cx: c.x, cy: c.y, r: rx, fill: t.front, ...line, class: "round" });
|
|
592
|
+
pen.el("path", {
|
|
593
|
+
d: `M${n(c.x - rx)} ${n(c.y)}A${n(rx)} ${n(q * rx)} 0 0 0 ${n(c.x + rx)} ${n(c.y)}`,
|
|
594
|
+
fill: "none",
|
|
595
|
+
stroke: ink,
|
|
596
|
+
"stroke-width": 1.5,
|
|
597
|
+
});
|
|
598
|
+
dash(`M${n(c.x + rx)} ${n(c.y)}A${n(rx)} ${n(q * rx)} 0 0 0 ${n(c.x - rx)} ${n(c.y)}`);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
if (p.shape === "cylinder" && p.lying) {
|
|
602
|
+
const f = at(p.cx, p.y0, p.z0 + p.r);
|
|
603
|
+
const b = at(p.cx, y1, p.z0 + p.r);
|
|
604
|
+
const m = Math.SQRT1_2 * rx;
|
|
605
|
+
round(`M${n(f.x + m)} ${n(f.y + m)}L${n(b.x + m)} ${n(b.y + m)}A${n(rx)} ${n(rx)} 0 0 0 ${n(b.x - m)} ${n(b.y - m)}L${n(f.x - m)} ${n(f.y - m)}A${n(rx)} ${n(rx)} 0 0 0 ${n(f.x + m)} ${n(f.y + m)}Z`, mix(t.top, t.right, 0.5));
|
|
606
|
+
dash(`M${n(b.x + m)} ${n(b.y + m)}A${n(rx)} ${n(rx)} 0 0 1 ${n(b.x - m)} ${n(b.y - m)}`);
|
|
607
|
+
pen.el("circle", { cx: f.x, cy: f.y, r: rx, fill: t.front, ...line, class: "round" });
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (p.shape === "cylinder") {
|
|
611
|
+
const c0 = at(p.cx, cy, p.z0);
|
|
612
|
+
const c1 = at(p.cx, cy, z1);
|
|
613
|
+
round(`M${n(c1.x - rx)} ${n(c1.y)}L${n(c0.x - rx)} ${n(c0.y)}A${n(rx)} ${n(ry)} 0 0 0 ${n(c0.x + rx)} ${n(c0.y)}L${n(c1.x + rx)} ${n(c1.y)}Z`, t.front);
|
|
614
|
+
dash(`M${n(c0.x + rx)} ${n(c0.y)}A${n(rx)} ${n(ry)} 0 0 0 ${n(c0.x - rx)} ${n(c0.y)}`);
|
|
615
|
+
pen.el("ellipse", { cx: c1.x, cy: c1.y, rx, ry, fill: t.top, ...line, class: "round" });
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (p.shape === "cone") {
|
|
619
|
+
const c0 = at(p.cx, cy, p.z0);
|
|
620
|
+
const apex = at(p.cx, cy, z1);
|
|
621
|
+
const far = (c0.y - apex.y) / ry;
|
|
622
|
+
const k = Math.sqrt(1 - 1 / (far * far));
|
|
623
|
+
const tl = { x: c0.x - rx * k, y: c0.y - ry / far };
|
|
624
|
+
const tr = { x: c0.x + rx * k, y: c0.y - ry / far };
|
|
625
|
+
round(`M${n(apex.x)} ${n(apex.y)}L${n(tl.x)} ${n(tl.y)}A${n(rx)} ${n(ry)} 0 1 0 ${n(tr.x)} ${n(tr.y)}Z`, t.front);
|
|
626
|
+
dash(`M${n(tr.x)} ${n(tr.y)}A${n(rx)} ${n(ry)} 0 0 0 ${n(tl.x)} ${n(tl.y)}`);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
const k = p.pts.length;
|
|
630
|
+
if (p.shape === "pyramid") {
|
|
631
|
+
const base = p.pts.map((v) => ({ x: p.cx + v.a, y: p.y0 + v.b }));
|
|
632
|
+
const apex = { x: p.cx, y: p.y0 + p.middle };
|
|
633
|
+
const sides = base.map((v, i) => {
|
|
634
|
+
const w = base[(i + 1) % k];
|
|
635
|
+
const [ax, ay] = [w.x - v.x, w.y - v.y];
|
|
636
|
+
const [bx, by, bz] = [apex.x - v.x, apex.y - v.y, p.h];
|
|
637
|
+
const [nx, ny, nz] = [ay * bz, -ax * bz, ax * by - ay * bx];
|
|
638
|
+
return { v, w, nx, ny, shown: -q * nx + ny - q * nz < -1e-9 };
|
|
639
|
+
});
|
|
640
|
+
for (const e of sides)
|
|
641
|
+
if (e.shown)
|
|
642
|
+
side([at(e.v.x, e.v.y, p.z0), at(e.w.x, e.w.y, p.z0), at(apex.x, apex.y, z1)], sideTone(t, e.nx, e.ny));
|
|
643
|
+
sides.forEach((e, i) => {
|
|
644
|
+
if (e.shown)
|
|
645
|
+
return;
|
|
646
|
+
dash(poly([at(e.v.x, e.v.y, p.z0), at(e.w.x, e.w.y, p.z0)], false));
|
|
647
|
+
if (!sides[(i - 1 + k) % k].shown)
|
|
648
|
+
dash(poly([at(e.v.x, e.v.y, p.z0), at(apex.x, apex.y, z1)], false));
|
|
649
|
+
});
|
|
650
|
+
return spot;
|
|
651
|
+
}
|
|
652
|
+
if (p.lying) {
|
|
653
|
+
const end = p.pts.map((v) => ({ x: p.cx + v.a, z: p.z0 + v.b }));
|
|
654
|
+
const sides = end.map((v, i) => {
|
|
655
|
+
const w = end[(i + 1) % k];
|
|
656
|
+
const l = Math.hypot(w.x - v.x, w.z - v.z);
|
|
657
|
+
const [na, nb] = [(w.z - v.z) / l, -(w.x - v.x) / l];
|
|
658
|
+
return { v, w, na, nb, shown: na + nb > 1e-9 };
|
|
659
|
+
});
|
|
660
|
+
for (const e of sides)
|
|
661
|
+
if (e.shown)
|
|
662
|
+
face([
|
|
663
|
+
at(e.v.x, p.y0, e.v.z),
|
|
664
|
+
at(e.w.x, p.y0, e.w.z),
|
|
665
|
+
at(e.w.x, y1, e.w.z),
|
|
666
|
+
at(e.v.x, y1, e.v.z),
|
|
667
|
+
], e.nb > Math.abs(e.na) ? t.top : e.na > 0 ? t.right : t.front);
|
|
668
|
+
face(end.map((v) => at(v.x, p.y0, v.z)), t.front);
|
|
669
|
+
sides.forEach((e, i) => {
|
|
670
|
+
if (e.shown)
|
|
671
|
+
return;
|
|
672
|
+
dash(poly([at(e.v.x, y1, e.v.z), at(e.w.x, y1, e.w.z)], false));
|
|
673
|
+
if (!sides[(i - 1 + k) % k].shown)
|
|
674
|
+
dash(poly([at(e.v.x, p.y0, e.v.z), at(e.v.x, y1, e.v.z)], false));
|
|
675
|
+
});
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
const base = p.pts.map((v) => ({ x: p.cx + v.a, y: p.y0 + v.b }));
|
|
679
|
+
const sides = base.map((v, i) => {
|
|
680
|
+
const w = base[(i + 1) % k];
|
|
681
|
+
const l = Math.hypot(w.x - v.x, w.y - v.y);
|
|
682
|
+
const [nx, ny] = [(w.y - v.y) / l, -(w.x - v.x) / l];
|
|
683
|
+
return { v, w, nx, ny, shown: -q * nx + ny < -1e-9 };
|
|
684
|
+
});
|
|
685
|
+
for (const e of sides)
|
|
686
|
+
if (e.shown)
|
|
687
|
+
side([
|
|
688
|
+
at(e.v.x, e.v.y, p.z0),
|
|
689
|
+
at(e.w.x, e.w.y, p.z0),
|
|
690
|
+
at(e.w.x, e.w.y, z1),
|
|
691
|
+
at(e.v.x, e.v.y, z1),
|
|
692
|
+
], sideTone(t, e.nx, e.ny));
|
|
693
|
+
face(base.map((v) => at(v.x, v.y, z1)), t.top);
|
|
694
|
+
sides.forEach((e, i) => {
|
|
695
|
+
if (e.shown)
|
|
696
|
+
return;
|
|
697
|
+
dash(poly([at(e.v.x, e.v.y, p.z0), at(e.w.x, e.w.y, p.z0)], false));
|
|
698
|
+
if (!sides[(i - 1 + k) % k].shown)
|
|
699
|
+
dash(poly([at(e.v.x, e.v.y, p.z0), at(e.v.x, e.v.y, z1)], false));
|
|
700
|
+
});
|
|
701
|
+
return spot;
|
|
702
|
+
}
|
|
703
|
+
/** labelAt is where the label of a round solid or a lying prism sits: on its front, low on a cone. */
|
|
704
|
+
function labelAt(p, at, s) {
|
|
705
|
+
const cy = p.y0 + p.d / 2;
|
|
706
|
+
const zm = p.z0 + p.h / 2;
|
|
707
|
+
switch (p.shape) {
|
|
708
|
+
case "sphere":
|
|
709
|
+
return at(p.cx, cy, p.z0 + p.r);
|
|
710
|
+
case "cone": {
|
|
711
|
+
const c = at(p.cx, cy, p.z0);
|
|
712
|
+
return { x: c.x, y: c.y + q * p.r * s * 0.4 - p.h * s * 0.3 };
|
|
713
|
+
}
|
|
714
|
+
case "cylinder": {
|
|
715
|
+
if (p.lying)
|
|
716
|
+
return at(p.cx, p.y0, p.z0 + p.r);
|
|
717
|
+
const c = at(p.cx, cy, zm);
|
|
718
|
+
return { x: c.x, y: c.y + q * p.r * s };
|
|
719
|
+
}
|
|
720
|
+
default:
|
|
721
|
+
return p.lying ? at(p.cx, p.y0, p.z0 + p.middle) : at(p.cx, p.y0, zm);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function tagWidth(label) {
|
|
725
|
+
return Math.max(24, textWidth(label, 15) + 10);
|
|
726
|
+
}
|
|
727
|
+
function tag(pen, x, y, label) {
|
|
728
|
+
const w = tagWidth(label);
|
|
729
|
+
pen.el("rect", {
|
|
730
|
+
x: x - w / 2,
|
|
731
|
+
y: y - 12,
|
|
732
|
+
width: w,
|
|
733
|
+
height: 24,
|
|
734
|
+
rx: 8,
|
|
735
|
+
fill: "#ffffff",
|
|
736
|
+
...line,
|
|
737
|
+
"stroke-width": 1.5,
|
|
738
|
+
});
|
|
739
|
+
pen.text(x, y, label, { size: 15 });
|
|
740
|
+
}
|
|
741
|
+
function drawPanel(pen, lay, pl, shadows) {
|
|
742
|
+
const { s, py, ph } = lay;
|
|
743
|
+
const { x, w, panel } = pl;
|
|
744
|
+
const cx = x + w / 2;
|
|
745
|
+
if (panel.ask) {
|
|
746
|
+
pen.el("rect", {
|
|
747
|
+
x,
|
|
748
|
+
y: py,
|
|
749
|
+
width: w,
|
|
750
|
+
height: ph,
|
|
751
|
+
rx: 10,
|
|
752
|
+
fill: "#ffffff",
|
|
753
|
+
stroke: ink,
|
|
754
|
+
"stroke-width": 2,
|
|
755
|
+
"stroke-dasharray": "6 5",
|
|
756
|
+
class: "ask",
|
|
757
|
+
});
|
|
758
|
+
pen.text(cx, py + ph / 2, "?", { size: 30 });
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
pen.el("rect", {
|
|
762
|
+
x,
|
|
763
|
+
y: py,
|
|
764
|
+
width: w,
|
|
765
|
+
height: ph,
|
|
766
|
+
rx: 10,
|
|
767
|
+
fill: "#ffffff",
|
|
768
|
+
stroke: faint,
|
|
769
|
+
"stroke-width": 2,
|
|
770
|
+
class: "panel",
|
|
771
|
+
});
|
|
772
|
+
const { lo, hi } = pl.bounds;
|
|
773
|
+
const left = cx - ((hi.a - lo.a) * s) / 2;
|
|
774
|
+
const bottom = py + ph / 2 + ((hi.b - lo.b) * s) / 2;
|
|
775
|
+
const at = (v) => ({ x: left + (v.a - lo.a) * s, y: bottom - (v.b - lo.b) * s });
|
|
776
|
+
const shape = (f, values) => {
|
|
777
|
+
if (f.type === "circle") {
|
|
778
|
+
const c = at(f.c);
|
|
779
|
+
pen.el("circle", { cx: c.x, cy: c.y, r: f.r * s, ...values });
|
|
780
|
+
}
|
|
781
|
+
else
|
|
782
|
+
pen.el("path", { d: poly(f.pts.map(at)), ...values });
|
|
783
|
+
};
|
|
784
|
+
if (panel.shape) {
|
|
785
|
+
const o = shapeOf(panel.shape);
|
|
786
|
+
pen.el("path", {
|
|
787
|
+
d: o.path(left, bottom, s),
|
|
788
|
+
fill: shadows ? shadowFill : outlineFill,
|
|
789
|
+
"fill-rule": "evenodd",
|
|
790
|
+
...line,
|
|
791
|
+
class: "piece",
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
else if (shadows) {
|
|
795
|
+
// Outlines first, twice as wide, then the fills over them: one outline round the whole shadow.
|
|
796
|
+
for (const p of pl.pieces)
|
|
797
|
+
shape(p.form, {
|
|
798
|
+
fill: shadowFill,
|
|
799
|
+
stroke: ink,
|
|
800
|
+
"stroke-width": 2 * outline,
|
|
801
|
+
"stroke-linejoin": "round",
|
|
802
|
+
});
|
|
803
|
+
for (const p of pl.pieces)
|
|
804
|
+
shape(p.form, { fill: shadowFill, class: "piece" });
|
|
805
|
+
}
|
|
806
|
+
else
|
|
807
|
+
for (const p of pl.pieces) {
|
|
808
|
+
shape(p.form, {
|
|
809
|
+
fill: p.color === "white" ? "#ffffff" : mix(colors[p.color].fill, "#ffffff", 0.35),
|
|
810
|
+
...line,
|
|
811
|
+
class: "piece",
|
|
812
|
+
});
|
|
813
|
+
for (const [a, b] of p.lines)
|
|
814
|
+
pen.el("path", {
|
|
815
|
+
d: poly([at(a), at(b)], false),
|
|
816
|
+
stroke: ink,
|
|
817
|
+
"stroke-width": 2,
|
|
818
|
+
"stroke-linecap": "round",
|
|
819
|
+
class: "line",
|
|
820
|
+
});
|
|
821
|
+
if (p.dot) {
|
|
822
|
+
const c = at(p.dot);
|
|
823
|
+
pen.el("circle", { cx: c.x, cy: c.y, r: 3, fill: ink });
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
if (pl.caption)
|
|
828
|
+
pen.text(cx, py + ph + 16, pl.caption, { size: 15 });
|
|
829
|
+
}
|
|
830
|
+
// --- words ---------------------------------------------------------------------------------
|
|
831
|
+
function saySolid(sol, p) {
|
|
832
|
+
const [a = 1, b = 1, c = 1] = sizeOf(sol);
|
|
833
|
+
const what = (() => {
|
|
834
|
+
switch (sol.shape) {
|
|
835
|
+
case "cube":
|
|
836
|
+
return `cube with edges of ${a}`;
|
|
837
|
+
case "cuboid":
|
|
838
|
+
return `cuboid ${a} wide, ${b} deep and ${c} tall`;
|
|
839
|
+
case "sphere":
|
|
840
|
+
return `sphere ${a} across`;
|
|
841
|
+
case "cylinder":
|
|
842
|
+
return p.lying
|
|
843
|
+
? `cylinder ${a} across and ${b} long, lying with a round face to the front`
|
|
844
|
+
: `upright cylinder ${a} across and ${b} tall`;
|
|
845
|
+
case "cone":
|
|
846
|
+
return `cone ${a} across and ${b} tall`;
|
|
847
|
+
case "pyramid":
|
|
848
|
+
return `pyramid ${b} tall on a ${baseNames[p.sides]} base ${a} wide`;
|
|
849
|
+
default:
|
|
850
|
+
return p.lying
|
|
851
|
+
? `${baseNames[p.sides]} prism ${b} long, lying with a ${polygonNames[p.sides]} face ${a} wide to the front`
|
|
852
|
+
: `${baseNames[p.sides]} prism ${b} tall, upright on a ${polygonNames[p.sides]} face ${a} wide`;
|
|
853
|
+
}
|
|
854
|
+
})();
|
|
855
|
+
const words = article(`${colors[p.color].word} ${what}`);
|
|
856
|
+
return sol.label ? `solid ${sol.label} (${words})` : words;
|
|
857
|
+
}
|
|
858
|
+
function sayPanel(pl, shadows) {
|
|
859
|
+
const v = pl.panel;
|
|
860
|
+
const name = v.label ? `${v.label}: ` : v.from ? `from the ${v.from}: ` : "";
|
|
861
|
+
if (v.ask)
|
|
862
|
+
return `${name}a box with a question mark`;
|
|
863
|
+
const content = v.shape
|
|
864
|
+
? shadows
|
|
865
|
+
? `a shadow shaped like ${article(shapeOf(v.shape).words)}`
|
|
866
|
+
: article(`gray ${shapeOf(v.shape).words}`)
|
|
867
|
+
: shadows
|
|
868
|
+
? `a shadow shaped like ${sayView(pl.pieces, v.from, false)}`
|
|
869
|
+
: sayView(pl.pieces, v.from, true);
|
|
870
|
+
return `${name}${content}`;
|
|
871
|
+
}
|
|
872
|
+
// --- the check -----------------------------------------------------------------------------
|
|
873
|
+
function checkSize(shape, lying, size, path, problems) {
|
|
874
|
+
const whole = (v, most) => typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= most;
|
|
875
|
+
if (shape === "cube" || shape === "sphere") {
|
|
876
|
+
if (!whole(size, 5))
|
|
877
|
+
problems.push(`${path}: must be a whole number from 1 to 5, the ${shape === "cube" ? "edge" : "width across"}`);
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
const want = shape === "cuboid"
|
|
881
|
+
? "[width, depth, height]"
|
|
882
|
+
: shape === "cylinder" || shape === "cone"
|
|
883
|
+
? lying
|
|
884
|
+
? "[width across, length]"
|
|
885
|
+
: "[width across, height]"
|
|
886
|
+
: lying
|
|
887
|
+
? "[width, length]"
|
|
888
|
+
: "[width, height]";
|
|
889
|
+
const k = shape === "cuboid" ? 3 : 2;
|
|
890
|
+
if (!Array.isArray(size) || size.length !== k || !size.every((v) => whole(v, 6)))
|
|
891
|
+
problems.push(`${path}: must be ${want}, whole numbers from 1 to 6`);
|
|
892
|
+
}
|
|
893
|
+
export const solids = {
|
|
894
|
+
kind: "solids",
|
|
895
|
+
members: ["kind", "solids", "hidden", "views", "shadows"],
|
|
896
|
+
check(scene, problems) {
|
|
897
|
+
only(scene, this.members, "scene", problems);
|
|
898
|
+
const items = list(scene.solids, "solids", problems, 1, 5);
|
|
899
|
+
items.forEach((sol, i) => {
|
|
900
|
+
const path = `solids[${i}]`;
|
|
901
|
+
if (!isObj(sol)) {
|
|
902
|
+
problems.push(`${path}: must be a solid with a shape`);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
only(sol, ["shape", "size", "sides", "lying", "on", "color", "label"], path, problems);
|
|
906
|
+
const before = problems.length;
|
|
907
|
+
const shape = oneOf(sol.shape, solidShapes, `${path}.shape`, problems);
|
|
908
|
+
if (problems.length > before)
|
|
909
|
+
return;
|
|
910
|
+
if (sol.lying !== undefined) {
|
|
911
|
+
if (shape !== "cylinder" && shape !== "prism")
|
|
912
|
+
problems.push(`${path}.lying: only a cylinder or a prism can lie`);
|
|
913
|
+
else if (sol.lying !== true)
|
|
914
|
+
problems.push(`${path}.lying: must be true, or left out`);
|
|
915
|
+
}
|
|
916
|
+
if (sol.size !== undefined)
|
|
917
|
+
checkSize(shape, sol.lying === true, sol.size, `${path}.size`, problems);
|
|
918
|
+
if (sol.sides !== undefined) {
|
|
919
|
+
if (shape !== "pyramid" && shape !== "prism")
|
|
920
|
+
problems.push(`${path}.sides: only a pyramid or a prism has sides to give`);
|
|
921
|
+
else
|
|
922
|
+
int(sol.sides, `${path}.sides`, problems, 3, 6);
|
|
923
|
+
}
|
|
924
|
+
if (sol.color !== undefined && !isColor(sol.color))
|
|
925
|
+
problems.push(`${path}.color: must be a colour: ${colorNames.join(", ")}`);
|
|
926
|
+
if (sol.label !== undefined)
|
|
927
|
+
text(sol.label, `${path}.label`, problems, 3);
|
|
928
|
+
if (sol.on !== undefined) {
|
|
929
|
+
if (i === 0)
|
|
930
|
+
problems.push(`${path}.on: the first solid stands on the table`);
|
|
931
|
+
else
|
|
932
|
+
int(sol.on, `${path}.on`, problems, 1, i);
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
if (scene.hidden !== undefined && typeof scene.hidden !== "boolean")
|
|
936
|
+
problems.push("hidden: must be true or false");
|
|
937
|
+
if (scene.shadows !== undefined && typeof scene.shadows !== "boolean")
|
|
938
|
+
problems.push("shadows: must be true or false");
|
|
939
|
+
if (scene.shadows === true && scene.views === undefined)
|
|
940
|
+
problems.push("shadows: there are no views to draw as shadows; give views");
|
|
941
|
+
if (scene.views !== undefined)
|
|
942
|
+
list(scene.views, "views", problems, 1, 5).forEach((v, k) => {
|
|
943
|
+
const path = `views[${k}]`;
|
|
944
|
+
if (!isObj(v)) {
|
|
945
|
+
problems.push(`${path}: must be a view, with from or shape`);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
only(v, ["from", "shape", "label", "ask"], path, problems);
|
|
949
|
+
if (v.from !== undefined && v.shape !== undefined)
|
|
950
|
+
problems.push(`${path}: give from or shape, not both`);
|
|
951
|
+
if (v.from === undefined && v.shape === undefined && v.ask !== true)
|
|
952
|
+
problems.push(`${path}: must give from, the side the solids are seen from, or shape, an outline by name`);
|
|
953
|
+
if (v.from !== undefined)
|
|
954
|
+
oneOf(v.from, directions, `${path}.from`, problems);
|
|
955
|
+
if (v.shape !== undefined)
|
|
956
|
+
oneOf(v.shape, outlines, `${path}.shape`, problems);
|
|
957
|
+
if (v.label !== undefined)
|
|
958
|
+
text(v.label, `${path}.label`, problems, 6);
|
|
959
|
+
if (v.ask !== undefined && v.ask !== true)
|
|
960
|
+
problems.push(`${path}.ask: must be true, or left out`);
|
|
961
|
+
if (v.ask === true && v.shape !== undefined)
|
|
962
|
+
problems.push(`${path}.ask: a question mark stands for a view; leave shape out`);
|
|
963
|
+
});
|
|
964
|
+
if (problems.length > 0)
|
|
965
|
+
return;
|
|
966
|
+
const s = scene;
|
|
967
|
+
const sized = s.solids.map((sol) => measure(sol));
|
|
968
|
+
s.solids.forEach((sol, i) => {
|
|
969
|
+
const path = `solids[${i}]`;
|
|
970
|
+
const m = sized[i];
|
|
971
|
+
if (sol.shape === "cone" && 4 * m.h < m.w)
|
|
972
|
+
problems.push(`${path}.size: a cone this flat cannot be drawn; make it at least a quarter as tall as it is wide`);
|
|
973
|
+
if (sol.on === undefined)
|
|
974
|
+
return;
|
|
975
|
+
const lo = s.solids[sol.on - 1];
|
|
976
|
+
const below = sized[sol.on - 1];
|
|
977
|
+
if (!carriers.includes(lo.shape) || below.lying)
|
|
978
|
+
problems.push(`${path}.on: solid ${sol.on} is ${article(below.lying ? `lying ${lo.shape}` : lo.shape)}, with no flat top to stand on; stand it on a cube, a cuboid or an upright cylinder`);
|
|
979
|
+
const first = s.solids.findIndex((o) => o.on === sol.on);
|
|
980
|
+
if (first < i)
|
|
981
|
+
problems.push(`${path}.on: solid ${sol.on} already carries solid ${first + 1}; one solid stands on another`);
|
|
982
|
+
if (m.w > below.w + 1e-9 || m.d > below.d + 1e-9)
|
|
983
|
+
problems.push(`${path}.size: wider or deeper than solid ${sol.on}, which it stands on`);
|
|
984
|
+
});
|
|
985
|
+
if (problems.length > 0)
|
|
986
|
+
return;
|
|
987
|
+
const towers = new Set(place(s).map((p) => p.tower)).size;
|
|
988
|
+
(s.views ?? []).forEach((v, k) => {
|
|
989
|
+
if ((v.from === "left" || v.from === "right") && towers > 1)
|
|
990
|
+
problems.push(`views[${k}].from: from the ${v.from} the solids hide one another; view them from the front, back or top`);
|
|
991
|
+
});
|
|
992
|
+
if (problems.length > 0)
|
|
993
|
+
return;
|
|
994
|
+
const lay = layout(s);
|
|
995
|
+
if (lay.tight === "solids")
|
|
996
|
+
problems.push("solids: too big to draw together; use fewer or smaller solids");
|
|
997
|
+
if (lay.tight === "views")
|
|
998
|
+
problems.push("views: too wide for one row; use fewer views or smaller solids");
|
|
999
|
+
if (lay.width > 640 + 1e-9)
|
|
1000
|
+
problems.push("views: too wide for one row; use fewer views or shorter labels");
|
|
1001
|
+
lay.placed.forEach((p) => {
|
|
1002
|
+
const label = s.solids[p.i].label;
|
|
1003
|
+
if (label === undefined)
|
|
1004
|
+
return;
|
|
1005
|
+
const room_ = Math.min(p.w, p.h) * lay.s * (p.shape === "cone" || p.shape === "pyramid" ? 0.55 : 0.85);
|
|
1006
|
+
if (room_ < tagWidth(label) || Math.min(p.w, p.h) * lay.s < 34)
|
|
1007
|
+
problems.push(`solids[${p.i}].label: the solid is too small for its label; make it bigger or the label shorter`);
|
|
1008
|
+
});
|
|
1009
|
+
},
|
|
1010
|
+
draw(scene, pen) {
|
|
1011
|
+
const s = scene;
|
|
1012
|
+
const lay = layout(s);
|
|
1013
|
+
const at = (x, y, z) => ({
|
|
1014
|
+
x: lay.ox + lay.s * (x + q * y),
|
|
1015
|
+
y: lay.oy - lay.s * (z + q * y),
|
|
1016
|
+
});
|
|
1017
|
+
pen.el("path", {
|
|
1018
|
+
d: `M${n(lay.ox + lay.left * lay.s - 10)} ${n(lay.oy + 2)}H${n(lay.ox + lay.right * lay.s + 10)}`,
|
|
1019
|
+
stroke: faint,
|
|
1020
|
+
"stroke-width": 3,
|
|
1021
|
+
"stroke-linecap": "round",
|
|
1022
|
+
});
|
|
1023
|
+
const order = [...lay.placed].sort((m, k) => m.tower - k.tower || m.z0 - k.z0);
|
|
1024
|
+
const spots = new Map();
|
|
1025
|
+
for (const p of order)
|
|
1026
|
+
spots.set(p.i, drawSolid(pen, p, at, lay.s, s.hidden === true));
|
|
1027
|
+
for (const p of lay.placed) {
|
|
1028
|
+
const label = s.solids[p.i].label;
|
|
1029
|
+
if (label === undefined)
|
|
1030
|
+
continue;
|
|
1031
|
+
const c = spots.get(p.i) ?? labelAt(p, at, lay.s);
|
|
1032
|
+
tag(pen, c.x, c.y, label);
|
|
1033
|
+
}
|
|
1034
|
+
for (const pl of lay.panels)
|
|
1035
|
+
drawPanel(pen, lay, pl, s.shadows === true);
|
|
1036
|
+
return { width: lay.width, height: lay.height };
|
|
1037
|
+
},
|
|
1038
|
+
describe(scene) {
|
|
1039
|
+
const s = scene;
|
|
1040
|
+
const lay = layout(s);
|
|
1041
|
+
const towers = [...new Set(lay.placed.map((p) => p.tower))].map((t) => lay.placed.filter((p) => p.tower === t).sort((m, k) => m.z0 - k.z0));
|
|
1042
|
+
const said = towers.map((g) => g
|
|
1043
|
+
.map((p, k) => {
|
|
1044
|
+
const w = saySolid(s.solids[p.i], p);
|
|
1045
|
+
return k === 0 ? w : k === 1 ? ` with ${w} on top` : `, and ${w} on top of that`;
|
|
1046
|
+
})
|
|
1047
|
+
.join(""));
|
|
1048
|
+
const head = `On a table${said.length > 1 ? ", from left to right" : ""}: ${said.join("; ")}.`;
|
|
1049
|
+
const hidden = s.hidden ? " Hidden edges are drawn dashed." : "";
|
|
1050
|
+
const k = lay.panels.length;
|
|
1051
|
+
const panels = k
|
|
1052
|
+
? ` Below, ${k === 1 ? `one ${s.shadows ? "shadow" : "picture"}` : `${k} ${s.shadows ? "shadows" : "pictures"} in a row`}: ${lay.panels
|
|
1053
|
+
.map((pl) => sayPanel(pl, s.shadows === true))
|
|
1054
|
+
.join("; ")}.`
|
|
1055
|
+
: "";
|
|
1056
|
+
return `${head}${hidden}${panels}`;
|
|
1057
|
+
},
|
|
1058
|
+
};
|