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).

srecord noeq FillOnePath(OnePathWithOrigin path) {
  // do we fill the right-hand side or the left-hand side when
  // walking the path
  settable bool rhsIsInside;
  
  Rect r; // bounds of path
  BitSet inBorder; // is pixel part of path itself?
  BitSet inside;   // is pixel inside the filled path?
  
  run {
    r = path.bounds();
    int size = r.w*r.h;
    inBorder = new BitSet(size);
    inside = new BitSet(size);
    
    Pt last = null;
    for (Pt p : path.pointIterator()) {
      int idx = (p.x-r.x)+(p.y-r.y)*r.w;
      inBorder.set(idx);
      
      if (last != null) {
        int dx = p.x-last.x, dy = p.y-last.y;
        if (dx == 0 && dy == 0) {}
        else if (dy == 0)
          setInside(rhsIsInside ? last.x+dx : last.y-dx, p.y);
        else if (dx == 0)
          setInside(p.x, rhsIsInside ? last.x-dx : last.x+dx);
        else { /*TODO*/ }
      }
      
      last = p;
    }
  }
  
  void setInside(int x, int y) {
    if (!rectContains(r, x, y)) ret;
    int idx = (x-r.x)+(y-r.y)*r.w;
    inside.set(idx);
  }
}

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: 78 / 134
Version history: 7 change(s)
Referenced in: [show references]