Skip to content

Commit 2ad3bae

Browse files
committed
@ operator does composition then normalization
1 parent 89f226b commit 2ad3bae

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎spatialmath/quaternion.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,10 @@ def __ne__(left, right): # lgtm[py/not-named-self] pylint: disable=no-self-argu
17241724
"""
17251725
return left.binop(right, lambda x, y: not base.isequal(x, y, unitq=True), list1=False)
17261726

1727+
def __matmul__(left, right): # lgtm[py/not-named-self] pylint: disable=no-self-argument
1728+
print('normalizing product')
1729+
return left.__mul__(right)
1730+
17271731
def interp(self, s=0, start=None, shortest=False):
17281732
"""
17291733
Interpolate between two unit quaternions

‎spatialmath/super_pose.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,30 @@ def __mul__(left, right): # lgtm[py/not-named-self] pylint: disable=no-self-arg
999999
else:
10001000
return NotImplemented
10011001

1002+
def __matmul__(left, right): # lgtm[py/not-named-self] pylint: disable=no-self-argument
1003+
"""
1004+
Overloaded ``@`` operator (superclass method)
1005+
1006+
:return: Product of two operands with normalization
1007+
:rtype: Pose instance or NumPy array
1008+
:raises ValueError: for incompatible arguments
1009+
1010+
- ``X @ Y`` compounds the poses ``X`` and ``Y`` and normalizes the result
1011+
- ``X @= Y`` compounds the poses ``X`` and ``Y``, normalizes the result,
1012+
and places the result in ``X``
1013+
1014+
.. note:: This operator is functionally equivalent to ``*`` but is more
1015+
costly. It is useful for cases where a pose is incrementally
1016+
update over many cycle.s
1017+
1018+
:seealso: :func:`__mul__`, :func:`~spatialmath.base.trnorm`
1019+
"""
1020+
if isinstance(left, right.__class__):
1021+
#print('*: pose x pose')
1022+
return left.__class__(left._op2(right, lambda x, y: base.trnorm(x @ y)), check=False)
1023+
else:
1024+
raise TypeError('@ only applies to pose composition')
1025+
10021026
def __rmul__(right, left): # lgtm[py/not-named-self] pylint: disable=no-self-argument
10031027
"""
10041028
Overloaded ``*`` operator (superclass method)

0 commit comments

Comments
 (0)