8000 autopep8, fixed one unhelpful E701 change · ViolinLee/spatialmath-python@7b00340 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b00340

Browse files
committed
autopep8, fixed one unhelpful E701 change
1 parent a357ad8 commit 7b00340

File tree

7 files changed

+1463
-1558
lines changed

7 files changed

+1463
-1558
lines changed

spatialmath/pose2d.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,56 @@
1010
import numpy as np
1111
import math
1212

13-
from spatialmath.base import argcheck
13+
from spatialmath.base import argcheck
1414
import spatialmath.base as tr
1515
from spatialmath import super_pose as sp
1616

17+
1718
class SO2(sp.SMPose):
18-
19+
1920
# SO2() identity matrix
2021
# SO2(angle, unit)
2122
# SO2( obj ) # deep copy
2223
# SO2( np ) # make numpy object
2324
# SO2( nplist ) # make from list of numpy objects
24-
25+
2526
# constructor needs to take ndarray -> SO2, or list of ndarray -> SO2
26-
def __init__(self, arg = None, *, unit='rad'):
27+
def __init__(self, arg=None, *, unit='rad'):
2728
super().__init__() # activate the UserList semantics
28-
29+
2930
if arg is None:
3031
# empty constructor
3132
self.data = [np.eye(2)]
32-
33+
3334
elif argcheck.isvector(arg):
3435
# SO2(value)
3536
# SO2(list of values)
3637
self.data = [tr.rot2(x, unit) for x in argcheck.getvector(arg)]
37-
38+
3839
else:
3940
super().arghandler(arg)
4041

4142
@classmethod
42-
def rand(cls, *, range=[0, 2*math.pi], unit='rad', N=1):
43+
def rand(cls, *, range=[0, 2 * math.pi], unit='rad', N=1):
4344
rand = np.random.uniform(low=range[0], high=range[1], size=N) # random values in the range
4445
return cls([tr.rot2(x) for x in argcheck.getunit(rand, unit)])
45-
46+
4647
@classmethod
4748
def isvalid(self, x):
4849
return tr.isrot2(x, check=True)
4950

5051
@property
5152
def T(self):
5253
return SO2(self.A.T)
53-
54+
5455
def inv(self):
5556
return SO2(self.A.T)
56-
57-
# for symmetry with other
57+
58+
# for symmetry with other
5859
@classmethod
5960
def R(cls, theta, unit='rad'):
6061
return SO2([tr.rot1(x, unit) for x in argcheck.getvector(theta)])
61-
62+
6263
@property
6364
def angle(self):
6465
"""Returns angle of SO2 object matrices in unit radians"""
@@ -71,30 +72,31 @@ def angle(self):
7172
elif len(angles) > 1:
7273
return angles
7374

75+
7476
class SE2(sp.SMPose):
7577
# constructor needs to take ndarray -> SO2, or list of ndarray -> SO2
76-
def __init__(self, x = None, y = None, theta = 0, *, unit='rad'):
78+
def __init__(self, x=None, y=None, theta=0, *, unit='rad'):
7779
super().__init__() # activate the UserList semantics
78-
80+
7981
if x is None:
8082
# empty constructor
8183
self.data = [np.eye(3)]
82-
83-
elif all(map(lambda x: isinstance(x, (int,float)), [x, y, theta])):
84+
85+
elif all(map(lambda x: isinstance(x, (int, float)), [x, y, theta])):
8486
# SE2(x, y, theta)
85-
self.data = [tr.trot2(theta, t=[x,y], unit=unit)]
86-
87+
self.data = [tr.trot2(theta, t=[x, y], unit=unit)]
88+
8789
elif argcheck.isvector(x) and argcheck.isvector(y) and argcheck.isvector(theta):
8890
# SE2(xvec, yvec, tvec)
8991
xvec = argcheck.getvector(x)
9092
yvec = argcheck.getvector(y, dim=len(xvec))
9193
tvec = argcheck.getvector(theta, dim=len(xvec))
9294
self.data = [tr.trot2(_t, t=[_x, _y]) for (_x, _y, _t) in zip(xvec, yvec, argcheck.getunit(tvec, unit))]
93-
95+
9496
elif isinstance(x, np.ndarray) and y is None and theta is None:
9597
assert x.shape[1] == 3, 'array argument must be Nx3'
9698
self.data = [tr.trot2(_t, t=[_x, _y], unit=unit) for (_x, _y, _t) in x]
97-
99+
98100
else:
99101
super().arghandler(x)
100102

@@ -103,33 +105,32 @@ def T(self):
103105
raise NotImplemented('transpose is not meaningful for SE3 object')
104106

105107
@classmethod
106-
def rand(cls, *, xrange=[-1, 1], yrange=[-1, 1], trange=[0, 2*math.pi], unit='rad', N=1):
108+
def rand(cls, *, xrange=[-1, 1], yrange=[-1, 1], trange=[0, 2 * math.pi], unit='rad', N=1):
107109
x = np.random.uniform(low=xrange[0], high=xrange[1], size=N) # random values in the range
108110
y = np.random.uniform(low=yrange[0], high=yrange[1], size=N) # random values in the range
109111
theta = np.random.uniform(low=trange[0], high=trange[1], size=N) # random values in the range
110-
return cls([tr.trot2(t, t=[x,y]) for (t,x,y) in zip(x, y, argcheck.getunit(theta, unit))])
111-
112+
return cls([tr.trot2(t, t=[x, y]) for (t, x, y) in zip(x, y, argcheck.getunit(theta, unit))])
113+
112114
@classmethod
113115
def isvalid(self, x):
114116
return tr.ishom2(x, check=True)
115117

116118
@property
117119
def t(self):
118-
return self.A[:2,2]
119-
120+
return self.A[:2, 2]
121+
120122
@property
121123
def R(self):
122-
return SO2(self.A[:2,:2])
123-
124+
return SO2(self.A[:2, :2])
125+
124126
def inv(self):
125127
return SO2(self.A.T)
126128
ArithmeticError()
127-
129+
128130

129131
if __name__ == '__main__': # pragma: no cover
130-
132+
131133
import pathlib
132134
import os.path
133-
134-
exec(open(os.path.join(pathlib.Path(__file__).parent.absolute(), "test_pose2d.py")).read() )
135-
135+
136+
exec(open(os.path.join(pathlib.Path(__file__).parent.absolute(), "test_pose2d.py")).read())

0 commit comments

Comments
 (0)
0