# HG changeset patch # User terkhen # Date 1322943573 0 # Node ID 8e86f44a113062f4c3b28cd99eb17676862c82f6 # Parent 436f5b4137d4fe856c1e0e592b3aec25fcbe7fa3 (svn r23402) -Add: Function to check if a TileArea contains a tile. (michi_cc) diff --git a/src/tilearea.cpp b/src/tilearea.cpp --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -94,6 +94,25 @@ } /** + * Does this tile area contain a tile? + * @param tile Tile to test for. + * @return True if the tile is inside the area. + */ +bool TileArea::Contains(TileIndex tile) const +{ + if (this->w == 0) return false; + + assert(this->w != 0 && this->h != 0); + + uint left = TileX(this->tile); + uint top = TileY(this->tile); + uint tile_x = TileX(tile); + uint tile_y = TileY(tile); + + return IsInsideBS(tile_x, left, this->w) && IsInsideBS(tile_y, top, this->h); +} + +/** * Clamp the tile area to map borders. */ void TileArea::ClampToMap() diff --git a/src/tilearea_type.h b/src/tilearea_type.h --- a/src/tilearea_type.h +++ b/src/tilearea_type.h @@ -48,6 +48,8 @@ bool Intersects(const TileArea &ta) const; + bool Contains(TileIndex tile) const; + void ClampToMap(); /**