Fix LineROI handle positions

This commit is contained in:
Kenneth Lyons 2021-07-03 07:51:23 -07:00
parent 02909999dc
commit 7ebae20c5d
2 changed files with 22 additions and 3 deletions

View File

@ -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)

View File

@ -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])