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.
This commit is contained in:
Kiara Navarro 2021-10-16 10:42:31 -03:00
parent 09366d73cc
commit 6e36d488e9
No known key found for this signature in database
GPG Key ID: CDEFDCA3F6E04955

View File

@ -97,8 +97,9 @@ QPoint TraceSmithChart::markerToPixel(Marker *m)
double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
{
double closestDistance = numeric_limits<double>::max();
unsigned int closestIndex = 0;
for(unsigned int i=0;i<t->size();i++) {
double closestXpos = 0;
auto samples = t->size();
for(unsigned int i=0;i<samples;i++) {
auto data = t->sample(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)