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:
parent
09366d73cc
commit
6e36d488e9
@ -97,8 +97,9 @@ QPoint TraceSmithChart::markerToPixel(Marker *m)
|
|||||||
double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
|
double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
|
||||||
{
|
{
|
||||||
double closestDistance = numeric_limits<double>::max();
|
double closestDistance = numeric_limits<double>::max();
|
||||||
unsigned int closestIndex = 0;
|
double closestXpos = 0;
|
||||||
for(unsigned int i=0;i<t->size();i++) {
|
auto samples = t->size();
|
||||||
|
for(unsigned int i=0;i<samples;i++) {
|
||||||
auto data = t->sample(i);
|
auto data = t->sample(i);
|
||||||
auto plotPoint = dataToPixel(data);
|
auto plotPoint = dataToPixel(data);
|
||||||
if (plotPoint.isNull()) {
|
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();
|
unsigned int distance = diff.x() * diff.x() + diff.y() * diff.y();
|
||||||
if(distance < closestDistance) {
|
if(distance < closestDistance) {
|
||||||
closestDistance = distance;
|
closestDistance = distance;
|
||||||
closestIndex = i;
|
closestXpos = t->sample(i).x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(distance) {
|
if(distance) {
|
||||||
*distance = closestDistance;
|
*distance = closestDistance;
|
||||||
}
|
}
|
||||||
return t->sample(closestIndex).x;
|
return closestXpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TraceSmithChart::xCoordinateVisible(double x)
|
bool TraceSmithChart::xCoordinateVisible(double x)
|
||||||
|
Loading…
Reference in New Issue
Block a user