Libraryless. Click here for Pure Java version (9301L/52K).
srecord noeq G22Tiling<Img extends WidthAndHeight>(Img img) { new L<Tile> tiles; // number of pixels covered by all tiles int pixelsCovered; // for each pixel: tile index+1 (or 0 for empty) int[] tileMatrix; // index = dual log of tile size, value = tile index //new L<IntBuffer> tilesBySize; // yay, extending Rect to save space class Tile extends Rect { int index; int color; // tile color as defined by the tiler *(int *index, int *color, Rect position) { position(position); } Rect position() { this; } selfType position(Rect r) { x = r.x; y = r.y; w = r.w; h = r.h; this; } S area_str() { ret nPixels(area()); } double ratioToImage() { ret doubleRatio(area(), imageArea()); } S percent_str() { ret formatDoubleX(ratioToImage()*100, 2) + "% of image"; } toString { ret intToHex_fullLength(color) + " colored tile covering " + percent_str() + " at " + super.toString(); } // Lists of neighbors in all 4 directions (index like NESWDirection) // (If only a corner is touching, it's not a neighbor.) // Not used yet //Cl<Tile>[] neighbors; } int w() { ret img.w(); } int h() { ret img.h(); } int imageArea() { ret img.area(); } void initTileMatrix { tileMatrix = new int[w()*h()]; } int numTiles() { ret l(tiles); } L<Tile> get() { ret tiles; } }
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: | 211 / 402 |
Version history: | 20 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) |