File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -989,9 +989,12 @@ def __init__(
989989 # a quaternion as a 1D array
990990 # an array of quaternions as an nx4 array
991991
992- if smb .isrot (s , check = check ):
993- # UnitQuaternion(R) R is 3x3 rotation matrix
994- self .data = [smb .r2q (s )]
992+ if s .shape == (3 , 3 ):
993+ if smb .isrot (s , check = check ):
994+ # UnitQuaternion(R) R is 3x3 rotation matrix
995+ self .data = [smb .r2q (s )]
996+ else :
997+ raise ValueError ("invalid rotation matrix provided to UnitQuaternion constructor" )
995998 elif s .shape == (4 ,):
996999 # passed a 4-vector
9971000 if norm :
@@ -1004,6 +1007,8 @@ def __init__(
10041007 else :
10051008 # self.data = [smb.qpositive(x) for x in s]
10061009 self .data = [x for x in s ]
1010+ else :
1011+ raise ValueError ("array could not be interpreted as UnitQuaternion" )
10071012
10081013 elif isinstance (s , SO3 ):
10091014 # UnitQuaternion(x) x is SO3 or SE3 (since SE3 is subclass of SO3)
Original file line number Diff line number Diff line change @@ -151,6 +151,19 @@ def test_constructor(self):
151151 q = UnitQuaternion (rotx (0.3 ))
152152 qcompare (UnitQuaternion (q ), q )
153153
154+ # fail when invalid arrays are provided
155+ # invalid rotation matrix
156+ R = 1.1 * np .eye (3 )
157+ with self .assertRaises (ValueError ):
158+ UnitQuaternion (R , check = True )
159+
160+ # wrong shape to be anything
161+ R = np .zeros ((5 , 5 ))
162+ with self .assertRaises (ValueError ):
163+ UnitQuaternion (R , check = True )
164+ with self .assertRaises (ValueError ):
165+ UnitQuaternion (R , check = False )
166+
154167 def test_concat (self ):
155168 u = UnitQuaternion ()
156169 uu = UnitQuaternion ([u , u , u , u ])
You can’t perform that action at this time.
0 commit comments