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

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

#include "routing/index_graph.hpp"
#include "routing/world_graph.hpp"

#include "geometry/mercator.hpp"
#include "geometry/parametrized_segment.hpp"

#include "base/math.hpp"

#include <utility>

using namespace routing;
using namespace std;

namespace
{
Junction CalcProjectionToSegment(Junction const & begin, Junction const & end,
                                 m2::PointD const & point)
{
  m2::ParametrizedSegment<m2::PointD> segment(begin.GetPoint(), end.GetPoint());

  auto const projectedPoint = segment.ClosestPointTo(point);
  auto const distBeginToEnd = MercatorBounds::DistanceOnEarth(begin.GetPoint(), end.GetPoint());

  double constexpr kEpsMeters = 2.0;
  if (base::AlmostEqualAbs(distBeginToEnd, 0.0, kEpsMeters))
    return Junction(projectedPoint, begin.GetAltitude());

  auto const distBeginToProjection =
      MercatorBounds::DistanceOnEarth(begin.GetPoint(), projectedPoint);
  auto const altitude = begin.GetAltitude() + (end.GetAltitude() - begin.GetAltitude()) *
                                                  distBeginToProjection / distBeginToEnd;
  return Junction(projectedPoint, altitude);
}

FakeEnding MakeFakeEndingImpl(Junction const & segmentBack, Junction const & segmentFront,
                              Segment const & segment, m2::PointD const & point, bool oneWay)
{
  auto const & projectedJunction = CalcProjectionToSegment(segmentBack, segmentFront, point);

  FakeEnding ending;
  ending.m_originJunction = Junction(point, projectedJunction.GetAltitude());
  ending.m_projections.emplace_back(segment, oneWay, segmentFront, segmentBack, projectedJunction);
  return ending;
}
}  // namespace

namespace routing
{
FakeEnding MakeFakeEnding(Segment const & segment, m2::PointD const & point, IndexGraph & graph)
{
  auto const & road = graph.GetGeometry().GetRoad(segment.GetFeatureId());
  bool const oneWay = road.IsOneWay();
  auto const & frontJunction = road.GetJunction(segment.GetPointId(true /* front */));
  auto const & backJunction = road.GetJunction(segment.GetPointId(false /* front */));
  return MakeFakeEndingImpl(backJunction, frontJunction, segment, point, oneWay);
}

FakeEnding MakeFakeEnding(Segment const & segment, m2::PointD const & point, WorldGraph & graph)
{
  bool const oneWay = graph.IsOneWay(segment.GetMwmId(), segment.GetFeatureId());
  auto const & frontJunction = graph.GetJunction(segment, true /* front */);
  auto const & backJunction = graph.GetJunction(segment, false /* front */);
  return MakeFakeEndingImpl(backJunction, frontJunction, segment, point, oneWay);
}
}  // namespace routing