mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Added some utility functions for QPointF distances
This commit is contained in:
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user