diff --git a/octa/algorithm.h b/octa/algorithm.h index c279fd0..2e82e46 100644 --- a/octa/algorithm.h +++ b/octa/algorithm.h @@ -206,6 +206,18 @@ namespace octa { return max_element(il.range(), compare).first(); } + /* clamp */ + + template + inline T clamp(const T &v, const U &lo, const U &hi) { + return max(T(lo), min(v, T(hi))); + } + + template + inline T clamp(const T &v, const U &lo, const U &hi, C compare) { + return max(T(lo), min(v, T(hi), compare), compare); + } + /* algos that don't change the range */ template