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

40
LINES

< > BotCompany Repo | #1035480 // FillOnePath [dev.]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (8973L/50K).

1  
srecord noeq FillOnePath(OnePathWithOrigin path) {
2  
  // do we fill the right-hand side or the left-hand side when
3  
  // walking the path
4  
  settable bool rhsIsInside;
5  
  
6  
  Rect r; // bounds of path
7  
  BitSet inBorder; // is pixel part of path itself?
8  
  BitSet inside;   // is pixel inside the filled path?
9  
  
10  
  run {
11  
    r = path.bounds();
12  
    int size = r.w*r.h;
13  
    inBorder = new BitSet(size);
14  
    inside = new BitSet(size);
15  
    
16  
    Pt last = null;
17  
    for (Pt p : path.pointIterator()) {
18  
      int idx = (p.x-r.x)+(p.y-r.y)*r.w;
19  
      inBorder.set(idx);
20  
      
21  
      if (last != null) {
22  
        int dx = p.x-last.x, dy = p.y-last.y;
23  
        if (dx == 0 && dy == 0) {}
24  
        else if (dy == 0)
25  
          setInside(rhsIsInside ? last.x+dx : last.y-dx, p.y);
26  
        else if (dx == 0)
27  
          setInside(p.x, rhsIsInside ? last.x-dx : last.x+dx);
28  
        else { /*TODO*/ }
29  
      }
30  
      
31  
      last = p;
32  
    }
33  
  }
34  
  
35  
  void setInside(int x, int y) {
36  
    if (!rectContains(r, x, y)) ret;
37  
    int idx = (x-r.x)+(y-r.y)*r.w;
38  
    inside.set(idx);
39  
  }
40  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035480
Snippet name: FillOnePath [dev.]
Eternal ID of this version: #1035480/8
Text MD5: dff47cfead9ac41731458d9d4ef47012
Transpilation MD5: 9e18df08b1c9440cbb2539e5e3a2e01b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-26 21:33:52
Source code size: 1088 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 141 / 229
Version history: 7 change(s)
Referenced in: [show references]