Changeset - r18548:bf70837bd31f
[Not reviewed]
master
0 2 0
terkhen - 12 years ago 2011-12-03 20:19:33
terkhen@openttd.org
(svn r23402) -Add: Function to check if a TileArea contains a tile. (michi_cc)
2 files changed with 21 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/tilearea.cpp
Show inline comments
 
@@ -94,6 +94,25 @@ bool TileArea::Intersects(const TileArea
 
}
 

	
 
/**
 
 * 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()
src/tilearea_type.h
Show inline comments
 
@@ -48,6 +48,8 @@ struct TileArea {
 

	
 
	bool Intersects(const TileArea &ta) const;
 

	
 
	bool Contains(TileIndex tile) const;
 

	
 
	void ClampToMap();
 

	
 
	/**
0 comments (0 inline, 0 general)