From eb81fbdd25b3cb684cf7ea793cf057f3be3fe420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Thu, 16 Feb 2023 00:40:22 +0100 Subject: [PATCH] use correct marker interpolation for markerToPixel --- .../LibreVNA-GUI/Traces/tracexyplot.cpp | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp index 94a3a9e..4018e61 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp @@ -585,28 +585,10 @@ void TraceXYPlot::draw(QPainter &p) if(!m->isVisible()) { continue; } - double xPosition = m->getPosition(); - if (xPosition < xAxis.getRangeMin() || xPosition > xAxis.getRangeMax()) { - // marker not in graph range + auto point = markerToPixel(m); + if(point.isNull()) { continue; } - if(xPosition < t->minX() || xPosition > t->maxX()) { - // marker not in trace range - continue; - } - auto t = m->getTrace(); - auto index = t->index(xPosition); - QPointF markerPoint; - if(xPosition < t->sample(index).x && index > 0) { - // marker is not located exactly at this point, interpolate display location - QPointF l0 = traceToCoordinate(t, index - 1, yAxis[i]); - QPointF l1 = traceToCoordinate(t, index, yAxis[i]); - auto t0 = (xPosition - t->sample(index - 1).x) / (t->sample(index).x - t->sample(index - 1).x); - markerPoint = l0 + (l1 - l0) * t0; - } else { - markerPoint = traceToCoordinate(t, t->index(xPosition), yAxis[i]); - } - auto point = plotValueToPixel(markerPoint, i); for(auto line : m->getLines()) { QPointF pF1 = QPointF(numeric_limits::quiet_NaN(), numeric_limits::quiet_NaN()); @@ -1062,8 +1044,31 @@ QPointF TraceXYPlot::pixelToPlotValue(QPoint pixel, int Yaxis) QPoint TraceXYPlot::markerToPixel(Marker *m) { auto t = m->getTrace(); - QPointF plotPoint = traceToCoordinate(t, t->index(m->getPosition()), yAxis[0]); - return plotValueToPixel(plotPoint, 0); + double xPosition = m->getPosition(); + double xPosGraph = xPosition; + if(xAxis.getType() == XAxis::Type::Distance) { + xPosGraph = t->timeToDistance(xPosition); + } + if (xPosGraph < xAxis.getRangeMin() || xPosGraph > xAxis.getRangeMax()) { + // marker not in graph range + return QPoint(0.0, 0.0); + } + if(xPosition < t->minX() || xPosition > t->maxX()) { + // marker not in trace range + return QPoint(0.0, 0.0); + } + auto index = t->index(xPosition); + QPointF markerPoint; + if(xPosition < t->sample(index).x && index > 0) { + // marker is not located exactly at this point, interpolate display location + QPointF l0 = traceToCoordinate(t, index - 1, yAxis[0]); + QPointF l1 = traceToCoordinate(t, index, yAxis[0]); + auto t0 = (xPosition - t->sample(index - 1).x) / (t->sample(index).x - t->sample(index - 1).x); + markerPoint = l0 + (l1 - l0) * t0; + } else { + markerPoint = traceToCoordinate(t, t->index(xPosition), yAxis[0]); + } + return plotValueToPixel(markerPoint, 0); } double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel, double *distance)