File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -989,9 +989,12 @@ def __init__(
989
989
# a quaternion as a 1D array
990
990
# an array of quaternions as an nx4 array
991
991
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" )
995
998
elif s .shape == (4 ,):
996
999
# passed a 4-vector
997
1000
if norm :
@@ -1004,6 +1007,8 @@ def __init__(
1004
1007
else :
1005
1008
# self.data = [smb.qpositive(x) for x in s]
1006
1009
self .data = [x for x in s ]
1010
+ else :
1011
+ raise ValueError ("array could not be interpreted as UnitQuaternion" )
1007
1012
1008
1013
elif isinstance (s , SO3 ):
1009
1014
# 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,23 @@ def test_constructor(self):
151
151
q = UnitQuaternion (rotx (0.3 ))
152
152
qcompare (UnitQuaternion (q ), q )
153
153
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
+ # no check, so try to interpret as a quaternion, but shape is wrong
161
+ with self .assertRaises (ValueError ):
162
+ UnitQuaternion (R , check = False )
163
+
164
+ # wrong shape to be anything
165
+ R = np .zeros ((5 , 5 ))
166
+ with self .assertRaises (ValueError ):
167
+ UnitQuaternion (R , check = True )
168
+ with self .assertRaises (ValueError ):
169
+ UnitQuaternion (R , check = False )
170
+
154
171
def test_concat (self ):
155
172
u = UnitQuaternion ()
156
173
uu = UnitQuaternion ([u , u , u , u ])
You can’t perform that action at this time.
0 commit comments