Skip to content

fix(graphics): ignore sign of scalar in expand_dims, document reversed limits - #262

Merged
taughz merged 1 commit into
rai-opensource:masterfrom
petercorke:fix/expand-dims-range
Oct 26, 2026
Merged

taughz merged 1 commit into
rai-opensource:masterfrom
petercorke:fix/expand-dims-range

Conversation

@petercorke

Copy link
Copy Markdown
Collaborator

A negative scalar passed to expand_dims (and so plotvol2/plotvol3/Animate) gave reversed limits, e.g. -3 -> [3, -3, 3, -3], silently inverting the axes. A scalar is symmetric about zero, so the sign is now ignored via abs().

For the 2/4/6 element forms no min < max check is added. Matplotlib inverts an axis when given reversed limits, so this is a useful way to flip an axis, and expand_dims is a pure function with no axes to call invert_xaxis() on. The docstring now says so.

Adds test_expand_dims.

🤖 Generated with Claude Code

…d limits

A negative scalar previously produced reversed limits (-3 -> [3,-3,...]),
silently inverting the axes. A scalar is symmetric about zero, so use abs().

Document that min > max in the 2/4/6 element forms is passed through and
matplotlib inverts the axis. Add test_expand_dims.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke requested a review from taughz as a code owner October 15, 2026 01:19
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
spatialmath/base/graphics.py 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@taughz
taughz merged commit 8c4f022 into rai-opensource:master Oct 26, 2026
13 checks passed
taughz pushed a commit that referenced this pull request Nov 5, 2026
Fixes #261.

`expand_dims()` raises `TypeError` even though `dim=None` is its
documented default. Return `None` for an unspecified extent so callers
can choose autoscaling or obtain limits elsewhere. Update the argument
and return annotations and docstring to describe this behavior.

Validate `nd` before returning, so unsupported dimensions still raise
`ValueError`, including when `dim` is `None`; zero remains an explicit
extent. Add regressions for omitted and explicit `None` in 2D/3D,
explicit numeric extents, malformed vectors, and unsupported dimensions.
Preserve the negative-scalar and reversed-limit behavior from #262 and
its regression tests.

Validation on this branch including upstream master `824a459`
(`MPLBACKEND=Agg`):

- Python 3.12.14 full suite: **476 passed, 3 skipped**, with 71 subtests
passed and 23 warnings.
- Graphics tests on Python 3.10.12 and 3.12.14: **21 passed**, with 8
subtests passed on each version.
- Repository pre-commit hooks (Black 23.10.0, EOF, debug statements,
trailing whitespace) and `git diff --check` pass. Black also wraps
existing long lines in the touched graphics module and test file.

The existing internal callers already guard `None`. Downstream bdsim
behavior has not been tested; the `scale=None` timing change noted in
#261 remains applicable.

Signed-off-by: 李永祺 <doribelove@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants