ensure that integer inputs to Rotation.fromX() translate into float quantities

This commit is contained in:
Yang Su 2019-09-19 16:58:17 -04:00
parent 8c77507bbc
commit 6fdab024b6
1 changed files with 18 additions and 12 deletions

View File

@ -252,7 +252,8 @@ class Rotation:
acceptHomomorph = False, acceptHomomorph = False,
P = -1): P = -1):
qu = quaternion if isinstance(quaternion, np.ndarray) else np.array(quaternion) qu = quaternion if isinstance(quaternion, np.ndarray) and quaternion.dtype == np.dtype(float) \
else np.array(quaternion,dtype=float)
if P > 0: qu[1:4] *= -1 # convert from P=1 to P=-1 if P > 0: qu[1:4] *= -1 # convert from P=1 to P=-1
if qu[0] < 0.0: if qu[0] < 0.0:
if acceptHomomorph: if acceptHomomorph:
@ -269,7 +270,8 @@ class Rotation:
eulers, eulers,
degrees = False): degrees = False):
eu = eulers if isinstance(eulers, np.ndarray) else np.array(eulers) eu = eulers if isinstance(eulers, np.ndarray) and eulers.dtype == np.dtype(float) \
else np.array(eulers,dtype=float)
eu = np.radians(eu) if degrees else eu eu = np.radians(eu) if degrees else eu
if np.any(eu < 0.0) or np.any(eu > 2.0*np.pi) or eu[1] > np.pi: if np.any(eu < 0.0) or np.any(eu > 2.0*np.pi) or eu[1] > np.pi:
raise ValueError('Euler angles outside of [0..2π],[0..π],[0..2π].\n{} {} {}.'.format(*eu)) raise ValueError('Euler angles outside of [0..2π],[0..π],[0..2π].\n{} {} {}.'.format(*eu))
@ -283,7 +285,8 @@ class Rotation:
normalise = False, normalise = False,
P = -1): P = -1):
ax = angleAxis if isinstance(angleAxis, np.ndarray) else np.array(angleAxis) ax = angleAxis if isinstance(angleAxis, np.ndarray) and angleAxis.dtype == np.dtype(float) \
else np.array(angleAxis,dtype=float)
if P > 0: ax[0:3] *= -1 # convert from P=1 to P=-1 if P > 0: ax[0:3] *= -1 # convert from P=1 to P=-1
if degrees: ax[ 3] = np.radians(ax[3]) if degrees: ax[ 3] = np.radians(ax[3])
if normalise: ax[0:3] /= np.linalg.norm(ax[0:3]) if normalise: ax[0:3] /= np.linalg.norm(ax[0:3])
@ -330,7 +333,8 @@ class Rotation:
normalise = False, normalise = False,
P = -1): P = -1):
ro = rodrigues if isinstance(rodrigues, np.ndarray) else np.array(rodrigues) ro = rodrigues if isinstance(rodrigues, np.ndarray) and rodrigues.dtype == np.dtype(float) \
else np.array(rodrigues,dtype=float)
if P > 0: ro[0:3] *= -1 # convert from P=1 to P=-1 if P > 0: ro[0:3] *= -1 # convert from P=1 to P=-1
if normalise: ro[0:3] /= np.linalg.norm(ro[0:3]) if normalise: ro[0:3] /= np.linalg.norm(ro[0:3])
if not np.isclose(np.linalg.norm(ro[0:3]), 1.0): if not np.isclose(np.linalg.norm(ro[0:3]), 1.0):
@ -345,7 +349,8 @@ class Rotation:
homochoric, homochoric,
P = -1): P = -1):
ho = homochoric if isinstance(homochoric, np.ndarray) else np.array(homochoric) ho = homochoric if isinstance(homochoric, np.ndarray) and homochoric.dtype == np.dtype(float) \
else np.array(homochoric,dtype=float)
if P > 0: ho *= -1 # convert from P=1 to P=-1 if P > 0: ho *= -1 # convert from P=1 to P=-1
return cls(ho2qu(ho)) return cls(ho2qu(ho))
@ -355,7 +360,8 @@ class Rotation:
cubochoric, cubochoric,
P = -1): P = -1):
cu = cubochoric if isinstance(cubochoric, np.ndarray) else np.array(cubochoric) cu = cubochoric if isinstance(cubochoric, np.ndarray) and cubochoric.dtype == np.dtype(float) \
else np.array(cubochoric,dtype=float)
ho = cu2ho(cu) ho = cu2ho(cu)
if P > 0: ho *= -1 # convert from P=1 to P=-1 if P > 0: ho *= -1 # convert from P=1 to P=-1