cageOutline関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
THE DASHED OUTLINE OF EVERY CAGE, as line segments in cell units: each cage drawn a little inside its own edge, the way a printed Killer Sudoku draws it, so a cage reads as a shape within the box rules rather than as one of them.
Each cell draws the sides where its neighbour is in another cage, inset inside the cell. Where
the cage goes on past a side's end, the line runs on to meet the next line of the outline: to the
cell's edge when the cage's edge carries on straight, and inset past it at an inside corner,
where the outline turns back into the cage. That is what makes the lines of one cage meet, with
no gap and no overshoot, whatever its shape.
インポート
import { cageOutline } from "@johnmorrisdotca/kazu";
定義
function cageOutline(size: number, cageOf: (index: number) => number | undefined, inset?: number): Segment[]
引数
| 名前 | 型 | 説明 |
|---|---|---|
size | number | The supported square grid side length. |
cageOf | (index: number) => number | undefined | Map a cell index to its containing cage number, or undefined for none. |
inset (省略可) | number | The outline inset in drawing units. |
戻り値
Segment[]
THE DASHED OUTLINE OF EVERY CAGE, as line segments in cell units: each cage drawn a little inside its own edge, the way a printed Killer Sudoku draws it, so a cage reads as a shape within the box rules rather than as one of them.
例
import type { KazuPuzzle } from "@johnmorrisdotca/kazu";
import { cageOutline, decodeKiller, readGivens } from "@johnmorrisdotca/kazu";
const puzzle: KazuPuzzle = {"kind":"number-place","size":4,"level":"easy","seed":42,"givens":"14..2..1412.3..4","solution":"1432234141233214"};
const kind = puzzle.kind;
const size = puzzle.size;
const givens = puzzle.givens;
const printed = readGivens(kind,size,givens)!;
const cells = printed.cells;
const killer = decodeKiller("2.....3..2................2...4.....012333412567882967aaa9bbccd9ebfgggee02050c0d03020309080e0c0a06020b040a",6)!;
console.log(cageOutline(6,index=>killer.cages.findIndex(cage=>cage.cells.includes(index))));[
{ x1: 0.12, y1: 0.12, x2: 0.88, y2: 0.12 },
{ x1: 0.12, y1: 0.88, x2: 0.88, y2: 0.88 },
{ x1: 0.12, y1: 0.12, x2: 0.12, y2: 0.88 },
{ x1: 0.88, y1: 0.12, x2: 0.88, y2: 0.88 },
{ x1: 1.12, y1: 0.12, x2: 1.88, y2: 0.12 },
{ x1: 1.12, y1: 0.12, x2: 1.12, y2: 1 },
{ x1: 1.88, y1: 0.12, x2: 1.88, y2: 1 },
{ x1: 2.12, y1: 0.12, x2: 2.88, y2: 0.12 },
{ x1: 2.12, y1: 0.12, x2: 2.12, y2: 1 },
{ x1: 2.88, y1: 0.12, x2: 2.88, y2: 1 },
{ x1: 3.12, y1: 0.12, x2: 4, y2: 0.12 },
{ x1: 3.12, y1: 0.88, x2: 4, y2: 0.88 },
{ x1: 3.12, y1: 0.12, x2: 3.12, y2: 0.88 },
{ x1: 4, y1: 0.12, x2: 5, y2: 0.12 },
{ x1: 4, y1: 0.88, x2: 5, y2: 0.88 },
{ x1: 5, y1: 0.12, x2: 5.88, y2: 0.12 },
{ x1: 5, y1: 0.88, x2: 5.88, y2: 0.88 },
{ x1: 5.88, y1: 0.12, x2: 5.88, y2: 0.88 },
{ x1: 0.12, y1: 1.12, x2: 0.88, y2: 1.12 },
{ x1: 0.12, y1: 1.88, x2: 0.88, y2: 1.88 },
{ x1: 0.12, y1: 1.12, x2: 0.12, y2: 1.88 },
{ x1: 0.88, y1: 1.12, x2: 0.88, y2: 1.88 },
{ x1: 1.12, y1: 1.88, x2: 1.88, y2: 1.88 },
{ x1: 1.12, y1: 1, x2: 1.12, y2: 1.88 },
{ x1: 1.88, y1: 1, x2: 1.88, y2: 1.88 },
{ x1: 2.12, y1: 1, x2: 2.12, y2: 2 },
{ x1: 2.88, y1: 1, x2: 2.88, y2: 2 },
{ x1: 3.12, y1: 1.12, x2: 3.88, y2: 1.12 },
{ x1: 3.12, y1: 1.88, x2: 3.88, y2: 1.88 },
{ x1: 3.12, y1: 1.12, x2: 3.12, y2: 1.88 },
{ x1: 3.88, y1: 1.12, x2: 3.88, y2: 1.88 },
{ x1: 4.12, y1: 1.12, x2: 4.88, y2: 1.12 },
{ x1: 4.12, y1: 1.12, x2: 4.12, y2: 2 },
{ x1: 4.88, y1: 1.12, x2: 4.88, y2: 2 },
{ x1: 5.12, y1: 1.12, x2: 5.88, y2: 1.12 },
{ x1: 5.12, y1: 1.12, x2: 5.12, y2: 2 },
{ x1: 5.88, y1: 1.12, x2: 5.88, y2: 2 },
{ x1: 0.12, y1: 2.12, x2: 1, y2: 2.12 },
{ x1: 0.12, y1: 2.88, x2: 1, y2: 2.88 },
{ x1: 0.12, y1: 2.12, x2: 0.12, y2: 2.88 },
{ x1: 1, y1: 2.12, x2: 1.88, y2: 2.12 },
{ x1: 1, y1: 2.88, x2: 1.88, y2: 2.88 },
{ x1: 1.88, y1: 2.12, x2: 1.88, y2: 2.88 },
{ x1: 2.12, y1: 2.88, x2: 2.88, y2: 2.88 },
{ x1: 2.12, y1: 2, x2: 2.12, y2: 2.88 },
{ x1: 2.88, y1: 2, x2: 2.88, y2: 2.88 },
{ x1: 3.12, y1: 2.12, x2: 3.88, y2: 2.12 },
{ x1: 3.12, y1: 2.12, x2: 3.12, y2: 3 },
{ x1: 3.88, y1: 2.12, x2: 3.88, y2: 3 },
{ x1: 4.12, y1: 2.88, x2: 4.88, y2: 2.88 },
{ x1: 4.12, y1: 2, x2: 4.12, y2: 2.88 },
{ x1: 4.88, y1: 2, x2: 4.88, y2: 2.88 },
{ x1: 5.12, y1: 2.88, x2: 5.88, y2: 2.88 },
{ x1: 5.12, y1: 2, x2: 5.12, y2: 2.88 },
{ x1: 5.88, y1: 2, x2: 5.88, y2: 2.88 },
{ x1: 0.12, y1: 3.12, x2: 1, y2: 3.12 },
{ x1: 0.12, y1: 3.88, x2: 1, y2: 3.88 },
{ x1: 0.12, y1: 3.12, x2: 0.12, y2: 3.88 },
{ x1: 1, y1: 3.12, x2: 2, y2: 3.12 },
{ x1: 1, y1: 3.88, x2: 2, y2: 3.88 },
{ x1: 2, y1: 3.12, x2: 2.88, y2: 3.12 },
{ x1: 2, y1: 3.88, x2: 2.88, y2: 3.88 },
{ x1: 2.88, y1: 3.12, x2: 2.88, y2: 3.88 },
{ x1: 3.12, y1: 3, x2: 3.12, y2: 4 },
{ x1: 3.88, y1: 3, x2: 3.88, y2: 4 },
{ x1: 4.12, y1: 3.12, x2: 5, y2: 3.12 },
{ x1: 4.12, y1: 3.88, x2: 5.12, y2: 3.88 },
{ x1: 4.12, y1: 3.12, x2: 4.12, y2: 3.88 },
{ x1: 5, y1: 3.12, x2: 5.88, y2: 3.12 },
{ x1: 5.88, y1: 3.12, x2: 5.88, y2: 4 },
{ x1: 0.12, y1: 4.12, x2: 1, y2: 4.12 },
{ x1: 0.12, y1: 4.88, x2: 1, y2: 4.88 },
{ x1: 0.12, y1: 4.12, x2: 0.12, y2: 4.88 },
{ x1: 1, y1: 4.12, x2: 1.88, y2: 4.12 },
{ x1: 1, y1: 4.88, x2: 1.88, y2: 4.88 },
{ x1: 1.88, y1: 4.12, x2: 1.88, y2: 4.88 },
{ x1: 2.12, y1: 4.12, x2: 2.88, y2: 4.12 },
{ x1: 2.12, y1: 4.88, x2: 2.88, y2: 4.88 },
{ x1: 2.12, y1: 4.12, x2: 2.12, y2: 4.88 },
{ x1: 2.88, y1: 4.12, x2: 2.88, y2: 4.88 },
{ x1: 3.12, y1: 4.88, x2: 3.88, y2: 4.88 },
{ x1: 3.12, y1: 4, x2: 3.12, y2: 4.88 },
{ x1: 3.88, y1: 4, x2: 3.88, y2: 4.88 },
{ x1: 4.12, y1: 4.12, x2: 4.88, y2: 4.12 },
{ x1: 4.12, y1: 4.12, x2: 4.12, y2: 5 },
{ x1: 4.88, y1: 4.12, x2: 4.88, y2: 5.12 },
{ x1: 5.12, y1: 4.88, x2: 5.88, y2: 4.88 },
{ x1: 5.12, y1: 3.88, x2: 5.12, y2: 4.88 },
{ x1: 5.88, y1: 4, x2: 5.88, y2: 4.88 },
{ x1: 0.12, y1: 5.12, x2: 0.88, y2: 5.12 },
{ x1: 0.12, y1: 5.88, x2: 0.88, y2: 5.88 },
{ x1: 0.12, y1: 5.12, x2: 0.12, y2: 5.88 },
{ x1: 0.88, y1: 5.12, x2: 0.88, y2: 5.88 },
{ x1: 1.12, y1: 5.12, x2: 2, y2: 5.12 },
{ x1: 1.12, y1: 5.88, x2: 2, y2: 5.88 },
{ x1: 1.12, y1: 5.12, x2: 1.12, y2: 5.88 },
{ x1: 2, y1: 5.12, x2: 3, y2: 5.12 },
{ x1: 2, y1: 5.88, x2: 3, y2: 5.88 },
{ x1: 3, y1: 5.12, x2: 3.88, y2: 5.12 },
{ x1: 3, y1: 5.88, x2: 3.88, y2: 5.88 },
... 6 more items
]出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。