Merge pull request #726 from afischerdev/rework-voicehint

Rework voicehint
This commit is contained in:
afischerdev 2024-11-17 11:01:37 +01:00 committed by GitHub
commit adf6bb5569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 20 deletions

View File

@ -42,6 +42,9 @@ public class VoiceHint {
}
float angle = Float.MAX_VALUE;
float lowerBadWayAngle = -181;
float higherBadWayAngle = 181;
boolean turnAngleConsumed;
boolean needsRealTurn;
int maxBadPrio = -1;
@ -470,8 +473,6 @@ public class VoiceHint {
}
public void calcCommand() {
float lowerBadWayAngle = -181;
float higherBadWayAngle = 181;
if (badWays != null) {
for (MessageData badWay : badWays) {
if (badWay.isBadOneway()) {

View File

@ -11,7 +11,8 @@ import java.util.List;
public final class VoiceHintProcessor {
double SIGNIFICANT_ANGLE = 22.5;
double INTERNAL_CATCHING_RANGE = 2.;
double INTERNAL_CATCHING_RANGE_NEAR = 2.;
double INTERNAL_CATCHING_RANGE_WIDE = 10.;
// private double catchingRange; // range to catch angles and merge turns
private boolean explicitRoundabouts;
@ -23,10 +24,10 @@ public final class VoiceHintProcessor {
this.transportMode = transportMode;
}
private float sumNonConsumedWithinCatchingRange(List<VoiceHint> inputs, int offset) {
private float sumNonConsumedWithinCatchingRange(List<VoiceHint> inputs, int offset, double range) {
double distance = 0.;
float angle = 0.f;
while (offset >= 0 && distance < INTERNAL_CATCHING_RANGE) {
while (offset >= 0 && distance < range) {
VoiceHint input = inputs.get(offset--);
if (input.turnAngleConsumed) {
break;
@ -82,7 +83,7 @@ public final class VoiceHintProcessor {
if (explicitRoundabouts && input.oldWay.isRoundabout()) {
if (roundaboudStartIdx == -1) roundaboudStartIdx = hintIdx;
roundAboutTurnAngle += sumNonConsumedWithinCatchingRange(inputs, hintIdx);
roundAboutTurnAngle += sumNonConsumedWithinCatchingRange(inputs, hintIdx, INTERNAL_CATCHING_RANGE_NEAR);
if (roundaboudStartIdx == hintIdx) {
if (input.badWays != null) {
// remove goodWay
@ -171,10 +172,12 @@ public final class VoiceHintProcessor {
}
if (badWay.isBadOneway()) {
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
continue; // ways from the back should not trigger a slight turn
}
@ -196,7 +199,7 @@ public final class VoiceHintProcessor {
}
// boolean hasSomethingMoreStraight = (Math.abs(turnAngle) - minAbsAngeRaw) > 20.;
boolean hasSomethingMoreStraight = (Math.abs(turnAngle - minAbsAngeRaw)) > 20. && input.badWays != null; // && !ignoreBadway;
boolean hasSomethingMoreStraight = (Math.abs(turnAngle) - minAbsAngeRaw) > 20. && input.badWays != null; // && !ignoreBadway;
// unconditional triggers are all junctions with
// - higher detour prios than the minimum route prio (except link->highway junctions)
@ -228,13 +231,13 @@ public final class VoiceHintProcessor {
}
}
input.angle = sumNonConsumedWithinCatchingRange(inputs, hintIdx);
input.angle = sumNonConsumedWithinCatchingRange(inputs, hintIdx, INTERNAL_CATCHING_RANGE_WIDE);
input.distanceToNext = distance;
distance = 0.;
results.add(input);
}
if (results.size() > 0 && distance < INTERNAL_CATCHING_RANGE) { //catchingRange
results.get(results.size() - 1).angle += sumNonConsumedWithinCatchingRange(inputs, hintIdx);
if (results.size() > 0 && distance < INTERNAL_CATCHING_RANGE_NEAR) { //catchingRange
results.get(results.size() - 1).angle += sumNonConsumedWithinCatchingRange(inputs, hintIdx, INTERNAL_CATCHING_RANGE_NEAR);
}
}
@ -251,7 +254,7 @@ public final class VoiceHintProcessor {
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)
while (dist < INTERNAL_CATCHING_RANGE && i > 0) {
while (dist < INTERNAL_CATCHING_RANGE_NEAR && i > 0) {
VoiceHint h2 = results.get(i - 1);
dist = h2.distanceToNext;
hint.distanceToNext += dist;
@ -292,7 +295,10 @@ public final class VoiceHintProcessor {
}
if (nextInput == null) {
if (input.cmd == VoiceHint.C && !input.goodWay.isLinktType()) {
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 {
@ -306,8 +312,13 @@ public final class VoiceHintProcessor {
}
} else {
if ((inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange) || input.distanceToNext > catchingRange) {
if (input.cmd == VoiceHint.C && !input.goodWay.isLinktType()) {
if (input.goodWay.getPrio() < input.maxBadPrio
if ((input.cmd == VoiceHint.C ||
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)) {
// add only on prio
@ -343,7 +354,10 @@ public final class VoiceHintProcessor {
dist += nextInput.distanceToNext;
angles += nextInput.angle;
if (input.cmd == VoiceHint.C && !input.goodWay.isLinktType()) {
if ((input.cmd == VoiceHint.C ||
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)

View File

@ -40,6 +40,8 @@ public class ServerHandler extends RequestHandler {
private RoutingContext rc;
private static boolean useRFCMimeType = Boolean.getBoolean("useRFCMimeType");
public ServerHandler(ServiceContext serviceContext, Map<String, String> params) {
super(serviceContext, params);
}
@ -107,7 +109,10 @@ public class ServerHandler extends RequestHandler {
} else if ("kml".equals(format)) {
result = "application/vnd.google-earth.kml+xml";
} else if ("geojson".equals(format)) {
if (useRFCMimeType)
result = "application/geo+json";
else
result = "application/vnd.geo+json";
} else if ("csv".equals(format)) {
result = "text/tab-separated-values";
}

View File

@ -6,7 +6,7 @@ REM java -cp brouter.jar btools.brouter.RouteServer <segmentdir> <profile-map> <
pushd %~dp0
REM maxRunningTime is the request timeout in seconds, set to 0 to disable timeout
set JAVA_OPTS=-Xmx128M -Xms128M -Xmn8M -DmaxRunningTime=300
set JAVA_OPTS=-Xmx128M -Xms128M -Xmn8M -DmaxRunningTime=300 -DuseRFCMimeType=false
REM First search in locations matching the directory structure as found in the official BRouter zip archive
set CLASSPATH=../brouter.jar

View File

@ -5,7 +5,7 @@ cd "$(dirname "$0")"
# java -cp brouter.jar btools.brouter.RouteServer <segmentdir> <profile-map> <customprofiledir> <port> <maxthreads> [bindaddress]
# maxRunningTime is the request timeout in seconds, set to 0 to disable timeout
JAVA_OPTS="-Xmx128M -Xms128M -Xmn8M -DmaxRunningTime=300"
JAVA_OPTS="-Xmx128M -Xms128M -Xmn8M -DmaxRunningTime=300 -DuseRFCMimeType=false"
# If paths are unset, first search in locations matching the directory structure
# as found in the official BRouter zip archive