Skip to content

refactor[physics] :: remove duplication and add constants#10

Merged
bniladridas merged 4 commits into
mainfrom
refactor/physics-engine-improvements
Jan 4, 2026
Merged

refactor[physics] :: remove duplication and add constants#10
bniladridas merged 4 commits into
mainfrom
refactor/physics-engine-improvements

Conversation

@bniladridas

@bniladridas bniladridas commented Jan 4, 2026

Copy link
Copy Markdown
Member

Summary

This PR follows up on #9 and addresses cleanup and correctness issues identified during review. It includes minor fixes to physics logic, constants, and module structure.

Why this change?

The initial refactor improved structure and numerical stability, but review feedback highlighted areas needing adjustment. This PR fixes collision logic, aligns imports and constants, clarifies unsupported paths, and updates module documentation and declarations.


What changed

  • Updated physics_engine.rs to import from numerics, fix wall collision logic, and use shared constants
  • Added physics constants in constants.rs (PERFECTLY_ELASTIC_RESTITUTION, WALL_BOUNCE_DAMPING_FACTOR, MAX_COORDINATE_VALUE)
  • Marked unsupported constraints explicitly using unimplemented! in physics_constraints.rs
  • Fixed module documentation in utilities.rs
  • Added PR title format guidelines to CONTRIBUTING.md
  • Adjusted module declarations in main.rs

Impact

  • Refactor / cleanup
  • Bug fix (wall collision logic)

Testing

  • Unit tests (all physics tests pass)
  • Manual testing (verified collision and gravity behavior)

Notes for reviewers

  • Changes preserve backward compatibility
  • All tests and pre-commit checks pass

Closes #11

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @bniladridas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors core components of the physics engine to enhance its robustness, correctness, and maintainability. It centralizes numerical utility functions to reduce duplication, fixes a logical error in wall collision detection, and improves code clarity by introducing named constants for key physical properties and limits. These changes collectively aim to make the simulation more accurate and the codebase easier to understand and extend, alongside updating project contribution standards.

Highlights

  • Code Duplication: Eliminated redundant numeric utility functions in physics_engine.rs by importing them from the numerics module, establishing a single source of truth.
  • Wall Collision Logic: Corrected wall collision behavior to only apply bounce effects when objects are moving towards the boundary, preventing incorrect bounces when moving away.
  • Constants Introduction: Introduced named constants for restitution, wall bounce damping, and coordinate limits, significantly improving code readability and maintainability.
  • Impulse Calculation: Enhanced collision impulse calculation by utilizing inverse masses, aligning with physics engine best practices for more accurate simulations.
  • Documentation & Guidelines: Updated module documentation in utilities.rs and added clear Pull Request title format guidelines to CONTRIBUTING.md.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/pull_request_template.md
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

Copy link
Copy Markdown

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 primarily refactors the physics engine by extracting numerical utilities and constants into a dedicated numerics module, improving modularity and centralizing values. Specifically, functions like clamp, safe_divide, clamp_velocity, validate_vector, and approx_eq were moved, and new constants such as EARTH_GRAVITY, PERFECTLY_ELASTIC_RESTITUTION, WALL_BOUNCE_DAMPING_FACTOR, and MAX_COORDINATE_VALUE were introduced. The Object::new constructor and PhysicsEngine calculations were updated to utilize these new utilities and constants, including a refinement of the wall bouncing logic to apply damping only when objects are moving towards a boundary. Additionally, the CONTRIBUTING.md file was updated with guidelines for pull request title formatting, engine/main.rs was modified to import simulation_manager from an external simulation_engine crate, and physics_constraints.rs now explicitly marks Distance and Axis constraints as unimplemented.

- Remove duplicated constants and functions from physics_engine.rs
- Import from numerics module for single source of truth
- Fix wall collision logic to only bounce when moving towards boundary
- Add named constants for restitution, damping, and coordinate limits
- Improve impulse calculation using inverse masses
- Fix module documentation in utilities.rs
- Update PR title format in contributing docs
@bniladridas bniladridas force-pushed the refactor/physics-engine-improvements branch from a2f060c to 5ad0961 Compare January 4, 2026 20:07
- Add local clippy hook to run Rust linting before commits
- Fix incorrect hook ID for shebang executability check
- Fix .pre-commit-config.yaml indentation to match yamllint rules
- Simplify .yamllint config for consistency
- Ensure all yaml files pass linting
- Update integration example to properly handle Result from Object::new
- Add missing Object import
- Make main return Result to propagate errors

@bniladridas bniladridas left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Follow up to the pr was created on 2026-01-04T20:05:15Z

@bniladridas bniladridas merged commit 9474a8d into main Jan 4, 2026
18 checks passed
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.

Refactor physics engine: remove duplication and improve constants

1 participant