* Advance the internal state to the next potential tile. * The tile may be outside the map though. */
| 363 | * The tile may be outside the map though. |
| 364 | */ |
| 365 | void SpiralTileIterator::Increment() |
| 366 | { |
| 367 | assert(!this->IsEnd()); |
| 368 | |
| 369 | /* Special value for first tile in areas with odd diameter */ |
| 370 | if (this->dir == INVALID_DIAGDIR) { |
| 371 | const auto west = TileIndexDiffCByDir(DIR_W); |
| 372 | this->x += west.x; |
| 373 | this->y += west.y; |
| 374 | this->dir = DIAGDIR_BEGIN; |
| 375 | this->InitPosition(); |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | /* Step to the next 'neighbour' in the circular line */ |
| 380 | const auto diff = TileIndexDiffCByDiagDir(this->dir); |
| 381 | this->x += diff.x; |
| 382 | this->y += diff.y; |
| 383 | --this->position; |
| 384 | if (this->position > 0) return; |
| 385 | |
| 386 | /* Corner reached, switch direction */ |
| 387 | ++this->dir; |
| 388 | |
| 389 | if (this->dir == DIAGDIR_END) { |
| 390 | /* Jump to next circle */ |
| 391 | const auto west = TileIndexDiffCByDir(DIR_W); |
| 392 | this->x += west.x; |
| 393 | this->y += west.y; |
| 394 | ++this->cur_radius; |
| 395 | this->dir = DIAGDIR_BEGIN; |
| 396 | } |
| 397 | |
| 398 | this->InitPosition(); |
| 399 | } |
no test coverage detected