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

feature_sorter.hpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9797aaea83187610046472209669530a15f89ecb (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
#pragma once
#include "generator/generate_info.hpp"

#include "geometry/point2d.hpp"
#include "geometry/simplification.hpp"
#include "geometry/distance.hpp"

#include "indexer/scales.hpp"

#include "std/string.hpp"


namespace feature
{
  /// Final generation of data from input feature-dat-file.
  /// @param path - path to folder with countries;
  /// @param name - name of generated country;
  bool GenerateFinalFeatures(feature::GenerateInfo const & info, string const & name, int mapType);

  template <class PointT>
  inline bool are_points_equal(PointT const & p1, PointT const & p2)
  {
    return p1 == p2;
  }

  template <>
  inline bool are_points_equal<m2::PointD>(m2::PointD const & p1, m2::PointD const & p2)
  {
    return AlmostEqualULPs(p1, p2);
  }

  class BoundsDistance : public m2::DistanceToLineSquare<m2::PointD>
  {
    m2::RectD const & m_rect;
    double m_eps;

  public:
    BoundsDistance(m2::RectD const & rect)
      : m_rect(rect), m_eps(5.0E-7)
    {
      // 5.0E-7 is near with minimal epsilon when integer points are different
      // PointD2PointU(x, y) != PointD2PointU(x + m_eps, y + m_eps)
    }

    double GetEpsilon() const { return m_eps; }

    double operator() (m2::PointD const & p) const
    {
      if (fabs(p.x - m_rect.minX()) <= m_eps || fabs(p.x - m_rect.maxX()) <= m_eps ||
          fabs(p.y - m_rect.minY()) <= m_eps || fabs(p.y - m_rect.maxY()) <= m_eps)
      {
        // points near rect should be in a result simplified vector
        return numeric_limits<double>::max();
      }

      return m2::DistanceToLineSquare<m2::PointD>::operator()(p);
    }
  };

  template <class DistanceT, class PointsContainerT>
  void SimplifyPoints(DistanceT dist, PointsContainerT const & in, PointsContainerT & out, int level)
  {
    if (in.size() >= 2)
    {
      double const eps = my::sq(scales::GetEpsilonForSimplify(level));

      SimplifyNearOptimal(20, in.begin(), in.end(), eps, dist,
                          AccumulateSkipSmallTrg<DistanceT, m2::PointD>(dist, out, eps));

      CHECK_GREATER ( out.size(), 1, () );
      CHECK ( are_points_equal(in.front(), out.front()), () );
      CHECK ( are_points_equal(in.back(), out.back()), () );
    }
  }
}