summaryrefslogtreecommitdiffhomepage
path: root/filter-accela
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-04 15:42:07 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-04 15:42:07 +0200
commitaaec8103ff70569a2773da6d1ca8cdbfd856075f (patch)
tree368d5561cd248abccf7fad850c2375adbf347082 /filter-accela
parent7f39b5709248c57860cf584d56f735a9e2273dcd (diff)
filter/accela: simplify signum, retval
Diffstat (limited to 'filter-accela')
-rw-r--r--filter-accela/ftnoir_filter_accela.cpp5
-rw-r--r--filter-accela/ftnoir_filter_accela.h18
2 files changed, 19 insertions, 4 deletions
diff --git a/filter-accela/ftnoir_filter_accela.cpp b/filter-accela/ftnoir_filter_accela.cpp
index 439638eb..24287e48 100644
--- a/filter-accela/ftnoir_filter_accela.cpp
+++ b/filter-accela/ftnoir_filter_accela.cpp
@@ -99,10 +99,7 @@ void FTNoIR_Filter::filter(const double* input, double *output)
? (std::pow(out_/s.max_rot_nl, rot_nl) * s.max_rot_nl)
: out_;
const double val = m.getValue(float(out));
- const double signum = int(vec < 0) * -2 + 1;
- const double result = last_output[i] + signum * dt * val;
-
- last_output[i] = output[i] = result;
+ last_output[i] = output[i] = last_output[i] + signum(vec) * dt * val;
}
}
diff --git a/filter-accela/ftnoir_filter_accela.h b/filter-accela/ftnoir_filter_accela.h
index b347c30b..da011228 100644
--- a/filter-accela/ftnoir_filter_accela.h
+++ b/filter-accela/ftnoir_filter_accela.h
@@ -50,6 +50,24 @@ private:
double last_output[6];
double smoothed_input[6];
Timer t;
+
+ template <typename T>
+ static inline int signum(T x, std::false_type)
+ {
+ return T(0) < x;
+ }
+
+ template <typename T>
+ static inline int signum(T x, std::true_type)
+ {
+ return (T(0) < x) - (x < T(0));
+ }
+
+ template <typename T>
+ static inline int signum(T x)
+ {
+ return signum(x, std::is_signed<T>());
+ }
};
class FilterControls: public IFilterDialog