Skip to content

Commit f71cb9b

Browse files
committed
Added various minor optimizations for axes/ticks drawing features
1 parent 64af9f7 commit f71cb9b

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

qwt/scale_draw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from qtpy.QtGui import QPalette, QFontMetrics, QTransform
2828
from qtpy.QtCore import Qt, qFuzzyCompare, QLocale, QRectF, QPointF, QRect, QPoint
2929

30+
from math import ceil
3031
import numpy as np
3132

3233

@@ -609,8 +610,7 @@ def getBorderDistHint(self, font):
609610
e = self.labelRect(font, maxTick).right()
610611
e -= abs(maxPos - self.scaleMap().p2())
611612

612-
start, end = np.ceil(np.nan_to_num(np.array([s, e])).clip(0, None))
613-
return start, end
613+
return max(ceil(s), 0), max(ceil(e), 0)
614614

615615
def minLabelDist(self, font):
616616
"""

qwt/scale_engine.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,8 @@ def contains(self, interval, value):
326326
"""
327327
if not interval.isValid():
328328
return False
329-
elif qwtFuzzyCompare(value, interval.minValue(), interval.width()) < 0:
330-
return False
331-
elif qwtFuzzyCompare(value, interval.maxValue(), interval.width()) > 0:
329+
eps = abs(1.0e-6 * interval.width())
330+
if interval.minValue() - value > eps or value - interval.maxValue() > eps:
332331
return False
333332
else:
334333
return True

qwt/text.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,17 @@ def __init__(self):
230230

231231
def fontmetrics(self, font):
232232
fid = font.toString()
233-
fm = self._fm_cache.get(fid)
234-
if fm is None:
233+
try:
234+
return self._fm_cache[fid]
235+
except KeyError:
235236
return self._fm_cache.setdefault(fid, QFontMetrics(font))
236-
else:
237-
return fm
238237

239238
def fontmetrics_f(self, font):
240239
fid = font.toString()
241-
fm = self._fm_cache_f.get(fid)
242-
if fm is None:
240+
try:
241+
return self._fm_cache_f[fid]
242+
except KeyError:
243243
return self._fm_cache_f.setdefault(fid, QFontMetricsF(font))
244-
else:
245-
return fm
246244

247245
def heightForWidth(self, font, flags, text, width):
248246
"""

0 commit comments

Comments
 (0)