Print corner coodinates in decimal form for more precision.
[gocam.git] / util.hh
blob92c3fbb8b94a4cbda364d656e7bbeea35917770c
1 #ifndef UTIL_HH
2 #define UTIL_HH
4 #include <algorithm>
5 #include <vector>
7 /** Common utility functions. */
8 namespace util {
10 /** The square of the value. */
11 template <typename T>
12 T sqr(T a)
14 return a * a;
17 /** Median of the values in a vector.
18 * \note For odd number (2n + 1) of values, the n'th value is returned.
20 template <typename T>
22 median(std::vector<T> v)
24 std::sort(v.begin(), v.end());
25 return v[v.size() / 2];
28 /** Absolute value. */
29 template <typename T>
31 abs(const T &value)
33 if (value < 0)
34 return -value;
35 return value;
38 /** Maximum of two values. */
39 template <typename T>
41 max(const T &a, const T &b)
43 if (a < b)
44 return b;
45 return a;
50 #endif /* UTIL_HH */