Aikido
algorithm-impl.hpp
Go to the documentation of this file.
1 #ifndef AIKIDO_COMMON_DETAIL_ALGORITHM_IMPL_HPP_
2 #define AIKIDO_COMMON_DETAIL_ALGORITHM_IMPL_HPP_
3 
4 #include <cassert>
5 #include <functional>
6 
8 
9 namespace aikido {
10 namespace common {
11 
12 //==============================================================================
13 template <class T, class Compare>
14 const T& clamp(const T& v, const T& lo, const T& hi, Compare comp)
15 {
16  assert(!comp(hi, lo));
17  return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
18 }
19 
20 //==============================================================================
21 template <class T>
22 const T& clamp(const T& v, const T& lo, const T& hi)
23 {
24  return clamp(v, lo, hi, std::less<T>());
25 }
26 
27 } // namespace common
28 } // namespace aikido
29 
30 #endif // AIKIDO_COMMON_DETAIL_ALGORITHM_IMPL_HPP_
algorithm.hpp
aikido
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
aikido::common::clamp
const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise r...
Definition: algorithm-impl.hpp:14