Skip to content

display: match McCode for hollow box/cylinder, box normal and annulus width - #399

Merged
g5t merged 1 commit into
mccode-dev:mainfrom
willend:2026-10-display-hollow-annulus
Oct 20, 2026
Merged

g5t merged 1 commit into
mccode-dev:mainfrom
willend:2026-10-display-hollow-annulus

Conversation

@willend

@willend willend commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #398.

The MCDISPLAY primitives drew some shapes differently from the McCode runtime (mccode-r.c) and from McCode's own mcdisplay tools (mccode-dev/McCode#2844, mccode-dev/McCode#2846). This PR brings to_polylines, to_mesh and the brep renderer in line with them.

Box (box(x,y,z, xw,yh,zd, thickness, nx,ny,nz))

  • thickness > 0 now draws a closed xw-2t × yh-2t × zd-2t cavity, as mcdis_box does. Before, it drew xw-t × …, from half-sizes d - t/2. The cavity is drawn only when all three sizes are positive.
  • The normal is applied everywhere: local y is rotated onto n by the smallest rotation (a half turn about z for n = -y), as mcdis_rotated_box does. Before, to_polylines and to_mesh ignored n, and brep rotated local z onto n. In brep that also scrambled the axes of a box with the default normal: Box(0,0,0, 0.1,0.2,0.3) came out 0.2 × 0.3 × 0.1.
  • to_mesh and brep now include the cavity. The cavity's mesh triangles are wound in reverse.

Cylinder

  • thickness > 0 adds the closed r-t, h-2t cavity, as mcdis_cylinder does. This applies in to_polylines, to_mesh and brep.

Annulus

  • The 5th argument is the ring width, as McStas and McXtrace Annulus.comp pass it (mcdis_annulus(0,0,0, radius, thickness, 0,1,0)). The inner radius is now max(0, r_outer - width), so Annulus(radius=0.06, thickness=0.02) gives a ring over [0.04, 0.06] instead of [0.02, 0.06].
  • The dataclass field is renamed r_inner → thickness, to match its meaning and the McCode argument name. This is an API change for anyone who builds Annulus(..., r_inner=...) by keyword (breaking-change label suggested). Positional construction and parsing are unchanged.

Tests

  • New TestHollowShapes classes in tests/test_display.py and tests/test_display_brep.py cover box rotation (+x, and -y as a half turn), the cavity sizes, the solid fallback when the walls are too thick, the cylinder cavity, the brep volumes, and the annulus radii.
  • I ran each case against the code on main: the old code gives a 0.09×0.19×0.29 cavity, an unrotated box, no cylinder cavity, an annulus inner radius of 0.02, and a brep default box of 0.2×0.3×0.1.
  • python -m pytest tests (macOS arm64, [test,brep] extras plus matplotlib, McCode latest): 1321 passed, 8 skipped, 0 failed. I did not run it against the v3.8.7 pin, since the change does not touch compiling or running instruments. Not run on Linux or Windows.

🤖 Generated with Claude Code

… width

The MCDISPLAY primitives drew some shapes differently from the McCode
runtime (mccode-r.c) and from McCode's own mcdisplay tools, so geometry
shown or exported by mccode-antlr did not match the component physics.

- box: the thickness cavity was w-t (half-sizes d-t/2) instead of the
  closed w-2t x h-2t x l-2t cavity mcdis_box draws, and the normal was
  ignored outside brep. The local y axis is now rotated onto n by the
  smallest rotation (half turn about z for n = -y), as mcdis_rotated_box,
  in to_polylines, to_mesh and brep. brep also had the axes of a
  default-normal box scrambled (0.1x0.2x0.3 came out 0.2x0.3x0.1).
- box to_mesh and brep now include the cavity.
- cylinder: thickness adds the closed r-t, h-2t cavity, as mcdis_cylinder,
  in to_polylines, to_mesh and brep.
- annulus: the 5th argument is the ring width, as McStas and McXtrace
  Annulus.comp pass it, so the inner radius is max(0, r_outer - width).
  The field is renamed r_inner -> thickness to say so.

Cavities are drawn only when all their sizes are positive, as in
mccode-r.c.

Fixes mccode-dev#398

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@g5t
g5t merged commit 29029f5 into mccode-dev:main Oct 20, 2026
14 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.

display: hollow box/cylinder and annulus differ from the McCode runtime and component physics

2 participants