Repository navigation
display: match McCode for hollow box/cylinder, box normal and annulus width - #399
Merged
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 bringsto_polylines,to_meshand the brep renderer in line with them.Box (
box(x,y,z, xw,yh,zd, thickness, nx,ny,nz))thickness > 0now draws a closedxw-2t × yh-2t × zd-2tcavity, asmcdis_boxdoes. Before, it drewxw-t × …, from half-sizesd - t/2. The cavity is drawn only when all three sizes are positive.mcdis_rotated_boxdoes. Before,to_polylinesandto_meshignored 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_meshand brep now include the cavity. The cavity's mesh triangles are wound in reverse.Cylinder
thickness > 0adds the closedr-t,h-2tcavity, asmcdis_cylinderdoes. This applies into_polylines,to_meshand brep.Annulus
Annulus.comppass it (mcdis_annulus(0,0,0, radius, thickness, 0,1,0)). The inner radius is nowmax(0, r_outer - width), soAnnulus(radius=0.06, thickness=0.02)gives a ring over [0.04, 0.06] instead of [0.02, 0.06].r_inner→thickness, to match its meaning and the McCode argument name. This is an API change for anyone who buildsAnnulus(..., r_inner=...)by keyword (breaking-changelabel suggested). Positional construction and parsing are unchanged.Tests
TestHollowShapesclasses intests/test_display.pyandtests/test_display_brep.pycover 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.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, McCodelatest): 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