[wpimath] Add const qualifier to C++ SwerveModuleVelocity Optimize and CosineScale (#8946)

These two functions were changed to return new objects instead of
modifying in-place, so the `const` qualifier should be added. Otherwise,
users with a const reference to a `SwerveModuleVelocity` need to make a
temporary copy first.
This commit is contained in:
Benjamin Hall
2026-06-03 22:42:05 -04:00
committed by GitHub
parent 3f0d7bc2c4
commit a734275cc5

View File

@@ -46,7 +46,8 @@ struct WPILIB_DLLEXPORT SwerveModuleVelocity {
* @return The optimized SwerveModuleVelocity.
*/
[[nodiscard]]
constexpr SwerveModuleVelocity Optimize(const Rotation2d& currentAngle) {
constexpr SwerveModuleVelocity Optimize(
const Rotation2d& currentAngle) const {
auto delta = angle - currentAngle;
if (wpi::units::math::abs(delta.Degrees()) > 90_deg) {
return {-velocity, angle + Rotation2d{180_deg}};
@@ -64,7 +65,8 @@ struct WPILIB_DLLEXPORT SwerveModuleVelocity {
* @return The scaled SwerveModuleVelocity.
*/
[[nodiscard]]
constexpr SwerveModuleVelocity CosineScale(const Rotation2d& currentAngle) {
constexpr SwerveModuleVelocity CosineScale(
const Rotation2d& currentAngle) const {
return {velocity * (angle - currentAngle).Cos(), angle};
}
};