Libraryless. Click here for Pure Java version (6828L/38K).
1 | srecord noeq NonOverlappingRandomRects(int n, Rect full, int rw, int rh) { |
2 | int maxFailures = 1000, failures; |
3 | new L<Rect> out; |
4 | |
5 | run { |
6 | double factor = doubleRatio(rw*rh*n, area(full)); |
7 | if (factor > 1) fail("Can't fit " + n2(n, "rectangle") + " in " + full); |
8 | |
9 | loop: while (l(out) < n && failures < maxFailures) { |
10 | Rect rNew = randomRect(rw, rh, full); |
11 | for (Rect r : out) |
12 | if (rectsOverlap(r, rNew)) |
13 | { ++failures; continue loop; } |
14 | out.add(rNew); |
15 | } |
16 | } |
17 | |
18 | L<Rect> get() { run(); ret out; } |
19 | } |
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: | 120 / 226 |
Version history: | 4 change(s) |
Referenced in: | [show references] |