Scribus
Open source desktop publishing at your fingertips
utils.h
1 #ifndef LIB2GEOM_UTILS_HEADER
2 #define LIB2GEOM_UTILS_HEADER
3 
34 #include <cmath>
35 
36 namespace Geom {
37 
38 // proper logical xor
39 inline bool logical_xor (bool a, bool b) { return (a || b) && !(a && b); }
40 
45 template <class T> inline int sgn(const T& x) {return (x < 0 ? -1 : (x > 0 ? 1 : 0) );}
46 
47 template <class T> inline T sqr(const T& x) {return x * x;}
48 template <class T> inline T cube(const T& x) {return x * x * x;}
49 
53 template <class T> inline const T& between (const T& min, const T& max, const T& x)
54  { return min < x && max > x; }
55 
60 inline double round(double const x) { return std::floor(x + .5); }
61 
73 inline double decimal_round(double const x, int const places) {
74  //TODO: possibly implement with modulus instead?
75  double const multiplier = std::pow(10.0, places);
76  return round( x * multiplier ) / multiplier;
77 }
78 
79 }
80 
81 #endif
Definition: angle.h:38
double decimal_round(double const x, int const places)
Definition: utils.h:73
double round(double const x)
Definition: utils.h:60
const T & between(const T &min, const T &max, const T &x)
Definition: utils.h:53
int sgn(const T &x)
Definition: utils.h:45