17 double clamp(
const double &value,
const double &limit_a,
const double &limit_b)
19 if (limit_b > limit_a)
20 return std::max(limit_a, std::min(value, limit_b));
22 return std::max(limit_b, std::min(value, limit_a));
25 template <
typename Vector>
26 Vector clamp(
const Vector &vector,
27 const double &limit_a,
const double &limit_b)
29 Vector clamped_vector = vector;
31 for(
size_t i = 0; i < clamped_vector.size(); i++)
33 clamped_vector[i] = clamp(clamped_vector[i], limit_a, limit_b);
35 return clamped_vector;
38 template <
typename Vector>
39 void append_to_vector(Vector &vector,
40 const double &element)
42 vector.conservativeResize(vector.size() + 1);
43 vector[vector.size() - 1] = element;
46 template <
typename Matrix>
47 void append_rows_to_matrix(Matrix &matrix,
50 if (matrix.cols() != rows.cols())
51 throw std::invalid_argument(
"need to have same number of cols");
53 matrix.conservativeResize(matrix.rows() + rows.rows(), matrix.cols());
54 matrix.bottomRows(rows.rows()) = rows;
57 bool approx_equal(
double x,
double y,
double epsilon = 1e-10)
59 return (std::fabs(x - y) < epsilon);
62 template <
typename Vector>
63 bool contains(Vector v,
double x)
65 for (
size_t i = 0; i < v.size(); i++)
67 if (mct::approx_equal(v[i], x))
Definition: basic_tools.hpp:14