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

cities_boundaries_table.hpp « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c1634ebe73aa55e04e4f8ddc1c25fe13d19ea81 (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
#pragma once

#include "indexer/city_boundary.hpp"
#include "indexer/feature_decl.hpp"

#include "geometry/point2d.hpp"

#include <cstdint>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

class DataSourceBase;

namespace feature
{
struct FeatureID;
}

namespace search
{
class CitiesBoundariesTable
{
public:
  class Boundaries
  {
  public:
    Boundaries() = default;

    Boundaries(std::vector<indexer::CityBoundary> const & boundaries, double eps)
      : m_boundaries(boundaries), m_eps(eps)
    {
    }

    Boundaries(std::vector<indexer::CityBoundary> && boundaries, double eps)
      : m_boundaries(std::move(boundaries)), m_eps(eps)
    {
    }

    // Returns true iff |p| is inside any of the regions bounded by
    // |*this|.
    bool HasPoint(m2::PointD const & p) const;

    friend std::string DebugPrint(Boundaries const & boundaries)
    {
      std::ostringstream os;
      os << "Boundaries [";
      os << ::DebugPrint(boundaries.m_boundaries) << ", ";
      os << "eps: " << boundaries.m_eps;
      os << "]";
      return os.str();
    }

  private:
    std::vector<indexer::CityBoundary> m_boundaries;
    double m_eps = 0.0;
  };

  explicit CitiesBoundariesTable(DataSourceBase const & dataSource) : m_dataSource(dataSource) {}

  bool Load();

  bool Has(FeatureID const & fid) const { return fid.m_mwmId == m_mwmId && Has(fid.m_index); }
  bool Has(uint32_t fid) const { return m_table.find(fid) != m_table.end(); }

  bool Get(FeatureID const & fid, Boundaries & bs) const;
  bool Get(uint32_t fid, Boundaries & bs) const;

private:
  DataSourceBase const & m_dataSource;
  MwmSet::MwmId m_mwmId;
  std::unordered_map<uint32_t, std::vector<indexer::CityBoundary>> m_table;
  double m_eps = 0.0;
};
}  // namespace search