--- a/src/basics.h Fri Mar 03 23:23:28 2017 +0200 +++ b/src/basics.h Sat Mar 04 00:54:46 2017 +0200 @@ -202,6 +202,7 @@ double getRadialPoint(int segment, int divisions, double(*func)(double)); QVector<QLineF> makeCircle(int segments, int divisions, double radius); +qreal distanceFromPointToRectangle(const QPointF& point, const QRectF& rectangle); /* * Implements a ring adapter over T. This class corrects indices given to the element-operator so that they're within bounds. @@ -327,3 +328,57 @@ else return x / qAbs(x); } + +/* + * Returns the maximum of a single parameter (the parameter itself). + */ +template <typename T> +T max(T a) +{ + return a; +} + +/* + * Returns the maximum of two parameters. + */ +template <typename T> +T max(T a, T b) +{ + return a > b ? a : b; +} + +/* + * Returns the maximum of n parameters. + */ +template <typename T, typename... Rest> +T max(T a, Rest&&... rest) +{ + return max(a, max(rest...)); +} + +/* + * Returns the minimum of a single parameter (the parameter itself). + */ +template <typename T> +T min(T a) +{ + return a; +} + +/* + * Returns the minimum of two parameters. + */ +template <typename T> +T min(T a, T b) +{ + return a < b ? a : b; +} + +/* + * Returns the minimum of n parameters. + */ +template <typename T, typename... Rest> +T min(T a, Rest&&... rest) +{ + return min(a, min(rest...)); +}