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

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

#include "routing/segment.hpp"
#include "routing/turns.hpp"

#include "base/math.hpp"

#include <vector>

namespace ftypes
{
enum class HighwayClass;
}

namespace routing
{
namespace turns
{
/// \brief The TurnCandidate struct contains information about possible ways from a junction.
struct TurnCandidate
{

  /// |m_angle| is the angle of the turn in degrees. It means the angle is 180 minus
  /// the angle between the current edge and the edge of the candidate. A counterclockwise rotation.
  /// The current edge is an edge which belongs to the route and is located before the junction.
  /// |m_angle| belongs to the range [-180; 180];
  double m_angle;

  /// |m_segment| is the first segment of a possible way from the junction.
  Segment m_segment;

  /// \brief highwayClass field for the road class caching. Because feature reading is a long
  /// function.
  ftypes::HighwayClass m_highwayClass;

  /// If |isLink| is true then the turn candidate is a link.
  bool m_isLink;

  TurnCandidate(double angle, Segment const & segment, ftypes::HighwayClass c, bool isLink)
    : m_angle(angle), m_segment(segment), m_highwayClass(c), m_isLink(isLink)
  {
  }

  bool IsAlmostEqual(TurnCandidate const & rhs) const
  {
    double constexpr kEpsilon = 0.01;
    return my::AlmostEqualAbs(m_angle, rhs.m_angle, kEpsilon) && m_segment == rhs.m_segment &&
           m_highwayClass == rhs.m_highwayClass && m_isLink == rhs.m_isLink;
  }
};

inline bool IsAlmostEqual(std::vector<TurnCandidate> const & lhs, std::vector<TurnCandidate> const & rhs)
{
  if (lhs.size() != rhs.size())
    return false;

  for (size_t i = 0; i < lhs.size(); ++i)
  {
    if (!lhs[i].IsAlmostEqual(rhs[i]))
      return false;
  }
  return true;
}

struct TurnCandidates
{
  std::vector<TurnCandidate> candidates;
  bool isCandidatesAngleValid;

  explicit TurnCandidates(bool angleValid = true) : isCandidatesAngleValid(angleValid) {}

  bool IsAlmostEqual(TurnCandidates const & rhs) const
  {
    return turns::IsAlmostEqual(candidates, rhs.candidates) &&
           isCandidatesAngleValid == rhs.isCandidatesAngleValid;
  }
};
}  // namespace routing
}  // namespace turns