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

13
LINES

< > BotCompany Repo | #1029737 // randomRect_enclosing_in - rect that contains x and is contained in y [dev.]

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

Libraryless. Click here for Pure Java version (2819L/18K).

1  
static Rect randomRect_enclosing_in(int w, int h, Rect inner, Rect outer) {
2  
  if (inner.w > w || inner.h > h) null;
3  
  if (outer.w < w || outer.h < h) null;
4  
  IntRange x1range = intersectIntRanges(
5  
    intRange_incl(inner.x2()-w, inner.x),
6  
    intRange_incl(outer.x1(), outer.x2()-w));
7  
  if (x1range.isEmpty()) null;
8  
  IntRange y1range = intersectIntRanges(
9  
    intRange_incl(inner.y2()-h, inner.y),
10  
    intRange_incl(outer.y1(), outer.y2()-h));
11  
  if (y1range.isEmpty()) null;
12  
  ret rect(random(x1range), random(y1range), w, h);
13  
}

Author comment

Began life as a copy of #1006676

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1029737
Snippet name: randomRect_enclosing_in - rect that contains x and is contained in y [dev.]
Eternal ID of this version: #1029737/5
Text MD5: 1fcf2971547596881a94873d93e2dc08
Transpilation MD5: d35934d06645c79297787442734e0812
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-10 00:36:09
Source code size: 541 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 181 / 287
Version history: 4 change(s)
Referenced in: [show references]