Skip to content

Commit

Permalink
[trajoptlib] Const-qualify solution passed to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jan 4, 2025
1 parent 09f03d5 commit 8fa0d18
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion trajoptlib/include/trajopt/path/Path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct TRAJOPT_DLLEXPORT Path {

/// A vector of callbacks to be called with the intermediate solution and a
/// user-specified handle at every iteration of the solver.
std::vector<std::function<void(Solution& solution, int64_t handle)>>
std::vector<std::function<void(const Solution& solution, int64_t handle)>>
callbacks;
};

Expand Down
3 changes: 2 additions & 1 deletion trajoptlib/include/trajopt/path/PathBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ class TRAJOPT_DLLEXPORT PathBuilder {
*
*/
void AddCallback(
const std::function<void(Solution& solution, int64_t handle)> callback) {
const std::function<void(const Solution& solution, int64_t handle)>
callback) {
path.callbacks.push_back(callback);
}

Expand Down
4 changes: 2 additions & 2 deletions trajoptlib/src/RustFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void SwerveTrajectoryGenerator::sgmt_keep_out_circle(size_t from_index,

void SwerveTrajectoryGenerator::add_callback(
rust::Fn<void(SwerveTrajectory, int64_t)> callback) {
path_builder.AddCallback([=](trajopt::SwerveSolution& solution,
path_builder.AddCallback([=](const trajopt::SwerveSolution& solution,
int64_t handle) {
trajopt::SwerveTrajectory cppTrajectory{solution};

Expand Down Expand Up @@ -638,7 +638,7 @@ void DifferentialTrajectoryGenerator::sgmt_keep_out_circle(size_t from_index,
void DifferentialTrajectoryGenerator::add_callback(
rust::Fn<void(DifferentialTrajectory, int64_t)> callback) {
path_builder.AddCallback(
[=](trajopt::DifferentialSolution& solution, int64_t handle) {
[=](const trajopt::DifferentialSolution& solution, int64_t handle) {
trajopt::DifferentialTrajectory cppTrajectory{solution};

rust::Vec<DifferentialTrajectorySample> rustSamples;
Expand Down

0 comments on commit 8fa0d18

Please sign in to comment.