Repository navigation
Conversation
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>
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 #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_prismandnormal_to_prismtreated it as the parallelogram spanned by the bottom edge andvps_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_prismtakes 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:intersect_line_with_prismtests 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.sidewall_angle = -30°, every line along x or y withinz·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_prismhad 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 diagonalvps_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 newmin_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_quadrilateralis unchanged; nothing else used it.For
sidewall_angle = 0both changes give the same faces as before.Test
test_slanted_prism_side_faces()inutils/test-prism.ccovers:intersect_line_with_prismtests 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;22 checks fail before this change and none fail after.
make checkpasses withOMP_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:These match the numbers in the issue, which came from the line-intersection change alone, so the
normal_to_prismchange 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