-
Couldn't load subscription status.
- Fork 664
[wpimath] Make swerve kinematics functions immutable #8274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2027
Are you sure you want to change the base?
[wpimath] Make swerve kinematics functions immutable #8274
Conversation
wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java
Outdated
Show resolved
Hide resolved
wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h
Outdated
Show resolved
Hide resolved
wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp
Show resolved
Hide resolved
b5cc719 to
994050e
Compare
994050e to
80c5438
Compare
wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more consistent if SwerveModuleState and SwerveModulePosition were entirely immutable, i.e final speed, angle, and distance properties, along with withX() member functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're still modifying specific members directly with no invariants to maintain (e.g., via withX()), then member function access is just more boilerplate for no gain. Spawning another object on top of that is just needlessly wasteful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make the other functions immutable then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Member variable mutation is easier for the reader to notice when done directly than when member functions do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, makes sense
No description provided.