mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-04 14:07:30 +00:00
Optionally interpolate markers
This commit is contained in:
parent
367451dc04
commit
2f7449ed21
8 changed files with 210 additions and 42 deletions
|
|
@ -85,8 +85,8 @@ void Marker::assignTrace(Trace *t)
|
|||
// Marker was just created and this is the first assignment to a trace.
|
||||
// Use display format on graph from preferences
|
||||
auto p = Preferences::getInstance();
|
||||
if(p.Graphs.markerBehavior.showDataOnGraphs) {
|
||||
if(p.Graphs.markerBehavior.showAllData) {
|
||||
if(p.Marker.defaultBehavior.showDataOnGraphs) {
|
||||
if(p.Marker.defaultBehavior.showAllData) {
|
||||
for(auto f : applicableFormats()) {
|
||||
formatGraph.insert(f);
|
||||
}
|
||||
|
|
@ -598,7 +598,7 @@ void Marker::traceDataChanged()
|
|||
newdata = numeric_limits<complex<double>>::quiet_NaN();
|
||||
} else {
|
||||
// some data of the parent trace changed, check if marker data also changed
|
||||
newdata = parentTrace->sample(parentTrace->index(position)).y;
|
||||
newdata = parentTrace->interpolatedSample(position).y;
|
||||
}
|
||||
}
|
||||
if (newdata != data) {
|
||||
|
|
@ -839,8 +839,10 @@ void Marker::constrainPosition()
|
|||
} else if(position < parentTrace->minX()) {
|
||||
position = parentTrace->minX();
|
||||
}
|
||||
// set position to closest trace index
|
||||
position = parentTrace->sample(parentTrace->index(position)).x;
|
||||
if(!Preferences::getInstance().Marker.interpolatePoints) {
|
||||
// marker interpolation disabled, set position to closest trace index
|
||||
position = parentTrace->sample(parentTrace->index(position)).x;
|
||||
}
|
||||
}
|
||||
traceDataChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "ui_smithchartdialog.h"
|
||||
#include "unit.h"
|
||||
#include "QFileDialog"
|
||||
#include "Util/util.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <array>
|
||||
|
|
@ -141,6 +142,7 @@ double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel, double *distan
|
|||
{
|
||||
double closestDistance = numeric_limits<double>::max();
|
||||
double closestXpos = 0;
|
||||
unsigned int closestIndex = 0;
|
||||
auto samples = t->size();
|
||||
for(unsigned int i=0;i<samples;i++) {
|
||||
auto data = t->sample(i);
|
||||
|
|
@ -154,6 +156,28 @@ double TraceSmithChart::nearestTracePoint(Trace *t, QPoint pixel, double *distan
|
|||
if(distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closestXpos = t->sample(i).x;
|
||||
closestIndex = i;
|
||||
}
|
||||
}
|
||||
closestDistance = sqrt(closestDistance);
|
||||
if(closestIndex > 0) {
|
||||
auto l1 = dataToPixel(t->sample(closestIndex-1));
|
||||
auto l2 = dataToPixel(t->sample(closestIndex));
|
||||
double ratio;
|
||||
auto distance = Util::distanceToLine(pixel, l1, l2, nullptr, &ratio);
|
||||
if(distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closestXpos = t->sample(closestIndex-1).x + (t->sample(closestIndex).x - t->sample(closestIndex-1).x) * ratio;
|
||||
}
|
||||
}
|
||||
if(closestIndex < t->size() - 1) {
|
||||
auto l1 = dataToPixel(t->sample(closestIndex));
|
||||
auto l2 = dataToPixel(t->sample(closestIndex+1));
|
||||
double ratio;
|
||||
auto distance = Util::distanceToLine(pixel, l1, l2, nullptr, &ratio);
|
||||
if(distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closestXpos = t->sample(closestIndex).x + (t->sample(closestIndex+1).x - t->sample(closestIndex).x) * ratio;
|
||||
}
|
||||
}
|
||||
if(distance) {
|
||||
|
|
|
|||
|
|
@ -491,7 +491,17 @@ void TraceXYPlot::draw(QPainter &p)
|
|||
continue;
|
||||
}
|
||||
auto t = m->getTrace();
|
||||
QPointF markerPoint = traceToCoordinate(t, t->index(xPosition), YAxis[i].type);
|
||||
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].type);
|
||||
QPointF l1 = traceToCoordinate(t, index, YAxis[i].type);
|
||||
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].type);
|
||||
}
|
||||
auto point = plotValueToPixel(markerPoint, i);
|
||||
if(!plotRect.contains(point)) {
|
||||
// out of screen
|
||||
|
|
@ -1096,6 +1106,7 @@ double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
|
|||
}
|
||||
double closestDistance = numeric_limits<double>::max();
|
||||
double closestXpos = 0;
|
||||
unsigned int closestIndex = 0;
|
||||
auto samples = t->size();
|
||||
for(unsigned int i=0;i<samples;i++) {
|
||||
auto point = traceToCoordinate(t, i, YAxis[0].type);
|
||||
|
|
@ -1108,6 +1119,28 @@ double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
|
|||
if(distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closestXpos = point.x();
|
||||
closestIndex = i;
|
||||
}
|
||||
}
|
||||
closestDistance = sqrt(closestDistance);
|
||||
if(closestIndex > 0) {
|
||||
auto l1 = plotValueToPixel(traceToCoordinate(t, closestIndex - 1, YAxis[0].type), 0);
|
||||
auto l2 = plotValueToPixel(traceToCoordinate(t, closestIndex, YAxis[0].type), 0);
|
||||
double ratio;
|
||||
auto distance = Util::distanceToLine(pixel, l1, l2, nullptr, &ratio);
|
||||
if(distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closestXpos = t->sample(closestIndex-1).x + (t->sample(closestIndex).x - t->sample(closestIndex-1).x) * ratio;
|
||||
}
|
||||
}
|
||||
if(closestIndex < t->size() - 1) {
|
||||
auto l1 = plotValueToPixel(traceToCoordinate(t, closestIndex, YAxis[0].type), 0);
|
||||
auto l2 = plotValueToPixel(traceToCoordinate(t, closestIndex + 1, YAxis[0].type), 0);
|
||||
double ratio;
|
||||
auto distance = Util::distanceToLine(pixel, l1, l2, nullptr, &ratio);
|
||||
if(distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closestXpos = t->sample(closestIndex).x + (t->sample(closestIndex+1).x - t->sample(closestIndex).x) * ratio;
|
||||
}
|
||||
}
|
||||
if(XAxis.type == XAxisType::Distance) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue