src/basics.h

changeset 1181
ca6d0ef9aadb
parent 1178
3a88e7a60b63
child 1207
b5df72b194f4
child 1273
900f1dfae46b
--- 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...));
+}

mercurial