rework voicehints #723

This commit is contained in:
afischerdev 2024-09-05 11:18:00 +02:00
parent 7b70cc5a6f
commit 7ead35e3f8
2 changed files with 31 additions and 16 deletions

View File

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

View File

@ -11,7 +11,8 @@ import java.util.List;
public final class VoiceHintProcessor { public final class VoiceHintProcessor {
double SIGNIFICANT_ANGLE = 22.5; 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 double catchingRange; // range to catch angles and merge turns
private boolean explicitRoundabouts; private boolean explicitRoundabouts;
@ -23,10 +24,10 @@ public final class VoiceHintProcessor {
this.transportMode = transportMode; this.transportMode = transportMode;
} }
private float sumNonConsumedWithinCatchingRange(List<VoiceHint> inputs, int offset) { private float sumNonConsumedWithinCatchingRange(List<VoiceHint> inputs, int offset, double range) {
double distance = 0.; double distance = 0.;
float angle = 0.f; float angle = 0.f;
while (offset >= 0 && distance < INTERNAL_CATCHING_RANGE) { while (offset >= 0 && distance < range) {
VoiceHint input = inputs.get(offset--); VoiceHint input = inputs.get(offset--);
if (input.turnAngleConsumed) { if (input.turnAngleConsumed) {
break; break;
@ -82,7 +83,7 @@ public final class VoiceHintProcessor {
if (explicitRoundabouts && input.oldWay.isRoundabout()) { if (explicitRoundabouts && input.oldWay.isRoundabout()) {
if (roundaboudStartIdx == -1) roundaboudStartIdx = hintIdx; if (roundaboudStartIdx == -1) roundaboudStartIdx = hintIdx;
roundAboutTurnAngle += sumNonConsumedWithinCatchingRange(inputs, hintIdx); roundAboutTurnAngle += sumNonConsumedWithinCatchingRange(inputs, hintIdx, INTERNAL_CATCHING_RANGE_NEAR);
if (roundaboudStartIdx == hintIdx) { if (roundaboudStartIdx == hintIdx) {
if (input.badWays != null) { if (input.badWays != null) {
// remove goodWay // remove goodWay
@ -171,10 +172,12 @@ public final class VoiceHintProcessor {
} }
if (badWay.isBadOneway()) { if (badWay.isBadOneway()) {
if (minAbsAngeRaw == 180f) minAbsAngeRaw = turnAngle; // disable hasSomethingMoreStraight
continue; // ignore wrong oneways continue; // ignore wrong oneways
} }
if (Math.abs(badTurn) - Math.abs(turnAngle) > 80.f) { 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 continue; // ways from the back should not trigger a slight turn
} }
@ -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; input.distanceToNext = distance;
distance = 0.; distance = 0.;
results.add(input); results.add(input);
} }
if (results.size() > 0 && distance < INTERNAL_CATCHING_RANGE) { //catchingRange if (results.size() > 0 && distance < INTERNAL_CATCHING_RANGE_NEAR) { //catchingRange
results.get(results.size() - 1).angle += sumNonConsumedWithinCatchingRange(inputs, hintIdx); 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))) { if (!(hint.needsRealTurn && (hint.cmd == VoiceHint.C || hint.cmd == VoiceHint.BL))) {
double dist = hint.distanceToNext; double dist = hint.distanceToNext;
// sum up other hints within the catching range (e.g. 40m) // 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); VoiceHint h2 = results.get(i - 1);
dist = h2.distanceToNext; dist = h2.distanceToNext;
hint.distanceToNext += dist; hint.distanceToNext += dist;
@ -292,7 +295,10 @@ public final class VoiceHintProcessor {
} }
if (nextInput == null) { 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)) { if (input.goodWay.getPrio() < input.maxBadPrio && (inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange)) {
results.add(input); results.add(input);
} else { } else {
@ -306,10 +312,15 @@ public final class VoiceHintProcessor {
} }
} else { } else {
if ((inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange) || input.distanceToNext > catchingRange) { if ((inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange) || input.distanceToNext > catchingRange) {
if (input.cmd == VoiceHint.C && !input.goodWay.isLinktType()) { if ((input.cmd == VoiceHint.C ||
if (input.goodWay.getPrio() < input.maxBadPrio input.cmd == VoiceHint.KR ||
&& (inputLastSaved != null && inputLastSaved.distanceToNext > minRange) input.cmd == VoiceHint.KL)
&& (input.distanceToNext > minRange)) { && !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 // add only on prio
results.add(input); results.add(input);
inputLastSaved = input; inputLastSaved = input;
@ -343,7 +354,10 @@ public final class VoiceHintProcessor {
dist += nextInput.distanceToNext; dist += nextInput.distanceToNext;
angles += nextInput.angle; 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 (input.goodWay.getPrio() < input.maxBadPrio) {
if (inputLastSaved != null && inputLastSaved.cmd != VoiceHint.C if (inputLastSaved != null && inputLastSaved.cmd != VoiceHint.C
&& (inputLastSaved != null && inputLastSaved.distanceToNext > minRange) && (inputLastSaved != null && inputLastSaved.distanceToNext > minRange)