summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2011-12-03 20:19:33 +0000
committerterkhen <terkhen@openttd.org>2011-12-03 20:19:33 +0000
commitbf1b6d570b19938279435a32a089448a7dd0a792 (patch)
treec2b51d14ab601f2ce64416183fb04742c30a525d /src
parentc792125d6ae4dcc6abc76c095a781cb418e7658c (diff)
downloadopenttd-bf1b6d570b19938279435a32a089448a7dd0a792.tar.xz
(svn r23402) -Add: Function to check if a TileArea contains a tile. (michi_cc)
Diffstat (limited to 'src')
-rw-r--r--src/tilearea.cpp19
-rw-r--r--src/tilearea_type.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/src/tilearea.cpp b/src/tilearea.cpp
index 29a164351..e6efd0559 100644
--- a/src/tilearea.cpp
+++ b/src/tilearea.cpp
@@ -94,6 +94,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.
*/
void TileArea::ClampToMap()
diff --git a/src/tilearea_type.h b/src/tilearea_type.h
index 46a093fc6..5826ce116 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();
/**