implements #949, wrong duration on first segment

This commit is contained in:
Dennis Luxen
2014-05-27 16:54:10 +02:00
parent 1090325c31
commit 38ebdbb563
8 changed files with 49 additions and 43 deletions
+8 -4
View File
@@ -38,17 +38,21 @@ std::vector<unsigned> const & DescriptionFactory::GetViaIndices() const
}
void DescriptionFactory::SetStartSegment(const PhantomNode &source)
void DescriptionFactory::SetStartSegment(const PhantomNode &source, const bool traversed_in_reverse)
{
start_phantom = source;
AppendSegment(source.location, PathData(0, source.name_id, TurnInstruction::HeadOn, source.forward_weight));
const EdgeWeight segment_duration = (!traversed_in_reverse ? source.forward_weight : source.reverse_weight);
AppendSegment(source.location, PathData(0, source.name_id, TurnInstruction::HeadOn, segment_duration));
BOOST_ASSERT(path_description.back().duration == segment_duration);
}
void DescriptionFactory::SetEndSegment(const PhantomNode &target)
void DescriptionFactory::SetEndSegment(const PhantomNode &target, const bool traversed_in_reverse)
{
target_phantom = target;
const EdgeWeight segment_duration = (traversed_in_reverse ? target.reverse_weight : target.forward_weight);
path_description.emplace_back(
target.location, target.name_id, 0, target.reverse_weight, TurnInstruction::NoTurn, true, true);
target.location, target.name_id, segment_duration, 0, TurnInstruction::NoTurn, true, true);
BOOST_ASSERT(path_description.back().duration == segment_duration);
}
void DescriptionFactory::AppendSegment(const FixedPointCoordinate &coordinate,
+5 -2
View File
@@ -81,8 +81,8 @@ class DescriptionFactory
JSON::Value AppendUnencodedPolylineString() const;
void AppendSegment(const FixedPointCoordinate &coordinate, const PathData &data);
void BuildRouteSummary(const double distance, const unsigned time);
void SetStartSegment(const PhantomNode &start_phantom);
void SetEndSegment(const PhantomNode &start_phantom);
void SetStartSegment(const PhantomNode &start_phantom, const bool traversed_in_reverse);
void SetEndSegment(const PhantomNode &start_phantom, const bool traversed_in_reverse);
JSON::Value AppendEncodedPolylineString(const bool return_encoded);
std::vector<unsigned> const & GetViaIndices() const;
@@ -155,6 +155,7 @@ class DescriptionFactory
entireLength += path_description[i].length;
segment_length += path_description[i].length;
segment_duration += path_description[i].duration;
SimpleLogger().Write() << "length: " << path_description[i].length << ", duration: " << path_description[i].duration;
path_description[segment_start_index].length = segment_length;
path_description[segment_start_index].duration = segment_duration;
@@ -172,6 +173,7 @@ class DescriptionFactory
{
if (path_description.size() > 2)
{
SimpleLogger().Write() << "removing last segment";
path_description.pop_back();
path_description.back().necessary = true;
path_description.back().turn_instruction = TurnInstruction::NoTurn;
@@ -182,6 +184,7 @@ class DescriptionFactory
{
if (path_description.size() > 2)
{
SimpleLogger().Write() << "removing first segment";
path_description.erase(path_description.begin());
path_description.front().turn_instruction = TurnInstruction::HeadOn;
path_description.front().necessary = true;
+9 -5
View File
@@ -73,7 +73,7 @@ template <class DataFacadeT> class JSONDescriptor : public BaseDescriptor<DataFa
void SetConfig(const DescriptorConfig &c) { config = c; }
unsigned DescribeLeg(const std::vector<PathData> route_leg, const PhantomNodes &leg_phantoms)
unsigned DescribeLeg(const std::vector<PathData> route_leg, const PhantomNodes &leg_phantoms, const bool target_traversed_in_reverse)
{
unsigned added_element_count = 0;
// Get all the coordinates for the computed route
@@ -84,7 +84,7 @@ template <class DataFacadeT> class JSONDescriptor : public BaseDescriptor<DataFa
description_factory.AppendSegment(current_coordinate, path_data);
++added_element_count;
}
description_factory.SetEndSegment(leg_phantoms.target_phantom);
description_factory.SetEndSegment(leg_phantoms.target_phantom, target_traversed_in_reverse);
++added_element_count;
BOOST_ASSERT((route_leg.size() + 1) == added_element_count);
return added_element_count;
@@ -109,7 +109,8 @@ template <class DataFacadeT> class JSONDescriptor : public BaseDescriptor<DataFa
BOOST_ASSERT(raw_route.unpacked_path_segments.size() ==
raw_route.segment_end_coordinates.size());
description_factory.SetStartSegment(raw_route.segment_end_coordinates.front().source_phantom);
description_factory.SetStartSegment(raw_route.segment_end_coordinates.front().source_phantom,
raw_route.source_traversed_in_reverse.front());
json_result.values["status"] = 0;
json_result.values["status_message"] = "Found route between points";
@@ -120,7 +121,8 @@ template <class DataFacadeT> class JSONDescriptor : public BaseDescriptor<DataFa
const int added_segments =
#endif
DescribeLeg(raw_route.unpacked_path_segments[i],
raw_route.segment_end_coordinates[i]);
raw_route.segment_end_coordinates[i],
raw_route.target_traversed_in_reverse[i]);
BOOST_ASSERT(0 < added_segments);
}
description_factory.Run(facade, config.zoom_level);
@@ -175,7 +177,9 @@ template <class DataFacadeT> class JSONDescriptor : public BaseDescriptor<DataFa
if (INVALID_EDGE_WEIGHT != raw_route.alternative_path_length)
{
json_result.values["found_alternative"] = JSON::True();
alternate_description_factory.SetStartSegment(raw_route.segment_end_coordinates.front().source_phantom);
BOOST_ASSERT(!raw_route.alt_source_traversed_in_reverse.empty());
alternate_description_factory.SetStartSegment(raw_route.segment_end_coordinates.front().source_phantom,
raw_route.alt_source_traversed_in_reverse.front());
// Get all the coordinates for the computed route
for (const PathData &path_data : raw_route.unpacked_alternative)
{