OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
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);
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
TileIndex tile
The current tile we are at.
constexpr void Swap(T &a, T &b)
Type safe swap operation.
OrthogonalTileArea(TileIndex tile=INVALID_TILE, uint16_t w=0, uint16_t h=0)
Construct this tile area with some set values.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
int b_cur
The current (rotated) y coordinate of the iteration.
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
uint base_x
The base tile x coordinate from where the iterating happens.
int16_t a
Extent in diagonal "x" direction (may be negative to signify the area stretches to the left)
uint16_t h
The height of the area.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
bool Intersects(const OrthogonalTileArea &ta) const
Does this tile area intersect with another?
Iterator to iterate over a tile area (rectangle) of the map.
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.
Base class for tile iterators.
OrthogonalTileIterator begin() const
Returns an iterator to the beginning 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.
Represents the covered area of e.g.
uint base_y
The base tile y coordinate from where the iterating happens.
OrthogonalTileIterator end() const
Returns an iterator to the end of the tile area.
int a_max
The (rotated) x coordinate of the end of the iteration.
static debug_inline uint SizeX()
Get the size of the map along the X.
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
static debug_inline uint Size()
Get the size of the map.
TileIndex tile
The base tile of the area.
uint16_t w
The width of the area.
TileIndex tile
Base tile of the area.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
void ClampToMap()
Clamp the tile area to map borders.
int16_t b
Extent in diagonal "y" direction (may be negative to signify the area stretches upwards)
int b_max
The (rotated) y coordinate of the end of the iteration.
static uint SizeY()
Get the size of the map along the Y.
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
int a_cur
The current (rotated) x coordinate of the iteration.