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

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

#include "indexer/classificator.hpp"
#include "indexer/data_source.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "indexer/scales.hpp"

#include "coding/read_write_utils.hpp"
#include "coding/reader.hpp"
#include "coding/writer.hpp"

#include "base/string_utils.hpp"
#include "base/math.hpp"

#include "std/limits.hpp"

namespace
{
double constexpr kCameraCheckRadiusMeters = 2.0;
double constexpr kCoordinateEqualityDelta = 0.000001;
}  // namespace

namespace routing
{
uint8_t const kNoSpeedCamera = numeric_limits<uint8_t>::max();

uint8_t ReadCameraRestriction(FeatureType & ft)
{
  using feature::Metadata;
  feature::Metadata const & md = ft.GetMetadata();
  string const & speed = md.Get(Metadata::FMD_MAXSPEED);
  if (speed.empty())
    return 0;
  int result;
  if (strings::to_int(speed, result))
    return result;
  return 0;
}

uint8_t CheckCameraInPoint(m2::PointD const & point, DataSource const & dataSource)
{
  uint32_t speedLimit = kNoSpeedCamera;

  auto const f = [&point, &speedLimit](FeatureType & ft) {
    if (ft.GetFeatureType() != feature::GEOM_POINT)
      return;

    feature::TypesHolder hl = ft;
    if (!ftypes::IsSpeedCamChecker::Instance()(hl))
      return;

    if (my::AlmostEqualAbs(ft.GetCenter().x, point.x, kCoordinateEqualityDelta) &&
        my::AlmostEqualAbs(ft.GetCenter().y, point.y, kCoordinateEqualityDelta))
      speedLimit = ReadCameraRestriction(ft);
  };

  dataSource.ForEachInRect(
      f, MercatorBounds::RectByCenterXYAndSizeInMeters(point, kCameraCheckRadiusMeters),
      scales::GetUpperScale());
  return speedLimit;
}
}  // namespace routing