Skip to content

Commit

Permalink
Merge pull request #179 from marq24/revert-turn-instruction-merging
Browse files Browse the repository at this point in the history
removing the code that is merging turn instructions - Issue #177
  • Loading branch information
rabidllama authored Jun 6, 2018
2 parents fef06ae + b3e68fa commit 7251372
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 106 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- Fixed problem with avoid polygons excluding ways that should have been accepted (Issue #95)
- Updated code to remove merging of instructions as this resulted in missing important turn instructions (Issue #177)

### Changed
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public void testSteps() {
.body("routes[0].segments[0].containsKey('steps')", is(true))
.body("routes[0].segments[1].containsKey('steps')", is(true))
.body("routes[0].segments[0].steps.size()", is(55))
.body("routes[0].segments[1].steps.size()", is(31))
.body("routes[0].segments[1].steps.size()", is(33))
.statusCode(200);
}

Expand All @@ -588,7 +588,7 @@ public void testStepsDetails() {
.body("routes[0].segments[0].containsKey('steps')", is(true))
.body("routes[0].segments[1].containsKey('steps')", is(true))
.body("routes[0].segments[0].steps.size()", is(55))
.body("routes[0].segments[1].steps.size()", is(31))
.body("routes[0].segments[1].steps.size()", is(33))
.body("routes[0].segments[0].steps[0].distance", is(511.4f))
.body("routes[0].segments[0].steps[0].duration", is(230.1f))
.body("routes[0].segments[0].steps[0].type", is(11))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public RouteResult createRouteResult(List<GHResponse> routes, RoutingRequest req
// nInstructions -= 1;

Instruction instr, prevInstr = null;
InstructionType instrType, prevInstrType = InstructionType.UNKNOWN;
InstructionType instrType = InstructionType.UNKNOWN;
RouteSegment seg = new RouteSegment(path, units);

if (includeDetourFactor)
Expand All @@ -145,7 +145,6 @@ public RouteResult createRouteResult(List<GHResponse> routes, RoutingRequest req
seg.setDetourFactor((dist == 0) ? 0 : FormatUtility.roundToDecimals(path.getDistance()/dist, 2));
}

RouteStep prevStep = null;
String instrText = "";
double stepDistance, stepDuration;

Expand Down Expand Up @@ -217,49 +216,19 @@ else if (instrType == InstructionType.FINISH)
}


// merge route steps with similar names
// example: http://localhost:8082/openrouteservice-4.0.0/routes?profile=driving-car&coordinates=8.690614,49.38365|8.7007,49.411699|8.7107,49.4516&prettify_instructions=true
if (prevStep != null && instrType == prevInstrType && canMergeInstructions(instr.getName(), prevInstr.getName()))
{
String mergedRoadName = mergeInstructions(instr.getName(), prevInstr.getName());

int[] wayPoints = prevStep.getWayPoints();
wayPoints[1] = wayPoints[1] + instr.getPoints().size();

stepDuration = FormatUtility.roundToDecimals(instr.getTime()/1000.0, 1);
_nameAppendix = null;

prevStep.setDistance(FormatUtility.roundToDecimals(DistanceUnitUtil.convert(prevStep.getDistance() + stepDistance, DistanceUnit.Meters, units), unitDecimals));
prevStep.setDuration(FormatUtility.roundToDecimals(prevStep.getDuration() + stepDuration, 1));
prevStep.setName(mergedRoadName);

if (_nameAppendix != null)
mergedRoadName += " ("+ _nameAppendix + ")";
if (formatInstructions)
mergedRoadName = "<b>" + mergedRoadName + "</b>";
step.setDistance(stepDistance);
step.setDuration(stepDuration);
step.setInstruction(instrText);
step.setName(instr.getName());
step.setType(instrType.ordinal());
step.setWayPoints(new int[] { startWayPointIndex, getWayPointEndIndex(startWayPointIndex, instrType, instr)});

prevStep.setInstruction(instrTranslator.getContinue(instrType, mergedRoadName));
if (request.getIncludeManeuvers())
step.setManeuver(calcManeuver(instrType, prevSegPoints, segPoints, nextSegPoints));

//if (request.getIncludeManeuvers())
// prevStep.setManeuver(computeManeuver(prevSegPoints, segPoints));
}
else
{
_nameAppendix = null;

step.setDistance(stepDistance);
step.setDuration(stepDuration);
step.setInstruction(instrText);
step.setName(instr.getName());
step.setType(instrType.ordinal());
step.setWayPoints(new int[] { startWayPointIndex, getWayPointEndIndex(startWayPointIndex, instrType, instr)});

if (request.getIncludeManeuvers())
step.setManeuver(calcManeuver(instrType, prevSegPoints, segPoints, nextSegPoints));

seg.addStep(step);

prevStep = step;
}
seg.addStep(step);

// step.setMessage(message);
// add message and message type
Expand All @@ -271,7 +240,6 @@ else if (instrType == InstructionType.FINISH)
distanceActual += stepDistance;

prevInstr = instr;
prevInstrType = instrType;
prevSegPoints = segPoints;
}

Expand Down Expand Up @@ -449,67 +417,6 @@ private RouteStepManeuver calcManeuver(InstructionType instrType, PointList prev
return maneuver;
}

private boolean canMergeInstructions(String name, String prevName)
{
if (prevName == null)
return false;

if (name.length() > prevName.length())
{
int pos = name.indexOf(prevName);
if (pos >= 0 && !Helper.isEmpty(prevName))
return true;
}
else
{
int pos = prevName.indexOf(name);
if (pos >= 0 && !Helper.isEmpty(name))
return true;
}

return false;
}

private String mergeInstructionsOrdered(String name, String prevName)
{
int pos = name.indexOf(prevName);
if (pos >= 0)
{
pos = pos + prevName.length() + 1;
if (pos < name.length())
{
String appendix = name.substring(pos, name.length());

if (appendix.length() > 1 && appendix.startsWith(","))
appendix = appendix.substring(1);

appendix = appendix.trim();

if (isValidAppendix(appendix))
{
if (_nameAppendix != null)
_nameAppendix += ", ";
else
_nameAppendix = "";

_nameAppendix += appendix;
}

return prevName;
}
}

return name;
}

private String mergeInstructions(String name, String prevName)
{
if (name.length() > prevName.length())
return mergeInstructionsOrdered(name, prevName);
else
return mergeInstructionsOrdered(prevName, name);
}

private boolean isValidAppendix(String name)
{
if (name == null)
Expand Down

0 comments on commit 7251372

Please sign in to comment.