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

22
LINES

< > BotCompany Repo | #1035379 // mergeOverlappingRects

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

Libraryless. Click here for Pure Java version (7986L/45K).

static L<Rect> mergeOverlappingRects(L<Rect> boxes) {
  while true {
    ping();
    bool change;
    for (box1 : boxes) {
      for (box2 : boxes) {
        if (box1 == box2) continue;
        if (rectsOverlap(box1, box2)) {
          //printVars("Merging", +box1, +box2);
          copyRect(rectUnion(box1, box2), box1);
          box2.w = 0;
          box2.h = 0;
          set change;
        };
      }
    }
    
    if (!change) break;
    boxes = filter(boxes, b -> nempty(b));
  }
  ret boxes;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1035379
Snippet name: mergeOverlappingRects
Eternal ID of this version: #1035379/4
Text MD5: 9b1477ec9a8a0ba8b827b253f747e1fb
Transpilation MD5: 0f417fb00f81b0ef6140208d5049ce59
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-03 20:30:05
Source code size: 525 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 186
Version history: 3 change(s)
Referenced in: [show references]