Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

29
LINES

< > BotCompany Repo | #1006206 // floodFillGrid_step

JavaX fragment (include)

1  
static Rect floodFillGrid_step(BitSet grid, int gw, int gh, int x, int y) {
2  
  Rect r = null;
3  
  new L<Pt> stack;
4  
  stack.add(new Pt(x, y));
5  
  while (nempty(stack)) {
6  
    Pt p = popLast(stack);
7  
    x = p.x;
8  
    y = p.y;
9  
10  
    if (!(x < 0 || y < 0 || x >= gw || y >= gh)) {
11  
      int idx = y*gw+x;
12  
      
13  
      if (grid.get(idx)) {
14  
        grid.clear(idx);
15  
        Rect me = new Rect(x, y, 1, 1);
16  
        if (r == null)
17  
          r = me;
18  
        else
19  
          r = rectUnion(r, me);
20  
21  
        stack.add(new Pt(x-1, y));
22  
        stack.add(new Pt(x+1, y));
23  
        stack.add(new Pt(x, y-1));
24  
        stack.add(new Pt(x, y+1));
25  
      }
26  
    }
27  
  }
28  
  ret r;
29  
}

Author comment

Began life as a copy of #1006204

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006206
Snippet name: floodFillGrid_step
Eternal ID of this version: #1006206/1
Text MD5: 55baa54cf1270108a5e5ff3ce0ed6162
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-23 13:58:23
Source code size: 676 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 488 / 503
Referenced in: [show references]