]> git.sesse.net Git - kdenlive/blobdiff - src/kis_cubic_curve.cpp
Const'ref
[kdenlive] / src / kis_cubic_curve.cpp
index 589fb6a09030966b5918ad2301ce3517428a48e2..128cde9b3dfef246938db50b5309de7900b6926e 100644 (file)
@@ -24,6 +24,7 @@
 #include <QList>
 #include <QSharedData>
 #include <QStringList>
+#include <QLocale>
 
 template <typename T>
 class KisTridiagonalSystem
@@ -80,7 +81,7 @@ public:
         alpha[1] = -c[0] / b[0];
         beta[1] =  f[0] / b[0];
 
-        for (i = 1; i < size - 1; i++) {
+        for (i = 1; i < size - 1; ++i) {
             alpha[i+1] = -c[i] /
                          (a[i-1] * alpha[i] + b[i]);
 
@@ -93,7 +94,7 @@ public:
                    /
                    (b.last() + a.last() * alpha.last());
 
-        for (i = size - 2; i >= 0; i--)
+        for (i = size - 2; i >= 0; --i)
             x[i] = alpha[i+1] * x[i+1] + beta[i+1];
 
         return x;
@@ -125,8 +126,9 @@ protected:
     int m_intervals;
 
 public:
-    KisCubicSpline() {}
-    KisCubicSpline(const QList<T_point> &a) {
+    KisCubicSpline() : m_begin(0), m_end(0), m_intervals(0) {}
+    KisCubicSpline(const QList<T_point> &a) : m_begin(0), m_end(0),
+      m_intervals(0) {
         createSpline(a);
     }
 
@@ -148,7 +150,7 @@ public:
         m_d.resize(intervals);
         m_h.resize(intervals);
 
-        for (i = 0; i < intervals; i++) {
+        for (i = 0; i < intervals; ++i) {
             m_h[i] = a[i+1].x() - a[i].x();
             m_a.append(a[i].y());
         }
@@ -159,12 +161,12 @@ public:
         QList<T> tri_f;
         QList<T> tri_a; /* equals to @tri_c */
 
-        for (i = 0; i < intervals - 1; i++) {
+        for (i = 0; i < intervals - 1; ++i) {
             tri_b.append(2.*(m_h[i] + m_h[i+1]));
 
             tri_f.append(6.*((m_a[i+2] - m_a[i+1]) / m_h[i+1] - (m_a[i+1] - m_a[i]) / m_h[i]));
         }
-        for (i = 1; i < intervals - 1; i++)
+        for (i = 1; i < intervals - 1; ++i)
             tri_a.append(m_h[i]);
 
         if (intervals > 1) {
@@ -174,10 +176,10 @@ public:
         m_c.prepend(0);
         m_c.append(0);
 
-        for (i = 0; i < intervals; i++)
+        for (i = 0; i < intervals; ++i)
             m_d[i] = (m_c[i+1] - m_c[i]) / m_h[i];
 
-        for (i = 0; i < intervals; i++)
+        for (i = 0; i < intervals; ++i)
             m_b[i] = -0.5 * (m_c[i] * m_h[i])  - (1 / 6.0) * (m_d[i] * m_h[i] * m_h[i]) + (m_a[i+1] - m_a[i]) / m_h[i];
     }
 
@@ -212,7 +214,7 @@ protected:
     int findRegion(T x, T &x0) const {
         int i;
         x0 = m_begin;
-        for (i = 0; i < m_intervals; i++) {
+        for (i = 0; i < m_intervals; ++i) {
             if (x >= x0 && x < x0 + m_h[i])
                 return i;
             x0 += m_h[i];
@@ -293,7 +295,7 @@ qreal KisCubicCurve::Data::value(qreal x)
      */
     x = qBound(spline.begin(), x, spline.end());
     qreal y = spline.getValue(x);
-    return qBound(0.0, y, 1.0);
+    return qBound((qreal)0.0, y, (qreal)1.0);
 }
 
 template<typename _T_, typename _T2_>
@@ -402,9 +404,10 @@ void KisCubicCurve::removePoint(int idx)
 QString KisCubicCurve::toString() const
 {
     QString sCurve;
+    QLocale locale;
     foreach(const QPointF & pair, d->data->points) {
-        sCurve += QString::number(pair.x());
-        sCurve += ',';
+        sCurve += locale.toString(pair.x());
+        sCurve += '/';
         sCurve += QString::number(pair.y());
         sCurve += ';';
     }
@@ -418,10 +421,10 @@ void KisCubicCurve::fromString(const QString& string)
     QList<QPointF> points;
 
     foreach(const QString & pair, data) {
-        if (pair.indexOf(',') > -1) {
+        if (pair.indexOf('/') > -1) {
             QPointF p;
-            p.rx() = pair.section(',', 0, 0).toDouble();
-            p.ry() = pair.section(',', 1, 1).toDouble();
+            p.rx() = pair.section('/', 0, 0).toDouble();
+            p.ry() = pair.section('/', 1, 1).toDouble();
             points.append(p);
         }
     }