Repository navigation
Conversation
init_prism placed each top vertex of a slanted prism at the intersection of the two adjacent offset edges, using the two-point line-line formula. That divides by the cross product of the edges: at a base vertex that is collinear with its neighbors it is 0/0 and the top vertex is NaN, which turns point_in_prism inside out for z > 0 and makes normal_to_prism abort with "degenerate plane in project_point_into_plane". When the vertex is collinear only to within rounding (e.g. a vertex partway along an edge of a rotated polygon) the formula cancels catastrophically instead and puts the top vertex up to several units away, silently. Compute the top vertex directly as the base vertex plus the miter vector m = (u1 + u2) / (1 + u1.u2 / w^2), where u1, u2 are the two edges' offsets (|u1| = |u2| = w). It satisfies m.u1 = w^2 and m.u2 = w^2, i.e. lies on both offset edges, and its denominator vanishes only where the polygon doubles back on itself. Add test_slanted_prism_collinear_vertices to test-prism: rectangles with extra vertices on their edges (exact, 1e-11 off, listed first, two of them) at +/-30 degrees, checked against the analytic top polygon, cross section and wall normals, plus rotated and translated rectangles whose extra vertex is collinear only to within rounding. 26 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 #100.
Problem
For
sidewall_angle != 0,init_prismplaced each top vertex at the intersection of the two adjacent offset edges, using the two-point line–line formula. That formula divides by the cross product of the two edges:point_in_prismthen turns the prism inside out for every z > 0, andnormal_to_prismaborts withdegenerate plane in project_point_into_plane, so Meep'sinit_simexits when subpixel averaging is on.Fix
Compute each top vertex directly as the base vertex plus the miter vector
where
u1andu2are the offsets of the two edges meeting at the vertex (|u1| = |u2| = w). Sincem·u1 = m·u2 = w²,mlies on both offset edges, so in exact arithmetic it is the same point as before. There is no division by the cross product, though. The denominator1 + cosof the angle between the edge normals vanishes only where the polygon doubles back on itself, where the old formula failed as well. The issue suggested a guard on the old formula; this approach needs no tolerance and also handles vertices that are collinear only to within rounding.Test
test_slanted_prism_collinear_vertices()inutils/test-prism.ccovers:26 checks fail before this change (8 NaN top vertices, 18 misplaced ones), 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 #100: a 4 × 2 rectangle with an extra vertex at the midpoint of its x = +2 edge, 30° sidewalls, probed at z = 0.25, where the expected cross section is x ∈ [−1.856, 1.856]:is_point_in_objectinside along xinit_simwith subpixel averagingdegenerate plane in project_point_into_planeWith this PR the prism with the extra vertex gives the same results as the plain rectangle.
This is independent of #103, the fix for #101. 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