Added some utility functions for QPointF distances

This commit is contained in:
Tats
2014-05-02 14:13:00 -04:00
parent f1e4c3465e
commit e560faa520
+18 -1
View File
@@ -27,7 +27,24 @@
inline qreal degreesToRadians(qreal degrees) { return degrees / 180.0f * M_PI; }
inline qreal radiansToDegrees(qreal radians) { return radians / M_PI * 180.0f; }
// Wrap value around ie. wrapAround(-1, 3) ==> 2
/// Wrap value around ie. wrapAround(-1, 3) ==> 2
inline int wrapAround(int index, int max) { return (index + max) % max; }
/// Square of x.
inline qreal sq(qreal x) { return x*x; }
///
inline qreal distSq(const QPointF& p1, const QPointF& p2) {
return sq(p1.x() - p2.x()) + sq(p1.y() - p2.y());
}
/// Euclidian distance between two points.
inline qreal dist(const QPointF& p1, const QPointF& p2) {
return sqrt( distSq(p1, p2) );
}
inline bool distIsInside(const QPointF& p1, const QPointF& p2, qreal radius) {
return distSq(p1, p2) < sq(radius);
}
#endif /* MATH_H_ */