Libraryless. Click here for Pure Java version (337L/2K).
1 | static Rect intersectRects(Rect a, Rect b) {
|
2 | int x = max(a.x, b.x), y = max(a.y, b.y); |
3 | int x2 = min(a.x+a.w, b.x+b.w), y2 = min(a.y+a.h, b.y+b.h); |
4 | ret new Rect(x, y, x2-x, y2-y); |
5 | } |
6 | |
7 | static Rect intersectRects(Rect a, int x1, int y1, int w, int h) {
|
8 | if (a == null |
9 | || a.x >= x1 && a.y >= y1 && a.x2() < x1+w && a.y2() < y1+h) |
10 | ret a; |
11 | ret rectFromPoints( |
12 | max(a.x, x1), max(a.y, y1), |
13 | min(a.x2(), x1+w), min(a.y2(), y1+h)); |
14 | } |
Began life as a copy of #1005838
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1006162 |
| Snippet name: | intersectRects |
| Eternal ID of this version: | #1006162/3 |
| Text MD5: | 90692dec13719c50a97207d18ed238b5 |
| Transpilation MD5: | 5ce3009ae9c4b55f60cc5b143ae2928b |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-08-20 21:59:38 |
| Source code size: | 458 bytes / 14 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 968 / 1055 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |