Skip to content

Cleanup raycast tests#2488

Open
StafaH wants to merge 4 commits intonewton-physics:mainfrom
StafaH:rework/raytest
Open

Cleanup raycast tests#2488
StafaH wants to merge 4 commits intonewton-physics:mainfrom
StafaH:rework/raytest

Conversation

@StafaH
Copy link
Copy Markdown
Contributor

@StafaH StafaH commented Apr 19, 2026

Description

Cleanup of raycast tests. Functionally similar but substantially more concise, and less kernels (avoiding excessive kernel compilation). ray_intersect_geomis a dispatch function for the remaining ray functions and can be used across all tests.

Checklist

  • New or existing tests cover these changes
  • The documentation is up to date with these changes
  • CHANGELOG.md has been updated (if user-facing change)

Test plan

uv run --extra dev -m newton.tests -k test_raycast

Summary by CodeRabbit

  • Tests
    • Consolidated ray-intersection tests into a single, unified test harness for improved maintainability and consistency.
    • Replaced repetitive per-primitive test code with table-driven cases, including a new rotated-box scenario.
    • Simplified mesh validation by streamlining mesh-specific test paths.
    • Reduced redundant test imports and cleaned up duplicated coverage, lowering overall test complexity.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 2eb90c08-2c4e-46e3-9362-79ed32179131

📥 Commits

Reviewing files that changed from the base of the PR and between 9e16b6a and 264f28b.

📒 Files selected for processing (1)
  • newton/tests/test_raycast.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • newton/tests/test_raycast.py

📝 Walkthrough

Walkthrough

Removed per-primitive Warp test kernels and refactored raycast tests to use a single unified kernel_test_geom calling ray_intersect_geom (and kernel_test_mesh / ray_intersect_mesh for meshes); tests converted to table-driven cases and redundant helpers removed.

Changes

Cohort / File(s) Summary
Test File
newton/tests/test_raycast.py
Removed per-primitive Warp kernel wrappers and direct primitive launches; consolidated primitive and mesh ray intersection tests to use kernel_test_geom (for primitives) and kernel_test_mesh (for meshes) with table-driven case lists. Updated imports to ray_intersect_geom and ray_intersect_mesh only; added rotated-box case and expanded plane cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • eric-heiden
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Cleanup raycast tests' directly and concisely describes the main purpose of the changeset: consolidating and refactoring raycast test code to reduce redundancy and kernel compilation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

test.assertAlmostEqual(out_t.numpy()[0], expected, delta=delta)


def test_ray_intersect_mesh(test: TestRaycast, device: str):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟡 After this refactor, test_ray_intersect_mesh launches kernel_test_geom with GeoType.MESH, which is the same dispatcher path already covered by test_mesh_ray_intersect_via_geom at lines 308-333. That leaves no direct coverage of the ray_intersect_mesh() entry point in this file, even though renderer code calls it directly at newton/_src/sensors/warp_raytrace/raytrace.py:439-446 and 680-687.

This distinction matters because ray_intersect_geom() hardcodes enable_backface_culling=False and _DEFAULT_MESH_MAX_T when it forwards to the helper (newton/_src/geometry/raycast.py:739-742), so a regression in the direct helper plumbing would slip past both tests here. The current test name and docstring also still read as if this test targets ray_intersect_mesh() itself.

Would you consider either restoring kernel_test_mesh so this test calls the helper directly, or renaming it to reflect that it is another ray_intersect_geom case and adding a separate direct ray_intersect_mesh() smoke test?

Comment thread newton/tests/test_raycast.py Outdated
test.assertAlmostEqual(out_t.numpy()[0], expected, delta=1e-5)


def test_geom_ray_intersect(test: TestRaycast, device: str):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⚪ After the refactor, every per-type test (test_ray_intersect_sphere, test_ray_intersect_box, and so on) also launches kernel_test_geom, so this function overlaps with them substantially. The sphere, box, capsule, cylinder, cone, and ellipsoid cases here use origin (-2, 0, 0) and direction (1, 0, 0), which match the hit case in each per-type test modulo delta. The only genuinely unique case is plane with origin (0, 0, 5) and direction (0, 0, -1) expecting 5.0, since test_ray_intersect_plane only uses 3-4-5 triples and never a unit-length axial ray.

Since this PR is a cleanup, consolidation would match that intent. A few options:

  • remove test_geom_ray_intersect entirely,
  • trim it to just the plane case,
  • or fold the plane case into test_ray_intersect_plane and delete this function.

If you keep it as-is, a short comment noting which coverage is unique would help future readers.

@StafaH StafaH had a problem deploying to external-pr-approval April 20, 2026 16:06 — with GitHub Actions Error
@StafaH StafaH had a problem deploying to external-pr-approval April 20, 2026 16:06 — with GitHub Actions Error
@StafaH StafaH requested a deployment to external-pr-approval April 20, 2026 16:23 — with GitHub Actions Waiting
@StafaH StafaH requested a deployment to external-pr-approval April 20, 2026 16:23 — with GitHub Actions Waiting
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.

2 participants