OpenTTD Source: SpiralTileIterator Class Reference

OpenTTD Source 15.3

Public Types | Public Member Functions | Private Member Functions | Private Attributes
SpiralTileIterator Class Reference

Helper class for SpiralTileSequence. More...

`#include <tilearea_type.h>`

## Public Types
using | value_type = TileIndex
using | difference_type = std::ptrdiff_t
using | iterator_category = std::forward_iterator_tag
using | pointer = void
using | reference = void

## Public Member Functions
| SpiralTileIterator (TileIndex center, uint diameter)
| See SpiralTileSequence constructor for description.
| SpiralTileIterator (TileIndex start_north, uint radius, uint w, uint h)
| See SpiralTileSequence constructor for description.
bool | operator== (const SpiralTileIterator &rhs) const
bool | operator== (const std::default_sentinel_t &) const
TileIndex | operator* () const
SpiralTileIterator & | operator++ ()
SpiralTileIterator | operator++ (int)

## Private Member Functions
void | SkipOutsideMap ()
| Advance the internal state until it reaches a valid tile or the end.
void | InitPosition ()
| Initialise "position" after "dir" was changed.
void | Increment ()
| Advance the internal state to the next potential tile.
bool | IsEnd () const
| Test whether the iterator reached the end.

## Private Attributes
uint | max_radius
std::array< uint, DIAGDIR_END > | extent
uint | cur_radius
DiagDirection | dir
uint | position
uint | x
uint | y

## Detailed Description

Helper class for SpiralTileSequence.

Definition at line 259 of file tilearea_type.h.

## Member Typedef Documentation

## ◆ difference_type

using SpiralTileIterator::difference_type = std::ptrdiff_t

Definition at line 262 of file tilearea_type.h.

## ◆ iterator_category

using SpiralTileIterator::iterator_category = std::forward_iterator_tag

Definition at line 263 of file tilearea_type.h.

## ◆ pointer

using SpiralTileIterator::pointer = void

Definition at line 264 of file tilearea_type.h.

## ◆ reference

using SpiralTileIterator::reference = void

Definition at line 265 of file tilearea_type.h.

## ◆ value_type

using SpiralTileIterator::value_type = TileIndex

Definition at line 261 of file tilearea_type.h.

## Constructor & Destructor Documentation

## ◆ SpiralTileIterator() [1/2]

SpiralTileIterator::SpiralTileIterator | ( | TileIndex | center,
|  | uint | diameter
| ) |  |

See SpiralTileSequence constructor for description.

Definition at line 302 of file tilearea.cpp.

References DIAGDIR_BEGIN, InitPosition(), INVALID_DIAGDIR, SkipOutsideMap(), TileX(), and TileY().

## ◆ SpiralTileIterator() [2/2]

SpiralTileIterator::SpiralTileIterator | ( | TileIndex | start_north,
|  | uint | radius,
|  | uint | w,
|  | uint | h
| ) |  |

See SpiralTileSequence constructor for description.

Definition at line 331 of file tilearea.cpp.

References InitPosition(), and SkipOutsideMap().

## Member Function Documentation

## ◆ Increment()

void SpiralTileIterator::Increment | ( |  | ) |
| private

Advance the internal state to the next potential tile.

The tile may be outside the map though.

Definition at line 365 of file tilearea.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, DIR_W, InitPosition(), INVALID_DIAGDIR, IsEnd(), TileIndexDiffCByDiagDir(), and TileIndexDiffCByDir().

Referenced by SkipOutsideMap().

## ◆ InitPosition()

void SpiralTileIterator::InitPosition | ( |  | ) |
| private

Initialise "position" after "dir" was changed.

Definition at line 356 of file tilearea.cpp.

Referenced by Increment(), SpiralTileIterator(), and SpiralTileIterator().

## ◆ IsEnd()

bool SpiralTileIterator::IsEnd | ( |  | ) | const
| inlineprivate

Test whether the iterator reached the end.

Definition at line 307 of file tilearea_type.h.

References INVALID_DIAGDIR.

Referenced by Increment(), and SkipOutsideMap().

## ◆ operator*()

TileIndex SpiralTileIterator::operator* | ( |  | ) | const
| inline

Definition at line 273 of file tilearea_type.h.

## ◆ operator++() [1/2]

SpiralTileIterator & SpiralTileIterator::operator++ | ( |  | ) |
| inline

Definition at line 275 of file tilearea_type.h.

## ◆ operator++() [2/2]

SpiralTileIterator SpiralTileIterator::operator++ | ( | int |  | ) |
| inline

Definition at line 282 of file tilearea_type.h.

## ◆ operator==() [1/2]

bool SpiralTileIterator::operator== | ( | const SpiralTileIterator & | rhs | ) | const
| inline

Definition at line 270 of file tilearea_type.h.

## ◆ operator==() [2/2]

bool SpiralTileIterator::operator== | ( | const std::default_sentinel_t & |  | ) | const
| inline

Definition at line 271 of file tilearea_type.h.

## ◆ SkipOutsideMap()

void SpiralTileIterator::SkipOutsideMap | ( |  | ) |
| private

Advance the internal state until it reaches a valid tile or the end.

Definition at line 348 of file tilearea.cpp.

References Increment(), IsEnd(), Map::SizeX(), and Map::SizeY().

Referenced by SpiralTileIterator(), and SpiralTileIterator().

## Field Documentation

## ◆ cur_radius

uint SpiralTileIterator::cur_radius
| private

Definition at line 295 of file tilearea_type.h.

## ◆ dir

DiagDirection SpiralTileIterator::dir
| private

Definition at line 296 of file tilearea_type.h.

## ◆ extent

std::array<uint, DIAGDIR_END> SpiralTileIterator::extent
| private

Definition at line 292 of file tilearea_type.h.

## ◆ max_radius

uint SpiralTileIterator::max_radius
| private

Definition at line 291 of file tilearea_type.h.

## ◆ position

uint SpiralTileIterator::position
| private

Definition at line 297 of file tilearea_type.h.

## ◆ x

uint SpiralTileIterator::x
| private

Definition at line 298 of file tilearea_type.h.

## ◆ y

uint SpiralTileIterator::y
| private

Definition at line 298 of file tilearea_type.h.

The documentation for this class was generated from the following files:

- src/tilearea_type.h
- src/tilearea.cpp