00001 /********************************************************************* 00002 * Software License Agreement (CC BY-NC-SA 4.0 License) 00003 * 00004 * Copyright (c) 2014, PAL Robotics, S.L. 00005 * All rights reserved. 00006 * 00007 * This work is licensed under the Creative Commons 00008 * Attribution-NonCommercial-ShareAlike 4.0 International License. 00009 * 00010 * To view a copy of this license, visit 00011 * http://creativecommons.org/licenses/by-nc-sa/4.0/ 00012 * or send a letter to 00013 * Creative Commons, 444 Castro Street, Suite 900, 00014 * Mountain View, California, 94041, USA. 00015 *********************************************************************/ 00016 00017 /* 00018 * @author Enrique Fernandez 00019 * @author Siegfried Gevatter 00020 */ 00021 00022 #ifndef UTILS_H 00023 #define UTILS_H 00024 00025 // This could be taken from #include <boost/algorithm/clamp.hpp> 00026 // but it seems that all versions of Boost have it. 00027 00035 template<typename T> 00036 static T clamp(T x, T min, T max) 00037 { 00038 if ( x < min) x = min; 00039 else if (max < x) x = max; 00040 return x; 00041 } 00042 00043 #endif // UTILS_H 00044