Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tile_utils.cpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24961035812dd66ff8be8febdbd267c3de4b3d4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "drape_frontend/tile_utils.hpp"

#include "indexer/scales.hpp"

#include "geometry/mercator.hpp"

#include "base/assert.hpp"
#include "base/stl_add.hpp"

namespace df
{

CoverageResult CalcTilesCoverage(m2::RectD const & rect, int targetZoom,
                                 function<void(int, int)> const & processTile)
{
  ASSERT_GREATER(targetZoom, 0, ());
  double const range = MercatorBounds::maxX - MercatorBounds::minX;
  double const rectSize = range / (1 << (targetZoom - 1));

  CoverageResult result;
  result.m_minTileX = static_cast<int>(floor(rect.minX() / rectSize));
  result.m_maxTileX = static_cast<int>(ceil(rect.maxX() / rectSize));
  result.m_minTileY = static_cast<int>(floor(rect.minY() / rectSize));
  result.m_maxTileY = static_cast<int>(ceil(rect.maxY() / rectSize));

  if (processTile != nullptr)
  {
    for (int tileY = result.m_minTileY; tileY < result.m_maxTileY; ++tileY)
      for (int tileX = result.m_minTileX; tileX < result.m_maxTileX; ++tileX)
        processTile(tileX, tileY);
  }

  return result;
}

bool IsNeighbours(TileKey const & tileKey1, TileKey const & tileKey2)
{
  return !((tileKey1.m_x == tileKey2.m_x) && (tileKey1.m_y == tileKey2.m_y)) &&
         (abs(tileKey1.m_x - tileKey2.m_x) < 2) &&
         (abs(tileKey1.m_y - tileKey2.m_y) < 2);
}

int ClipTileZoomByMaxDataZoom(int zoom)
{
  int const upperScale = scales::GetUpperScale();
  return zoom <= upperScale ? zoom : upperScale;
}

TileKey GetTileKeyByPoint(m2::PointD const & pt, int zoom)
{
  ASSERT_GREATER(zoom, 0, ());
  double const range = MercatorBounds::maxX - MercatorBounds::minX;
  double const rectSize = range / (1 << (zoom - 1));
  return TileKey(static_cast<int>(floor(pt.x / rectSize)),
                 static_cast<int>(floor(pt.y / rectSize)), zoom);
}

} // namespace df