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

geometry_cache.cpp « v2 « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2884e76aa1f380e16ec396f42871589fb945a993 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "search/v2/geometry_cache.hpp"

#include "search/geometry_utils.hpp"
#include "search/retrieval.hpp"
#include "search/v2/mwm_context.hpp"

#include "geometry/mercator.hpp"

namespace search
{
namespace v2
{
namespace
{
double constexpr kCellEps = MercatorBounds::GetCellID2PointAbsEpsilon();
}  // namespace

// GeometryCache -----------------------------------------------------------------------------------
GeometryCache::GeometryCache(size_t maxNumEntries, my::Cancellable const & cancellable)
  : m_maxNumEntries(maxNumEntries), m_cancellable(cancellable)
{
  CHECK_GREATER(m_maxNumEntries, 0, ());
}

void GeometryCache::InitEntry(MwmContext const & context, m2::RectD const & rect, int scale,
                              Entry & entry)
{
  entry.m_rect = rect;
  entry.m_cbv = v2::RetrieveGeometryFeatures(context, m_cancellable, rect, scale);
  entry.m_scale = scale;
}

// PivotRectsCache ---------------------------------------------------------------------------------
PivotRectsCache::PivotRectsCache(size_t maxNumEntries, my::Cancellable const & cancellable,
                                 double maxRadiusMeters)
  : GeometryCache(maxNumEntries, cancellable), m_maxRadiusMeters(maxRadiusMeters)
{
}

coding::CompressedBitVector const * PivotRectsCache::Get(MwmContext const & context,
                                                         m2::RectD const & rect, int scale)
{
  auto p = FindOrCreateEntry(context.GetId(), [&rect, &scale](Entry const & entry)
  {
    return scale == entry.m_scale &&
           (entry.m_rect.IsRectInside(rect) || IsEqualMercator(rect, entry.m_rect, kCellEps));
  });
  auto & entry = p.first;
  if (p.second)
  {
    m2::RectD normRect =
        MercatorBounds::RectByCenterXYAndSizeInMeters(rect.Center(), m_maxRadiusMeters);
    if (!normRect.IsRectInside(rect))
      normRect = rect;
    InitEntry(context, normRect, scale, entry);
  }
  return entry.m_cbv.get();
}

// LocalityRectsCache ------------------------------------------------------------------------------
LocalityRectsCache::LocalityRectsCache(size_t maxNumEntries, my::Cancellable const & cancellable)
  : GeometryCache(maxNumEntries, cancellable)
{
}

coding::CompressedBitVector const * LocalityRectsCache::Get(MwmContext const & context,
                                                            m2::RectD const & rect, int scale)
{
  auto p = FindOrCreateEntry(context.GetId(), [&rect, &scale](Entry const & entry)
  {
    return scale == entry.m_scale && IsEqualMercator(rect, entry.m_rect, kCellEps);
  });
  auto & entry = p.first;
  if (p.second)
    InitEntry(context, rect, scale, entry);
  return entry.m_cbv.get();
}
}  // namespace v2
}  // namespace search