diff options
author | frosch <frosch@openttd.org> | 2011-01-11 16:45:45 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-01-11 16:45:45 +0000 |
commit | 12b4fa7dba25af2ecffe344390caffb7730b763d (patch) | |
tree | d1c511a9e382c6edeab16600eddd8c9b6f328f3e /src | |
parent | 7e6ccf3a0a1c42c978dff5f4d59e4e0052af70f1 (diff) | |
download | openttd-12b4fa7dba25af2ecffe344390caffb7730b763d.tar.xz |
(svn r21768) -Fix [FS#4396]: Diagonal tile iterator needed a special case for A * 0 selections.
Diffstat (limited to 'src')
-rw-r--r-- | src/tilearea.cpp | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/src/tilearea.cpp b/src/tilearea.cpp index c518fe8f1..498714ec0 100644 --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -139,26 +139,38 @@ TileIterator &DiagonalTileIterator::operator++() { assert(this->tile != INVALID_TILE); + /* Determine the next tile, while clipping at map borders */ bool new_line = false; do { /* Iterate using the rotated coordinates. */ - if (this->a_max > 0) { - this->a_cur += 2; - new_line = this->a_cur >= this->a_max; - } else { - this->a_cur -= 2; - new_line = this->a_cur <= this->a_max; - } - if (new_line) { - /* offset of initial a_cur: one tile in the same direction as a_max - * every second line. - */ - this->a_cur = abs(this->a_cur) % 2 ? 0 : (this->a_max > 0 ? 1 : -1); - + if (this->a_max == 1 || this->a_max == -1) { + /* Special case: Every second column has zero length, skip them completely */ + this->a_cur = 0; if (this->b_max > 0) { - ++this->b_cur; + this->b_cur = min(this->b_cur + 2, this->b_max); } else { - --this->b_cur; + this->b_cur = max(this->b_cur - 2, this->b_max); + } + } else { + /* Every column has at least one tile to process */ + if (this->a_max > 0) { + this->a_cur += 2; + new_line = this->a_cur >= this->a_max; + } else { + this->a_cur -= 2; + new_line = this->a_cur <= this->a_max; + } + if (new_line) { + /* offset of initial a_cur: one tile in the same direction as a_max + * every second line. + */ + this->a_cur = abs(this->a_cur) % 2 ? 0 : (this->a_max > 0 ? 1 : -1); + + if (this->b_max > 0) { + ++this->b_cur; + } else { + --this->b_cur; + } } } |