26 uint sx =
TileX(start);
27 uint sy =
TileY(start);
31 if (sx > ex) std::swap(sx, ex);
32 if (sy > ey) std::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;
91 return !(left2 > right1 || right2 < left1 || top2 > bottom1 || bottom2 < top1);
101 if (this->
w == 0)
return false;
103 assert(this->
w != 0 && this->
h != 0);
105 uint left =
TileX(this->tile);
106 uint top =
TileY(this->tile);
123 int sx = std::max<int>(x - rad, 0);
124 int sy = std::max<int>(y - rad, 0);
125 int ex = std::min<int>(x + this->
w + rad,
Map::SizeX());
126 int ey = std::min<int>(y + this->
h + rad,
Map::SizeY());
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?
std::default_sentinel_t end() const
Returns an iterator to the end of the tile area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the 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.
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.
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.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
static uint SizeX()
Get the size of the map along the X.
static uint SizeY()
Get the size of the map along the Y.
static uint Size()
Get the size of the map.
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.
Type for storing and iterating orthogonal tile areas.