26 uint sx =
TileX(start);
27 uint sy =
TileY(start);
31 if (sx > ex)
Swap(sx, ex);
32 if (sy > ey)
Swap(sy, ey);
35 this->
w = ex - sx + 1;
36 this->
h = ey - sy + 1;
54 uint ex = sx + this->
w - 1;
55 uint ey = sy + this->
h - 1;
57 uint ax =
TileX(to_add);
58 uint ay =
TileY(to_add);
60 sx = std::min(ax, sx);
61 sy = std::min(ay, sy);
62 ex = std::max(ax, ex);
63 ey = std::max(ay, ey);
66 this->w = ex - sx + 1;
67 this->h = ey - sy + 1;
77 if (ta.
w == 0 || this->w == 0)
return false;
79 assert(ta.
w != 0 && ta.
h != 0 && this->w != 0 && this->h != 0);
83 uint right1 = left1 + this->
w - 1;
84 uint bottom1 = top1 + this->
h - 1;
88 uint right2 = left2 + ta.
w - 1;
89 uint bottom2 = top2 + ta.
h - 1;
106 if (this->
w == 0)
return false;
108 assert(this->
w != 0 && this->
h != 0);
110 uint left =
TileX(this->tile);
111 uint top =
TileY(this->tile);
128 int sx = std::max<int>(x - rad, 0);
129 int sy = std::max<int>(y - rad, 0);
130 int ex = std::min<int>(x + this->
w + rad,
Map::SizeX());
131 int ey = std::min<int>(y + this->
h + rad,
Map::SizeY());
210 int start_a =
TileY(this->tile) +
TileX(this->tile);
211 int start_b =
TileY(this->tile) -
TileX(this->tile);
213 int end_a = start_a + this->
a;
214 int end_b = start_b + this->
b;
217 if (start_a > end_a) {
222 if (start_b > end_b) {
228 return (
a >= start_a && a < end_a && b >= start_b &&
b < end_b);
239 bool new_line =
false;
245 if (this->
b_max > 0) {
252 if (this->
a_max > 0) {
265 if (this->
b_max > 0) {
294 return std::make_unique<DiagonalTileIterator>(corner1, corner2);
296 return std::make_unique<OrthogonalTileIterator>(corner1, corner2);
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
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.
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.
Base class for tile iterators.
TileIndex tile
The current tile we are at.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr void Swap(T &a, T &b)
Type safe swap operation.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
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.
static uint SizeY()
Get the size of the map along the Y.
static debug_inline uint SizeX()
Get the size of the map along the X.
static debug_inline uint Size()
Get the size of the map.
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.
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 tile
The base tile of the area.
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.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Type for storing the 'area' of something uses on the map.