Skip to content

Commit 8935607

Browse files
committed
protect matrix formatting from black
1 parent 81d509a commit 8935607

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎spatialmath/base/transforms2d.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ def rot2(theta, unit='rad'):
4646
theta = base.getunit(theta, unit)
4747
ct = base.sym.cos(theta)
4848
st = base.sym.sin(theta)
49+
# fmt: off
4950
R = np.array([
5051
[ct, -st],
51-
[st, ct]])
52+
[st, ct]])
53+
# fmt: on
5254
return R
5355

5456

@@ -492,10 +494,12 @@ def adjoint2(T):
492494
elif T.shape == (3,3):
493495
# SE(2) adjoint
494496
(R, t) = base.tr2rt(T)
497+
# fmt: off
495498
return np.block([
496499
[R, np.c_[t[1], -t[0]].T],
497-
[0, 0, 1]
500+
[0, 0, 1]
498501
])
502+
# fmt: on
499503
else:
500504
raise ValueError('bad argument')
501505

‎spatialmath/base/transforms3d.py‎

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ def rotx(theta, unit="rad"):
5454
theta = base.getunit(theta, unit)
5555
ct = base.sym.cos(theta)
5656
st = base.sym.sin(theta)
57+
# fmt: off
5758
R = np.array([
5859
[1, 0, 0],
5960
[0, ct, -st],
6061
[0, st, ct]])
62+
# fmt: on
6163
return R
6264

6365

