Interactive 2D BFS Dropout Island & Scroll Saw Blade Verifier
Executed live in your browser via src/index.mjs. Inspect how 4-connected perimeter flood fill isolates unanchored red dropout islands and welds them with shortest-Euclidean structural tabs while computing the 3-tooth blade & wire-gauge pilot drill.
Interactive 31-Bit Nonogram Line DP & Uniqueness Verifier
Test both 1D register bitmask line deduction (deduceNonogramLine) and full 2D queue propagation + minimum-entropy uniqueness verification (solveNonogramBitmask).
1. 31-Bit Bitmask Nonogram Line Deduction & Switching-Component Proofs
A Nonogram (Picross / Griddlers) puzzle specifies ordered contiguous block lengths $R = [r_0, r_1, \dots, r_{k-1}]$ along each row and column of an $H \times W$ binary grid. Naive backtracking over pixels explodes as $O(2^{HW})$, whereas encoding each row and column into a 31-bit integer mask turns run placement and forced-cell intersection into register-level bitwise operations.
Why 31 Bits Instead of 32 in JavaScript?
ECMAScript bitwise operators (<<, |, &, ^) coerce Numbers to signed 32-bit two's-complement integers (Int32), where 1 << 31 evaluates to -2147483648. Restricting single-word masks to $1 \le N \le 31$ with 0x7fffffff keeps all block masks non-negative across standard $5\times 5$ through $30\times 30$ puzzles.
forcedFilledMask = fullMask ^ unionEmpty, forcedEmptyMask = fullMask ^ unionFill
Instead of enumerating exponentially many full-line combinations on sparse clues such as [1, 1, 1, 1, 1], deduceNonogramLine memoizes suffix states (runIdx, startPos) in flat typed arrays (Float64Array / Int32Array), bounding worst-case line complexity to $O(k \cdot N^2)$. When generating puzzles from photos, solveNonogramBitmask verifies both unique === true (eliminating $2 \times 2$ checkerboard switching components) and lineSolvable === true so players never have to guess.
import { computeNonogramClues, deduceNonogramLine, solveNonogramBitmask } from "./src/index.mjs";
// 1D overlap deduction: clue [6, 2] on a 10-cell line has only 3 valid placements
const d = deduceNonogramLine(10, [6, 2]);
// d.forcedFilledMask => 0b0100111100 (cells 2,3,4,5 and cell 8 are 100% forced!)
// 2D uniqueness & pure deterministic line-solvability audit
const { rowClues, colClues } = computeNonogramClues(pixelGrid);
const proof = solveNonogramBitmask(rowClues, colClues);
// proof => { solvable: true, unique: true, lineSolvable: true, solutionCount: 1, ... }
2. 2D 4-Connected BFS Dropout Detection & Shortest-Euclidean Tab Synthesis
When converting a portrait photo or script lettering into a wood scroll-saw pattern or Mylar airbrush stencil, binary thresholding partitions the canvas into keep material (1 = solid wood / stencil sheet) and cut void (0 = saw kerf / open window). Any solid component that lacks an orthogonal path to the outer plaque border becomes a floating dropout island that falls into the dust collection chute the moment its surrounding contour is cut.
Strict 4-Connectivity vs. Diagonal Corner Snap
Raster contour libraries frequently group pixels using 8-neighbor Moore adjacency. In physical woodworking, two solid cells touching only diagonally at $(x, y)$ and $(x+1, y+1)$ meet at a zero-width mathematical point—a 0.034" scroll saw blade severs both kerfs right through the vertex. detectFloatingIslands enforces strict 4-connected Von Neumann flood fill seeded from the outer frame:
import { detectFloatingIslands, autoBridgeIslands } from "./src/index.mjs";
const audit = detectFloatingIslands(keepMask, width, height);
// audit.stateMask: 0 = cut void, 1 = frame-anchored wood, 2 = floating dropout island
if (audit.islandCount > 0) {
// Iteratively bridges the globally closest (anchorBoundary <-> islandBoundary) Euclidean pair,
// promoting newly welded rings so nested islands cascade across short local tabs!
const welded = autoBridgeIslands(keepMask, width, height, 1);
// welded.remainingIslandCount === 0
}
3. Scroll Saw 3-Tooth Engagement Physics & Wire-Gauge Pilot Drills
Scroll saw blade sizing balances two competing mechanical failure modes across stock thickness $t_{\text{in}}$:
- Under-Engagement (< 3 Teeth in Stock): Tooth gullets straddle the entire board thickness, hooking bottom-face fibers on the upstroke and violently slamming the workpiece against the saw table.
- Over-Engagement (> 10 Teeth in Stock): Sawdust generated near the top of the kerf fills every gullet before exiting the bottom face, creating friction heat that burns cherry, hard maple, and walnut black.
| Blade Size | Blade Width | Kerf Thickness | Pitch (TPI) | Min Stock ($3/\text{TPI}$) | Pilot Drill (Wire Gauge) | Fractional Drill |
|---|---|---|---|---|---|---|
#2/0 |
0.022" (0.56 mm) |
0.010" (0.25 mm) |
28 |
0.107" (stack veneer) |
#65 (0.035" / 0.89 mm) |
1/32"–3/64" |
#0 |
0.024" (0.61 mm) |
0.011" (0.28 mm) |
25 |
0.120" (1/8") |
#63 (0.037" / 0.94 mm) |
3/64" (0.047") |
#1 |
0.029" (0.74 mm) |
0.012" (0.30 mm) |
20 |
0.150" (3/16") |
#60 (0.040" / 1.02 mm) |
3/64" (0.047") |
#3 |
0.034" (0.86 mm) |
0.014" (0.36 mm) |
16 |
0.188" (3/16"–1/4") |
#58 (0.042" / 1.07 mm) |
3/64" (0.047") |
#5 |
0.041" (1.04 mm) |
0.016" (0.41 mm) |
12.5 |
0.240" (1/4"–1/2") |
#55 (0.052" / 1.32 mm) |
1/16" (0.063") |
#7 |
0.045" (1.14 mm) |
0.018" (0.46 mm) |
11.5 |
0.261" (1/2"–3/4") |
#53 (0.0595" / 1.51 mm) |
1/16" (0.063") |
#9 |
0.053" (1.35 mm) |
0.019" (0.48 mm) |
11 |
0.273" (3/4"–1.25") |
#50 (0.070" / 1.78 mm) |
5/64" (0.078") |
#12 |
0.062" (1.57 mm) |
0.024" (0.61 mm) |
9.5 |
0.316" (1.25"–2.0") |
#44 (0.086" / 2.18 mm) |
3/32" (0.094") |
4. Interactive Browser Implementations (Zero Login, 100% Client-Side)
The ten zero-backend web tools below run these exact bitmask deduction and 2D BFS topology pipelines directly in the browser:
Nonogram Picture Logic Suite (nonogramgrid.com)
Scroll Saw, Stencil & Pyrography CAD Suite (scrollsawpatterngenerator.com)
5. Run the Open-Source CLI, Tests & Engineering Notes
Clone github.com/kaiyilu/grid-and-fretwork-math and execute the zero-dependency Node.js test suite (Node.js 18+):
git clone https://github.com/kaiyilu/grid-and-fretwork-math.git
cd grid-and-fretwork-math
node --test
node ./src/index.mjs
For a full architectural walkthrough of how these algorithms power browser-native Canvas2D and SVG editors, read the companion article: Bitmask Nonogram Line Solvers & 2D BFS Stencil Island Bridging in Pure TypeScript.