@altnovatrail/picture-kit 0.1.0 → 0.2.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 (130) hide show
  1. package/README.md +2 -1
  2. package/lib/index.d.ts +45 -1
  3. package/lib/index.js +34 -3
  4. package/lib/kinds/balance.js +2 -3
  5. package/lib/kinds/calendar.d.ts +5 -1
  6. package/lib/kinds/calendar.js +33 -11
  7. package/lib/kinds/chart.js +2 -4
  8. package/lib/kinds/clock.d.ts +5 -0
  9. package/lib/kinds/clock.js +45 -4
  10. package/lib/kinds/coins.js +3 -2
  11. package/lib/kinds/column.js +2 -3
  12. package/lib/kinds/commands.d.ts +8 -6
  13. package/lib/kinds/commands.js +57 -15
  14. package/lib/kinds/containers.js +2 -1
  15. package/lib/kinds/countfig.d.ts +2 -0
  16. package/lib/kinds/countfig.js +6 -1
  17. package/lib/kinds/cubes.d.ts +29 -5
  18. package/lib/kinds/cubes.js +82 -34
  19. package/lib/kinds/die.d.ts +8 -0
  20. package/lib/kinds/die.js +75 -14
  21. package/lib/kinds/domino.js +3 -3
  22. package/lib/kinds/dotgrid.d.ts +3 -0
  23. package/lib/kinds/dotgrid.js +6 -4
  24. package/lib/kinds/figure.js +5 -4
  25. package/lib/kinds/fold-parts.d.ts +0 -2
  26. package/lib/kinds/fold-parts.js +0 -4
  27. package/lib/kinds/fold.d.ts +20 -1
  28. package/lib/kinds/fold.js +15 -6
  29. package/lib/kinds/fraction.js +3 -2
  30. package/lib/kinds/gauges.js +2 -1
  31. package/lib/kinds/gears.d.ts +21 -2
  32. package/lib/kinds/gears.js +113 -62
  33. package/lib/kinds/grid.d.ts +5 -0
  34. package/lib/kinds/grid.js +30 -2
  35. package/lib/kinds/groups.d.ts +3 -1
  36. package/lib/kinds/groups.js +142 -28
  37. package/lib/kinds/lanes.js +3 -2
  38. package/lib/kinds/layers.d.ts +6 -0
  39. package/lib/kinds/layers.js +23 -4
  40. package/lib/kinds/line.d.ts +4 -0
  41. package/lib/kinds/line.js +117 -32
  42. package/lib/kinds/matchsticks.d.ts +4 -0
  43. package/lib/kinds/matchsticks.js +5 -3
  44. package/lib/kinds/net.js +4 -3
  45. package/lib/kinds/overlay.d.ts +23 -1
  46. package/lib/kinds/overlay.js +7 -3
  47. package/lib/kinds/pieces.js +3 -2
  48. package/lib/kinds/plane-parts.d.ts +0 -2
  49. package/lib/kinds/plane-parts.js +0 -6
  50. package/lib/kinds/plane.js +6 -6
  51. package/lib/kinds/ropes.js +1 -3
  52. package/lib/kinds/shapes.js +5 -7
  53. package/lib/kinds/solids.js +3 -2
  54. package/lib/kinds/tangram.js +2 -4
  55. package/lib/kinds/target.js +4 -6
  56. package/lib/kinds/tiles.js +5 -4
  57. package/lib/kinds/venn.js +3 -5
  58. package/lib/noto.js +1 -0
  59. package/lib/objects.js +2 -1
  60. package/lib/read.d.ts +2 -2
  61. package/lib/read.js +3 -3
  62. package/lib/solve/balance.d.ts +11 -0
  63. package/lib/solve/balance.js +116 -1
  64. package/lib/solve/calendar.d.ts +46 -0
  65. package/lib/solve/calendar.js +206 -0
  66. package/lib/solve/choice-scenes.d.ts +20 -0
  67. package/lib/solve/choice-scenes.js +51 -0
  68. package/lib/solve/clock.d.ts +54 -0
  69. package/lib/solve/clock.js +240 -0
  70. package/lib/solve/coins.d.ts +71 -0
  71. package/lib/solve/coins.js +222 -0
  72. package/lib/solve/commands.d.ts +36 -0
  73. package/lib/solve/commands.js +210 -0
  74. package/lib/solve/countfig.d.ts +41 -0
  75. package/lib/solve/countfig.js +199 -0
  76. package/lib/solve/cubes.d.ts +49 -0
  77. package/lib/solve/cubes.js +255 -0
  78. package/lib/solve/die.d.ts +39 -0
  79. package/lib/solve/die.js +93 -0
  80. package/lib/solve/domino.d.ts +57 -0
  81. package/lib/solve/domino.js +263 -0
  82. package/lib/solve/enumerate.d.ts +75 -0
  83. package/lib/solve/enumerate.js +323 -0
  84. package/lib/solve/figure.d.ts +26 -0
  85. package/lib/solve/figure.js +88 -0
  86. package/lib/solve/fold.d.ts +22 -0
  87. package/lib/solve/fold.js +68 -0
  88. package/lib/solve/gaps.d.ts +65 -0
  89. package/lib/solve/gaps.js +292 -0
  90. package/lib/solve/gears.d.ts +33 -0
  91. package/lib/solve/gears.js +130 -0
  92. package/lib/solve/grid.d.ts +35 -0
  93. package/lib/solve/grid.js +194 -0
  94. package/lib/solve/groups.d.ts +93 -0
  95. package/lib/solve/groups.js +346 -0
  96. package/lib/solve/index.d.ts +60 -0
  97. package/lib/solve/index.js +194 -0
  98. package/lib/solve/layers.d.ts +30 -0
  99. package/lib/solve/layers.js +72 -0
  100. package/lib/solve/magic.d.ts +32 -0
  101. package/lib/solve/magic.js +216 -0
  102. package/lib/solve/matchsticks.d.ts +37 -0
  103. package/lib/solve/matchsticks.js +214 -0
  104. package/lib/solve/order.d.ts +94 -0
  105. package/lib/solve/order.js +419 -0
  106. package/lib/solve/overlay.d.ts +22 -0
  107. package/lib/solve/overlay.js +56 -0
  108. package/lib/solve/parity.d.ts +22 -0
  109. package/lib/solve/parity.js +27 -0
  110. package/lib/solve/pattern.d.ts +62 -0
  111. package/lib/solve/pattern.js +533 -0
  112. package/lib/solve/pieces.d.ts +57 -0
  113. package/lib/solve/pieces.js +309 -0
  114. package/lib/solve/pigeonhole.d.ts +38 -0
  115. package/lib/solve/pigeonhole.js +95 -0
  116. package/lib/solve/proof.d.ts +115 -0
  117. package/lib/solve/proof.js +105 -0
  118. package/lib/solve/pyramid.d.ts +28 -0
  119. package/lib/solve/pyramid.js +161 -0
  120. package/lib/solve/question.d.ts +25 -0
  121. package/lib/solve/question.js +75 -0
  122. package/lib/solve/shapes.d.ts +30 -0
  123. package/lib/solve/shapes.js +182 -0
  124. package/lib/solve/target.d.ts +40 -0
  125. package/lib/solve/target.js +190 -0
  126. package/lib/style.d.ts +1 -1
  127. package/lib/style.js +1 -1
  128. package/lib/words.d.ts +15 -0
  129. package/lib/words.js +39 -0
  130. package/package.json +1 -1
