Skip to content

Commit 4f36110

Browse files
committed
fix: support scalar/2-elem dim shorthand in tranimate/Animate
tranimate() popped "dims" from kwargs but forwarded it to Animate() as dim=, and every other function in this codebase (plotvol2, plotvol3) uses the singular "dim" as the actual keyword name. Calling tranimate(T, dim=1.5) -- correct per that convention -- left dim=1.5 sitting in **kwargs, colliding with the explicit dim=dim already being passed to Animate() and raising "got multiple values for keyword argument 'dim'". Now accepts dim, with dims kept as a back-compat alias for the previous docstring examples. Animate.__init__ also had its own hand-rolled dim-length check that only accepted 2 or 6 elements, so even a correctly-named dim=1.5 would have failed validation afterward. Replaced it with expand_dims(), the same helper plotvol3 already uses, so the scalar-shorthand convention (A -> [-A,A] on every axis) works consistently everywhere.
1 parent 8b83c1f commit 4f36110

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

spatialmath/base/animate.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ def __init__(
6060
6161
:param ax: the axes to plot into, defaults to current axes
6262
:type ax: Axes3D reference
63-
:param dim: dimension of plot volume as [xmin, xmax, ymin, ymax,
64-
zmin, zmax]. If dims is [min, max] those limits are applied
65-
to the x-, y- and z-axes.
66-
:type dim: array_like(6) or array_like(2)
63+
:param dim: dimension of plot volume, using the same shorthand as
64+
``plotvol3``: a scalar ``A`` gives ``[-A,A]`` on every axis, a
65+
2-vector ``[A,B]`` gives ``[A,B]`` on every axis, and a 6-vector
66+
gives ``[xmin, xmax, ymin, ymax, zmin, zmax]`` explicitly.
67+
:type dim: scalar, array_like(2) or array_like(6)
6768
:param projection: 3D projection: ortho [default] or persp
6869
:type projection: str
6970
:param labels: labels for the axes, defaults to X, Y and Z
@@ -105,13 +106,9 @@ def __init__(
105106
# # ax.set_aspect('equal')
106107
ax = smb.plotvol3(ax=ax, dim=dim)
107108
if dim is not None:
108-
dim = list(np.ndarray.flatten(np.array(dim)))
109-
if len(dim) == 2:
110-
dim = dim * 3
111-
elif len(dim) != 6:
112-
raise ValueError(
113-
f"dim must have 2 or 6 elements, got {dim}. See docstring for details."
114-
)
109+
# same shorthand as plotvol3: scalar A -> [-A,A]*3, [A,B] -> [A,B]*3,
110+
# or a full [xmin,xmax,ymin,ymax,zmin,zmax]
111+
dim = smb.expand_dims(dim, nd=3)
115112
ax.set_xlim(dim[0:2])
116113
ax.set_ylim(dim[2:4])
117114
ax.set_zlim(dim[4:])

spatialmath/base/transforms3d.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,8 +3402,8 @@ def tranimate(T: Union[SO3Array, SE3Array], **kwargs) -> str:
34023402
34033403
Examples:
34043404
3405-
>>> tranimate(transl(1,2,3)@trotx(1), frame='A', arrow=False, dims=[0, 5])
3406-
>>> tranimate(transl(1,2,3)@trotx(1), frame='A', arrow=False, dims=[0, 5], movie='spin.mp4')
3405+
>>> tranimate(transl(1,2,3)@trotx(1), frame='A', arrow=False, dim=[0, 5])
3406+
>>> tranimate(transl(1,2,3)@trotx(1), frame='A', arrow=False, dim=[0, 5], movie='spin.mp4')
34073407
34083408
.. note:: For Jupyter this works with the ``notebook`` and ``TkAgg``
34093409
backends.
@@ -3419,7 +3419,9 @@ def tranimate(T: Union[SO3Array, SE3Array], **kwargs) -> str:
34193419
34203420
:seealso: `trplot`, `plotvol3`
34213421
"""
3422-
dim = kwargs.pop("dims", None)
3422+
# accept dim (matches Animate/plotvol2/plotvol3), keep dims as an
3423+
# alias for backward compatibility with the previous docstring/API
3424+
dim = kwargs.pop("dim", kwargs.pop("dims", None))
34233425
ax = kwargs.pop("ax", None)
34243426
anim = Animate(dim=dim, ax=ax, **kwargs)
34253427
anim.trplot(T, **kwargs)

0 commit comments

Comments
 (0)