From 14f7a7825151ab55975a24f53e4178fb7a595bea Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Tue, 15 Feb 2022 16:14:57 +0100 Subject: [PATCH] nav: handle route responses with duplicate points (#23769) --- selfdrive/ui/qt/maps/map_helpers.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/selfdrive/ui/qt/maps/map_helpers.cc b/selfdrive/ui/qt/maps/map_helpers.cc index f87e80403f..f0545924c0 100644 --- a/selfdrive/ui/qt/maps/map_helpers.cc +++ b/selfdrive/ui/qt/maps/map_helpers.cc @@ -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);