Skip to content

Multisize Ball-Ball Collision#289

Closed
derek-mcblane wants to merge 1 commit into
ekiefl:mainfrom
derek-mcblane:mutli-size-ball-ball
Closed

Multisize Ball-Ball Collision#289
derek-mcblane wants to merge 1 commit into
ekiefl:mainfrom
derek-mcblane:mutli-size-ball-ball

Conversation

@derek-mcblane
Copy link
Copy Markdown
Collaborator

@derek-mcblane derek-mcblane commented May 9, 2026

Update ball_ball/frictional_inelastic to support collisions between balls of different sizes.

I checked the A-14 and A-27 plots before and after this change (See my other PR). They appear slightly different, which is pretty annoying. It might be floating point error, but I'm surprised it's noticeable at all on the plots.

@derek-mcblane derek-mcblane requested a review from ekiefl as a code owner May 9, 2026 03:49
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Multisize Ball-Ball Collision' clearly and concisely summarizes the main change: updating ball-ball collision logic to handle balls of different sizes and masses.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 May 9, 2026

Codecov Report

❌ Patch coverage is 5.00000% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.33%. Comparing base (91b4bd7) to head (51eafff).

Files with missing lines Patch % Lines
...resolve/ball_ball/frictional_inelastic/__init__.py 5.00% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #289      +/-   ##
==========================================
- Coverage   46.36%   46.33%   -0.03%     
==========================================
  Files         144      144              
  Lines       10314    10320       +6     
==========================================
  Hits         4782     4782              
- Misses       5532     5538       +6     
Flag Coverage Δ
service 46.33% <5.00%> (-0.03%) ⬇️
service-no-ani 56.46% <5.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pooltool/physics/resolve/ball_ball/frictional_inelastic/__init__.py (2)

107-107: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update class docstring — model now handles unequal masses.

The docstring still claims this is for equal-mass balls, which contradicts the new per-ball (m1, R1, m2, R2) support added in this PR.

📝 Proposed wording
-    """A simple ball-ball collision model including ball-ball friction, and coefficient of restitution for equal-mass balls
+    """A simple ball-ball collision model including ball-ball friction and a coefficient of restitution, supporting balls of unequal mass and radius.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pooltool/physics/resolve/ball_ball/frictional_inelastic/__init__.py` at line
107, Update the module/class docstring to reflect that the frictional_inelastic
collision model supports unequal masses and radii by accepting per-ball
parameters (m1, R1, m2, R2); replace the phrase "for equal-mass balls" with
wording that it handles unequal masses and radii, briefly state it models
ball-ball friction and a coefficient of restitution for two possibly different
masses, and mention the expected input parameters (m1, R1, m2, R2) so the
docstring matches the implemented behavior.

76-83: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

No-slip path ignores the new per-ball parameters — defeats the purpose of this PR.

Lines 78–79 correctly compute D_v2_t and D_w2, but lines 82–83 still apply the old equal-mass / equal-radius forms (- D_v1_t and D_w1) to ball 2. Concretely:

  • Line 82: rvw2[1] - D_v1_t equals rvw2[1] + D_v2_t only when m1 == m2 (since D_v2_t = -(m1/m2)*D_v1_t).
  • Line 83: rvw2[2] + D_w1 equals rvw2[2] + D_w2 only when m1 == m2 and R1 == R2 (since D_w2 = (m1/m2) * (R1/R2) * D_w1).

For any unequal-mass or unequal-radius collision that falls into the no-slip branch (including the not has_relative_velocity case), ball 2's tangential velocity and angular velocity updates will violate Newton's third law and the no-slip contact condition. The newly computed D_v2_t / D_w2 are also dead values as written.

🐛 Proposed fix
         # velocity tangent component for no-slip condition
         D_v1_t = -(2.0 / 7.0) * v12_c / (1 + m1 / m2)
         D_w1 = 2.5 / R1 * ptmath.cross(unit_x, D_v1_t)
         D_v2_t = -(m1 / m2) * D_v1_t
         D_w2 = 2.5 / R2 * ptmath.cross(-unit_x, D_v2_t)
         rvw1_f[1] = rvw1[1] + D_v1_t
         rvw1_f[2] = rvw1[2] + D_w1
-        rvw2_f[1] = rvw2[1] - D_v1_t
-        rvw2_f[2] = rvw2[2] + D_w1
+        rvw2_f[1] = rvw2[1] + D_v2_t
+        rvw2_f[2] = rvw2[2] + D_w2

It would be worth adding a regression test that exercises the no-slip branch with m1 != m2 and R1 != R2 (e.g., zero relative surface velocity at contact, or a large u_b that drives the slip-direction-flip fallback) and asserts conservation of linear/angular momentum about the contact point.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pooltool/physics/resolve/ball_ball/frictional_inelastic/__init__.py` around
lines 76 - 83, The no-slip branch incorrectly applies D_v1_t and D_w1 to ball 2,
ignoring the computed D_v2_t and D_w2; update the rvw2_f assignments so
rvw2_f[1] = rvw2[1] + D_v2_t and rvw2_f[2] = rvw2[2] + D_w2 (mirror of rvw1_f
using the D_*_2 values) wherever the no-slip path / not has_relative_velocity
branch runs, ensuring momentum/torque consistency for unequal m1/m2 and R1/R2;
also add a regression test that triggers the no-slip branch with m1 != m2 and R1
!= R2 (e.g., zero relative surface velocity or large u_b) and asserts
conservation about the contact point.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pooltool/physics/resolve/ball_ball/frictional_inelastic/__init__.py`:
- Line 107: Update the module/class docstring to reflect that the
frictional_inelastic collision model supports unequal masses and radii by
accepting per-ball parameters (m1, R1, m2, R2); replace the phrase "for
equal-mass balls" with wording that it handles unequal masses and radii, briefly
state it models ball-ball friction and a coefficient of restitution for two
possibly different masses, and mention the expected input parameters (m1, R1,
m2, R2) so the docstring matches the implemented behavior.
- Around line 76-83: The no-slip branch incorrectly applies D_v1_t and D_w1 to
ball 2, ignoring the computed D_v2_t and D_w2; update the rvw2_f assignments so
rvw2_f[1] = rvw2[1] + D_v2_t and rvw2_f[2] = rvw2[2] + D_w2 (mirror of rvw1_f
using the D_*_2 values) wherever the no-slip path / not has_relative_velocity
branch runs, ensuring momentum/torque consistency for unequal m1/m2 and R1/R2;
also add a regression test that triggers the no-slip branch with m1 != m2 and R1
!= R2 (e.g., zero relative surface velocity or large u_b) and asserts
conservation about the contact point.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 45e6c0e7-807c-4c9a-be4d-ca40cde02e7d

📥 Commits

Reviewing files that changed from the base of the PR and between 91b4bd7 and 51eafff.

📒 Files selected for processing (1)
  • pooltool/physics/resolve/ball_ball/frictional_inelastic/__init__.py

@derek-mcblane
Copy link
Copy Markdown
Collaborator Author

Might be worth profiling this. There's probably a slight performance hit, but I'm not sure how significant.

@derek-mcblane derek-mcblane deleted the mutli-size-ball-ball branch May 9, 2026 05:13
@derek-mcblane
Copy link
Copy Markdown
Collaborator Author

Branch name has typo, going to re-open the PR

@derek-mcblane
Copy link
Copy Markdown
Collaborator Author

derek-mcblane commented May 9, 2026

Lines 78–79 correctly compute D_v2_t and D_w2, but lines 82–83 still apply the old equal-mass / equal-radius forms (- D_v1_t and D_w1) to ball 2.

Good catch

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