From b76cb40daf030adef16c983654a0ee8fea259e37 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Tue, 19 Nov 2024 15:53:33 +0100 Subject: [PATCH 1/7] added vh for motorway exit --- .../main/java/btools/router/FormatGpx.java | 18 +++---- .../main/java/btools/router/FormatJson.java | 6 +-- .../main/java/btools/router/VoiceHint.java | 52 +++++++++++++++++-- .../btools/router/VoiceHintProcessor.java | 19 +++++++ docs/features/voicehints.md | 3 ++ 5 files changed, 81 insertions(+), 17 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/FormatGpx.java b/brouter-core/src/main/java/btools/router/FormatGpx.java index 06f8564..582cb44 100644 --- a/brouter-core/src/main/java/btools/router/FormatGpx.java +++ b/brouter-core/src/main/java/btools/router/FormatGpx.java @@ -49,7 +49,7 @@ public class FormatGpx extends Formatter { sb.append("\n"); sb.append("\n"); @@ -121,7 +121,7 @@ public class FormatGpx extends Formatter { sb.append(" \n") .append(" ") - .append(turnInstructionMode == 3 ? hint.getMessageString() : hint.getCruiserMessageString()) + .append(turnInstructionMode == 3 ? hint.getMessageString(turnInstructionMode) : hint.getCruiserMessageString()) .append("\n \n"); rteTime = t.getVoiceHintTime(i + 1); @@ -132,7 +132,7 @@ public class FormatGpx extends Formatter { lastRteTime = rteTime; } sb.append(" ") - .append(turnInstructionMode == 3 ? hint.getCommandString() : hint.getCruiserCommandString()) + .append(turnInstructionMode == 3 ? hint.getCommandString(turnInstructionMode) : hint.getCruiserCommandString()) .append("\n ").append("" + (int) hint.angle) .append("\n ").append("" + hint.indexInTrack).append("\n \n \n"); } @@ -154,7 +154,7 @@ public class FormatGpx extends Formatter { .append(formatILat(hint.ilat)).append("\">") .append(hint.selev == Short.MIN_VALUE ? "" : "" + (hint.selev / 4.) + "") .append("") - .append(hint.getMessageString()) + .append(hint.getMessageString(turnInstructionMode)) .append("") .append("").append("" + hint.distanceToNext).append(""); float rteTime = t.getVoiceHintTime(i + 1); @@ -173,9 +173,9 @@ public class FormatGpx extends Formatter { for (VoiceHint hint : t.voiceHints.list) { sb.append(" ") - .append("").append(hint.getMessageString()).append("") - .append("").append(hint.getSymbolString().toLowerCase()).append("") - .append("").append(hint.getSymbolString()).append("") + .append("").append(hint.getMessageString(turnInstructionMode)).append("") + .append("").append(hint.getSymbolString(turnInstructionMode).toLowerCase()).append("") + .append("").append(hint.getSymbolString(turnInstructionMode)).append("") .append("\n"); } } @@ -270,7 +270,7 @@ public class FormatGpx extends Formatter { sele += "" + mwpt.name + ""; } sele += "" + hint.getCruiserMessageString() + ""; - sele += "" + hint.getCommandString(hint.cmd) + ""; + sele += "" + hint.getCommandString(hint.cmd, turnInstructionMode) + ""; if (mwpt != null) { sele += "Via"; } @@ -287,7 +287,7 @@ public class FormatGpx extends Formatter { sele += "" + (((int) (speed * 10)) / 10.f) + ""; } - sele += "" + hint.getCommandString() + ";" + (int) (hint.distanceToNext) + "," + hint.formatGeometry() + ""; + sele += "" + hint.getCommandString(turnInstructionMode) + ";" + (int) (hint.distanceToNext) + "," + hint.formatGeometry() + ""; if (n.message != null && n.message.wayKeyValues != null && !n.message.wayKeyValues.equals(lastway)) { sele += "" + n.message.wayKeyValues + ""; lastway = n.message.wayKeyValues; diff --git a/brouter-core/src/main/java/btools/router/FormatJson.java b/brouter-core/src/main/java/btools/router/FormatJson.java index dc7dcd4..3c52d9a 100644 --- a/brouter-core/src/main/java/btools/router/FormatJson.java +++ b/brouter-core/src/main/java/btools/router/FormatJson.java @@ -41,13 +41,13 @@ public class FormatJson extends Formatter { for (VoiceHint hint : t.voiceHints.list) { sb.append(" ["); sb.append(hint.indexInTrack); - sb.append(',').append(hint.getJsonCommandIndex()); + sb.append(',').append(hint.getJsonCommandIndex(turnInstructionMode)); sb.append(',').append(hint.getExitNumber()); sb.append(',').append(hint.distanceToNext); sb.append(',').append((int) hint.angle); // not always include geometry because longer and only needed for comment style - if (turnInstructionMode == 4) { // comment style + if (turnInstructionMode == 4 || turnInstructionMode == 9) { // comment style sb.append(",\"").append(hint.formatGeometry()).append("\""); } @@ -122,7 +122,7 @@ public class FormatJson extends Formatter { .append(sele).append("],\n"); nn = n; } - if (t.nodes != null && !t.nodes.isEmpty()) sb.deleteCharAt(sb.lastIndexOf(",")); + sb.deleteCharAt(sb.lastIndexOf(",")); sb.append(" ]\n"); sb.append(" }\n"); diff --git a/brouter-core/src/main/java/btools/router/VoiceHint.java b/brouter-core/src/main/java/btools/router/VoiceHint.java index 09123a5..20a66f4 100644 --- a/brouter-core/src/main/java/btools/router/VoiceHint.java +++ b/brouter-core/src/main/java/btools/router/VoiceHint.java @@ -26,6 +26,8 @@ public class VoiceHint { static final int RNLB = 14; // Roundabout left static final int TU = 15; // 180 degree u-turn static final int BL = 16; // Beeline routing + static final int EL = 17; // Beeline routing + static final int ER = 18; // Beeline routing int ilon; int ilat; @@ -65,7 +67,7 @@ public class VoiceHint { badWays.add(badWay); } - public int getJsonCommandIndex() { + public int getJsonCommandIndex(int timode) { switch (cmd) { case TLU: return 10; @@ -97,6 +99,10 @@ public class VoiceHint { return 14; case BL: return 16; + case EL: + return timode == 2 || timode == 9 ? 17 : 8; + case ER: + return timode == 2 || timode == 9 ? 18 : 9; case OFFR: return 12; default: @@ -111,7 +117,7 @@ public class VoiceHint { /* * used by comment style, osmand style */ - public String getCommandString() { + public String getCommandString(int timode) { switch (cmd) { case TLU: return "TU"; // should be changed to TLU when osmand uses new voice hint constants @@ -143,6 +149,10 @@ public class VoiceHint { return "RNLB" + (-roundaboutExit); case BL: return "BL"; + case EL: + return timode == 2 || timode == 9 ? "EL" : "KL"; + case ER: + return timode == 2 || timode == 9 ? "ER" : "KR"; case OFFR: return "OFFR"; default: @@ -153,7 +163,7 @@ public class VoiceHint { /* * used by trkpt/sym style */ - public String getCommandString(int c) { + public String getCommandString(int c, int timode) { switch (c) { case TLU: return "TLU"; @@ -185,6 +195,10 @@ public class VoiceHint { return "RNLB" + (-roundaboutExit); case BL: return "BL"; + case EL: + return timode == 2 || timode == 9 ? "EL" : "KL"; + case ER: + return timode == 2 || timode == 9 ? "ER" : "KR"; case OFFR: return "OFFR"; default: @@ -195,7 +209,7 @@ public class VoiceHint { /* * used by gpsies style */ - public String getSymbolString() { + public String getSymbolString(int timode) { switch (cmd) { case TLU: return "TU"; @@ -227,6 +241,10 @@ public class VoiceHint { return "RNLB" + (-roundaboutExit); case BL: return "BL"; + case EL: + return timode == 2 || timode == 9 ? "EL" : "KL"; + case ER: + return timode == 2 || timode == 9 ? "ER" : "KR"; case OFFR: return "OFFR"; default: @@ -269,6 +287,10 @@ public class VoiceHint { return "roundabout_e" + (-roundaboutExit); case BL: return "beeline"; + case EL: + return "exit_left"; + case ER: + return "exit_right"; default: throw new IllegalArgumentException("unknown command: " + cmd); } @@ -277,7 +299,7 @@ public class VoiceHint { /* * used by osmand style */ - public String getMessageString() { + public String getMessageString(int timode) { switch (cmd) { case TLU: return "u-turn"; // should be changed to u-turn-left when osmand uses new voice hint constants @@ -307,6 +329,10 @@ public class VoiceHint { return "Take exit " + roundaboutExit; case RNLB: return "Take exit " + (-roundaboutExit); + case EL: + return timode == 2 || timode == 9 ? "exit left" : "keep left"; + case ER: + return timode == 2 || timode == 9 ? "exit right" : "keep right"; default: throw new IllegalArgumentException("unknown command: " + cmd); } @@ -345,6 +371,10 @@ public class VoiceHint { return 26 + roundaboutExit; case RNLB: return 26 - roundaboutExit; + case EL: + return 9; + case ER: + return 10; default: throw new IllegalArgumentException("unknown command: " + cmd); } @@ -383,6 +413,10 @@ public class VoiceHint { return 1008 + roundaboutExit; case RNLB: return 1008 + roundaboutExit; + case EL: + return 1015; + case ER: + return 1014; default: throw new IllegalArgumentException("unknown command: " + cmd); } @@ -423,6 +457,10 @@ public class VoiceHint { return "RNLB" + (-roundaboutExit); case BL: return "BL"; + case EL: + return "EL"; + case ER: + return "ER"; case OFFR: return "OFFR"; default: @@ -465,6 +503,10 @@ public class VoiceHint { return "take exit " + (-roundaboutExit); case BL: return "beeline"; + case EL: + return "exit left"; + case ER: + return "exit right"; case OFFR: return "offroad"; default: diff --git a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java index ebc61c7..ee2d905 100644 --- a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java +++ b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java @@ -334,6 +334,17 @@ public final class VoiceHintProcessor { inputLastSaved.distanceToNext += input.distanceToNext; } } + } else if ((input.goodWay.getPrio() == 29 && input.maxBadPrio == 30) && + ((hintIdx + 1 < inputs.size() && inputs.get(hintIdx+1).goodWay.getPrio() < 29) || + (hintIdx + 2 < inputs.size() && inputs.get(hintIdx+2).goodWay.getPrio() < 29))) { + // leave motorway + if (input.cmd == VoiceHint.KR || input.cmd == VoiceHint.TSLR) { + input.cmd = VoiceHint.ER; + } else if (input.cmd == VoiceHint.KL || input.cmd == VoiceHint.TSLL) { + input.cmd = VoiceHint.EL; + } + results.add(input); + inputLastSaved = input; } else { // add all others // ignore motorway / primary continue @@ -384,6 +395,14 @@ public final class VoiceHintProcessor { inputLastSaved.distanceToNext += input.distanceToNext; } } + } else if ((input.goodWay.getPrio() == 29 && input.maxBadPrio == 30)) { + // leave motorway + if (input.cmd == VoiceHint.KR || input.cmd == VoiceHint.TSLR) { + input.cmd = VoiceHint.ER; + } else if (input.cmd == VoiceHint.KL || input.cmd == VoiceHint.TSLL) { + input.cmd = VoiceHint.EL; + } + save = true; } else if (VoiceHint.is180DegAngle(input.angle)) { // add u-turn, 180 degree save = true; diff --git a/docs/features/voicehints.md b/docs/features/voicehints.md index f4c3e78..446190f 100644 --- a/docs/features/voicehints.md +++ b/docs/features/voicehints.md @@ -25,6 +25,7 @@ And there are other rules * merge two hints when near to each other - e.g. left, left to u-turn left * marker when highway exit and continue nearly same direction * beeline goes direct from via to via point +* junction on motorway via motorway_link and next way less then motorway_link is a motorway exit There are some variables in the profiles that affect on the voice hint generation: * considerTurnRestrictions - @@ -51,4 +52,6 @@ Voice hint variables | RNDB | roundabout | | RNLB | roundabout left | | BL | beeline routing | +| EL | exit left | +| ER | exit right | From 0056a9d0084f4ecc8b59234593994953ba352ae2 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Tue, 19 Nov 2024 17:48:00 +0100 Subject: [PATCH 2/7] changed comments --- brouter-core/src/main/java/btools/router/VoiceHint.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/VoiceHint.java b/brouter-core/src/main/java/btools/router/VoiceHint.java index 20a66f4..1fae285 100644 --- a/brouter-core/src/main/java/btools/router/VoiceHint.java +++ b/brouter-core/src/main/java/btools/router/VoiceHint.java @@ -26,8 +26,8 @@ public class VoiceHint { static final int RNLB = 14; // Roundabout left static final int TU = 15; // 180 degree u-turn static final int BL = 16; // Beeline routing - static final int EL = 17; // Beeline routing - static final int ER = 18; // Beeline routing + static final int EL = 17; // exit left + static final int ER = 18; // exit right int ilon; int ilat; From 5f86e2f2cde738217d2fcafd867273dcbcae9399 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Wed, 20 Nov 2024 20:50:10 +0100 Subject: [PATCH 3/7] added motorway exit check on short distance --- .../main/java/btools/router/VoiceHint.java | 4 + .../btools/router/VoiceHintProcessor.java | 73 ++++++++++++------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/VoiceHint.java b/brouter-core/src/main/java/btools/router/VoiceHint.java index 1fae285..691453c 100644 --- a/brouter-core/src/main/java/btools/router/VoiceHint.java +++ b/brouter-core/src/main/java/btools/router/VoiceHint.java @@ -29,6 +29,8 @@ public class VoiceHint { static final int EL = 17; // exit left static final int ER = 18; // exit right + static final int END = 100; // end point + int ilon; int ilat; short selev; @@ -155,6 +157,8 @@ public class VoiceHint { return timode == 2 || timode == 9 ? "ER" : "KR"; case OFFR: return "OFFR"; + case END: + return "END"; default: throw new IllegalArgumentException("unknown command: " + cmd); } diff --git a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java index ee2d905..e8526a2 100644 --- a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java +++ b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java @@ -72,6 +72,12 @@ public final class VoiceHintProcessor { results.add(input); continue; } + if (hintIdx == 0) { + input.cmd = VoiceHint.END; + results.add(input); + continue; + } + float turnAngle = input.goodWay.turnangle; distance += input.goodWay.linkdist; int currentPrio = input.goodWay.getPrio(); @@ -119,7 +125,7 @@ public final class VoiceHintProcessor { float tmpangle = 0; VoiceHint tmpRndAbt = new VoiceHint(); tmpRndAbt.badWays = new ArrayList<>(); - for (int i = hintIdx-1; i > roundaboudStartIdx; i--) { + for (int i = hintIdx - 1; i > roundaboudStartIdx; i--) { VoiceHint vh = inputs.get(i); tmpangle += inputs.get(i).goodWay.turnangle; if (vh.badWays != null) { @@ -172,12 +178,14 @@ public final class VoiceHintProcessor { } if (badWay.isBadOneway()) { - if (minAbsAngeRaw == 180f) minAbsAngeRaw = turnAngle; // disable hasSomethingMoreStraight + if (minAbsAngeRaw == 180f) + minAbsAngeRaw = turnAngle; // disable hasSomethingMoreStraight continue; // ignore wrong oneways } if (Math.abs(badTurn) - Math.abs(turnAngle) > 80.f) { - if (minAbsAngeRaw == 180f) minAbsAngeRaw = turnAngle; // disable hasSomethingMoreStraight + if (minAbsAngeRaw == 180f) + minAbsAngeRaw = turnAngle; // disable hasSomethingMoreStraight continue; // ways from the back should not trigger a slight turn } @@ -300,10 +308,12 @@ public final class VoiceHintProcessor { } if (nextInput == null) { - if ((input.cmd == VoiceHint.C || - input.cmd == VoiceHint.KR || - input.cmd == VoiceHint.KL) - && !input.goodWay.isLinktType()) { + if (input.cmd == VoiceHint.END) { + continue; + } else if ((input.cmd == VoiceHint.C || + input.cmd == VoiceHint.KR || + input.cmd == VoiceHint.KL) + && !input.goodWay.isLinktType()) { if (input.goodWay.getPrio() < input.maxBadPrio && (inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange)) { results.add(input); } else { @@ -318,14 +328,14 @@ public final class VoiceHintProcessor { } else { if ((inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange) || input.distanceToNext > catchingRange) { if ((input.cmd == VoiceHint.C || - input.cmd == VoiceHint.KR || - input.cmd == VoiceHint.KL) - && !input.goodWay.isLinktType()) { + input.cmd == VoiceHint.KR || + input.cmd == VoiceHint.KL) + && !input.goodWay.isLinktType()) { if (((Math.abs(input.lowerBadWayAngle) < 35.f || - input.higherBadWayAngle < 35.f) - || input.goodWay.getPrio() < input.maxBadPrio) - && (inputLastSaved != null && inputLastSaved.distanceToNext > minRange) - && (input.distanceToNext > minRange)) { + input.higherBadWayAngle < 35.f) + || input.goodWay.getPrio() < input.maxBadPrio) + && (inputLastSaved != null && inputLastSaved.distanceToNext > minRange) + && (input.distanceToNext > minRange)) { // add only on prio results.add(input); inputLastSaved = input; @@ -335,8 +345,8 @@ public final class VoiceHintProcessor { } } } else if ((input.goodWay.getPrio() == 29 && input.maxBadPrio == 30) && - ((hintIdx + 1 < inputs.size() && inputs.get(hintIdx+1).goodWay.getPrio() < 29) || - (hintIdx + 2 < inputs.size() && inputs.get(hintIdx+2).goodWay.getPrio() < 29))) { + checkForNextNoneMotorway(inputs, hintIdx, 3) + ) { // leave motorway if (input.cmd == VoiceHint.KR || input.cmd == VoiceHint.TSLR) { input.cmd = VoiceHint.ER; @@ -349,10 +359,10 @@ public final class VoiceHintProcessor { // add all others // ignore motorway / primary continue if (((input.goodWay.getPrio() != 28) && - (input.goodWay.getPrio() != 30) && - (input.goodWay.getPrio() != 26)) - || input.isRoundabout() - || Math.abs(input.angle) > 21.f) { + (input.goodWay.getPrio() != 30) && + (input.goodWay.getPrio() != 26)) + || input.isRoundabout() + || Math.abs(input.angle) > 21.f) { results.add(input); inputLastSaved = input; } else { @@ -371,20 +381,20 @@ public final class VoiceHintProcessor { angles += nextInput.angle; if ((input.cmd == VoiceHint.C || - input.cmd == VoiceHint.KR || - input.cmd == VoiceHint.KL) - && !input.goodWay.isLinktType()) { + input.cmd == VoiceHint.KR || + input.cmd == VoiceHint.KL) + && !input.goodWay.isLinktType()) { if (input.goodWay.getPrio() < input.maxBadPrio) { if (inputLastSaved != null && inputLastSaved.cmd != VoiceHint.C - && (inputLastSaved != null && inputLastSaved.distanceToNext > minRange) - && transportMode != VoiceHintList.TRANS_MODE_CAR) { + && (inputLastSaved != null && inputLastSaved.distanceToNext > minRange) + && transportMode != VoiceHintList.TRANS_MODE_CAR) { // add when straight and not linktype // and last vh not straight save = true; // remove when next straight and not linktype if (nextInput != null && - nextInput.cmd == VoiceHint.C && - !nextInput.goodWay.isLinktType()) { + nextInput.cmd == VoiceHint.C && + !nextInput.goodWay.isLinktType()) { input.distanceToNext += nextInput.distanceToNext; hintIdx++; } @@ -448,5 +458,14 @@ public final class VoiceHintProcessor { return results; } + boolean checkForNextNoneMotorway(List inputs, int offset, int testsize) { + for (int i = 1; i < testsize + 1 && offset + i < inputs.size(); i++) { + int prio = inputs.get(offset + i).goodWay.getPrio(); + if (prio < 29) return true; + if (prio == 30) return false; + } + return false; + } + } From 422f23336d59de9637cf20dbaff69549a2f88c0f Mon Sep 17 00:00:00 2001 From: afischerdev Date: Mon, 9 Dec 2024 16:35:31 +0100 Subject: [PATCH 4/7] fixed problem vh miss calculation --- brouter-core/src/main/java/btools/router/VoiceHintProcessor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java index e8526a2..b44e525 100644 --- a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java +++ b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java @@ -74,6 +74,7 @@ public final class VoiceHintProcessor { } if (hintIdx == 0) { input.cmd = VoiceHint.END; + input.distanceToNext = input.goodWay.linkdist; results.add(input); continue; } From 60b7cf658dd93ec71df744a96f2535868b43e36b Mon Sep 17 00:00:00 2001 From: afischerdev Date: Thu, 12 Dec 2024 13:43:12 +0100 Subject: [PATCH 5/7] repair alternativ idx --- .../src/main/java/btools/router/RoutingEngine.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 18d7149..d714259 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -592,8 +592,8 @@ public class RoutingEngine extends Thread { int startSize = matchedWaypoints.size(); matchWaypointsToNodes(matchedWaypoints); if (startSize < matchedWaypoints.size()) { - refTracks = new OsmTrack[matchedWaypoints.size()]; // used ways for alternatives - lastTracks = new OsmTrack[matchedWaypoints.size()]; + refTracks = new OsmTrack[matchedWaypoints.size()-1]; // used ways for alternatives + lastTracks = new OsmTrack[matchedWaypoints.size()-1]; hasDirectRouting = true; } @@ -624,9 +624,9 @@ public class RoutingEngine extends Thread { matchedWaypoints.add(nearbyTrack.endPoint); } } else { - if (lastTracks.length < matchedWaypoints.size()) { - refTracks = new OsmTrack[matchedWaypoints.size()]; // used ways for alternatives - lastTracks = new OsmTrack[matchedWaypoints.size()]; + if (lastTracks.length < matchedWaypoints.size()-1) { + refTracks = new OsmTrack[matchedWaypoints.size()-1]; // used ways for alternatives + lastTracks = new OsmTrack[matchedWaypoints.size()-1]; hasDirectRouting = true; } } From b9b0e21cb6b4f93ebddebd92ea235da8d9956451 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Thu, 12 Dec 2024 13:52:35 +0100 Subject: [PATCH 6/7] repair vh END problems --- .../src/main/java/btools/router/OsmTrack.java | 11 +++++++++++ .../btools/router/VoiceHintProcessor.java | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/OsmTrack.java b/brouter-core/src/main/java/btools/router/OsmTrack.java index ff13498..ccc232a 100644 --- a/brouter-core/src/main/java/btools/router/OsmTrack.java +++ b/brouter-core/src/main/java/btools/router/OsmTrack.java @@ -469,6 +469,17 @@ public final class OsmTrack { List inputs = new ArrayList<>(); while (node != null) { if (node.origin != null) { + if (nodeNr == nodes.size() - 1) { + VoiceHint input = new VoiceHint(); + inputs.add(0, input); + input.ilat = node.getILat(); + input.ilon = node.getILon(); + input.selev = node.getSElev(); + input.goodWay = node.message; + input.oldWay = node.message; + input.indexInTrack = nodes.size() - 1; + input.cmd = VoiceHint.END; + } VoiceHint input = new VoiceHint(); inputs.add(input); input.ilat = node.origin.getILat(); diff --git a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java index b44e525..5df8a67 100644 --- a/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java +++ b/brouter-core/src/main/java/btools/router/VoiceHintProcessor.java @@ -29,7 +29,7 @@ public final class VoiceHintProcessor { float angle = 0.f; while (offset >= 0 && distance < range) { VoiceHint input = inputs.get(offset--); - if (input.turnAngleConsumed) { + if (input.turnAngleConsumed || input.cmd == VoiceHint.BL || input.cmd == VoiceHint.END) { break; } angle += input.goodWay.turnangle; @@ -72,15 +72,10 @@ public final class VoiceHintProcessor { results.add(input); continue; } - if (hintIdx == 0) { - input.cmd = VoiceHint.END; - input.distanceToNext = input.goodWay.linkdist; - results.add(input); - continue; - } float turnAngle = input.goodWay.turnangle; - distance += input.goodWay.linkdist; + if (hintIdx != 0) distance += input.goodWay.linkdist; + // System.out.println("range " + distance); int currentPrio = input.goodWay.getPrio(); int oldPrio = input.oldWay.getPrio(); int minPrio = Math.min(oldPrio, currentPrio); @@ -260,6 +255,10 @@ public final class VoiceHintProcessor { if (hint.cmd == 0) { hint.calcCommand(); } + if (hint.cmd == VoiceHint.END) { + results2.add(hint); + continue; + } if (!(hint.needsRealTurn && (hint.cmd == VoiceHint.C || hint.cmd == VoiceHint.BL))) { double dist = hint.distanceToNext; // sum up other hints within the catching range (e.g. 40m) @@ -455,6 +454,10 @@ public final class VoiceHintProcessor { } inputLast = input; } + if (results.size() > 0) { + // don't use END tag + if (results.get(results.size()-1).cmd == VoiceHint.END) results.remove(results.size()-1); + } return results; } From 27127773120e7f2a3041a2320946042d2d8f5f49 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Fri, 13 Dec 2024 17:05:11 +0100 Subject: [PATCH 7/7] added a second chance to waypoints - beeline --- .../java/btools/router/RoutingEngine.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index d714259..dda43c9 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -36,12 +36,14 @@ public class RoutingEngine extends Thread { private boolean finished = false; protected List waypoints = null; + List extraWaypoints = null; protected List matchedWaypoints; private int linksProcessed = 0; private int nodeLimit; // used for target island search private int MAXNODES_ISLAND_CHECK = 500; private OsmNodePairSet islandNodePairs = new OsmNodePairSet(MAXNODES_ISLAND_CHECK); + private boolean useNodePoints = false; // use the start/end nodes instead of crosspoint private int engineMode = 0; @@ -548,6 +550,20 @@ public class RoutingEngine extends Thread { try { return tryFindTrack(refTracks, lastTracks); } catch (RoutingIslandException rie) { + if (routingContext.useDynamicDistance) { + useNodePoints = true; + boolean useNodeOne = true; + if (extraWaypoints != null) useNodeOne = false; + extraWaypoints = new ArrayList<>(); + for (MatchedWaypoint mwp : matchedWaypoints) { + if (mwp.name.contains("_add")) { + OsmNodeNamed wp = new OsmNodeNamed(useNodeOne ? mwp.node1 : mwp.node1); + wp.name = mwp.name; + wp.direct = mwp.direct; + extraWaypoints.add(wp); + } + } + } islandNodePairs.freezeTempPairs(); nodesCache.clean(true); matchedWaypoints = null; @@ -560,6 +576,26 @@ public class RoutingEngine extends Thread { int nUnmatched = waypoints.size(); boolean hasDirectRouting = false; + if (useNodePoints && extraWaypoints != null) { + // add extra waypoints from the last broken round + for (OsmNodeNamed wp : extraWaypoints) { + if (wp.direct) hasDirectRouting = true; + if (wp.name.startsWith("from")) { + waypoints.add(1, wp); + waypoints.get(0).direct = true; + nUnmatched++; + } else { + waypoints.add(waypoints.size()-1, wp); + waypoints.get(waypoints.size()-2).direct = true; + nUnmatched++; + } + } + } + if (lastTracks.length < waypoints.size()-1) { + refTracks = new OsmTrack[waypoints.size()-1]; // used ways for alternatives + lastTracks = new OsmTrack[waypoints.size()-1]; + hasDirectRouting = true; + } for (OsmNodeNamed wp : waypoints) { if (hasInfo()) logInfo("wp=" + wp + (wp.direct ? " direct" : "")); if (wp.direct) hasDirectRouting = true;