Skip to content

Commit

Permalink
Applied chrstrom saturateVectorValues() fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mokaz committed Nov 12, 2023
1 parent 5b08048 commit 236579e
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,15 @@ inline void calculateRightPseudoinverse(const Eigen::MatrixXd &M,
* otherwise.
*/
inline bool saturateVectorValues(Eigen::VectorXd &vec, double min, double max) {
bool vector_in_range = std::all_of(vec.begin(), vec.end(), [&](double &val) {
if (val > max) {
val = max;
return false;
} else if (val < min) {
val = min;
return false;
}
return true;
bool all_values_in_range =
std::all_of(vec.begin(), vec.end(),
[min, max](double val) { return val >= min && val <= max; });

std::transform(vec.begin(), vec.end(), vec.begin(), [min, max](double val) {
return std::min(std::max(val, min), max);
});
return vector_in_range;

return all_values_in_range;
}

/**
Expand Down

0 comments on commit 236579e

Please sign in to comment.