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

29
LINES

< > BotCompany Repo | #1006206 // floodFillGrid_step

JavaX fragment (include)

static Rect floodFillGrid_step(BitSet grid, int gw, int gh, int x, int y) {
  Rect r = null;
  new L<Pt> stack;
  stack.add(new Pt(x, y));
  while (nempty(stack)) {
    Pt p = popLast(stack);
    x = p.x;
    y = p.y;

    if (!(x < 0 || y < 0 || x >= gw || y >= gh)) {
      int idx = y*gw+x;
      
      if (grid.get(idx)) {
        grid.clear(idx);
        Rect me = new Rect(x, y, 1, 1);
        if (r == null)
          r = me;
        else
          r = rectUnion(r, me);

        stack.add(new Pt(x-1, y));
        stack.add(new Pt(x+1, y));
        stack.add(new Pt(x, y-1));
        stack.add(new Pt(x, y+1));
      }
    }
  }
  ret r;
}

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: 476 / 492
Referenced in: [show references]