#ifndef mathex_h
#define mathex_h

#include <math.h>
#ifndef M_PI //we need the definition of M_PI
#include <ode/common.h>
#endif
#ifndef EPSILON
#define EPSILON 1.0e-8
#endif
#ifndef ZERO
#define ZERO EPSILON
#endif

template <class T> inline T limit(const T &x, const T &lower, const T &upper)
{
	if (x < lower) return lower;
	if (x > upper) return upper;
	return x;
}

template <class T> inline T sqr(const T &x) { return x*x; }

/** Converts radians to degrees */
template <class T> inline T RadToDeg(const T &rad) { return (rad * 180.0) / M_PI; }

/** Converts degrees to radians */
template <class T> inline T DegToRad(const T &deg) { return (deg * M_PI) / 180.0; }

#endif
