From a734275cc5223a066583963adc2d7458168276ff Mon Sep 17 00:00:00 2001 From: Benjamin Hall Date: Wed, 3 Jun 2026 22:42:05 -0400 Subject: [PATCH] [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. --- .../include/wpi/math/kinematics/SwerveModuleVelocity.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp index 7fff7e6867..7b09c86f96 100644 --- a/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp +++ b/wpimath/src/main/native/include/wpi/math/kinematics/SwerveModuleVelocity.hpp @@ -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}; } };