src/basics.h

changeset 1181
ca6d0ef9aadb
parent 1178
3a88e7a60b63
child 1207
b5df72b194f4
child 1273
900f1dfae46b
equal deleted inserted replaced
1180:2005e4147ad6 1181:ca6d0ef9aadb
200 return index >= EnumLimits<Enum>::First and index <= EnumLimits<Enum>::Last; 200 return index >= EnumLimits<Enum>::First and index <= EnumLimits<Enum>::Last;
201 } 201 }
202 202
203 double getRadialPoint(int segment, int divisions, double(*func)(double)); 203 double getRadialPoint(int segment, int divisions, double(*func)(double));
204 QVector<QLineF> makeCircle(int segments, int divisions, double radius); 204 QVector<QLineF> makeCircle(int segments, int divisions, double radius);
205 qreal distanceFromPointToRectangle(const QPointF& point, const QRectF& rectangle);
205 206
206 /* 207 /*
207 * Implements a ring adapter over T. This class corrects indices given to the element-operator so that they're within bounds. 208 * Implements a ring adapter over T. This class corrects indices given to the element-operator so that they're within bounds.
208 * The maximum amount can be specified manually. 209 * The maximum amount can be specified manually.
209 * 210 *
325 if (isZero(x)) 326 if (isZero(x))
326 return {}; 327 return {};
327 else 328 else
328 return x / qAbs(x); 329 return x / qAbs(x);
329 } 330 }
331
332 /*
333 * Returns the maximum of a single parameter (the parameter itself).
334 */
335 template <typename T>
336 T max(T a)
337 {
338 return a;
339 }
340
341 /*
342 * Returns the maximum of two parameters.
343 */
344 template <typename T>
345 T max(T a, T b)
346 {
347 return a > b ? a : b;
348 }
349
350 /*
351 * Returns the maximum of n parameters.
352 */
353 template <typename T, typename... Rest>
354 T max(T a, Rest&&... rest)
355 {
356 return max(a, max(rest...));
357 }
358
359 /*
360 * Returns the minimum of a single parameter (the parameter itself).
361 */
362 template <typename T>
363 T min(T a)
364 {
365 return a;
366 }
367
368 /*
369 * Returns the minimum of two parameters.
370 */
371 template <typename T>
372 T min(T a, T b)
373 {
374 return a < b ? a : b;
375 }
376
377 /*
378 * Returns the minimum of n parameters.
379 */
380 template <typename T, typename... Rest>
381 T min(T a, Rest&&... rest)
382 {
383 return min(a, min(rest...));
384 }

mercurial