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

22
LINES

< > BotCompany Repo | #1035380 // mergeNeighboringRects

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

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

1  
static L<Rect> mergeNeighboringRects(L<Rect> boxes, int maxDistance) {
2  
  while true {
3  
    ping();
4  
    bool change;
5  
    for (box1 : boxes) {
6  
      for (box2 : boxes) {
7  
        if (box1 == box2) continue;
8  
        if (rectDistance(box1, box2) <= maxDistance) {
9  
          //printVars("Merging", +box1, +box2);
10  
          copyRect(rectUnion(box1, box2), box1);
11  
          box2.w = 0;
12  
          box2.h = 0;
13  
          set change;
14  
        };
15  
      }
16  
    }
17  
    
18  
    if (!change) break;
19  
    boxes = filter(boxes, b -> nempty(b));
20  
  }
21  
  ret boxes;
22  
}

Author comment

Began life as a copy of #1035379

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035380
Snippet name: mergeNeighboringRects
Eternal ID of this version: #1035380/1
Text MD5: 344ca7c8d96c66d30747ca9c6e2980b6
Transpilation MD5: 16e80e749400e7680f9db73ea6591d2a
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:34:30
Source code size: 557 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 121 / 176
Referenced in: [show references]