package/lib/kinds/die.js CHANGED
@@ -5,6 +5,9 @@ import { colors, ink, outline } from "../style.js";
5
5
  import { n } from "../svg.js";
6
6
  import { box, cornersOf, onFace, projector } from "./cubes.js";
7
7
  const shown = ["top", "front", "right"];
8
+ export const turnings = [0, 90];
9
+ /** The values whose pips look different turned a quarter turn. */
10
+ const turnable = [2, 3, 6];
8
11
  const biggest = 62;
9
12
  const room = 640 - 2 * margin;
10
13
  const across = Math.cos(Math.PI / 6);
@@ -101,7 +104,7 @@ function shows(l, view) {
101
104
  return corners.some((corner) => [0, 1, 2].some((turn) => want.every((w, k) => w === "?" || w === l[corner[(k + turn) % 3]])));
102
105
  }
103
106
  /** drawFlat draws one face of a die, flat, its top left at x, y, size across. */
104
- function drawFlat(pen, value, x, y, size) {
107
+ function drawFlat(pen, value, turn, x, y, size) {
105
108
  pen.el("rect", {
106
109
  x,
107
110
  y,
@@ -113,18 +116,20 @@ function drawFlat(pen, value, x, y, size) {
113
116
  "stroke-width": outline,
114
117
  });
115
118
  const sub = pen.sub();
116
- facePrint(sub, value);
119
+ facePrint(sub, value, turn);
117
120
  const k = size / box;
118
121
  pen.add(`<g transform="translate(${n(x)} ${n(y)}) scale(${k.toFixed(4)})">${sub.markup()}</g>`);
119
122
  }
120
- /** facePrint draws the pips of a value, or a "?", on a box × box face. */
121
- function facePrint(pen, value) {
123
+ /** facePrint draws the pips of a value, or a "?", on a box × box face, turned 90 a quarter turn clockwise. */
124
+ function facePrint(pen, value, turn = 0) {
122
125
  if (value === "?") {
123
126
  pen.text(box / 2, box / 2, "?", { size: 40 });
124
127
  return;
125
128
  }
126
- for (const [x, y] of pips[value])
127
- pen.el("circle", { cx: x, cy: y, r: spot, fill: ink });
129
+ for (const [x, y] of pips[value]) {
130
+ const [cx, cy] = turn === 90 ? [box - y, x] : [x, y];
131
+ pen.el("circle", { cx, cy, r: spot, fill: ink });
132
+ }
128
133
  }
129
134
  /** rounded is the outline of a polygon whose corners are rounded r pixels back. */
130
135
  function rounded(points, r) {
@@ -178,7 +183,7 @@ function drawView(pen, view, x, y, s) {
178
183
  "stroke-linejoin": "round",
179
184
  });
180
185
  const sub = pen.sub();
181
- facePrint(sub, view[face]);
186
+ facePrint(sub, view[face], view.turns?.[face]);
182
187
  pen.add(`<g transform="${onFace(corners_)}">${sub.markup()}</g>`);
183
188
  }
184
189
  }
@@ -187,7 +192,53 @@ function sizeOf(dice, arrows) {
187
192
  const units = dice.reduce((sum, d) => sum + (isView(d) ? 2 * across : 1.15), 0);
188
193
  return Math.min(biggest, (room - gap * (dice.length - 1)) / units);
189
194
  }
190
- const say = (v) => (v === "?" ? "a question mark" : `${v} pip${v === 1 ? "" : "s"}`);
195
+ function checkTurn(turn, value, path, problems) {
196
+ if (!turnings.includes(turn))
197
+ problems.push(`${path}: must be 0 or 90, a quarter turn clockwise`);
198
+ else if (!turnable.includes(value))
199
+ problems.push(value === "?"
200
+ ? `${path}: a question mark has no pips to turn`
201
+ : `${path}: only the pips of 2, 3 and 6 lie one way or another; ${value === 1 ? "1 pip looks" : `${String(value)} pips look`} the same turned`);
202
+ }
203
+ const say = (v) => (v === "?" ? "a question mark" : `${v} dot${v === 1 ? "" : "s"}`);
204
+ // Where the pips of 2, 3 and 6 lie, on a face seen square on and on the top
205
+ // of a die, whose corner nearest the eye is its front-right one.
206
+ const lie = {
207
+ flat: {
208
+ 0: {
209
+ line: "from the top-left corner to the bottom-right corner",
210
+ rows: "in two columns of three",
211
+ },
212
+ 90: {
213
+ line: "from the top-right corner to the bottom-left corner",
214
+ rows: "in two rows of three",
215
+ },
216
+ },
217
+ top: {
218
+ 0: {
219
+ line: "from the back-left corner to the front-right corner",
220
+ rows: "in two lines of three from back to front",
221
+ },
222
+ 90: {
223
+ line: "from the back-right corner to the front-left corner",
224
+ rows: "in two lines of three from left to right",
225
+ },
226
+ },
227
+ };
228
+ /** lies says how the pips of a face lie, when the scene gives their turn: ", in two rows of three". */
229
+ function lies(v, turn, on) {
230
+ if (turn === undefined)
231
+ return "";
232
+ const how = lie[on][turn];
233
+ return `, ${v === 6 ? how.rows : `in a line ${how.line}`}`;
234
+ }
235
+ /** sayView says the three faces of a view, each with how its pips lie when it is turned. */
236
+ function sayView(d) {
237
+ if (d.turns === undefined)
238
+ return `${say(d.top)} on top, ${say(d.front)} on the front and ${say(d.right)} on the right`;
239
+ const t = d.turns;
240
+ return `${say(d.top)} on top${lies(d.top, t.top, "top")}; ${say(d.front)} on the front${lies(d.front, t.front, "flat")}; and ${say(d.right)} on the right${lies(d.right, t.right, "flat")}`;
241
+ }
191
242
  export const die = {
192
243
  kind: "die",
193
244
  members: ["kind", "dice", "standard", "same", "arrows"],
@@ -206,13 +257,25 @@ export const die = {
206
257
  if (d.label !== undefined)
207
258
  text(d.label, `${path}.label`, problems, 10);
208
259
  if ("face" in d) {
209
- only(d, ["face", "label"], path, problems);
260
+ only(d, ["face", "label", "turn"], path, problems);
210
261
  checkValue(d.face, `${path}.face`, problems);
262
+ if (d.turn !== undefined)
263
+ checkTurn(d.turn, d.face, `${path}.turn`, problems);
211
264
  return;
212
265
  }
213
- only(d, ["top", "front", "right", "label"], path, problems);
266
+ only(d, ["top", "front", "right", "label", "turns"], path, problems);
214
267
  for (const f of shown)
215
268
  checkValue(d[f], `${path}.${f}`, problems);
269
+ if (d.turns === undefined)
270
+ return;
271
+ if (!isObj(d.turns)) {
272
+ problems.push(`${path}.turns: must give a turn, 0 or 90, for any of top, front and right`);
273
+ return;
274
+ }
275
+ only(d.turns, shown, `${path}.turns`, problems);
276
+ for (const f of shown)
277
+ if (d.turns[f] !== undefined)
278
+ checkTurn(d.turns[f], d[f], `${path}.turns.${f}`, problems);
216
279
  });
217
280
  if (problems.length > 0)
218
281
  return;
@@ -257,7 +320,7 @@ export const die = {
257
320
  if (isView(d))
258
321
  drawView(pen, d, left, margin, s);
259
322
  else
260
- drawFlat(pen, d.face, left, margin + (high - w) / 2, w);
323
+ drawFlat(pen, d.face, d.turn ?? 0, left, margin + (high - w) / 2, w);
261
324
  if (d.label)
262
325
  pen.text(x + bw / 2, margin + high + 22, d.label, { size: 18 });
263
326
  x += bw;
@@ -284,9 +347,7 @@ export const die = {
284
347
  },
285
348
  describe(scene) {
286
349
  const typed = scene;
287
- const one = (d) => isView(d)
288
- ? `${say(d.top)} on top, ${say(d.front)} on the front and ${say(d.right)} on the right`
289
- : `one face, flat, with ${say(d.face)}`;
350
+ const one = (d) => isView(d) ? sayView(d) : `one face, flat, with ${say(d.face)}${lies(d.face, d.turn, "flat")}`;
290
351
  const notes = [
291
352
  typed.standard ? "Every die is a standard die: opposite faces add up to 7." : "",
292
353
  typed.same && typed.dice.length > 1 ? "All the pictures show one and the same die." : "",
@@ -245,8 +245,8 @@ function drawTile(pen, halves, x, y, h, upright, face, inset) {
245
245
  drawPips(pen, half, hx, hy, h, upright, ink_);
246
246
  });
247
247
  }
248
- const sayPips = (v) => v === "?" ? "a question mark" : v === "cloud" ? "a cloud" : v === 0 ? "blank" : plural(v, "pip");
249
- /** sayTile says a tile's halves: "3 pips on the top half and the bottom half hidden under a cloud". */
248
+ const sayDots = (v) => v === "?" ? "a question mark" : v === "cloud" ? "a cloud" : v === 0 ? "blank" : plural(v, "dot");
249
+ /** sayTile says a tile's halves: "3 dots on the top half and the bottom half hidden under a cloud". */
250
250
  function sayTile(halves, upright) {
251
251
  const sides = upright ? ["top", "bottom"] : ["left", "right"];
252
252
  return halves
@@ -254,7 +254,7 @@ function sayTile(halves, upright) {
254
254
  ? `the ${sides[i]} half hidden under a cloud`
255
255
  : v === 0
256
256
  ? `the ${sides[i]} half blank`
257
- : `${sayPips(v)} on the ${sides[i]} half`)
257
+ : `${sayDots(v)} on the ${sides[i]} half`)
258
258
  .join(" and ");
259
259
  }
260
260
  /** noteOf says how to read the values of a ring or a grid that holds a cloud or a 0, if it does. */
@@ -1,5 +1,6 @@
1
1
  import type { Kind } from "../kind.ts";
2
2
  import { type ColorName } from "../style.ts";
3
+ import { type P } from "../svg.ts";
3
4
  /**
4
5
  * Dotgrid: dot paper, squared paper or a geoboard — points in a square or a
5
6
  * triangular lattice — with shapes whose corners are points of it: shaded
@@ -33,6 +34,8 @@ export type DotgridScene = {
33
34
  areas: number[];
34
35
  };
35
36
  };
37
+ /** cornersOf are the places of the corners of a shape, in steps between neighbouring points. */
38
+ export declare const cornersOf: (d: DotgridScene, s: DotShape) => P[];
36
39
  /** areaOf is the area of a shape: unit squares on a square lattice, small triangles on a triangular one. */
37
40
  export declare function areaOf(d: DotgridScene, s: DotShape): number;
38
41
  export declare const dotgrid: Kind;
@@ -3,7 +3,8 @@ import { textWidth } from "../pen.js";
3
3
  import { int, isObj, list, oneOf, only, text } from "../read.js";
4
4
  import { colorNames, colors, faint, ink, isColor, outline, soft, textOn, } from "../style.js";
5
5
  import { poly } from "../svg.js";
6
- import { area, boxAt, boxToSegment, capital, centroid, crossing, decimal, distance, edgesOf, inside, listOf, meet, ordinal, overlap, pointOf, say, toBox, toLine, toSegment, } from "./plane-parts.js";
6
+ import { article, listOf } from "../words.js";
7
+ import { area, boxAt, boxToSegment, capital, centroid, crossing, decimal, distance, edgesOf, inside, meet, ordinal, overlap, pointOf, say, toBox, toLine, toSegment, } from "./plane-parts.js";
7
8
  /**
8
9
  * Dotgrid: dot paper, squared paper or a geoboard — points in a square or a
9
10
  * triangular lattice — with shapes whose corners are points of it: shaded
@@ -35,7 +36,8 @@ function spot(d, x, y) {
35
36
  return { x, y };
36
37
  return { x: x + (y % 2 === 1 ? 0.5 : 0), y: y * tall };
37
38
  }
38
- const cornersOf = (d, s) => s.corners.map(([x, y]) => spot(d, x, y));
39
+ /** cornersOf are the places of the corners of a shape, in steps between neighbouring points. */
40
+ export const cornersOf = (d, s) => s.corners.map(([x, y]) => spot(d, x, y));
39
41
  /** areaOf is the area of a shape: unit squares on a square lattice, small triangles on a triangular one. */
40
42
  export function areaOf(d, s) {
41
43
  const a = area(cornersOf(d, s));
@@ -397,8 +399,8 @@ export const dotgrid = {
397
399
  const band = (s.style ?? "fill") === "band";
398
400
  const how = band
399
401
  ? look === "board"
400
- ? `a ${colors[s.color].word} rubber band stretched round`
401
- : `a ${colors[s.color].word} outline, not shaded, with corners at`
402
+ ? `${article(colors[s.color].word)} rubber band stretched round`
403
+ : `${article(colors[s.color].word)} outline, not shaded, with corners at`
402
404
  : `shaded ${colors[s.color].word}, with corners at`;
403
405
  out.push(`${name}${s.label ? " (the letter stands inside it)" : ""}: ${how} ${s.corners.length} ${point}s, in order round it: ${listOf(s.corners.map(sayPoint))}.`);
404
406
  });
@@ -3,6 +3,7 @@ import { isObj, list, oneOf, only, text } from "../read.js";
3
3
  import { colorNames, colors, ink, isColor, outline } from "../style.js";
4
4
  import { n, poly } from "../svg.js";
5
5
  import { checkThing, drawThing, wordOf } from "../things.js";
6
+ import { article } from "../words.js";
6
7
  /**
7
8
  * Figure: a square or round card with a pattern — its face cut into parts of
8
9
  * colours, and marks on it: dots, things, arrows, letters — and what the card
@@ -502,13 +503,13 @@ const placeWords = (at) => (at === "centre" ? "in the centre" : `at the ${at}`);
502
503
  const directions = ["up", "right", "down", "left"];
503
504
  function markWords(mark) {
504
505
  if ("dot" in mark)
505
- return `a ${colors[mark.dot].word} dot ${placeWords(mark.at)}`;
506
+ return `${article(colors[mark.dot].word)} dot ${placeWords(mark.at)}`;
506
507
  if ("arrow" in mark)
507
- return `a ${colors[mark.arrow].word} arrow ${placeWords(mark.at)} pointing ${directions[(mark.turn ?? 0) / 90]}`;
508
+ return `${article(colors[mark.arrow].word)} arrow ${placeWords(mark.at)} pointing ${directions[(mark.turn ?? 0) / 90]}`;
508
509
  if ("letter" in mark)
509
510
  return `the ${mark.color ? `${colors[mark.color].word} ` : ""}letter ${mark.letter} ${placeWords(mark.at)}${lookWords(mark)}`;
510
511
  const word = wordOf(mark.thing);
511
- return `${/^[aeiou]/.test(word) ? "an" : "a"} ${word} ${placeWords(mark.at)}${lookWords(mark)}`;
512
+ return `${article(word)} ${placeWords(mark.at)}${lookWords(mark)}`;
512
513
  }
513
514
  /** sayCard says a card in words. */
514
515
  export function sayCard(card) {
@@ -516,7 +517,7 @@ export function sayCard(card) {
516
517
  const shape = card.shape === "square" ? "square card" : "round card";
517
518
  let words;
518
519
  if (cut === "none")
519
- words = `a ${colors[card.colors[0]].word} ${shape}`;
520
+ words = article(`${colors[card.colors[0]].word} ${shape}`);
520
521
  else {
521
522
  const named = pieces[cut]
522
523
  .map((piece, i) => `the ${piece.name} is ${colors[card.colors[i]].word}`)
@@ -69,5 +69,3 @@ export declare function turnOf(m: Mat, from: number): number;
69
69
  export declare function turnMat(turn: number): Mat;
70
70
  /** linear is a map without its shift; transposed, an orthogonal one is undone. */
71
71
  export declare function transposed(m: Mat): Mat;
72
- /** article puts "a" or "an" before words. */
73
- export declare function article(words: string): string;
@@ -309,7 +309,3 @@ export function turnMat(turn) {
309
309
  export function transposed(m) {
310
310
  return [m[0], m[2], m[1], m[3], 0, 0];
311
311
  }
312
- /** article puts "a" or "an" before words. */
313
- export function article(words) {
314
- return `${/^[aeiou]/.test(words) ? "an" : "a"} ${words}`;
315
- }
@@ -1,6 +1,6 @@
1
1
  import type { Kind } from "../kind.ts";
2
2
  import { type ColorName } from "../style.ts";
3
- import { type Part } from "./fold-parts.ts";
3
+ import { type Atom, type Part } from "./fold-parts.ts";
4
4
  /**
5
5
  * Fold: a sheet of paper, a rectangle of squares, folded in half one to three
6
6
  * times, then punched with holes or cut, drawn as steps in a row: the sheet
@@ -49,4 +49,23 @@ export type FoldScene = {
49
49
  cuts?: Cut[];
50
50
  show?: Show;
51
51
  };
52
+ /**
53
+ * Image is a hole as it lies on the sheet laid open: its square, from 0 at the top left, its shape,
54
+ * and its turn, 0 for a shape that looks the same turned.
55
+ */
56
+ export type Image = {
57
+ r: number;
58
+ c: number;
59
+ shape: HoleShape;
60
+ turn: number;
61
+ };
62
+ /**
63
+ * unfold works out the sheet of a checked scene laid open, as the kind draws and words it: the
64
+ * atoms of the sheet that stay, the parts cut away gone, and every image of every hole, in the
65
+ * order of their squares. An open sheet, with no folds, is itself.
66
+ */
67
+ export declare function unfold(scene: FoldScene): {
68
+ atoms: Atom[];
69
+ holes: Image[];
70
+ };
52
71
  export declare const fold: Kind;
package/lib/kinds/fold.js CHANGED
@@ -3,7 +3,8 @@ import { int, isObj, list, oneOf, only } from "../read.js";
3
3
  import { colorNames, colors, ink, isColor, outline } from "../style.js";
4
4
  import { n, poly } from "../svg.js";
5
5
  import { shapePath } from "../things.js";
6
- import { andThen, article, atomsOf, boxOf, centreOf, identity, innerLines, key, loopsOf, mapAtom, partQuarters, parts, partWords, pieceCount, sheetAtoms, transposed, turnMat, turnOf, ways, } from "./fold-parts.js";
6
+ import { article, listOf } from "../words.js";
7
+ import { andThen, atomsOf, boxOf, centreOf, identity, innerLines, key, loopsOf, mapAtom, partQuarters, parts, partWords, pieceCount, sheetAtoms, transposed, turnMat, turnOf, ways, } from "./fold-parts.js";
7
8
  /**
8
9
  * Fold: a sheet of paper, a rectangle of squares, folded in half one to three
9
10
  * times, then punched with holes or cut, drawn as steps in a row: the sheet
@@ -151,8 +152,16 @@ function originOf(final) {
151
152
  const c = Math.floor(box.x0);
152
153
  return { r, c, rows: Math.ceil(box.y1) - r, cols: Math.ceil(box.x1) - c };
153
154
  }
154
- /** unfold works out the flat sheet: the atoms that stay, and every image of every hole. */
155
- function unfold(scene, folded) {
155
+ /**
156
+ * unfold works out the sheet of a checked scene laid open, as the kind draws and words it: the
157
+ * atoms of the sheet that stay, the parts cut away gone, and every image of every hole, in the
158
+ * order of their squares. An open sheet, with no folds, is itself.
159
+ */
160
+ export function unfold(scene) {
161
+ return laidOpen(scene, foldSheet(scene.sheet, scene.folds ?? []));
162
+ }
163
+ /** laidOpen is unfold of a sheet already folded. */
164
+ function laidOpen(scene, folded) {
156
165
  const o = originOf(folded.final);
157
166
  const cut = new Set();
158
167
  for (const c of scene.cuts ?? [])
@@ -488,7 +497,7 @@ function sayPlace(r, c) {
488
497
  }
489
498
  /** flatWords says the sheet unfolded: its holes, the parts cut away, the pieces it falls into. */
490
499
  function flatWords(scene, folded) {
491
- const { atoms, holes } = unfold(scene, folded);
500
+ const { atoms, holes } = laidOpen(scene, folded);
492
501
  const out = [];
493
502
  const groups = new Map();
494
503
  for (const h of holes) {
@@ -512,7 +521,7 @@ function flatWords(scene, folded) {
512
521
  const part = Object.keys(partQuarters).find((p) => partQuarters[p].length === qs.length && partQuarters[p].every((q) => qs.includes(q)));
513
522
  gone.push(part
514
523
  ? partWords(part, r + 1, c + 1)
515
- : `the ${qs.map((q) => ["top", "right", "bottom", "left"][q]).join(", ")} quarters of the square at ${sayPlace(r + 1, c + 1)}`);
524
+ : `the ${listOf(qs.map((q) => ["top", "right", "bottom", "left"][q]))} quarters of the square at ${sayPlace(r + 1, c + 1)}`);
516
525
  }
517
526
  if (gone.length > 0)
518
527
  out.push(`with cut away: ${gone.join("; ")}`);
@@ -584,7 +593,7 @@ export const fold = {
584
593
  }
585
594
  }
586
595
  else if (frame.what === "flat") {
587
- const { atoms, holes } = unfold(typed, folded);
596
+ const { atoms, holes } = laidOpen(typed, folded);
588
597
  drawPaper(pen, atoms, at, typed);
589
598
  for (const h of holes) {
590
599
  const c = at({ x: h.c + 0.5, y: h.r + 0.5 });
@@ -2,6 +2,7 @@ import { margin } from "../kind.js";
2
2
  import { int, isObj, list, oneOf, only, text } from "../read.js";
3
3
  import { colorNames, colors, ink, isColor, outline } from "../style.js";
4
4
  import { n, poly } from "../svg.js";
5
+ import { article } from "../words.js";
5
6
  import { capital, runs } from "./plane-parts.js";
6
7
  /**
7
8
  * Fraction: shapes cut into parts, some of them coloured — a circle cut from
@@ -283,12 +284,12 @@ function checkCut(cut, sizes, parts, path, problems, depth) {
283
284
  const k = triangles[cut];
284
285
  const items = list(parts, `${path}.parts`, problems, 0);
285
286
  if (Array.isArray(parts) && items.length !== k)
286
- problems.push(`${path}.parts: a ${cut} cut makes ${k} triangles; give a colour for each`);
287
+ problems.push(`${path}.parts: ${article(cut)} cut makes ${k} triangles; give a colour for each`);
287
288
  items.forEach((c, i) => {
288
289
  checkPart(c, `${path}.parts[${i}]`, problems, depth, true);
289
290
  });
290
291
  if (sizes !== undefined)
291
- problems.push(`${path}.sizes: a ${cut} cut has no sizes; its triangles are what they are`);
292
+ problems.push(`${path}.sizes: ${article(cut)} cut has no sizes; its triangles are what they are`);
292
293
  }
293
294
  const cutWords = {
294
295
  diagonal: {
@@ -4,7 +4,8 @@ import { isObj, list, oneOf, only, text } from "../read.js";
4
4
  import { colorNames, colors, ink, isColor, outline, soft } from "../style.js";
5
5
  import { n, poly } from "../svg.js";
6
6
  import { checkThing, count, drawThing } from "../things.js";
7
- import { article, mix } from "./cubes.js";
7
+ import { article } from "../words.js";
8
+ import { mix } from "./cubes.js";
8
9
  /**
9
10
  * Gauges: measuring instruments, one to five of one sort side by side — a
10
11
  * ruler, whole or a broken piece of one, with things laid along it; a
@@ -6,9 +6,11 @@ import { type ColorName } from "../style.ts";
6
6
  * gear set beside a gear with no gap meshes with it: the program puts it
7
7
  * exactly where the teeth of the two fit, and draws every tooth. Some gears
8
8
  * carry an arrow of the way they turn, and one may carry a "?". The check
9
- * refuses wheels that overlap without meshing, a ring of wheels that locks,
9
+ * refuses wheels that overlap without meshing, teeth that miss each other,
10
10
  * arrows that disagree with the gears, and belts that run over a wheel or
11
- * another belt.
11
+ * another belt. A ring of wheels that locks — an odd number of meshes and
12
+ * crossed belts round it — is drawn as it stands, so that a task asks whether
13
+ * the wheels can turn: its train shows one arrow at most, the way it is pushed.
12
14
  */
13
15
  export declare const directions: readonly ["up", "up-right", "right", "down-right", "down", "down-left", "left", "up-left"];
14
16
  export type Direction = (typeof directions)[number];
@@ -37,4 +39,21 @@ export type GearsScene = {
37
39
  gears: Wheel[];
38
40
  belts?: Belt[];
39
41
  };
42
+ /**
43
+ * Trains is how the wheels of a scene are joined, by meshes and belts, each by its index in gears:
44
+ * root, the first wheel of each wheel's train; side, 0 or 1, whether a wheel turns the way the
45
+ * first of its train does or the other way; and locked, the first wheels of the trains with a ring
46
+ * that locks, which no way of turning agrees with.
47
+ */
48
+ export type Trains = {
49
+ root: number[];
50
+ side: number[];
51
+ locked: ReadonlySet<number>;
52
+ };
53
+ /**
54
+ * trains gives how the wheels of a checked scene are joined, by the meshes the kind lays out and
55
+ * draws: a gear set beside a gear meshes with it, and so does one that meets another on its pitch
56
+ * circle where the layout puts them.
57
+ */
58
+ export declare function trains(scene: GearsScene): Trains;
40
59
  export declare const gears: Kind;