-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
I found some potential issues in the caching in GraphicsItem.pixelVectors.
In both the local cache lookup:
pyqtgraph/pyqtgraph/graphicsItems/GraphicsItem.py
Lines 189 to 190 in 720fa5f
| if direction is None and dt == self._pixelVectorCache[0]: | |
| return tuple(map(Point, self._pixelVectorCache[1])) ## return a *copy* |
and global cache lookup:
pyqtgraph/pyqtgraph/graphicsItems/GraphicsItem.py
Lines 194 to 198 in 720fa5f
| key = (dt.m11(), dt.m21(), dt.m12(), dt.m22()) | |
| pv = self._pixelVectorGlobalCache.get(key, None) | |
| if direction is None and pv is not None: | |
| self._pixelVectorCache = [dt, pv] | |
| return tuple(map(Point,pv)) ## return a *copy* |
the cached value is used if direction is None (implicitly QtCore.QPointF(1, 0)). However, the cached value may have been calculated for any direction, and the direction does seem not affect the key obtained from dt. This may result in returning an incorrect value in when pixelVectors has been called with an explicit direction prior to calling it with direction=None.
Furthermore, when pixelVectors is called with direction=Point([1, 0]), as done here:
pyqtgraph/pyqtgraph/graphicsItems/ROI.py
Line 2266 in 720fa5f
| pxl = self.pixelLength(Point([1, 0])) |
and here
| px = self.pixelLength(direction=Point(1,0), ortho=True) ## get pixel length orthogonal to the line |
through here:
pyqtgraph/pyqtgraph/graphicsItems/GraphicsItem.py
Lines 262 to 268 in 720fa5f
| def pixelLength(self, direction, ortho=False): | |
| """Return the length of one pixel in the direction indicated (in local coordinates) | |
| If ortho=True, then return the length of one pixel orthogonal to the direction indicated. | |
| Return None if pixel size is not yet defined (usually because the item has not yet been displayed). | |
| """ | |
| normV, orthoV = self.pixelVectors(direction) |
No cache lookup is done since direction is not None, but should be since it's set to that value implicitly if direction is None. This slows down updating e.g. InfiniteLines a lot, which is an issue for a project I'm currently working on.
I'd be happy to help out fixing this, but I'd like to know what the intended behavior is first. Is including the direction in the cache key and then not checking if direction is None a potential good fix/improvement?