Libraryless. Click here for Pure Java version (7883L/44K).
persistable sclass FloodFill is Steppable { // input int w, h; swappable bool isConnectable(Pt a, Pt b) { throw unimplemented(); } void visited(Pt p) {} // internal new PtBuffer stack; BitMatrix visited; *(int *w, int *h) { visited = new BitSetMatrix(w, h); } *(int *w, int *h, BitMatrix *visited) {} selfType useQuadTree() { visited = new QuadTreeBitMatrix(w, h); this; } bool isPointVisited(Pt p) { ret visited.get(p); } void startAt aka addPoint(Pt p) { if (!isAddable(p)) ret; stack.add(p); addedPoint(p); } bool isValidPoint(Pt p) { ret p != null && !(p.x < 0 || p.y < 0 || p.x >= w || p.y >= h); } bool isAddable(Pt p) { if (!isValidPoint(p)) false; if (isPointVisited(p)) false; true; } void addedPoint(Pt p) {} public bool step() { if (empty(stack)) false; Pt p = popLast(stack); int x = p.x, y = p.y; visited.set(p, true); visited(p); possibleBridge(p, new Pt(x-1, y)); possibleBridge(p, new Pt(x+1, y)); possibleBridge(p, new Pt(x, y-1)); possibleBridge(p, new Pt(x, y+1)); true; } void possibleBridge(Pt a, Pt b) { if (isValidPoint(b) && isConnectable(a, b)) { addPoint(b); createBridge(a, b); } } void createBridge(Pt a, Pt b) {} void addAllPoints { for (p : allPointsInRect_virtual(w, h)) addPoint(p); } void doAllPoints { for (p : allPointsInRect_virtual(w, h)) { addPoint(p); stepAll(this); } } }
Began life as a copy of #1006206
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033582 |
Snippet name: | FloodFill |
Eternal ID of this version: | #1033582/23 |
Text MD5: | 8a0c1cd1caa15f25cec594d6bb829321 |
Transpilation MD5: | 48944a56cbd7d29695aa72a58beefc41 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-22 18:55:16 |
Source code size: | 1624 bytes / 77 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 262 / 457 |
Version history: | 22 change(s) |
Referenced in: | #1033583 - FloodFillBWImage [dev.] #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |