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

index_helpers.cpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b95fd7bc259e081cea028a2253da907cae757a64 (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
#include "indexer/index_helpers.hpp"
#include "indexer/index.hpp"
#include "indexer/feature_algo.hpp"
#include "indexer/scales.hpp"

namespace indexer
{
void ForEachFeatureAtPoint(Index const & index, function<void(FeatureType &)> && fn, m2::PointD const & mercator, double toleranceInMeters)
{
  double constexpr kSelectRectWidthInMeters = 1.1;
  double constexpr kMetersToLinearFeature = 3;
  int constexpr kScale = scales::GetUpperScale();
  m2::RectD const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(mercator, kSelectRectWidthInMeters);

  auto const emitter = [&fn, &rect, &mercator, kScale, kMetersToLinearFeature, toleranceInMeters](FeatureType & ft)
  {
   switch (ft.GetFeatureType())
   {
     case feature::GEOM_POINT:
       if (rect.IsPointInside(ft.GetCenter()))
         fn(ft);
       break;
     case feature::GEOM_LINE:
       if (feature::GetMinDistanceMeters(ft, mercator) < kMetersToLinearFeature)
         fn(ft);
       break;
     case feature::GEOM_AREA:
     {
       auto limitRect = ft.GetLimitRect(kScale);
       // Be a little more tolerant. When used by editor mercator is given
       // with some error, so we must extend limit rect a bit.
       limitRect.Inflate(MercatorBounds::GetCellID2PointAbsEpsilon(),
                         MercatorBounds::GetCellID2PointAbsEpsilon());
       if (limitRect.IsPointInside(mercator) &&
           feature::GetMinDistanceMeters(ft, mercator) <= toleranceInMeters)
       {
         fn(ft);
       }
     }
       break;
     case feature::GEOM_UNDEFINED:
       ASSERT(false, ("case feature::GEOM_UNDEFINED"));
       break;
   }
  };

  index.ForEachInRect(emitter, rect, kScale);
}
}  // namespace indexer