diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp index d5c7487..55c67a6 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp @@ -181,6 +181,10 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance) auto samples = t->size(); for(unsigned int i=0;isample(i); + if(data.x < minimumVisibleFrequency() || data.x > maximumVisibleFrequency()) { + // outside of displayed range + continue; + } data = dataAddOffset(data); auto plotPoint = dataToPixel(data); if (plotPoint.isNull()) { @@ -197,7 +201,7 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance) } closestDistance = sqrt(closestDistance); - if(closestIndex > 0) { + if(closestIndex > 0 && t->sample(closestIndex-1).x >= minimumVisibleFrequency()) { auto l1 = dataToPixel(dataAddOffset(t->sample(closestIndex-1))); auto l2 = dataToPixel(dataAddOffset(t->sample(closestIndex))); double ratio; @@ -207,7 +211,7 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance) closestXpos = t->sample(closestIndex-1).x + (t->sample(closestIndex).x - t->sample(closestIndex-1).x) * ratio; } } - if(closestIndex < t->size() - 1) { + if(closestIndex < t->size() - 1 && t->sample(closestIndex+1).x <= maximumVisibleFrequency()) { auto l1 = dataToPixel(dataAddOffset(t->sample(closestIndex))); auto l2 = dataToPixel(dataAddOffset(t->sample(closestIndex+1))); double ratio; @@ -295,6 +299,28 @@ void TracePolar::updateContextMenu() finishContextMenu(); } +double TracePolar::minimumVisibleFrequency() +{ + if(manualFrequencyRange) { + return fmin; + } else if(limitToSpan) { + return sweep_fmin; + } else { + return std::numeric_limits::lowest(); + } +} + +double TracePolar::maximumVisibleFrequency() +{ + if(manualFrequencyRange) { + return fmax; + } else if(limitToSpan) { + return sweep_fmax; + } else { + return std::numeric_limits::max(); + } +} + bool TracePolar::constrainLineToCircle(QPointF &a, QPointF &b, QPointF center, double radius) { auto distance = [](const QPointF &a, const QPointF &b) { diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.h b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.h index c17630d..2dabc78 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.h +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.h @@ -49,6 +49,9 @@ protected: virtual void updateContextMenu() override; virtual bool supported(Trace *t) override {Q_UNUSED(t) return false;} + double minimumVisibleFrequency(); + double maximumVisibleFrequency(); + // given two points and a circle, the two points are adjusted in such a way that the line they describe // is constrained within the circle. Returns true if there is a remaining line segment in the circle, false // if the line lies completely outside of the circle (or is tangent to the circle) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolarchart.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolarchart.cpp index bbc32bb..556a152 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolarchart.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolarchart.cpp @@ -90,16 +90,6 @@ void TracePolarChart::draw(QPainter &p) { transform = p.transform(); p.restore(); - auto minimumVisibleFrequency = std::numeric_limits::lowest(); - auto maximumVisibleFrequency = std::numeric_limits::max(); - if(manualFrequencyRange) { - minimumVisibleFrequency = fmin; - maximumVisibleFrequency = fmax; - } else if(limitToSpan) { - minimumVisibleFrequency = sweep_fmin; - maximumVisibleFrequency = sweep_fmax; - } - auto drawArc = [&](PolarArc a) { a.constrainToCircle(QPointF(0,0), edgeReflection); auto topleft = dataToPixel(complex(a.center.x() - a.radius, a.center.y() - a.radius)); @@ -183,7 +173,7 @@ void TracePolarChart::draw(QPainter &p) { for(int i=1;isample(i-1); auto now = trace->sample(i); - if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency || now.x > maximumVisibleFrequency)) { + if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency() || now.x > maximumVisibleFrequency())) { continue; } if(isnan(now.y.real())) { @@ -192,7 +182,7 @@ void TracePolarChart::draw(QPainter &p) { if(pref.Graphs.SweepIndicator.hide && !isnan(xSweep) && trace->getSource() == Trace::Source::Live && trace->isVisible() && !trace->isPaused()) { // check if this part of the trace is visible - double range = maximumVisibleFrequency - minimumVisibleFrequency; + double range = maximumVisibleFrequency() - minimumVisibleFrequency(); double afterSweep = now.x - xSweep; if(afterSweep > 0 && afterSweep * 100 / range <= pref.Graphs.SweepIndicator.hidePercent) { // do not display this part of the trace @@ -225,7 +215,7 @@ void TracePolarChart::draw(QPainter &p) { if(!m->isVisible()) { continue; } - if (m->getPosition() < minimumVisibleFrequency || m->getPosition() > maximumVisibleFrequency) { + if (m->getPosition() < minimumVisibleFrequency() || m->getPosition() > maximumVisibleFrequency()) { continue; } if(m->getPosition() < trace->minX() || m->getPosition() > trace->maxX()) { diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp index 57badc1..2f70049 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp @@ -239,16 +239,6 @@ void TraceSmithChart::draw(QPainter &p) { transform = p.transform(); p.restore(); - auto minimumVisibleFrequency = std::numeric_limits::lowest(); - auto maximumVisibleFrequency = std::numeric_limits::max(); - if(manualFrequencyRange) { - minimumVisibleFrequency = fmin; - maximumVisibleFrequency = fmax; - } else if(limitToSpan) { - minimumVisibleFrequency = sweep_fmin; - maximumVisibleFrequency = sweep_fmax; - } - auto drawArc = [&](SmithChartArc a) { a.constrainToCircle(QPointF(0,0), edgeReflection); auto topleft = dataToPixel(complex(a.center.x() - a.radius, a.center.y() - a.radius)); @@ -316,7 +306,7 @@ void TraceSmithChart::draw(QPainter &p) { for(int i=1;isample(i-1); auto now = trace->sample(i); - if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency || now.x > maximumVisibleFrequency)) { + if ((trace->getDataType() == Trace::DataType::Frequency) && (last.x < minimumVisibleFrequency() || now.x > maximumVisibleFrequency())) { continue; } if(isnan(now.y.real())) { @@ -325,7 +315,7 @@ void TraceSmithChart::draw(QPainter &p) { if(pref.Graphs.SweepIndicator.hide && !isnan(xSweep) && trace->getSource() == Trace::Source::Live && trace->isVisible() && !trace->isPaused()) { // check if this part of the trace is visible - double range = maximumVisibleFrequency - minimumVisibleFrequency; + double range = maximumVisibleFrequency() - minimumVisibleFrequency(); double afterSweep = now.x - xSweep; if(afterSweep > 0 && afterSweep * 100 / range <= pref.Graphs.SweepIndicator.hidePercent) { // do not display this part of the trace @@ -361,7 +351,7 @@ void TraceSmithChart::draw(QPainter &p) { // if (m->isTimeDomain()) { // continue; // } - if (m->getPosition() < minimumVisibleFrequency || m->getPosition() > maximumVisibleFrequency) { + if (m->getPosition() < minimumVisibleFrequency() || m->getPosition() > maximumVisibleFrequency()) { continue; } if(m->getPosition() < trace->minX() || m->getPosition() > trace->maxX()) {