Libraryless. Click here for Pure Java version (9301L/52K).
1 | srecord noeq G22Tiling<Img extends WidthAndHeight>(Img img) { |
2 | new L<Tile> tiles; |
3 | |
4 | // number of pixels covered by all tiles |
5 | int pixelsCovered; |
6 | |
7 | // for each pixel: tile index+1 (or 0 for empty) |
8 | int[] tileMatrix; |
9 | |
10 | // index = dual log of tile size, value = tile index |
11 | //new L<IntBuffer> tilesBySize; |
12 | |
13 | // yay, extending Rect to save space |
14 | class Tile extends Rect { |
15 | int index; |
16 | int color; // tile color as defined by the tiler |
17 | |
18 | *(int *index, int *color, Rect position) { |
19 | position(position); |
20 | } |
21 | |
22 | Rect position() { this; } |
23 | |
24 | selfType position(Rect r) { |
25 | x = r.x; y = r.y; w = r.w; h = r.h; |
26 | this; |
27 | } |
28 | |
29 | S area_str() { |
30 | ret nPixels(area()); |
31 | } |
32 | |
33 | double ratioToImage() { |
34 | ret doubleRatio(area(), imageArea()); |
35 | } |
36 | |
37 | S percent_str() { |
38 | ret formatDoubleX(ratioToImage()*100, 2) + "% of image"; |
39 | } |
40 | |
41 | toString { |
42 | ret intToHex_fullLength(color) + " colored tile covering " + percent_str() + " at " + super.toString(); |
43 | } |
44 | |
45 | // Lists of neighbors in all 4 directions (index like NESWDirection) |
46 | // (If only a corner is touching, it's not a neighbor.) |
47 | // Not used yet |
48 | //Cl<Tile>[] neighbors; |
49 | } |
50 | |
51 | int w() { ret img.w(); } |
52 | int h() { ret img.h(); } |
53 | int imageArea() { ret img.area(); } |
54 | |
55 | void initTileMatrix { |
56 | tileMatrix = new int[w()*h()]; |
57 | } |
58 | |
59 | int numTiles() { ret l(tiles); } |
60 | |
61 | L<Tile> get() { ret tiles; } |
62 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035225 |
Snippet name: | G22Tiling - a set of non-overlapping rectangles (partially or completely) covering an image |
Eternal ID of this version: | #1035225/21 |
Text MD5: | 6ec486476808abd661fff6deb396e265 |
Transpilation MD5: | 5bdf966cf6ad8df86ea0787089217042 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-23 23:56:53 |
Source code size: | 1522 bytes / 62 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 210 / 401 |
Version history: | 20 change(s) |
Referenced in: | [show references] |