Skip to content

feat(brep): end-to-end trim-aware torus-face SDF, matched against OCCT#74

Merged
lv416e merged 1 commit intomainfrom
feat/torus-face-sdf
Apr 24, 2026
Merged

feat(brep): end-to-end trim-aware torus-face SDF, matched against OCCT#74
lv416e merged 1 commit intomainfrom
feat/torus-face-sdf

Conversation

@lv416e
Copy link
Copy Markdown
Owner

@lv416e lv416e commented Apr 24, 2026

Summary

  • Add torus_face_sdf_from_frame (pure JAX, jittable) and torus_face_sdf (convenience wrapper) closing the torus branch of Marschner-style trim-aware SDF built in feat(brep): extract torus trim-frame data for Marschner composition #73. sign_flip is applied to the torus primitive's sqrt((r - R)^2 + h^2) - minor and the (major-angle u, minor-angle v) UV pair feeds trim_aware_sdf.
  • Three degenerate cases protected by the safe-square / double-where guards accumulated on this stack: polar axis (r == 0, u undefined), tube-centre ring (r == major AND axial == 0, v undefined + sqrt(0)), and torus centre (delta == 0, both angles undefined).
  • 16 unit tests across two fixtures. sample_torus.step (major 5, minor 1.5) exercises the untrimmed collapse on four off-seam queries, all matching OCCT to 0.15. A quarter torus built in-test via BRepPrimAPI_MakeTorus(5, 1, pi/2) exercises the phantom regime: (-5, 0, 0) sits on the tube-centre ring at u = pi outside the quarter's [0, pi/2] range; untrimmed primitive would say d_S < 0 (inside tube), the signed blend flips it positive.

Verification

  • uv run pytest 697 passed, 1 skipped (matplotlib), 54 deselected (slow)
  • uv run mypy src/ 0 errors
  • uv run ruff check src/ tests/ clean
  • uv run ruff format src/ tests/ clean
  • jax.grad is finite at the torus centre, on the polar axis, on the tube-centre ring, and in the phantom regime; the pure composition JITs end to end.

Related

Add torus_face_sdf_from_frame (pure JAX, jittable) and
torus_face_sdf (convenience wrapper) closing the torus branch of
Marschner-style trim-aware SDF built in #73.  The composition
computes the torus primitive's signed distance
sqrt((r - R)^2 + h^2) - minor, applies sign_flip, and feeds the
(major-angle u, minor-angle v) UV pair into trim_aware_sdf.

Three degenerate cases need the safe-square + double-where guards
accumulated on this stack:

- polar axis (r == 0): major angle u undefined;
- tube-centre ring (r == major AND axial == 0): minor angle v
  undefined and the primitive distance has a sqrt(0);
- torus centre (delta == 0): both angles undefined.

16 unit tests across two fixtures:

- sample_torus.step (major=5, minor=1.5) exercises the untrimmed
  collapse on four off-seam queries, all matching OCCT
  BRepExtrema_DistShapeShape within 0.15.
- A quarter torus built in-test via BRepPrimAPI_MakeTorus(5, 1, pi/2)
  exercises the phantom regime: query (-5, 0, 0) sits on the
  tube-centre ring at u=pi (outside the quarter's [0, pi/2]) where the
  untrimmed primitive classifies it as inside the tube (d_S < 0).
  The signed blend flips it positive.

jax.grad through the query is finite at the torus centre, on the
polar axis, on the tube-centre ring, and in the phantom regime.  The
pure composition JITs end to end.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

Warning

Rate limit exceeded

@lv416e has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 2 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 2 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d15af0b8-9e76-4f70-bed3-e78602a49012

📥 Commits

Reviewing files that changed from the base of the PR and between b22c9e4 and 01f24fb.

📒 Files selected for processing (2)
  • src/brepax/brep/trim_frame.py
  • tests/unit/brep/test_torus_face_sdf.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/torus-face-sdf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for torus-face signed distance functions (SDF). It adds torus_face_sdf_from_frame and a convenience wrapper torus_face_sdf in src/brepax/brep/trim_frame.py, implementing JAX-compatible logic with guards for degenerate cases to ensure finite gradients. Additionally, a new test suite tests/unit/brep/test_torus_face_sdf.py is included to verify the implementation against OCCT and validate gradient behavior. I have no feedback to provide.

@lv416e lv416e merged commit 10e123a into main Apr 24, 2026
12 checks passed
@lv416e lv416e deleted the feat/torus-face-sdf branch April 24, 2026 10:33
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.

1 participant