diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index f58042f0..66b09d39 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -1676,8 +1676,8 @@ class LineROI(ROI): pos2 = Point(pos2) d = pos2-pos1 l = d.length() - ra = Point(1, 0).angle(d, units="radians") - c = Point(-width/2. * sin(ra), -width/2. * cos(ra)) + ra = d.angle(Point(1, 0), units="radians") + c = Point(width/2. * sin(ra), -width/2. * cos(ra)) pos1 = pos1 + c ROI.__init__(self, pos1, size=Point(l, width), angle=degrees(ra), **args) diff --git a/tests/graphicsItems/test_ROI.py b/tests/graphicsItems/test_ROI.py index 68a59544..b2db38fd 100644 --- a/tests/graphicsItems/test_ROI.py +++ b/tests/graphicsItems/test_ROI.py @@ -6,6 +6,7 @@ import platform from pyqtgraph.Qt import QtCore, QtGui, QtTest from tests.image_testing import assertImageApproved from tests.ui_testing import mouseMove, mouseDrag, mouseClick, resizeWindow +import math app = pg.mkQApp() pg.setConfigOption("mouseRateLimit", 0) @@ -251,4 +252,22 @@ def test_PolyLineROI(): assert len(r.getState()['points']) == 3 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])