diff options
author | Gard Spreemann <gspreemann@gmail.com> | 2019-01-08 23:28:14 +0100 |
---|---|---|
committer | Gard Spreemann <gspreemann@gmail.com> | 2019-01-08 23:28:14 +0100 |
commit | d1728e33e48d258d72058082a22b0406f48c9e9e (patch) | |
tree | ea3c3bdfd2255c7f00296d65c5a0ee0f4b2620fb /src/util.cpp | |
parent | 4c6f7799004b4d10641dfe659a9a7b9af0653513 (diff) | |
parent | 7807d9c60d2574fb58069eb3faf65cd478905ff7 (diff) |
Merge tag 'v2.1' into debian/sid
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/util.cpp b/src/util.cpp index d5e2b96..304f9e7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -19,31 +19,31 @@ #include "util.h" -float bezierInterpolate(float dist, float c0, float c1, float c2, float c3) { - float distp = 1 - dist; +qreal bezierInterpolate(qreal dist, qreal c0, qreal c1, qreal c2, qreal c3) { + qreal distp = 1 - dist; return (distp*distp*distp) * c0 + 3 * (distp*distp) * dist * c1 + 3 * (dist*dist) * distp * c2 + (dist*dist*dist) * c3; } -QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3) { +QPointF bezierInterpolateFull (qreal dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3) { return QPointF(bezierInterpolate (dist, c0.x(), c1.x(), c2.x(), c3.x()), bezierInterpolate (dist, c0.y(), c1.y(), c2.y(), c3.y())); } -float roundToNearest(float stepSize, float val) { - if (stepSize==0.0f) return val; +qreal roundToNearest(qreal stepSize, qreal val) { + if (stepSize==0.0) return val; else return round(val/stepSize)*stepSize; } -float radiansToDegrees (float radians) { - return (radians * 180.0f) / M_PI; +qreal radiansToDegrees (qreal radians) { + return (radians * 180.0) / M_PI; } -float degreesToRadians(float degrees) { - return (degrees * M_PI) / 180.0f; +qreal degreesToRadians(qreal degrees) { + return (degrees * M_PI) / 180.0; } int normaliseAngleDeg (int degrees) { @@ -56,7 +56,7 @@ int normaliseAngleDeg (int degrees) { return degrees; } -float normaliseAngleRad (float rads) { +qreal normaliseAngleRad (qreal rads) { while (rads > M_PI) { rads -= 2 * M_PI; } @@ -66,8 +66,17 @@ float normaliseAngleRad (float rads) { return rads; } -// convert float to string, squashing very small floats to zero -QString floatToString(float f) { - if (f >= -0.000001 && f <= 0.000001) return "0"; +bool almostZero(qreal f) { + return (f >= -0.000001 && f <= 0.000001); +} + +bool almostEqual(qreal f1, qreal f2) { + return almostZero(f1 - f2); +} + +// convert qreal to string, squashing very small qreals to zero +QString floatToString(qreal f) { + if (almostZero(f)) return "0"; else return QString::number(f); } + |