Skip to content

Add na.plt.dimension for mechanical-drawing distance annotations#186

Merged
roytsmart merged 7 commits into
mainfrom
plt-dimension
Jun 12, 2026
Merged

Add na.plt.dimension for mechanical-drawing distance annotations#186
roytsmart merged 7 commits into
mainfrom
plt-dimension

Conversation

@roytsmart

Copy link
Copy Markdown
Contributor

Summary

Adds a dimension function to named_arrays.plt that annotates the distance between two 2D points like a mechanical drawing: extension lines from each point out to a dimension line with arrowheads at both ends, plus a label that auto-rotates to align with the dimension line.

Key features

  • offset displaces the dimension line perpendicular to the ab segment; the sign selects the side, so the annotation can be moved clear of other components in the drawing. A unitless offset inherits the coordinate unit, so the default offset=0 works with unitful points.
  • Extension lines are gray by default and stop short of each point by a configurable gap fraction (default 0.1), matching mechanical-drawing convention.
  • Default label is the measured length |b - a|, rounded to decimals places (default 2).
  • Fully vectorized (arrays of points/offsets broadcast, including per-element label rotation) and supports nested vector components via cartesian_nd, like annotate.
  • Styling hooks: kwargs_extension, kwargs_dimension, kwargs_text, and arrowstyle.

Built as a pure composition over the existing plot, annotate, and text wrappers, following the brace_vertical pattern.

Tests

Adds test_dimension to tests/test_plt.py covering scalar, vectorized, nested-component, unitful/unitless, default-offset, and decimals cases (24 parametrized cases, all passing).

🤖 Generated with Claude Code

Add a `dimension` function to `named_arrays.plt` that annotates the distance between two 2D points like a mechanical drawing: extension lines from each point out to a dimension line with arrowheads at both ends, plus an auto-rotated label.

The `offset` parameter displaces the dimension line perpendicular to the segment (sign selects the side) so the annotation can be moved clear of other components. Extension lines are gray and stop short of each point by a configurable `gap` fraction. The default label is the measured length rounded to `decimals` places. A unitless `offset` inherits the coordinate unit so the default `offset=0` works with unitful points.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.24%. Comparing base (738f860) to head (f6de71f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #186      +/-   ##
==========================================
+ Coverage   97.23%   97.24%   +0.01%     
==========================================
  Files         105      105              
  Lines       14129    14210      +81     
==========================================
+ Hits        13738    13819      +81     
  Misses        391      391              
Flag Coverage Δ
unittests 97.24% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

roytsmart and others added 6 commits June 10, 2026 13:01
The second example block uses np.array but no block imported numpy,
breaking the docs build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The displacement direction and label rotation were computed in data
coordinates, so with a non-equal aspect ratio the dimension line did not
look perpendicular to the segment and the label was tilted at the wrong
angle.

Compute the perpendicular direction and label angle in display
coordinates via a snapshot of the data-to-display scale ratio (sy/sx)
per axes, while keeping the offset magnitude in data coordinates. With
an equal aspect ratio the ratio is 1 and the behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Center the label vertically on the dimension line, draw it on a
background matching the axes face color, and raise its zorder so the
label cleanly masks the dimension line behind it, as in a mechanical
drawing. The defaults can still be overridden via kwargs_text.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When rotate=False, the label is drawn horizontally instead of being
rotated to match the dimension line angle.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the None->gca() default out of _display_aspect and _facecolor and
into dimension, so the helpers always receive a concrete axes. This
removes the per-helper None branches (which were not covered by tests)
and the default is exercised once by the new test_dimension_default_ax.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@roytsmart roytsmart merged commit 82d7639 into main Jun 12, 2026
34 of 35 checks passed
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.

1 participant