Skip to content

Conversation

@Exotik850
Copy link
Contributor

Objective

Fixes #907

Solution

This PR splits the RigidBodyForces trait into ReadRigidbodyForces and WriteRigidBodyForces, and implements ReadRigidBodyForces for the ForcesReadOnlyItem type. This allows for immutable functions to be called on a Forces item immutably retrieved from queries, as shown below.

Testing

Tested by building the example shown in the issue:

fn get_total_inertia(objects: Query<(Forces, &Mass)>) {
    let total = objects
        .iter()
        .map(|(forces, mass)| forces.linear_velocity() * mass.0)
        .reduce(|a, b| a + b);
}

Which now compiles without errors and works as expected.

@Jondolf Jondolf added A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Usability A quality-of-life improvement that makes Avian easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Dec 10, 2025
@Jondolf Jondolf added this to the 0.5 milestone Dec 10, 2025
@Jondolf Jondolf added the M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide label Dec 17, 2025
Copy link
Member

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

Thanks! I fixed up some of the warnings that were causing CI to fail, so this should be good to merge now :)

@Jondolf Jondolf enabled auto-merge (squash) December 17, 2025 16:48
@Jondolf Jondolf merged commit 0c06418 into avianphysics:main Dec 17, 2025
6 checks passed
@Exotik850 Exotik850 deleted the forces-read-only branch December 17, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Usability A quality-of-life improvement that makes Avian easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forces QueryData not able to call read-only functions from a ForcesReadOnlyItem

2 participants