Skip to content

Use the true trapezoid side faces of slanted prisms - #103

Open
Andeloth wants to merge 1 commit into
NanoComp:masterfrom
Andeloth:slanted-prism-side-faces
Open

Andeloth wants to merge 1 commit into
NanoComp:masterfrom
Andeloth:slanted-prism-side-faces

Conversation

@Andeloth

@Andeloth Andeloth commented Nov 13, 2026 •

Copy link
Copy Markdown

Fixes #101.

Problem

A side face of a slanted prism is the trapezoid vps_bottom[nv], vps_bottom[nvp1], vps_top[nvp1], vps_top[nv]. intersect_line_with_prism and normal_to_prism treated it as the parallelogram spanned by the bottom edge and vps_top[nv] - vps_bottom[nv]. Wherever the edge meets its neighbor at an angle, the two ends of the top edge are offset differently. Near the edge's second end the parallelogram then overhangs the face (inward taper) or falls short of it (outward taper).

intersect_line_segment_with_prism takes the inside/outside state of a segment from the parity of the crossings before it, so one spurious or missed crossing flips every segment after it:

  • Inward taper (the case in Slanted prism: intersect_line_with_prism tests side faces as parallelograms, so subpixel fill fractions next to a sidewall depend on geometry far away #101): a line just outside a side wall crosses the overhang of an end face. If the line has further crossings, e.g. through a part of the prism far away, segments next to the wall count as inside. Subpixel fill fractions next to a sidewall therefore depended on distant geometry.
  • Outward taper: a line through the shortfall misses an end face, so it has an odd number of crossings. On a plain 4 × 2 rectangle with sidewall_angle = -30°, every line along x or y within z·tan 30° of a wall gets chord 0 instead of the full width, so in subpixel averaging that whole strip along each wall counts as outside.

normal_to_prism had the matching problem. It took a point beside an overhang to be at its normal distance from the face, and a point over a shortfall to be off the face, so near corners it could return the normal of a face that isn't the nearest one.

Fix

  • intersect_line_with_prism: intersect the line with each side face as the two triangles that share the diagonal vps_bottom[nv]–vps_top[nvp1]. A hit on the diagonal is counted once.
  • normal_to_prism: measure the distance to the actual trapezoid, using a new min_distance_to_planar_quadrilateral. The face is planar because both ends of its top edge lie on the offset copy of the bottom edge. min_distance_to_quadrilateral is unchanged; nothing else used it.

For sidewall_angle = 0 both changes give the same faces as before.

Test

test_slanted_prism_side_faces() in utils/test-prism.c covers:

  1. the ridge from Slanted prism: intersect_line_with_prism tests side faces as parallelograms, so subpixel fill fractions next to a sidewall depend on geometry far away #101 (inward taper, 35°), straight and with a step 3 units from the probed segments: short segments and full chords just inside and outside both side walls at three heights;
  2. a 4 × 2 rectangle at −30°: chords along x and y just inside each wall, and well inside it;
  3. normals at points beside each of the four corners, at +30° and −30°.

22 checks fail before this change and none fail after. make check passes with OMP_NUM_THREADS = 1 and 8.

Meep check (Meep 1.34.0; conda-forge libctl 4.7.1 vs this branch, loaded with LD_PRELOAD), using the reproducer from #101:

libctl 4.7.1 this PR
largest ε difference between the straight and the stepped ridge 2.321 0.000
sidewall voxel at y = −0.617 (about half inside): straight / stepped 2.174 / 4.000 2.140 / 2.140

These match the numbers in the issue, which came from the line-intersection change alone, so the normal_to_prism change does not alter ε there.

This is independent of #102, the fix for #100. Both add a test to run_unit_tests(), so whichever is merged second will have a trivial conflict there; with both applied all tests pass.

🤖 Generated with Claude Code

intersect_line_with_prism and normal_to_prism treated each side face of
a slanted prism as the parallelogram spanned by the bottom edge and the
top offset of the edge's first vertex, vps_top[nv] - vps_bottom[nv]. The
real face is the trapezoid vps_bottom[nv], vps_bottom[nvp1], vps_top[nvp1],
vps_top[nv]; wherever the edge meets its neighbor at an angle the two top
offsets differ, and near the edge's second end the parallelogram
overhangs the face (inward taper) or falls short of it (outward taper).

intersect_line_segment_with_prism takes the inside/outside state of a
segment from the parity of the crossings before it, so a spurious or
missed crossing flips every segment after it on the line:

 * inward taper: a line just outside a side wall crosses the overhang of
   an end face. If the line has further crossings, e.g. with a part of
   the prism far away, the segment counts as inside, so subpixel fill
   fractions next to a sidewall depended on distant geometry.
 * outward taper: a line just inside any wall of a plain rectangle
   misses one end face, has a single crossing and gets chord 0.

normal_to_prism likewise took points beside an overhang to be at their
normal distance from the face, and points over a shortfall to be off
it, and could return the normal of a face other than the nearest.

Intersect lines with each face as the two triangles sharing the diagonal
vps_bottom[nv]-vps_top[nvp1], and measure distances to the actual
trapezoid in normal_to_prism (min_distance_to_planar_quadrilateral).

Add test_slanted_prism_side_faces to test-prism: a straight ridge and
the same ridge with a step far from the probed segments, an outward-
tapered rectangle, and normals beside the corners for both tapers.
22 checks fail before this change, none after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

Slanted prism: intersect_line_with_prism tests side faces as parallelograms, so subpixel fill fractions next to a sidewall depend on geometry far away

1 participant