#include // https://stackoverflow.com/questions/9323903/most-efficient-elegant-way-to-clip-a-number template T clip(const T& n, const T& lower, const T& upper) { return std::max(lower, std::min(n, upper)); }