2020-05-18 18:58:17 +00:00
|
|
|
# NanoVNASaver
|
2020-06-25 17:52:30 +00:00
|
|
|
#
|
2020-05-18 18:58:17 +00:00
|
|
|
# A python program to view and export Touchstone data from a NanoVNA
|
2020-06-25 17:52:30 +00:00
|
|
|
# Copyright (C) 2019, 2020 Rune B. Broberg
|
2021-06-30 05:21:14 +00:00
|
|
|
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
2019-09-01 21:13:21 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-09-05 12:56:40 +00:00
|
|
|
import math
|
2019-09-22 11:42:05 +00:00
|
|
|
import logging
|
2020-05-18 18:58:17 +00:00
|
|
|
from typing import List
|
2019-09-01 21:13:21 +00:00
|
|
|
|
2023-03-12 07:02:58 +00:00
|
|
|
from PyQt6 import QtGui
|
2019-09-01 21:13:21 +00:00
|
|
|
|
2022-10-06 16:15:59 +00:00
|
|
|
from NanoVNASaver.Marker.Widget import Marker
|
2020-05-18 18:58:17 +00:00
|
|
|
from NanoVNASaver.RFTools import Datapoint
|
2019-11-10 18:52:40 +00:00
|
|
|
from NanoVNASaver.SITools import Format, Value
|
2021-07-06 15:01:20 +00:00
|
|
|
from NanoVNASaver.Charts.Chart import Chart
|
|
|
|
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
2023-03-08 08:40:39 +00:00
|
|
|
|
2019-09-22 11:42:05 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2019-09-01 21:13:21 +00:00
|
|
|
|
|
|
|
|
2019-11-08 12:58:14 +00:00
|
|
|
class PermeabilityChart(FrequencyChart):
|
|
|
|
def __init__(self, name=""):
|
|
|
|
super().__init__(name)
|
|
|
|
self.leftMargin = 40
|
|
|
|
self.rightMargin = 30
|
2021-06-26 22:55:43 +00:00
|
|
|
self.dim.width = 230
|
|
|
|
self.dim.height = 250
|
2019-11-08 12:58:14 +00:00
|
|
|
self.fstart = 0
|
|
|
|
self.fstop = 0
|
|
|
|
self.span = 0.01
|
|
|
|
self.max = 0
|
|
|
|
|
|
|
|
self.maxDisplayValue = 100
|
|
|
|
self.minDisplayValue = -100
|
|
|
|
|
2021-02-21 20:48:28 +00:00
|
|
|
def logarithmicYAllowed(self) -> bool:
|
2022-09-13 16:46:02 +00:00
|
|
|
return True
|
2019-11-08 22:07:24 +00:00
|
|
|
|
2019-11-08 12:58:14 +00:00
|
|
|
def drawChart(self, qp: QtGui.QPainter):
|
2021-07-06 15:01:20 +00:00
|
|
|
qp.setPen(QtGui.QPen(Chart.color.text))
|
2023-03-08 08:40:39 +00:00
|
|
|
qp.drawText(
|
|
|
|
self.leftMargin + 5,
|
|
|
|
15,
|
|
|
|
self.name + " (\N{MICRO SIGN}\N{OHM SIGN} / Hz)",
|
|
|
|
)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.drawText(10, 15, "R")
|
2021-06-26 22:55:43 +00:00
|
|
|
qp.drawText(self.leftMargin + self.dim.width + 10, 15, "X")
|
2021-07-06 15:01:20 +00:00
|
|
|
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
2023-03-08 08:40:39 +00:00
|
|
|
qp.drawLine(
|
|
|
|
self.leftMargin,
|
|
|
|
self.topMargin - 5,
|
|
|
|
self.leftMargin,
|
|
|
|
self.topMargin + self.dim.height + 5,
|
|
|
|
)
|
|
|
|
qp.drawLine(
|
|
|
|
self.leftMargin - 5,
|
|
|
|
self.topMargin + self.dim.height,
|
|
|
|
self.leftMargin + self.dim.width + 5,
|
|
|
|
self.topMargin + self.dim.height,
|
|
|
|
)
|
2019-12-12 14:16:37 +00:00
|
|
|
self.drawTitle(qp)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
def drawValues(self, qp: QtGui.QPainter):
|
2022-09-15 05:53:08 +00:00
|
|
|
if not self.data and not self.reference:
|
2019-11-08 12:58:14 +00:00
|
|
|
return
|
2022-09-15 05:53:08 +00:00
|
|
|
|
2021-07-06 15:01:20 +00:00
|
|
|
pen = QtGui.QPen(Chart.color.sweep)
|
2021-06-26 22:55:43 +00:00
|
|
|
pen.setWidth(self.dim.point)
|
2021-07-06 15:01:20 +00:00
|
|
|
line_pen = QtGui.QPen(Chart.color.sweep)
|
2021-06-26 22:55:43 +00:00
|
|
|
line_pen.setWidth(self.dim.line)
|
2021-06-27 09:45:22 +00:00
|
|
|
|
|
|
|
self._set_start_stop()
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
# Draw bands if required
|
|
|
|
if self.bands.enabled:
|
2021-06-27 09:45:22 +00:00
|
|
|
self.drawBands(qp, self.fstart, self.fstop)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
# Find scaling
|
|
|
|
if self.fixedValues:
|
2019-11-10 18:52:40 +00:00
|
|
|
min_val = self.minDisplayValue
|
|
|
|
max_val = self.maxDisplayValue
|
2019-11-08 12:58:14 +00:00
|
|
|
else:
|
2019-11-10 18:52:40 +00:00
|
|
|
min_val = 1000
|
|
|
|
max_val = -1000
|
2019-11-08 12:58:14 +00:00
|
|
|
for d in self.data:
|
2019-11-17 13:13:37 +00:00
|
|
|
imp = d.impedance()
|
|
|
|
re, im = imp.real, imp.imag
|
2019-11-08 12:58:14 +00:00
|
|
|
re = re * 10e6 / d.freq
|
|
|
|
im = im * 10e6 / d.freq
|
2022-09-15 05:53:08 +00:00
|
|
|
max_val = max(max_val, re)
|
|
|
|
max_val = max(max_val, im)
|
|
|
|
min_val = min(min_val, re)
|
|
|
|
min_val = min(min_val, im)
|
2022-09-15 19:05:07 +00:00
|
|
|
# Also check min/max for the reference sweep
|
|
|
|
for d in self.reference:
|
2021-06-27 09:45:22 +00:00
|
|
|
if d.freq < self.fstart or d.freq > self.fstop:
|
2019-11-08 12:58:14 +00:00
|
|
|
continue
|
2019-11-17 13:13:37 +00:00
|
|
|
imp = d.impedance()
|
|
|
|
re, im = imp.real, imp.imag
|
2019-11-08 12:58:14 +00:00
|
|
|
re = re * 10e6 / d.freq
|
|
|
|
im = im * 10e6 / d.freq
|
2022-09-15 05:53:08 +00:00
|
|
|
max_val = max(max_val, re)
|
|
|
|
max_val = max(max_val, im)
|
|
|
|
min_val = min(min_val, re)
|
|
|
|
min_val = min(min_val, im)
|
2019-11-10 18:52:40 +00:00
|
|
|
|
|
|
|
if self.logarithmicY:
|
|
|
|
min_val = max(0.01, min_val)
|
|
|
|
|
|
|
|
self.max = max_val
|
2022-09-15 05:53:08 +00:00
|
|
|
self.span = (max_val - min_val) or 0.01
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
# We want one horizontal tick per 50 pixels, at most
|
2022-09-15 05:53:08 +00:00
|
|
|
horizontal_ticks = math.floor(self.dim.height / 50)
|
2019-11-10 18:52:40 +00:00
|
|
|
fmt = Format(max_nr_digits=4)
|
2019-11-08 12:58:14 +00:00
|
|
|
for i in range(horizontal_ticks):
|
2021-06-26 22:55:43 +00:00
|
|
|
y = self.topMargin + round(i * self.dim.height / horizontal_ticks)
|
2021-07-06 15:01:20 +00:00
|
|
|
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
2023-03-08 08:40:39 +00:00
|
|
|
qp.drawLine(
|
|
|
|
self.leftMargin - 5, y, self.leftMargin + self.dim.width + 5, y
|
|
|
|
)
|
2021-07-06 15:01:20 +00:00
|
|
|
qp.setPen(QtGui.QPen(Chart.color.text))
|
2019-11-10 18:52:40 +00:00
|
|
|
val = Value(self.valueAtPosition(y)[0], fmt=fmt)
|
|
|
|
qp.drawText(3, y + 4, str(val))
|
2019-11-08 12:58:14 +00:00
|
|
|
|
2023-03-08 08:40:39 +00:00
|
|
|
qp.drawText(
|
|
|
|
3, self.dim.height + self.topMargin, str(Value(min_val, fmt=fmt))
|
|
|
|
)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
self.drawFrequencyTicks(qp)
|
|
|
|
|
|
|
|
primary_pen = pen
|
2021-07-06 15:01:20 +00:00
|
|
|
secondary_pen = QtGui.QPen(Chart.color.sweep_secondary)
|
2019-11-08 12:58:14 +00:00
|
|
|
if len(self.data) > 0:
|
2021-07-06 15:01:20 +00:00
|
|
|
c = QtGui.QColor(Chart.color.sweep)
|
2019-11-08 12:58:14 +00:00
|
|
|
c.setAlpha(255)
|
|
|
|
pen = QtGui.QPen(c)
|
|
|
|
pen.setWidth(2)
|
|
|
|
qp.setPen(pen)
|
|
|
|
qp.drawLine(20, 9, 25, 9)
|
2021-07-06 15:01:20 +00:00
|
|
|
c = QtGui.QColor(Chart.color.sweep_secondary)
|
2019-11-08 12:58:14 +00:00
|
|
|
c.setAlpha(255)
|
|
|
|
pen.setColor(c)
|
|
|
|
qp.setPen(pen)
|
2020-06-15 11:27:00 +00:00
|
|
|
qp.drawLine(
|
2023-03-08 08:40:39 +00:00
|
|
|
self.leftMargin + self.dim.width,
|
|
|
|
9,
|
|
|
|
self.leftMargin + self.dim.width + 5,
|
|
|
|
9,
|
|
|
|
)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
2021-06-26 22:55:43 +00:00
|
|
|
primary_pen.setWidth(self.dim.point)
|
|
|
|
secondary_pen.setWidth(self.dim.point)
|
|
|
|
line_pen.setWidth(self.dim.line)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
2022-09-15 05:53:08 +00:00
|
|
|
for i, data in enumerate(self.data):
|
|
|
|
x = self.getXPosition(data)
|
|
|
|
y_re = self.getReYPosition(data)
|
|
|
|
y_im = self.getImYPosition(data)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.setPen(primary_pen)
|
|
|
|
if self.isPlotable(x, y_re):
|
|
|
|
qp.drawPoint(x, y_re)
|
|
|
|
qp.setPen(secondary_pen)
|
|
|
|
if self.isPlotable(x, y_im):
|
|
|
|
qp.drawPoint(x, y_im)
|
2021-06-27 08:59:07 +00:00
|
|
|
if self.flag.draw_lines and i > 0:
|
2019-11-08 12:58:14 +00:00
|
|
|
prev_x = self.getXPosition(self.data[i - 1])
|
2022-09-15 05:53:08 +00:00
|
|
|
prev_y_re = self.getReYPosition(self.data[i - 1])
|
|
|
|
prev_y_im = self.getImYPosition(self.data[i - 1])
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
# Real part first
|
2021-07-06 15:01:20 +00:00
|
|
|
line_pen.setColor(Chart.color.sweep)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.setPen(line_pen)
|
2022-09-15 19:05:07 +00:00
|
|
|
if self.isPlotable(x, y_re):
|
|
|
|
if self.isPlotable(prev_x, prev_y_re):
|
|
|
|
qp.drawLine(x, y_re, prev_x, prev_y_re)
|
|
|
|
else:
|
|
|
|
new_x, new_y = self.getPlotable(
|
2023-03-08 08:40:39 +00:00
|
|
|
x, y_re, prev_x, prev_y_re
|
|
|
|
)
|
2022-09-15 19:05:07 +00:00
|
|
|
qp.drawLine(x, y_re, new_x, new_y)
|
|
|
|
elif self.isPlotable(prev_x, prev_y_re):
|
2019-11-08 12:58:14 +00:00
|
|
|
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
|
|
|
|
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
|
|
|
|
|
|
|
|
# Imag part second
|
2021-07-06 15:01:20 +00:00
|
|
|
line_pen.setColor(Chart.color.sweep_secondary)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.setPen(line_pen)
|
2022-09-15 19:05:07 +00:00
|
|
|
if self.isPlotable(x, y_im):
|
|
|
|
if self.isPlotable(prev_x, prev_y_im):
|
|
|
|
qp.drawLine(x, y_im, prev_x, prev_y_im)
|
|
|
|
else:
|
|
|
|
new_x, new_y = self.getPlotable(
|
2023-03-08 08:40:39 +00:00
|
|
|
x, y_im, prev_x, prev_y_im
|
|
|
|
)
|
2022-09-15 19:05:07 +00:00
|
|
|
qp.drawLine(x, y_im, new_x, new_y)
|
|
|
|
elif self.isPlotable(prev_x, prev_y_im):
|
2019-11-08 12:58:14 +00:00
|
|
|
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
|
|
|
|
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
|
|
|
|
|
2021-07-06 15:01:20 +00:00
|
|
|
primary_pen.setColor(Chart.color.reference)
|
|
|
|
line_pen.setColor(Chart.color.reference)
|
|
|
|
secondary_pen.setColor(Chart.color.reference_secondary)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.setPen(primary_pen)
|
|
|
|
if len(self.reference) > 0:
|
2021-07-06 15:01:20 +00:00
|
|
|
c = QtGui.QColor(Chart.color.reference)
|
2019-11-08 12:58:14 +00:00
|
|
|
c.setAlpha(255)
|
|
|
|
pen = QtGui.QPen(c)
|
|
|
|
pen.setWidth(2)
|
|
|
|
qp.setPen(pen)
|
|
|
|
qp.drawLine(20, 14, 25, 14)
|
2021-07-06 15:01:20 +00:00
|
|
|
c = QtGui.QColor(Chart.color.reference_secondary)
|
2019-11-08 12:58:14 +00:00
|
|
|
c.setAlpha(255)
|
|
|
|
pen = QtGui.QPen(c)
|
|
|
|
pen.setWidth(2)
|
|
|
|
qp.setPen(pen)
|
2023-03-08 08:40:39 +00:00
|
|
|
qp.drawLine(
|
|
|
|
self.leftMargin + self.dim.width,
|
|
|
|
14,
|
|
|
|
self.leftMargin + self.dim.width + 5,
|
|
|
|
14,
|
|
|
|
)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
2022-09-15 05:53:08 +00:00
|
|
|
for i, reference in enumerate(self.reference):
|
|
|
|
if reference.freq < self.fstart or reference.freq > self.fstop:
|
2019-11-08 12:58:14 +00:00
|
|
|
continue
|
2022-09-15 05:53:08 +00:00
|
|
|
x = self.getXPosition(reference)
|
|
|
|
y_re = self.getReYPosition(reference)
|
|
|
|
y_im = self.getImYPosition(reference)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.setPen(primary_pen)
|
|
|
|
if self.isPlotable(x, y_re):
|
|
|
|
qp.drawPoint(x, y_re)
|
|
|
|
qp.setPen(secondary_pen)
|
|
|
|
if self.isPlotable(x, y_im):
|
|
|
|
qp.drawPoint(x, y_im)
|
2021-06-27 08:59:07 +00:00
|
|
|
if self.flag.draw_lines and i > 0:
|
2019-11-08 12:58:14 +00:00
|
|
|
prev_x = self.getXPosition(self.reference[i - 1])
|
2022-09-15 05:53:08 +00:00
|
|
|
prev_y_re = self.getReYPosition(self.reference[i - 1])
|
|
|
|
prev_y_im = self.getImYPosition(self.reference[i - 1])
|
2019-11-08 12:58:14 +00:00
|
|
|
|
2021-07-06 15:01:20 +00:00
|
|
|
line_pen.setColor(Chart.color.reference)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.setPen(line_pen)
|
|
|
|
# Real part first
|
2022-09-15 19:05:07 +00:00
|
|
|
if self.isPlotable(x, y_re):
|
|
|
|
if self.isPlotable(prev_x, prev_y_re):
|
|
|
|
qp.drawLine(x, y_re, prev_x, prev_y_re)
|
|
|
|
else:
|
|
|
|
new_x, new_y = self.getPlotable(
|
2023-03-08 08:40:39 +00:00
|
|
|
x, y_re, prev_x, prev_y_re
|
|
|
|
)
|
2022-09-15 19:05:07 +00:00
|
|
|
qp.drawLine(x, y_re, new_x, new_y)
|
|
|
|
elif self.isPlotable(prev_x, prev_y_re):
|
2019-11-08 12:58:14 +00:00
|
|
|
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
|
|
|
|
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
|
|
|
|
|
2021-07-06 15:01:20 +00:00
|
|
|
line_pen.setColor(Chart.color.reference_secondary)
|
2019-11-08 12:58:14 +00:00
|
|
|
qp.setPen(line_pen)
|
|
|
|
# Imag part second
|
2022-09-15 19:05:07 +00:00
|
|
|
if self.isPlotable(x, y_im):
|
|
|
|
if self.isPlotable(prev_x, prev_y_im):
|
|
|
|
qp.drawLine(x, y_im, prev_x, prev_y_im)
|
|
|
|
else:
|
|
|
|
new_x, new_y = self.getPlotable(
|
2023-03-08 08:40:39 +00:00
|
|
|
x, y_im, prev_x, prev_y_im
|
|
|
|
)
|
2022-09-15 19:05:07 +00:00
|
|
|
qp.drawLine(x, y_im, new_x, new_y)
|
|
|
|
elif self.isPlotable(prev_x, prev_y_im):
|
2019-11-08 12:58:14 +00:00
|
|
|
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
|
|
|
|
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
|
|
|
|
|
|
|
|
# Now draw the markers
|
|
|
|
for m in self.markers:
|
|
|
|
if m.location != -1:
|
|
|
|
x = self.getXPosition(self.data[m.location])
|
|
|
|
y_re = self.getReYPosition(self.data[m.location])
|
|
|
|
y_im = self.getImYPosition(self.data[m.location])
|
|
|
|
|
2023-03-08 08:40:39 +00:00
|
|
|
self.drawMarker(x, y_re, qp, m.color, self.markers.index(m) + 1)
|
|
|
|
self.drawMarker(x, y_im, qp, m.color, self.markers.index(m) + 1)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
def getImYPosition(self, d: Datapoint) -> int:
|
2019-11-17 13:13:37 +00:00
|
|
|
im = d.impedance().imag
|
2019-11-08 12:58:14 +00:00
|
|
|
im = im * 10e6 / d.freq
|
2019-11-08 22:07:24 +00:00
|
|
|
if self.logarithmicY:
|
2019-11-10 18:52:40 +00:00
|
|
|
min_val = self.max - self.span
|
|
|
|
if self.max > 0 and min_val > 0 and im > 0:
|
|
|
|
span = math.log(self.max) - math.log(min_val)
|
|
|
|
else:
|
|
|
|
return -1
|
2022-09-13 16:46:02 +00:00
|
|
|
return int(
|
2023-03-08 08:40:39 +00:00
|
|
|
self.topMargin
|
|
|
|
+ (math.log(self.max) - math.log(im)) / span * self.dim.height
|
|
|
|
)
|
|
|
|
return int(
|
|
|
|
self.topMargin + (self.max - im) / self.span * self.dim.height
|
|
|
|
)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
def getReYPosition(self, d: Datapoint) -> int:
|
2019-11-17 13:13:37 +00:00
|
|
|
re = d.impedance().real
|
2019-11-08 12:58:14 +00:00
|
|
|
re = re * 10e6 / d.freq
|
2019-11-08 22:07:24 +00:00
|
|
|
if self.logarithmicY:
|
2019-11-10 18:52:40 +00:00
|
|
|
min_val = self.max - self.span
|
|
|
|
if self.max > 0 and min_val > 0 and re > 0:
|
|
|
|
span = math.log(self.max) - math.log(min_val)
|
|
|
|
else:
|
|
|
|
return -1
|
2022-09-13 16:46:02 +00:00
|
|
|
return int(
|
2023-03-08 08:40:39 +00:00
|
|
|
self.topMargin
|
|
|
|
+ (math.log(self.max) - math.log(re)) / span * self.dim.height
|
|
|
|
)
|
2022-09-13 16:46:02 +00:00
|
|
|
return int(
|
2023-03-08 08:40:39 +00:00
|
|
|
self.topMargin + (self.max - re) / self.span * self.dim.height
|
|
|
|
)
|
2019-11-08 12:58:14 +00:00
|
|
|
|
|
|
|
def valueAtPosition(self, y) -> List[float]:
|
|
|
|
absy = y - self.topMargin
|
2019-11-08 22:07:24 +00:00
|
|
|
if self.logarithmicY:
|
2019-11-10 18:52:40 +00:00
|
|
|
min_val = self.max - self.span
|
|
|
|
if self.max > 0 and min_val > 0:
|
|
|
|
span = math.log(self.max) - math.log(min_val)
|
2021-06-26 22:55:43 +00:00
|
|
|
step = span / self.dim.height
|
2019-11-10 18:52:40 +00:00
|
|
|
val = math.exp(math.log(self.max) - absy * step)
|
|
|
|
else:
|
|
|
|
val = -1
|
2019-11-08 22:07:24 +00:00
|
|
|
else:
|
2021-06-26 22:55:43 +00:00
|
|
|
val = -1 * ((absy / self.dim.height * self.span) - self.max)
|
2019-11-08 12:58:14 +00:00
|
|
|
return [val]
|
|
|
|
|
|
|
|
def getNearestMarker(self, x, y) -> Marker:
|
|
|
|
if len(self.data) == 0:
|
|
|
|
return None
|
|
|
|
shortest = 10**6
|
|
|
|
nearest = None
|
|
|
|
for m in self.markers:
|
|
|
|
mx, _ = self.getPosition(self.data[m.location])
|
|
|
|
myr = self.getReYPosition(self.data[m.location])
|
|
|
|
myi = self.getImYPosition(self.data[m.location])
|
|
|
|
dx = abs(x - mx)
|
2022-09-15 05:53:08 +00:00
|
|
|
dy = min(abs(y - myr), abs(y - myi))
|
2019-11-08 12:58:14 +00:00
|
|
|
distance = math.sqrt(dx**2 + dy**2)
|
|
|
|
if distance < shortest:
|
|
|
|
shortest = distance
|
|
|
|
nearest = m
|
|
|
|
return nearest
|