Merge pull request #1876 from ixjlyons/fix-lineroi-coords
Fix LineROI handle positions
This commit is contained in:
commit
4b7dfdef88
@ -1676,8 +1676,8 @@ class LineROI(ROI):
|
|||||||
pos2 = Point(pos2)
|
pos2 = Point(pos2)
|
||||||
d = pos2-pos1
|
d = pos2-pos1
|
||||||
l = d.length()
|
l = d.length()
|
||||||
ra = Point(1, 0).angle(d, units="radians")
|
ra = d.angle(Point(1, 0), units="radians")
|
||||||
c = Point(-width/2. * sin(ra), -width/2. * cos(ra))
|
c = Point(width/2. * sin(ra), -width/2. * cos(ra))
|
||||||
pos1 = pos1 + c
|
pos1 = pos1 + c
|
||||||
|
|
||||||
ROI.__init__(self, pos1, size=Point(l, width), angle=degrees(ra), **args)
|
ROI.__init__(self, pos1, size=Point(l, width), angle=degrees(ra), **args)
|
||||||
|
@ -6,6 +6,7 @@ import platform
|
|||||||
from pyqtgraph.Qt import QtCore, QtGui, QtTest
|
from pyqtgraph.Qt import QtCore, QtGui, QtTest
|
||||||
from tests.image_testing import assertImageApproved
|
from tests.image_testing import assertImageApproved
|
||||||
from tests.ui_testing import mouseMove, mouseDrag, mouseClick, resizeWindow
|
from tests.ui_testing import mouseMove, mouseDrag, mouseClick, resizeWindow
|
||||||
|
import math
|
||||||
|
|
||||||
app = pg.mkQApp()
|
app = pg.mkQApp()
|
||||||
pg.setConfigOption("mouseRateLimit", 0)
|
pg.setConfigOption("mouseRateLimit", 0)
|
||||||
@ -252,3 +253,21 @@ def test_PolyLineROI():
|
|||||||
|
|
||||||
plt.hide()
|
plt.hide()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("p1,p2", [
|
||||||
|
((1, 1), (2, 5)),
|
||||||
|
((0.1, 0.1), (-1, 5)),
|
||||||
|
((3, -1), (5, -6)),
|
||||||
|
((-2, 1), (-4, -8)),
|
||||||
|
])
|
||||||
|
def test_LineROI_coords(p1, p2):
|
||||||
|
pw = pg.plot()
|
||||||
|
|
||||||
|
lineroi = pg.LineROI(p1, p2, width=0.5, pen="r")
|
||||||
|
pw.addItem(lineroi)
|
||||||
|
|
||||||
|
# first two handles are the scale-rotate handles positioned by pos1, pos2
|
||||||
|
for expected, (name, scenepos) in zip([p1, p2], lineroi.getSceneHandlePositions()):
|
||||||
|
got = lineroi.mapSceneToParent(scenepos)
|
||||||
|
assert math.isclose(got.x(), expected[0])
|
||||||
|
assert math.isclose(got.y(), expected[1])
|
||||||
|
Loading…
Reference in New Issue
Block a user