From 6e36d488e9c02e2d52f5a9c50f182e406f6123c6 Mon Sep 17 00:00:00 2001 From: Kiara Navarro Date: Sat, 16 Oct 2021 10:42:31 -0300 Subject: [PATCH] gui/traces: prevent out of range when marker is added on smith chart When a marker is added in enabled trace for smith chart and there no samples received yet, an out of range is produced causing that application closes. This implementation set closes point when iterating over samples preventing mentioned behavior. --- Software/PC_Application/Traces/tracesmithchart.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Software/PC_Application/Traces/tracesmithchart.cpp b/Software/PC_Application/Traces/tracesmithchart.cpp index ffd17cf..9ece00c 100644 --- a/Software/PC_Application/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/Traces/tracesmithchart.cpp @@ -97,8 +97,9 @@ QPoint TraceSmithChart::markerToPixel(Marker *m) double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel, double *distance) { double closestDistance = numeric_limits::max(); - unsigned int closestIndex = 0; - for(unsigned int i=0;isize();i++) { + double closestXpos = 0; + auto samples = t->size(); + for(unsigned int i=0;isample(i); auto plotPoint = dataToPixel(data); if (plotPoint.isNull()) { @@ -109,13 +110,13 @@ double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel, double *distan unsigned int distance = diff.x() * diff.x() + diff.y() * diff.y(); if(distance < closestDistance) { closestDistance = distance; - closestIndex = i; + closestXpos = t->sample(i).x; } } if(distance) { *distance = closestDistance; } - return t->sample(closestIndex).x; + return closestXpos; } bool TraceSmithChart::xCoordinateVisible(double x)