refactor[physics] :: remove duplication and add constants#10
Conversation
Summary of ChangesHello @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
Ignored Files
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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
a2f060c to
5ad0961
Compare
- 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
left a comment
There was a problem hiding this comment.
Follow up to the pr was created on 2026-01-04T20:05:15Z
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
physics_engine.rsto import fromnumerics, fix wall collision logic, and use shared constantsconstants.rs(PERFECTLY_ELASTIC_RESTITUTION,WALL_BOUNCE_DAMPING_FACTOR,MAX_COORDINATE_VALUE)unimplemented!inphysics_constraints.rsutilities.rsCONTRIBUTING.mdmain.rsImpact
Testing
Notes for reviewers
Closes #11