srecord noeq G22Tiling(Img img) {
new L 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 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[] 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 get() { ret tiles; }
}