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

7
LINES

< > BotCompany Repo | #1006880 // selectRandomPartContaining

JavaX fragment (include)

static Rect selectRandomPartContaining(RGBImage img, Rect r, int w, int h) {
  int maxX = min(r.x, img.w()-w), maxY = min(r.y, img.h()-h);
  int minX = max(r.x2()-w, 0), minY = max(r.y2()-h, 0);
  if (minX > maxX || minY > maxY)
    fail("selectRandomPartContaining fail " + struct(ll(r, img.w(), img.h(), w, h, minX, maxX, minY, maxY)));
  ret new Rect(random(minX, maxX+1), random(minY, maxY+1), w, h);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006880
Snippet name: selectRandomPartContaining
Eternal ID of this version: #1006880/6
Text MD5: 0dfcb3dd500f3cb1957446f9b0945837
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-03 00:39:56
Source code size: 412 bytes / 7 lines
Pitched / IR pitched: No / No
Views / Downloads: 589 / 600
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1006903 - selectRandomPart - synonym of randomRect