diff options
| author | Simon Tatham <anakin@pobox.com> | 2005-02-24 08:13:32 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2005-02-24 08:13:32 +0000 |
| commit | e500ef963734dcf35ffa146ee917e0e0e09c325c (patch) | |
| tree | c6474ce830c79771afd9376d254e478f0b2c7e4c /pattern.c | |
| parent | 1c05db3fb55cab70267a80087cd64f3da0bdfc47 (diff) | |
| download | puzzles-e500ef963734dcf35ffa146ee917e0e0e09c325c.zip puzzles-e500ef963734dcf35ffa146ee917e0e0e09c325c.tar.gz puzzles-e500ef963734dcf35ffa146ee917e0e0e09c325c.tar.bz2 puzzles-e500ef963734dcf35ffa146ee917e0e0e09c325c.tar.xz | |
Fixes in grid generation for pedantic special cases when one or both
grid dimensions are very small.
[originally from svn r5390]
Diffstat (limited to 'pattern.c')
| -rw-r--r-- | pattern.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -281,6 +281,15 @@ static void generate(random_state *rs, int w, int h, unsigned char *retgrid) for (q = -1; q <= +1; q++) { if (i+p < 0 || i+p >= h || j+q < 0 || j+q >= w) continue; + /* + * An additional special case not mentioned + * above: if a grid dimension is 2xn then + * we do not average across that dimension + * at all. Otherwise a 2x2 grid would + * contain four identical squares. + */ + if ((h==2 && p!=0) || (w==2 && q!=0)) + continue; n++; sx += fgrid[(i+p)*w+(j+q)]; } @@ -303,7 +312,7 @@ static void generate(random_state *rs, int w, int h, unsigned char *retgrid) for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { - retgrid[i*w+j] = (fgrid[i*w+j] > threshold ? GRID_FULL : + retgrid[i*w+j] = (fgrid[i*w+j] >= threshold ? GRID_FULL : GRID_EMPTY); } } |