OpenTTD Source 20261112-master-gbcbec5e63f
tilearea_diagonal.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef TILEAREA_DIAGONAL_H
11#define TILEAREA_DIAGONAL_H
12
13#include "map_func.h"
14
17public:
19 int16_t a;
20 int16_t b;
21
28 DiagonalTileArea(TileIndex tile = INVALID_TILE, int16_t a = 0, int16_t b = 0) : tile(tile), a(a), b(b) {}
29
31
35 void Clear()
36 {
37 this->tile = INVALID_TILE;
38 this->a = 0;
39 this->b = 0;
40 }
41
42 bool Contains(TileIndex tile) const;
43
45 class iterator {
46 private:
48 uint base_x;
49 uint base_y;
50 int a_cur;
51 int b_cur;
52 int a_max;
53 int b_max;
54
55 public:
57 using difference_type = std::ptrdiff_t;
58 using iterator_category = std::forward_iterator_tag;
59 using pointer = void;
60 using reference = void;
61
66 explicit iterator(const DiagonalTileArea &ta) : tile(ta.tile), base_x(TileX(ta.tile)), base_y(TileY(ta.tile)), a_cur(0), b_cur(0), a_max(ta.a), b_max(ta.b) {}
67
72 bool operator==(const iterator &) const = default;
73
78 bool operator==(const std::default_sentinel_t &) const
79 {
80 return **this == INVALID_TILE;
81 }
82
88 {
89 return this->tile;
90 }
91
93 };
94
99 inline iterator begin() const
100 {
101 return iterator{*this};
102 }
103
108 inline std::default_sentinel_t end() const
109 {
110 return std::default_sentinel_t();
111 }
112};
113
114#endif /* TILEAREA_DIAGONAL_H */
Iterator to iterate over a diagonal area of the map.
uint base_y
The base tile y coordinate from where the iterating happens.
iterator & operator++()
Increment the iterator and set it to the next position.
std::ptrdiff_t difference_type
difference_type iterator trait
TileIndex operator*() const
Get the current tile.
TileIndex value_type
value_type iterator trait
bool operator==(const std::default_sentinel_t &) const
Compare with end sentinel.
int b_max
The (rotated) y coordinate of the end of the iteration.
int a_max
The (rotated) x coordinate of the end of the iteration.
uint base_x
The base tile x coordinate from where the iterating happens.
iterator(const DiagonalTileArea &ta)
Construct the iterator.
bool operator==(const iterator &) const =default
Compare with other iterator.
void reference
reference iterator trait
void pointer
pointer iterator trait
int b_cur
The current (rotated) y coordinate of the iteration.
std::forward_iterator_tag iterator_category
iterator_category iterator trait
TileIndex tile
The current tile.
int a_cur
The current (rotated) x coordinate of the iteration.
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.
std::default_sentinel_t end() const
Returns an iterator to the end of the tile area.
iterator begin() const
Returns an iterator to the start of the tile area.
DiagonalTileArea(TileIndex tile=INVALID_TILE, int16_t a=0, int16_t b=0)
Construct this tile area with some set values.
Functions related to maps.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
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.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100