forked from pyqtgraph/pyqtgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_srttransform3d.py
54 lines (46 loc) · 1.62 KB
/
test_srttransform3d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import pytest
from numpy.testing import assert_almost_equal, assert_array_almost_equal
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
testPoints = np.array([
[0, 0, 0],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[-1, -1, 0],
[0, -1, -1]])
def testMatrix():
"""
SRTTransform3D => Transform3D => SRTTransform3D
"""
tr = pg.SRTTransform3D()
tr.setRotate(45, (0, 0, 1))
tr.setScale(0.2, 0.4, 1)
tr.setTranslate(10, 20, 40)
assert tr.getRotation() == (45, QtGui.QVector3D(0, 0, 1))
assert tr.getScale() == QtGui.QVector3D(0.2, 0.4, 1)
assert tr.getTranslation() == QtGui.QVector3D(10, 20, 40)
tr2 = pg.Transform3D(tr)
assert np.all(tr.matrix() == tr2.matrix())
# This is the most important test:
# The transition from Transform3D to SRTTransform3D is a tricky one.
tr3 = pg.SRTTransform3D(tr2)
assert_array_almost_equal(tr.matrix(), tr3.matrix())
assert_almost_equal(tr3.getRotation()[0], tr.getRotation()[0])
assert_array_almost_equal(tr3.getRotation()[1], tr.getRotation()[1])
assert_array_almost_equal(tr3.getScale(), tr.getScale())
assert_array_almost_equal(tr3.getTranslation(), tr.getTranslation())
@pytest.mark.parametrize("v", [
pg.Vector((0, 0, 0)),
QtGui.QVector3D(0, 0, 0),
np.array((0, 0, 0)),
QtCore.QPoint(0, 0),
QtCore.QPointF(0.0, 0.0),
(0, 0, 0),
[0, 0],
])
def testMapTypes(v):
tr = pg.SRTTransform3D()
res = tr.map(v)
assert isinstance(res, type(v))