Skip to content

Commit 1ab70cd

Browse files
committed
Fix QwtScaleMap rectangle transform and degenerate scale handling
* Stop inflating transformed rectangles by 1 unit * Collapse degenerate scales (``s1 == s2``) to ``p1``
1 parent 7dc3f4d commit 1ab70cd

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

qwt/scale_map.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ def updateFactor(self):
217217
if self.__transform:
218218
self.__ts1 = self.__transform.transform(self.__ts1)
219219
ts2 = self.__transform.transform(ts2)
220-
self.__cnv = 1.0
221-
if self.__ts1 != ts2:
220+
if self.__ts1 == ts2:
221+
# Degenerate scale: collapse every value to ``p1`` (matches the
222+
# symmetric guard in ``invTransform_scalar`` and the C++ Qwt
223+
# behaviour).
224+
self.__cnv = 0.0
225+
else:
222226
self.__cnv = (self.__p2 - self.__p1) / (ts2 - self.__ts1)
223227

224228
def transform(self, *args):
@@ -269,7 +273,7 @@ def transform(self, *args):
269273
y1 = 0.0
270274
if qwtFuzzyCompare(y2, 0.0, y2 - y1) == 0:
271275
y2 = 0.0
272-
return QRectF(x1, y1, x2 - x1 + 1, y2 - y1 + 1)
276+
return QRectF(x1, y1, x2 - x1, y2 - y1)
273277
else:
274278
raise TypeError(
275279
"%s().transform() takes 1 or 3 argument(s) (%s "
@@ -292,8 +296,8 @@ def invTransform(self, *args):
292296
elif isinstance(args[2], QRectF):
293297
xMap, yMap, rect = args
294298
x1 = xMap.invTransform(rect.left())
295-
x2 = xMap.invTransform(rect.right() - 1)
299+
x2 = xMap.invTransform(rect.right())
296300
y1 = yMap.invTransform(rect.top())
297-
y2 = yMap.invTransform(rect.bottom() - 1)
301+
y2 = yMap.invTransform(rect.bottom())
298302
r = QRectF(x1, y1, x2 - x1, y2 - y1)
299303
return r.normalized()

0 commit comments

Comments
 (0)