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);
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);
112 uint tile_x =
TileX(tile);
113 uint tile_y =
TileY(tile);
128 int sx =
max(x - rad, 0);
129 int sy =
max(y - rad, 0);
192 int start_a =
TileY(this->tile) +
TileX(this->tile);
193 int start_b =
TileY(this->tile) -
TileX(this->tile);
195 int end_a = start_a + this->
a;
196 int end_b = start_b + this->
b;
199 if (start_a > end_a) {
204 if (start_b > end_b) {
210 return (a >= start_a && a < end_a && b >= start_b && b < end_b);
221 bool new_line =
false;
224 if (this->a_max == 1 || this->a_max == -1) {
227 if (this->b_max > 0) {
228 this->b_cur =
min(this->b_cur + 2, this->b_max);
230 this->b_cur =
max(this->b_cur - 2, this->b_max);
234 if (this->a_max > 0) {
236 new_line = this->a_cur >= this->a_max;
239 new_line = this->a_cur <= this->a_max;
245 this->a_cur =
abs(this->a_cur) % 2 ? 0 : (this->a_max > 0 ? 1 : -1);
247 if (this->b_max > 0) {
256 uint x = this->base_x + (this->a_cur - this->b_cur) / 2;
257 uint y = this->base_y + (this->b_cur + this->a_cur) / 2;
260 }
while (this->
tile >
MapSize() && this->b_max != this->b_cur);
TileIndex tile
Base tile of the area.
static void Swap(T &a, T &b)
Type safe swap operation.
void ClampToMap()
Clamp the tile area to map borders.
static uint MapSizeX()
Get the size of the map along the X.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
DiagonalTileArea(TileIndex tile=INVALID_TILE, int8 a=0, int8 b=0)
Construct this tile area with some set values.
static uint MapSizeY()
Get the size of the map along the Y.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
static uint TileX(TileIndex tile)
Get the X component of a tile.
int16 a
Extent in diagonal "x" direction (may be negative to signify the area stretches to the left) ...
static T max(const T a, const T b)
Returns the maximum of two values.
uint16 w
The width of the area.
OrthogonalTileArea(TileIndex tile=INVALID_TILE, uint8 w=0, uint8 h=0)
Construct this tile area with some set values.
static 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.
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?
int16 b
Extent in diagonal "y" direction (may be negative to signify the area stretches upwards) ...
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
Represents the covered area of e.g.
Base class for tile iterators.
static T min(const T a, const T b)
Returns the minimum of two values.
TileIterator & operator++()
Move ourselves to the next tile in the rectangle on the map.
TileIndex tile
The base tile of the area.
static uint MapSize()
Get the size of the map.
uint32 TileIndex
The index/ID of a Tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Type for storing the 'area' of something uses on the map.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
uint16 h
The height of the area.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?