@@ -90,11 +92,12 @@ def roty(theta, unit="rad"):
9092
theta = base.getunit(theta, unit)
9193
ct = base.sym.cos(theta)
9294
st = base.sym.sin(theta)
93-
R = np.array([
95+
# fmt: off
96+
return np.array([
9497
[ct, 0, st],
9598
[0, 1, 0],
9699
[-st, 0, ct]])
97-
return R
100+
# fmt: on
98101

99102

100103
# ---------------------------------------------------------------------------------------#
@@ -125,11 +128,12 @@ def rotz(theta, unit="rad"):
125128
theta = base.getunit(theta, unit)
126129
ct = base.sym.cos(theta)
127130
st = base.sym.sin(theta)
128-
R = np.array([
131+
# fmt: off
132+
return np.array([
129133
[ct, -st, 0],
130134
[st, ct, 0],
131135
[0, 0, 1]])
132-
return R
136+
# fmt: on
133137

134138

135139
# ---------------------------------------------------------------------------------------#
@@ -367,7 +371,6 @@ def isrot(R, check=False, tol=100):
367371
>>> isrot(R) # a quick check says it is an SO(3)
368372
>>> isrot(R, check=True) # but if we check more carefully...
369373
370-
371374
:seealso: :func:`~spatialmath.base.transformsNd.isR`, :func:`~spatialmath.base.transforms2d.isrot2`, :func:`~ishom`
372375
"""
373376
return isinstance(R, np.ndarray) and R.shape == (3, 3) and (not check or base.isR(R, tol=tol))
@@ -1658,12 +1661,13 @@ def eul2jac(angles):
16581661
cphi = base.sym.cos(phi)
16591662
sphi = base.sym.sin(phi)
16601663

1664+
# fmt: off
16611665
return np.array([
16621666
[ 0, -sphi, cphi * stheta],
16631667
[ 0, cphi, sphi * stheta],
16641668
[ 1, 0, ctheta ]
16651669
])
1666-
1670+
# fmt: on
16671671

16681672
def rpy2jac(angles, order='zyx'):
16691673
"""
@@ -1721,25 +1725,29 @@ def rpy2jac(angles, order='zyx'):
17211725
sy = base.sym.sin(yaw)
17221726

17231727
if order == 'xyz':
1728+
# fmt: off
17241729
J = np.array([
17251730
[ sp, 0, 1],
17261731
[-cp * sy, cy, 0],
17271732
[ cp * cy, sy, 0]
17281733
])
1729-
1734+
# fmt: on
17301735
elif order == 'zyx':
1736+
# fmt: off
17311737
J = np.array([
17321738
[ cp * cy, -sy, 0],
17331739
[ cp * sy, cy, 0],
17341740
[-sp, 0, 1],
17351741
])
1736-
1742+
# fmt: on
17371743
elif order == 'yxz':
1744+
# fmt: off
17381745
J = np.array([
17391746
[ cp * sy, cy, 0],
17401747
[-sp, 0, 1],
17411748
[ cp * cy, -sy, 0]
17421749
])
1750+
# fmt: on
17431751
return J
17441752

17451753
def exp2jac(v):
@@ -1916,18 +1924,22 @@ def angvelxform(𝚪, inverse=False, full=True, representation='rpy/xyz'):
19161924
# autogenerated by symbolic/angvelxform.ipynb
19171925
if inverse:
19181926
# analytical rates -> angular velocity
1927+
# fmt: off
19191928
A = np.array([
19201929
[math.sin(beta), 0, 1],
19211930
[-math.sin(gamma)*math.cos(beta), math.cos(gamma), 0],
19221931
[math.cos(beta)*math.cos(gamma), math.sin(gamma), 0]
19231932
])
1933+
# fmt: on
19241934
else:
19251935
# angular velocity -> analytical rates
1936+
# fmt: off
19261937
A = np.array([
19271938
[0, -math.sin(gamma)/math.cos(beta), math.cos(gamma)/math.cos(beta)],
19281939
[0, math.cos(gamma), math.sin(gamma)],
19291940
[1, math.sin(gamma)*math.tan(beta), -math.cos(gamma)*math.tan(beta)]
19301941
])
1942+
# fmt: on
19311943

19321944
elif representation == 'rpy/zyx':
19331945
alpha = 𝚪[0]
@@ -1936,38 +1948,45 @@ def angvelxform(𝚪, inverse=False, full=True, representation='rpy/xyz'):
19361948
# autogenerated by symbolic/angvelxform.ipynb
19371949
if inverse:
19381950
# analytical rates -> angular velocity
1951+
# fmt: off
19391952
A = np.array([
19401953
[math.cos(beta)*math.cos(gamma), -math.sin(gamma), 0],
19411954
[math.sin(gamma)*math.cos(beta), math.cos(gamma), 0],
19421955
[-math.sin(beta), 0, 1]
19431956
])
1957+
# fmt: on
19441958
else:
19451959
# angular velocity -> analytical rates
1960+
# fmt: off
19461961
A = np.array([
19471962
[math.cos(gamma)/math.cos(beta), math.sin(gamma)/math.cos(beta), 0],
19481963
[-math.sin(gamma), math.cos(gamma), 0],
19491964
[math.cos(gamma)*math.tan(beta), math.sin(gamma)*math.tan(beta), 1]
19501965
])
1951-
1966+
# fmt: on
19521967
elif representation == 'eul':
19531968
phi = 𝚪[0]
19541969
theta = 𝚪[1]
19551970
psi = 𝚪[2]
19561971
# autogenerated by symbolic/angvelxform.ipynb
19571972
if inverse:
19581973
# analytical rates -> angular velocity
1974+
# fmt: off
19591975
A = np.array([
19601976
[0, -math.sin(phi), math.sin(theta)*math.cos(phi)],
19611977
[0, math.cos(phi), math.sin(phi)*math.sin(theta)],
19621978
[1, 0, math.cos(theta)]
19631979
])
1980+
# fmt: on
19641981
else:
19651982
# angular velocity -> analytical rates
1983+
# fmt: off
19661984
A = np.array([
19671985
[-math.cos(phi)/math.tan(theta), -math.sin(phi)/math.tan(theta), 1],
19681986
[-math.sin(phi), math.cos(phi), 0],
19691987
[math.cos(phi)/math.sin(theta), math.sin(phi)/math.sin(theta), 0]
19701988
])
1989+
# fmt: on
19711990
elif representation == 'exp':
19721991
# from ETHZ class notes
19731992
sk = base.skew(𝚪)
@@ -2166,17 +2185,21 @@ def tr2adjoint(T):
21662185
Z = np.zeros((3, 3), dtype=T.dtype)
21672186
if T.shape == (3,3):
21682187
# SO(3) adjoint
2188+
# fmt: off
21692189
return np.block([
21702190
[R, Z],
21712191
[Z, R]
21722192
])
2193+
# fmt: on
21732194
elif T.shape == (4,4):
21742195
# SE(3) adjoint
21752196
(R, t) = base.tr2rt(T)
2197+
# fmt: off
21762198
return np.block([
21772199
[R, base.skew(t) @ R],
21782200
[Z, R]
21792201
])
2202+
# fmt: on
21802203
else:
21812204
raise ValueError('bad argument')
21822205

0 commit comments

Comments
 (0)