|
OpenTTD Source 20261123-master-g1c55c72fd0
|
Helper class for SpiralTileSequence. More...
#include <tilearea_spiral.h>
Public Types | |
| using | value_type = TileIndex |
| value_type iterator trait | |
| using | difference_type = std::ptrdiff_t |
| difference_type iterator trait | |
| using | iterator_category = std::forward_iterator_tag |
| iterator_category iterator trait | |
| using | pointer = void |
| pointer iterator trait | |
| using | reference = void |
| reference iterator trait | |
Public Member Functions | |
| SpiralTileIterator (TileIndex center, uint diameter) | |
| Create the iterator. | |
| SpiralTileIterator (TileIndex start_north, uint radius, uint w, uint h) | |
| Create the iterator. | |
| bool | operator== (const SpiralTileIterator &rhs) const |
| Compare with other iterator. | |
| bool | operator== (const std::default_sentinel_t &) const |
| Compare with end sentinel. | |
| TileIndex | operator* () const |
| Get the current tile. | |
| SpiralTileIterator & | operator++ () |
| Increment the iterator and set it to the next position. | |
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 | |
| const uint | max_radius |
| The maximum radius of the spiral. | |
| DiagDirectionIndexArray< uint > | extent |
| Size of hole in the centre of the spiral. | |
| uint | cur_radius |
| The current radius. | |
| DiagDirection | dir |
| The current spiral direction. | |
| uint | position |
| The current position along an edge. | |
| uint | x |
| The current tile X-coordinate. | |
| uint | y |
| The current tile Y-coordinate. | |
Helper class for SpiralTileSequence.
Definition at line 20 of file tilearea_spiral.h.
| using SpiralTileIterator::difference_type = std::ptrdiff_t |
difference_type iterator trait
Definition at line 23 of file tilearea_spiral.h.
| using SpiralTileIterator::iterator_category = std::forward_iterator_tag |
iterator_category iterator trait
Definition at line 24 of file tilearea_spiral.h.
| using SpiralTileIterator::pointer = void |
pointer iterator trait
Definition at line 25 of file tilearea_spiral.h.
| using SpiralTileIterator::reference = void |
reference iterator trait
Definition at line 26 of file tilearea_spiral.h.
value_type iterator trait
Definition at line 22 of file tilearea_spiral.h.
| SpiralTileIterator::SpiralTileIterator | ( | TileIndex | center, |
| uint | diameter ) |
Create the iterator.
Generate TileIndices for a square area around a center tile.
The size of the square is given by the length of the edge. If the size is even, the south extent will be larger than the north extent.
Example for diameter=4, [ ] is the "center": 1 1 1 1 [0] 1 1 0 0 1 1 0 1 1 1 1 The sequence starts with the "0" tiles, and continues with the shells around it.
| center | Center of the square area. |
| diameter | Edge length of the square. |
Definition at line 19 of file tilearea_spiral.cpp.
References Begin, cur_radius, dir, extent, InitPosition(), Invalid, max_radius, position, SkipOutsideMap(), TileX(), TileY(), x, and y.
Referenced by operator++(), and operator==().
| SpiralTileIterator::SpiralTileIterator | ( | TileIndex | start_north, |
| uint | radius, | ||
| uint | w, | ||
| uint | h ) |
Create the iterator.
Generate TileIndices for a rectangular area with an optional rectangular hole in the center.
The TileIndices will be sorted by increasing distance from the center (hole).
Example for radius=2, w=2, h=1, [ ] is "start_north": 1 1 1 1 [0] 1 1 0 0 1 1 0 H 0 1 1 0 H 0 1 1 0 0 1 1 0 1 1 1 1 The sequence starts with the "0" tiles, and continues with the shells around it.
| start_north | Tile directly north from the center hole. |
| radius | Radial distance between outer rectangle and center hole. |
| w | Width of the inner rectangular hole. |
| h | Height of the inner rectangular hole. |
Definition at line 43 of file tilearea_spiral.cpp.
References cur_radius, dir, extent, InitPosition(), max_radius, SkipOutsideMap(), TileX(), TileY(), x, and y.
|
private |
Advance the internal state to the next potential tile.
The tile may be outside the map though.
Definition at line 73 of file tilearea_spiral.cpp.
References Begin, cur_radius, dir, End, InitPosition(), Invalid, IsEnd(), position, TileIndexDiffCByDiagDir(), TileIndexDiffCByDir(), W, x, and y.
Referenced by operator++(), and SkipOutsideMap().
|
private |
Initialise "position" after "dir" was changed.
Definition at line 64 of file tilearea_spiral.cpp.
References cur_radius, dir, extent, and position.
Referenced by Increment(), SpiralTileIterator(), and SpiralTileIterator().
|
inlineprivate |
Test whether the iterator reached the end.
true iff the end of the iteration is reached. Definition at line 90 of file tilearea_spiral.h.
References Invalid.
Referenced by Increment(), operator==(), and SkipOutsideMap().
|
inline |
|
inline |
Increment the iterator and set it to the next position.
Definition at line 63 of file tilearea_spiral.h.
References Increment(), SkipOutsideMap(), and SpiralTileIterator().
|
inline |
Compare with other iterator.
| rhs | The other iterator to compare with. |
true iff the other iterator matches this value. Definition at line 36 of file tilearea_spiral.h.
References SpiralTileIterator(), x, and y.
|
inline |
Compare with end sentinel.
true iff this iterator is at the end. Definition at line 45 of file tilearea_spiral.h.
References IsEnd().
|
private |
Advance the internal state until it reaches a valid tile or the end.
Definition at line 56 of file tilearea_spiral.cpp.
References Increment(), IsEnd(), Map::SizeX(), Map::SizeY(), x, and y.
Referenced by operator++(), SpiralTileIterator(), and SpiralTileIterator().
|
private |
The current radius.
Definition at line 76 of file tilearea_spiral.h.
Referenced by Increment(), InitPosition(), SpiralTileIterator(), and SpiralTileIterator().
|
private |
The current spiral direction.
Definition at line 77 of file tilearea_spiral.h.
Referenced by Increment(), InitPosition(), SpiralTileIterator(), and SpiralTileIterator().
|
private |
Size of hole in the centre of the spiral.
Definition at line 73 of file tilearea_spiral.h.
Referenced by InitPosition(), SpiralTileIterator(), and SpiralTileIterator().
|
private |
The maximum radius of the spiral.
Definition at line 72 of file tilearea_spiral.h.
Referenced by SpiralTileIterator(), and SpiralTileIterator().
|
private |
The current position along an edge.
Definition at line 78 of file tilearea_spiral.h.
Referenced by Increment(), InitPosition(), and SpiralTileIterator().
|
private |
The current tile X-coordinate.
Definition at line 79 of file tilearea_spiral.h.
Referenced by Increment(), operator*(), operator==(), SkipOutsideMap(), SpiralTileIterator(), and SpiralTileIterator().
|
private |
The current tile Y-coordinate.
Definition at line 80 of file tilearea_spiral.h.
Referenced by Increment(), operator*(), operator==(), SkipOutsideMap(), SpiralTileIterator(), and SpiralTileIterator().