From fa210ceace46e5e7e9fddb1116029afb74dd2c46 Mon Sep 17 00:00:00 2001 From: terkhen Date: Sat, 3 Dec 2011 20:19:33 +0000 Subject: [PATCH] (svn r23402) -Add: Function to check if a TileArea contains a tile. (michi_cc) --- src/tilearea.cpp | 19 +++++++++++++++++++ src/tilearea_type.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/tilearea.cpp b/src/tilearea.cpp index 29a164351e..e6efd05593 100644 --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -93,6 +93,25 @@ bool TileArea::Intersects(const TileArea &ta) const ); } +/** + * 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. */ diff --git a/src/tilearea_type.h b/src/tilearea_type.h index 46a093fc6d..5826ce116f 100644 --- a/src/tilearea_type.h +++ b/src/tilearea_type.h @@ -48,6 +48,8 @@ struct TileArea { bool Intersects(const TileArea &ta) const; + bool Contains(TileIndex tile) const; + void ClampToMap(); /**