10#ifndef TILEAREA_TYPE_H
11#define TILEAREA_TYPE_H
78 return TileAddXY(this->tile, this->w / 2, this->h / 2);
169 return this->tile == rhs.
tile;
179 return this->tile == rhs;
221 }
else if (--this->y > 0) {
271 using difference_type = std::ptrdiff_t;
272 using iterator_category = std::forward_iterator_tag;
273 using pointer = void;
274 using reference = void;
279 bool operator==(
const SpiralTileIterator &rhs)
const {
return this->x == rhs.x && this->y == rhs.y; }
280 bool operator==(
const std::default_sentinel_t &)
const {
return this->
IsEnd(); }
378 std::default_sentinel_t end()
const {
return std::default_sentinel_t(); }
381 SpiralTileIterator start;
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
DiagonalTileIterator(const DiagonalTileArea &ta)
Construct the iterator.
uint base_x
The base tile x coordinate from where the iterating happens.
int a_max
The (rotated) x coordinate of the end of the iteration.
DiagonalTileIterator(TileIndex corner1, TileIndex corner2)
Construct the iterator.
int b_max
The (rotated) y coordinate of the end of the iteration.
int b_cur
The current (rotated) y coordinate of the iteration.
int a_cur
The current (rotated) x coordinate of the iteration.
uint base_y
The base tile y coordinate from where the iterating happens.
Iterator to iterate over a tile area (rectangle) of the map.
OrthogonalTileIterator(TileIndex corner1, TileIndex corner2)
Construct the iterator.
OrthogonalTileIterator(const OrthogonalTileArea &ta)
Construct the iterator.
int y
The current 'y' position in the rectangle.
int w
The width of the iterated area.
int x
The current 'x' position in the rectangle.
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
Helper class for SpiralTileSequence.
SpiralTileIterator(TileIndex center, uint diameter)
Create the iterator.
void InitPosition()
Initialise "position" after "dir" was changed.
bool IsEnd() const
Test whether the iterator reached the end.
void Increment()
Advance the internal state to the next potential tile.
void SkipOutsideMap()
Advance the internal state until it reaches a valid tile or the end.
SpiralTileSequence(TileIndex center, uint diameter)
Generate TileIndices for a square area around a center tile.
SpiralTileSequence(TileIndex start_north, uint radius, uint w, uint h)
Generate TileIndices for a rectangular area with an optional rectangular hole in the center.
Base class for tile iterators.
TileIndex operator*() const
Get the tile we are currently at.
TileIterator(TileIndex tile=INVALID_TILE)
Initialise the iterator starting at this tile.
TileIndex tile
The current tile we are at.
bool operator==(const TileIterator &rhs) const
Equality comparison.
virtual ~TileIterator()=default
Ensure the destructor of the sub classes are called as well.
virtual TileIterator & operator++()=0
Move ourselves to the next tile in the rectangle on the map.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
EnumIndexArray< T, DiagDirection, DiagDirection::End > DiagDirectionIndexArray
Array with DiagDirection as index.
DiagDirection
Enumeration for diagonal directions.
@ Invalid
Flag for an invalid DiagDirection.
Functions related to maps.
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Represents a diagonal tile area.
void Clear()
Clears the TileArea by making the tile invalid and setting a and b to 0.
int16_t b
Extent in diagonal "y" direction (may be negative to signify the area stretches upwards).
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
int16_t a
Extent in diagonal "x" direction (may be negative to signify the area stretches to the left).
TileIndex tile
Base tile of the area.
DiagonalTileArea(TileIndex tile=INVALID_TILE, int16_t a=0, int16_t b=0)
Construct this tile area with some set values.
Represents the covered area of e.g.
OrthogonalTileIterator end() const
Returns an iterator to the end of the tile area.
void ClampToMap()
Clamp the tile area to map borders.
void Add(const OrthogonalTileArea &area)
Add another tile area to this tile area.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
uint16_t w
The width of the area.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
bool Intersects(const OrthogonalTileArea &ta) const
Does this tile area intersect with another?
TileIndex GetCenterTile() const
Get the center tile.
void Clear()
Clears the 'tile area', i.e.
TileIndex tile
The base tile of the area.
bool IsEmpty() const
Test if this tile area is empty.
uint16_t h
The height of the area.
OrthogonalTileIterator begin() const
Returns an iterator to the beginning of the tile area.
OrthogonalTileArea(TileIndex tile=INVALID_TILE, uint16_t w=0, uint16_t h=0)
Construct this tile area with some set values.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.