MorphoGraphX
Clamp.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef CLAMP_H
12 #define CLAMP_H
13 
14 #include <Config.hpp>
15 
22 //#include <config.h>
23 namespace mgx {
24 namespace util {
33 template <class T> T clamp(const T& val, const T& min, const T& max)
34 {
35  if(min >= max)
36  return max;
37  else if(val < min)
38  return min;
39  else if(val > max)
40  return max;
41  else
42  return val;
43 }
44 } // namespace util
45 } // namespace mgx
46 
47 #endif
T clamp(const T &val, const T &min, const T &max)
A function to clamp a value to a range.
Definition: Clamp.hpp:33
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26