nav: handle route responses with duplicate points (#23769)

pull/23774/head
Willem Melching 2022-02-15 16:14:57 +01:00 committed by GitHub
parent e5edbe98da
commit 14f7a78251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -160,6 +160,11 @@ static float dot(QGeoCoordinate v, QGeoCoordinate w) {
}
float minimum_distance(QGeoCoordinate a, QGeoCoordinate b, QGeoCoordinate p) {
// If a and b are the same coordinate the computation below doesn't work
if (a.distanceTo(b) < 0.01) {
return a.distanceTo(p);
}
const QGeoCoordinate ap = sub(p, a);
const QGeoCoordinate ab = sub(b, a);
const float t = std::clamp(dot(ap, ab) / dot(ab, ab), 0.0f, 1.0f);