Remove rest_length field from DistanceJoint.#517
Merged
Conversation
Just added a '&' where needed.
Add From<Scalar> and From<(Scalar, Scalar)> for DistanceLimit.
she's trying to help you out."--Hansel, Zoolander (2001)
Jondolf
approved these changes
Aug 18, 2025
Member
There was a problem hiding this comment.
Thanks! And sorry for getting to this so late 😅
I pushed some changes:
- Also implement
From<[Scalar; 2]>forDistanceLimit - Implement the same conversions for
AngleLimit - Revert the API changes related to
with_limits; it takesminandmaxseparately again
That last change might be the most contentious. My motivation there is:
- I would like the limit APIs to be consistent. Having
DistanceJoint::with_length_limitstakeimpl Into<DistanceLimit>is inconsistent with e.g. thePrismaticJointorRevoluteJointAPIs. - The conversion behavior is not entirely clear without reading through the docs or source code. Creating a distance limit from a scalar value can easily be interpreted as limiting the maximum distance, not both the minimum and maximum distance.
- Typing out the min and max with the same value is really not much longer, and it is more explicit and readable.
- Not using
impl Intoallows the method to beconst.
In a follow-up, we could consider adding with_min_distance and with_max_distance helpers for the cases where you only want to specify one though.
Note that #803 also includes similar changes, but I'll merge this one first to do things more incrementally :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Remove
rest_lengthfromDistanceJointwhich is ignored iflength_limitsis present.Problem
I was using distance joints as muscles, changing their rest length to exert them. However, when I set the
length_limits, nothing worked anymore. I looked into the code and saw my error:rest_lengthis ignored whenlength_limitsis set, which seems like a foot gun to me. A TODO in the code said "Remove rest_length" and after surveying the code, I agreed.Solution
I removed
rest_lengthandwith_rest_length()fromDistanceJoint.I changed the name and arguments of
with_limits()towith_length_limits(). I think this makes it clearer that it's associated with thelength_limitsfield. And I altered the arguments to acceptInto<DistanceLimit>, so that it can be set with aScalar, a pair ofScalars, or aDistanceLimit. My hope was thatwith_length_limits()could serve in place of bothwith_limits()andwith_rest_length().Edit by Jondolf: The changes to
with_limitswere reverted for now, see this message.Auxillary Changes
Some doc tests weren't passing. I added the necessary ampersands (&) to make them pass.
Changelog
From<Scalar>andFrom<[Scalar; 2]>forDistanceLimitandAngleLimit.From<Scalar>andFrom<(Scalar, Scalar)>forDistanceLimitandAngleLimit.rest_lengthfield fromDistanceJoint.with_rest_length()method fromDistanceJoint.Migration Guide
DistanceJoint::with_rest_length(1.0)withDistanceJoint::with_limits(1.0, 1.0).joint.rest_length = 1.0withjoint.length_limits = 1.0.into().