public static Rectangle GetBounds(MapTile tile, TmpFile tmp)
{
if (tmp == null) return Rectangle.Empty;
tmp.Initialize();
if (tile.SubTile >= tmp.Images.Count) return Rectangle.Empty;
var img = tmp.Images[tile.SubTile];
int left = tile.Dx * tmp.BlockWidth / 2;
int top = (tile.Dy - tile.Z) * tmp.BlockHeight / 2;
int width = tmp.BlockWidth;
int height = tmp.BlockHeight;
if (img.HasExtraData) {
if (img.ExtraX < 0) { left += img.ExtraX; width -= img.ExtraX; }
if (img.ExtraY < 0) { top += img.ExtraY; height -= img.ExtraY; }
width = Math.Max(width, img.ExtraWidth);
height = Math.Max(height, img.ExtraHeight);
}
return new Rectangle(left, top, width, height);
}