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

routing_helpers_tests.cpp « routing_tests « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 16597911ad6d6db39999ecf0a9534f18e6d0d3ea (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "testing/testing.hpp"

#include "routing/road_graph.hpp"
#include "routing/route.hpp"
#include "routing/road_graph.hpp"
#include "routing/routing_helpers.hpp"
#include "routing/segment.hpp"
#include "routing/turns.hpp"

#include "indexer/feature_altitude.hpp"

#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"

#include <vector>

namespace routing_test
{
using namespace routing::turns;
using namespace routing;
using namespace std;

UNIT_TEST(FillSegmentInfoSmokeTest)
{
  vector<Segment> const segments = {
      {0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */}};
  vector<Junction> const junctions = {
      {m2::PointD(0.0 /* x */, 0.0 /* y */), feature::kInvalidAltitude},
      {m2::PointD(0.1 /* x */, 0.0 /* y */), feature::kInvalidAltitude}};
  Route::TTurns const & turnDirs = {{1 /* point index */, CarDirection::ReachedYourDestination}};
  Route::TStreets const streets = {};
  Route::TTimes const times = {{0 /* point index */, 0.0 /* time in seconds */}, {1, 1.0}};

  vector<RouteSegment> segmentInfo;
  FillSegmentInfo(segments, junctions, turnDirs, streets, times, nullptr, segmentInfo);

  TEST_EQUAL(segmentInfo.size(), 1, ());
  TEST_EQUAL(segmentInfo[0].GetTurn().m_turn, CarDirection::ReachedYourDestination, ());
  TEST(segmentInfo[0].GetStreet().empty(), ());
}

UNIT_TEST(FillSegmentInfoTest)
{
  vector<Segment> const segments = {
      {0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */}, {0, 2, 0, true}};
  vector<Junction> const junctions = {
      {m2::PointD(0.0 /* x */, 0.0 /* y */), feature::kInvalidAltitude},
      {m2::PointD(0.1 /* x */, 0.0 /* y */), feature::kInvalidAltitude},
      {m2::PointD(0.2 /* x */, 0.0 /* y */), feature::kInvalidAltitude}};
  Route::TTurns const & turnDirs = {{1 /* point index */, CarDirection::TurnRight},
                                    {2 /* point index */, CarDirection::ReachedYourDestination}};
  Route::TStreets const streets = {{0 /* point index */, "zero"}, {1, "first"}, {2, "second"}};
  Route::TTimes const times = {
      {0 /* point index */, 0.0 /* time in seconds */}, {1, 1.0}, {2, 2.0}};

  vector<RouteSegment> segmentInfo;
  FillSegmentInfo(segments, junctions, turnDirs, streets, times, nullptr, segmentInfo);

  TEST_EQUAL(segmentInfo.size(), 2, ());
  TEST_EQUAL(segmentInfo[0].GetTurn().m_turn, CarDirection::TurnRight, ());
  TEST_EQUAL(segmentInfo[0].GetStreet(), string("first"), ());
  TEST_EQUAL(segmentInfo[0].GetSegment(), segments[0], ());

  TEST_EQUAL(segmentInfo[1].GetTurn().m_turn, CarDirection::ReachedYourDestination, ());
  TEST_EQUAL(segmentInfo[1].GetStreet(), string("second"), ());
  TEST_EQUAL(segmentInfo[1].GetSegment(), segments[1], ());
}

UNIT_TEST(PolylineInRectTest)
{
  // Empty polyline.
  TEST(!RectCoversPolyline({}, m2::RectD()), ());
  TEST(!RectCoversPolyline({}, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());

  // One point polyline outside the rect.
  {
    auto const junctions = IRoadGraph::JunctionVec({{m2::PointD(3.0, 3.0), 0 /* altitude */}});
    TEST(!RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
  }

  // One point polyline inside the rect.
  {
    auto const junctions = IRoadGraph::JunctionVec({{m2::PointD(1.0, 1.0), 0 /* altitude */}});
    TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
  }

  // One point polyline on the rect border.
  {
    auto const junctions = IRoadGraph::JunctionVec({{m2::PointD(0.0, 0.0), 0 /* altitude */}});
    TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
  }

  // Two point polyline touching the rect border.
  {
    auto const junctions = IRoadGraph::JunctionVec({
        {m2::PointD(-1.0, -1.0), 0 /* altitude */},
        {m2::PointD(0.0, 0.0), 0 /* altitude */},
    });
    TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
  }

  // Crossing rect by a segment but no polyline points inside the rect.
  {
    auto const junctions = IRoadGraph::JunctionVec({
        {m2::PointD(-1.0, -1.0), 0 /* altitude */},
        {m2::PointD(5.0, 5.0), 0 /* altitude */},
    });
    TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
  }

  {
    auto const junctions = IRoadGraph::JunctionVec({
        {m2::PointD(0.0, 1.0), 0 /* altitude */},
        {m2::PointD(100.0, 2.0), 0 /* altitude */},
    });
    TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 100.0, 1.0)), ());
  }

  // Crossing a rect very close to a corner.
  {
    auto const junctions = IRoadGraph::JunctionVec({
        {m2::PointD(-1.0, 0.0), 0 /* altitude */},
        {m2::PointD(1.0, 1.9), 0 /* altitude */},
    });
    TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 1.0, 1.0)), ());
  }

  // Three point polyline crossing the rect.
  {
    auto const junctions = IRoadGraph::JunctionVec({
        {m2::PointD(0.0, -1.0), 0 /* altitude */},
        {m2::PointD(1.0, 0.01), 0 /* altitude */},
        {m2::PointD(2.0, -1.0), 0 /* altitude */},
    });
    TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 1.0, 1.0)), ());
  }
}
}  // namespace routing_test