Commit 0c06418
authored
Forces read only (#908)
# 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:
```rust
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.1 parent 567b9f5 commit 0c06418
File tree
4 files changed
+230
-149
lines changed- migration-guides
- src/dynamics
- rigid_body/forces
4 files changed
+230
-149
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
205 | 208 | | |
206 | 209 | | |
207 | 210 | | |
| |||
0 commit comments