diff --git a/number_8hpp_source.html b/number_8hpp_source.html index 5acfadd..7de567a 100644 --- a/number_8hpp_source.html +++ b/number_8hpp_source.html @@ -144,14 +144,14 @@
71 #endif // KEISAN__NUMBER_HPP_
keisan::Angle
Definition: angle.hpp:52
keisan
Definition: angle.hpp:27
-
keisan::clamp
T clamp(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:60
+
keisan::clamp
T clamp(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:65
keisan::sign
T sign(const T &value)
Definition: number.impl.hpp:34
keisan::enable_if_is_integral
std::enable_if_t< std::is_integral< T >::value, bool > enable_if_is_integral
Definition: number.hpp:33
-
keisan::smooth
T smooth(T value, T target, T ratio)
Definition: number.impl.hpp:98
+
keisan::smooth
T smooth(T value, T target, T ratio)
Definition: number.impl.hpp:103
keisan::scale
T scale(const T &value, const T &source, const T &target)
Definition: number.impl.hpp:46
keisan::map
T map(const T &value, const T &source_min, const T &source_max, const T &target_min, const T &target_max)
Definition: number.impl.hpp:52
keisan::enable_if_is_floating_point
std::enable_if_t< std::is_floating_point< T >::value, bool > enable_if_is_floating_point
Definition: number.hpp:36
-
keisan::wrap
T wrap(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:80
+
keisan::wrap
T wrap(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:85
number.impl.hpp
diff --git a/number_8impl_8hpp_source.html b/number_8impl_8hpp_source.html index d7d9cd3..d8886cc 100644 --- a/number_8impl_8hpp_source.html +++ b/number_8impl_8hpp_source.html @@ -126,65 +126,70 @@
53  const T & value, const T & source_min, const T & source_max,
54  const T & target_min, const T & target_max)
55 {
-
56  return target_min + scale(value - source_min, source_max - source_min, target_max - target_min);
-
57 }
-
58 
-
59 template<typename T>
-
60 T clamp(const T & value, const T & min, const T & max)
-
61 {
-
62  return std::min(std::max(value, min), max);
-
63 }
-
64 
-
65 template<typename T>
-
66 Angle<T> clamp(const Angle<T> & value, const Angle<T> & min, const Angle<T> & max)
-
67 {
-
68  if (value < min) {
-
69  return min;
-
70  }
-
71 
-
72  if (value > max) {
-
73  return max;
-
74  }
-
75 
-
76  return value;
-
77 }
-
78 
-
79 template<typename T, enable_if_is_floating_point<T> = true>
-
80 T wrap(const T & value, const T & min, const T & max)
-
81 {
-
82  auto min_value = value - min;
-
83  auto min_max = max - min;
-
84 
-
85  return min + std::fmod(min_max + std::fmod(min_value, min_max), min_max);
-
86 }
-
87 
-
88 template<typename T, enable_if_is_integral<T> = true>
-
89 T wrap(const T & value, const T & min, const T & max)
-
90 {
-
91  auto min_value = value - min;
-
92  auto min_max = max - min;
-
93 
-
94  return min + (min_max + min_value % min_max) % min_max;
-
95 }
-
96 
-
97 template<typename T>
-
98 T smooth(T value, T target, T ratio)
-
99 {
-
100  return ((1.0 - ratio) * value) + (ratio * target);
-
101 }
-
102 
-
103 } // namespace keisan
-
104 
-
105 #endif // KEISAN__NUMBER_IMPL_HPP_
+
56  auto source_val = value;
+
57  source_val = std::min(source_val, std::max(source_min, source_max));
+
58  source_val = std::max(source_val, std::min(source_min, source_max));
+
59 
+
60  return target_min +
+
61  scale(source_val - source_min, source_max - source_min, target_max - target_min);
+
62 }
+
63 
+
64 template<typename T>
+
65 T clamp(const T & value, const T & min, const T & max)
+
66 {
+
67  return std::min(std::max(value, min), max);
+
68 }
+
69 
+
70 template<typename T>
+
71 Angle<T> clamp(const Angle<T> & value, const Angle<T> & min, const Angle<T> & max)
+
72 {
+
73  if (value < min) {
+
74  return min;
+
75  }
+
76 
+
77  if (value > max) {
+
78  return max;
+
79  }
+
80 
+
81  return value;
+
82 }
+
83 
+
84 template<typename T, enable_if_is_floating_point<T> = true>
+
85 T wrap(const T & value, const T & min, const T & max)
+
86 {
+
87  auto min_value = value - min;
+
88  auto min_max = max - min;
+
89 
+
90  return min + std::fmod(min_max + std::fmod(min_value, min_max), min_max);
+
91 }
+
92 
+
93 template<typename T, enable_if_is_integral<T> = true>
+
94 T wrap(const T & value, const T & min, const T & max)
+
95 {
+
96  auto min_value = value - min;
+
97  auto min_max = max - min;
+
98 
+
99  return min + (min_max + min_value % min_max) % min_max;
+
100 }
+
101 
+
102 template<typename T>
+
103 T smooth(T value, T target, T ratio)
+
104 {
+
105  return ((1.0 - ratio) * value) + (ratio * target);
+
106 }
+
107 
+
108 } // namespace keisan
+
109 
+
110 #endif // KEISAN__NUMBER_IMPL_HPP_
angle.hpp
keisan::Angle
Definition: angle.hpp:52
keisan
Definition: angle.hpp:27
-
keisan::clamp
T clamp(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:60
+
keisan::clamp
T clamp(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:65
keisan::sign
T sign(const T &value)
Definition: number.impl.hpp:34
-
keisan::smooth
T smooth(T value, T target, T ratio)
Definition: number.impl.hpp:98
+
keisan::smooth
T smooth(T value, T target, T ratio)
Definition: number.impl.hpp:103
keisan::scale
T scale(const T &value, const T &source, const T &target)
Definition: number.impl.hpp:46
keisan::map
T map(const T &value, const T &source_min, const T &source_max, const T &target_min, const T &target_max)
Definition: number.impl.hpp:52
-
keisan::wrap
T wrap(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:80
+
keisan::wrap
T wrap(const T &value, const T &min, const T &max)
Definition: number.impl.hpp:85
number.hpp