Libraryless. Click here for Pure Java version (6828L/38K).
srecord noeq NonOverlappingRandomRects(int n, Rect full, int rw, int rh) { int maxFailures = 1000, failures; new L<Rect> out; run { double factor = doubleRatio(rw*rh*n, area(full)); if (factor > 1) fail("Can't fit " + n2(n, "rectangle") + " in " + full); loop: while (l(out) < n && failures < maxFailures) { Rect rNew = randomRect(rw, rh, full); for (Rect r : out) if (rectsOverlap(r, rNew)) { ++failures; continue loop; } out.add(rNew); } } L<Rect> get() { run(); ret out; } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034164 |
Snippet name: | NonOverlappingRandomRects |
Eternal ID of this version: | #1034164/5 |
Text MD5: | ba94a307378a9f5b39f86313814cd630 |
Transpilation MD5: | 7ebc53f2c8da0814f171368a6b8be7e5 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-25 00:14:40 |
Source code size: | 568 bytes / 19 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 121 / 226 |
Version history: | 4 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |