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

data_source_helpers.cpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f17f22072fb1d4e5be34609a0f10c32367b5a678 (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/data_source_helpers.hpp"

#include "indexer/data_source.hpp"
#include "indexer/feature_algo.hpp"
#include "indexer/scales.hpp"

namespace indexer
{
void ForEachFeatureAtPoint(DataSource const & dataSource, 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, 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;
    }
  };

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