Skip to content

Commit ebe918d

Browse files
committed
Fix SO2/SE2.interp1(), which raised NameError for every input
The fix for #33 dropped the `start` local from interp1() but only replaced its two uses in the N == 3 branch, so the SO(2)/SE(2) branch has referenced an undefined name ever since: SE2(1, 2, 0.3).interp1(0.5) # NameError: name 'start' is not defined #33 did report it for both SE2 and SE3. Pass None like the N == 3 branch does; trinterp2() already treats a None start as the identity. interp1() had no test coverage for either dimension, hence the four years.
1 parent 2f20bf7 commit ebe918d

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

spatialmath/baseposematrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,10 @@ def interp1(self, s: float = None) -> Self:
512512
# SO(2) or SE(2)
513513
if len(s) > 1:
514514
assert len(self) == 1, "if len(s) > 1, len(X) must == 1"
515-
return self.__class__([smb.trinterp2(start, self.A, s=_s) for _s in s])
515+
return self.__class__([smb.trinterp2(None, self.A, s=_s) for _s in s])
516516
else:
517517
return self.__class__(
518-
[smb.trinterp2(start, x, s=s[0]) for x in self.data]
518+
[smb.trinterp2(None, x, s=s[0]) for x in self.data]
519519
)
520520
elif self.N == 3:
521521
# SO(3) or SE(3)

tests/test_pose2d.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,23 @@ def test_interp(self):
466466
array_compare(T1.interp(T2, s=0.5, shortest=False), SE2(0, 0, 0.05))
467467
array_compare(T1.interp(T2, s=0.5, shortest=True), SE2(0, 0, -math.pi + 0.05))
468468

469+
def test_interp1(self):
470+
# interpolate from the identity pose
471+
TT = SE2(2, -4, 0.6)
472+
array_compare(TT.interp1(0), SE2())
473+
array_compare(TT.interp1(1), TT)
474+
array_compare(TT.interp1(0.5), SE2(1, -2, 0.3))
475+
476+
z = TT.interp1([0, 0.5, 1])
477+
self.assertEqual(len(z), 3)
478+
array_compare(z[2], TT)
479+
480+
R = SO2(0.6)
481+
array_compare(R.interp1(0), SO2())
482+
array_compare(R.interp1(1), R)
483+
array_compare(R.interp1(0.5), SO2(0.3))
484+
self.assertEqual(len(SE2([TT, TT]).interp1(0.5)), 2)
485+
469486
def test_miscellany(self):
470487
TT = SE2(1, 2, 0.3)
471488

0 commit comments

Comments
 (0)