Warning: session_start(): open(/var/lib/php/sessions/sess_bfu1iaiujd5lj909mpp85bd853, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// firstIntFromLong(l) = x, secondIntFromLong(l) = y
static LongIterator pixelSpiral_longIterator(int sx, int sy, int imageWidth, int imageHeight) {
ret pixelSpiral_longIterator(sx, sy, imageWidth, imageHeight, Int.MAX_VALUE);
}
// thanks to https://stackoverflow.com/questions/398299/looping-in-a-spiral
static LongIterator pixelSpiral_longIterator(int sx, int sy, int imageWidth, int imageHeight, int maxPixels) {
ret new LongIterator {
int x, y, dx, dy = -1;
int maxPixels2 = min(maxPixels, sqr(max4(sx+1, imageWidth-sx, sy+1, imageHeight-sy)*2));
int i;
public bool hasNext() { ret i < maxPixels2; }
public long next() {
do {
int px = sx+x, py = sy+y;
if ((x == y) || ((x < 0) && (x == -y)) || ((x > 0) && (x == 1-y))) {
int t=dx; dx=-dy; dy=t;
}
x += dx; y += dy;
if (px >= 0 && py >= 0 && px < imageWidth && py < imageHeight)
ret twoIntsToLong(px, py);
} while (i++ < maxPixels2);
}
};
}