8000 Make LGTM happier · StephLin/spatialmath-python@fc57ebc · GitHub
[go: up one dir, main page]

Skip to content

Commit fc57ebc

Browse files
committed
Make LGTM happier
clear a bunch of alerts which stay despite pylint pragmas have to roll over with first named method arguments being called self :( cleanup unused and multiple imports rollout new convention of import spatialmath.base as base
1 parent e75427c commit fc57ebc

File tree

5 files changed

+188
-163
lines changed

5 files changed

+188
-163
lines changed

spatialmath/geom3d.py

Lines changed: 46 additions & 42 deletions
< AC3F /tr>
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
#!/usr/bin/env python3
1+
# Part of Spatial Math Toolbox for Python
2+
# Copyright (c) 2000 Peter Corke
3+
# MIT Licence, see details in top-level file: LICENCE
24

35
import numpy as np
46
import math
57
from collections import namedtuple
6-
from collections import UserList
7-
8-
from spatialmath.base import argcheck as arg
9-
import spatialmath.base as base
108
import matplotlib.pyplot as plt
11-
from mpl_toolkits.mplot3d import Axes3D
9+
import spatialmath.base as base
1210
from spatialmath import SE3
1311
from spatialmath.smuserlist import SMUserList
1412

@@ -30,7 +28,7 @@ class Plane:
3028
"""
3129
def __init__(self, c):
3230

33-
self.plane = arg.getvector(c, 4)
31+
self.plane = base.getvector(c, 4)
3432

3533
# point and normal
3634
@classmethod
@@ -46,8 +44,8 @@ def PN(cls, p, n):
4644
:rtype: Plane
4745
4846
"""
49-
n = arg.getvector(n, 3) # normal to the plane
50-
p = arg.getvector(p, 3) # point on the plane
47+
n = base.getvector(n, 3) # normal to the plane
48+
p = base.getvector(p, 3) # point on the plane
5149
return cls(np.r_[n, -np.dot(n, p)])
5250

5351
# point and normal
@@ -62,7 +60,7 @@ def P3(cls, p):
6260
:rtype: Plane
6361
"""
6462

65-
p = arg.ismatrix((3,3))
63+
p = base.ismatrix(p, (3,3))
6664
v1 = p[:,0]
6765
v2 = p[:,1]
6866
v3 = p[:,2]
@@ -235,7 +233,7 @@ def __init__(self, v=None, w=None):
235233

236234
else:
237235
# additional arguments
238-
assert arg.isvector(v, 3) and arg.isvector(w, 3), 'expecting two 3-vectors'
236+
assert base.isvector(v, 3) and base.isvector(w, 3), 'expecting two 3-vectors'
239237
self.data = [np.r_[v, w]]
240238

241239
# needed to allow __rmul__ to work if left multiplied by ndarray
@@ -271,8 +269,8 @@ def PQ(P=None, Q=None):
271269
272270
:seealso: Plucker, Plucker.Planes, Plucker.PointDir
273271
"""
274-
P = arg.getvector(P, 3)
275-
Q = arg.getvector(Q, 3)
272+
P = base.getvector(P, 3)
273+
Q = base.getvector(Q, 3)
276274
# compute direction and moment
277275
w = P - Q
278276
v = np.cross(P - Q, P)
@@ -300,9 +298,9 @@ def Planes(pi1, pi2):
300298
"""
301299

302300
if not isinstance(pi1, Plane):
303-
pi1 = Plane(arg.getvector(pi1, 4))
301+
pi1 = Plane(base.getvector(pi1, 4))
304302
if not isinstance(pi2, Plane):
305-
pi2 = Plane(arg.getvector(pi2, 4))
303+
pi2 = Plane(base.getvector(pi2, 4))
306304

307305
w = np.cross(pi1.n, pi2.n)
308306
v = pi2.d * pi1.n - pi1.d * pi2.n
@@ -326,8 +324,8 @@ def PointDir(point, dir):
326324
:seealso: Plucker, Plucker.Planes, Plucker.PQ
327325
"""
328326

329-
point = arg.getvector(point, 3)
330-
dir = arg.getvector(dir, 3)
327+
point = base.getvector(point, 3)
328+
dir = base.getvector(dir, 3)
331329

332330
return Plucker(np.r_[np.cross(dir, point), dir])
333331

@@ -486,7 +484,7 @@ def point(self, lam):
486484
487485
:seealso: Plucker.pp, Plucker.closest, Plucker.uw
488486
"""
489-
lam = arg.getvector(lam, out='row')
487+
lam = base.getvector(lam, out='row')
490488
return self.pp.reshape((3,1)) + self.uw.reshape((3,1)) * lam
491489

492490
# ------------------------------------------------------------------------- #
@@ -511,15 +509,15 @@ def contains(self, x, tol=50*_eps):
511509
If ``X`` is an array with 3 rows, the test is performed on every column and
512510
an array of booleans is returned.
513511
"""
514-
if arg.isvector(x, 3):
515-
x = arg.getvector(x)
512+
if base.isvector(x, 3):
513+
x = base.getvector(x)
516514
return np.linalg.norm( np.cross(x - self.pp, self.w) ) < tol
517-
elif arg.ismatrix(x, (3,None)):
515+
elif base.ismatrix(x, (3,None)):
518516
return [np.linalg.norm(np.cross(_ - self.pp, self.w)) < tol for _ in x.T]
519517
else:
520518
raise ValueError('bad argument')
521519

522-
def __eq__(l1, l2): # pylint: disable=no-self-argument
520+
def __eq__(self, l2): # pylint: disable=no-self-argument
523521
"""
524522
Test if two lines are equivalent
525523
@@ -535,9 +533,10 @@ def __eq__(l1, l2): # pylint: disable=no-self-argument
535533
space. Note that because of the over parameterization, lines can be
536534
equivalent even if their coordinate vectors are different.
537535
"""
536+
l1 = self
538537
return abs( 1 - np.dot(base.unitvec(l1.vec), base.unitvec(l2.vec))) < 10*_eps
539538

540-
def __ne__(l1, l2): # pylint: disable=no-self-argument
539+
def __ne__(self, l2): # pylint: disable=no-self-argument
541540
"""
542541
Test if two lines are not equivalent
543542
@@ -552,10 +551,10 @@ def __ne__(l1, l2): # pylint: disable=no-self-argument
552551
space. Note that because of the over parameterization, lines can be
553552
equivalent even if their coordinate vectors are different.
554553
"""
555-
554+
l1 = self
556555
return not l1.__eq__(l2)
557556

558-
def isparallel(l1, l2, tol=10*_eps): # pylint: disable=no-self-argument
557+
def isparallel(self, l2, tol=10*_eps): # pylint: disable=no-self-argument
559558
"""
560559
Test if lines are parallel
561560
@@ -572,11 +571,11 @@ def isparallel(l1, l2, tol=10*_eps): # pylint: disable=no-self-argument
572571
573572
:seealso: Plucker.or, Plucker.intersects
574573
"""
575-
574+
l1 = self
576575
return np.linalg.norm(np.cross(l1.w, l2.w) ) < tol
577576

578577

579-
def __or__(l1, l2): # pylint: disable=no-self-argument
578+
def __or__(self, l2): # pylint: disable=no-self-argument
580579
"""
581580
Test if lines are parallel as a binary operator
582581
@@ -591,10 +590,11 @@ def __or__(l1, l2): # pylint: disable=no-self-argument
591590
592591
:seealso: Plucker.isparallel, Plucker.__xor__
593592
"""
593+
l1 = self
594594
return l1.isparallel(l2)
595595

596596

597-
def __xor__(l1, l2): # pylint: disable=no-self-argument
597+
def __xor__(self, l2): # pylint: disable=no-self-argument
598598

599599
"""
600600
Test if lines intersect as a binary operator
@@ -615,14 +615,15 @@ def __xor__(l1, l2): # pylint: disable=no-self-argument
615615
616616
:seealso: Plucker.intersects, Plucker.parallel
617617
"""
618+
l1 = self
618619
return not l1.isparallel(l2) and (abs(l1 * l2) < 10*_eps )
619620

620621
# ------------------------------------------------------------------------- #
621622
# PLUCKER LINE DISTANCE AND INTERSECTION
622623
# ------------------------------------------------------------------------- #
623624

624625

625-
def intersects(l1, l2): # pylint: disable=no-self-argument
626+
def intersects(self, l2): # pylint: disable=no-self-argument
626627
"""
627628
Intersection point of two lines
628629
@@ -639,6 +640,7 @@ def intersects(l1, l2): # pylint: disable=no-self-argument
639640
640641
:seealso: Plucker.commonperp, Plucker.eq, Plucker.__xor__
641642
"""
643+
l1 = self
642644
if l1^l2:
643645
# lines do intersect
644646
return -(np.dot(l1.v, l2.w) * np.eye(3, 3) + \
@@ -648,7 +650,7 @@ def intersects(l1, l2): # pylint: disable=no-self-argument
648650
# lines don't intersect
649651
return None
650652

651-
def distance(l1, l2): # pylint: disable=no-self-argument
653+
def distance(self, l2): # pylint: disable=no-self-argument
652654
"""
653655
Minimum distance between lines
654656
@@ -664,7 +666,8 @@ def distance(l1, l2): # pylint: disable=no-self-argument
664666
Notes:
665667
666668
- Works for parallel, skew and intersecting lines.
667-
"""
669+
"""
670+
l1 = self
668671
if l1 | l2:
669672
# lines are parallel
670673
l = np.cross(l1.w, l1.v - l2.v * np.dot(l1.w, l2.w) / dot(l2.w, l2.w)) / np.linalg.norm(l1.w)
@@ -706,7 +709,7 @@ def closest(self, x):
706709
# http://www.ahinson.com/algorithms_general/Sections/Geometry/PluckerLine.pdf
707710
# has different equation for moment, the negative
708711

709-
x = arg.getvector(x, 3)
712+
x = base.getvector(x, 3)
710713

711714
lam = np.dot(x - self.pp, self.uw)
712715
p = self.point(lam).flatten() # is the closest point on the line
@@ -715,7 +718,7 @@ def closest(self, x):
715718
return namedtuple('closest', 'p d lam')(p, d, lam)
716719

717720

718-
def commonperp(l1, l2): # pylint: disable=no-self-argument
721+
def commonperp(self, l2): # pylint: disable=no-self-argument
719722
"""
720723
Common perpendicular to two lines
721724
@@ -731,7 +734,7 @@ def commonperp(l1, l2): # pylint: disable=no-self-argument
731734
732735
:seealso: Plucker.intersect
733736
"""
734-
737+
l1 = self
735738
if l1 | l2:
736739
# no common perpendicular if lines are parallel
737740
return None
@@ -744,7 +747,7 @@ def commonperp(l1, l2): # pylint: disable=no-self-argument
744747
return Plucker(v, w)
745748

746749

747-
def __mul__(left, right): # pylint: disable=no-self-argument
750+
def __mul__(self, right): # pylint: disable=no-self-argument
748751
r"""
749752
Reciprocal product
750753
@@ -764,13 +767,14 @@ def __mul__(left, right): # pylint: disable=no-self-argument
764767
765768
:seealso: Plucker.__rmul__
766769
"""
770+
left = self
767771
if isinstance(right, Plucker):
768772
# reciprocal product
769773
return np.dot(left.uw, right.v) + np.dot(right.uw, left.v)
770774
else:
771775
raise ValueError('bad arguments')
772776

773-
def __rmul__(right, left): # pylint: disable=no-self-argument
777+
def __rmul__(self, left): # pylint: disable=no-self-argument
774778
"""
775779
Line transformation
776780
@@ -786,6 +790,7 @@ def __rmul__(right, left): # pylint: disable=no-self-argument
786790
787791
:seealso: Plucker.__mul__
788792
"""
793+
right = self
789794
if isinstance(left, SE3):
790795
A = np.r_[ np.c_[left.R, base.skew(-left.t) @ left.R],
791796
np.c_[np.zeros((3,3)), left.R]
@@ -799,7 +804,7 @@ def __rmul__(right, left): # pylint: disable=no-self-argument
799804
# ------------------------------------------------------------------------- #
800805

801806

802-
def intersect_plane(line, plane): # pylint: disable=no-self-argument
807+
def intersect_plane(self, plane): # pylint: disable=no-self-argument
803808
r"""
804809
Line intersection with a plane
805810
@@ -835,17 +840,16 @@ def intersect_plane(line, plane): # pylint: disable=no-self-argument
835840
# Note that this is in homogeneous coordinates.
836841
# intersection of plane (n,p) with the line (v,p)
837842
# returns point and line parameter
838-
839843
if not isinstance(plane, Plane):
840-
plane = Plane(arg.getvector(plane, 4))
844+
plane = Plane(base.getvector(plane, 4))
841845

842-
den = np.dot(line.w, plane.n)
846+
den = np.dot(self.w, plane.n)
843847

844848
if abs(den) > (100*_eps):
845849
# P = -(np.cross(line.v, plane.n) + plane.d * line.w) / den
846-
p = (np.cross(line.v, plane.n) - plane.d * line.w) / den
850+
p = (np.cross(self.v, plane.n) - plane.d * self.w) / den
847851

848-
t = np.dot( line.pp - p, plane.n)
852+
t = np.dot( self.pp - p, plane.n)
849853
return namedtuple('intersect_plane', 'p lam')(p, t)
850854
else:
851855
return None

0 commit comments

Comments
 (0)
0