diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-26 13:23:58 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-05-26 13:23:58 +0200 |
commit | 875a401f7d99a31f13ae901b445c930803473dbe (patch) | |
tree | a912db1d2ceb7ecddc650074e52029c4573954fa /spline-widget | |
parent | aa54f156f51179025844ab2f864be0333d68539e (diff) |
spline-widget: fix lack of initialization in one ctor
Diffstat (limited to 'spline-widget')
-rw-r--r-- | spline-widget/functionconfig.cpp | 41 | ||||
-rw-r--r-- | spline-widget/functionconfig.h | 12 |
2 files changed, 27 insertions, 26 deletions
diff --git a/spline-widget/functionconfig.cpp b/spline-widget/functionconfig.cpp index 0491f792..5390e9bd 100644 --- a/spline-widget/functionconfig.cpp +++ b/spline-widget/functionconfig.cpp @@ -23,12 +23,21 @@ void Map::setTrackingActive(bool blnActive) activep = blnActive; } -Map::Map() : +Map::Map() : Map(0, 0) +{ +} + +Map::Map(double maxx, double maxy) : _mutex(QMutex::Recursive), - activep(false), max_x(0), - max_y(0) + max_y(0), + activep(false) { + setMaxInput(maxx); + setMaxOutput(maxy); + if (cur.input.size() == 0) + cur.input.push_back(QPointF(maxx, maxy)); + reload(); } float Map::getValue(float x) { @@ -86,12 +95,12 @@ void Map::reload() { data = std::vector<float>(value_count); const float mult = precision(); const float mult_ = mult * 30; - + const int sz = data.size(); - + for (int i = 0; i < sz; i++) data[i] = -1; - + if (input.size() == 1 && input[0].x() > 1e-2) { for (int k = 0; k < input[0].x() * mult; k++) { @@ -101,7 +110,7 @@ void Map::reload() { } else if (input[0].x() > 1e-2) input.prepend(QPointF(0, 0)); - + for (int i = 0; i < sz; i++) { const QPointF p0 = ensureInBounds(input, i - 1); const QPointF p1 = ensureInBounds(input, i); @@ -110,11 +119,11 @@ void Map::reload() { const float p0_x = p0.x(), p1_x = p1.x(), p2_x = p2.x(), p3_x = p3.x(); const float p0_y = p0.y(), p1_y = p1.y(), p2_y = p2.y(), p3_y = p3.y(); - + // multiplier helps fill in all the x's needed const int end = std::min<int>(sz, p2_x * mult_); const int start = p1_x * mult; - + for (int j = start; j < end; j++) { const float t = (j - start) / (float) (end - start); const float t2 = t*t; @@ -125,17 +134,17 @@ void Map::reload() { (2 * p0_x - 5 * p1_x + 4 * p2_x - p3_x) * t2 + (-p0_x + 3 * p1_x - 3 * p2_x + p3_x) * t3) * mult; - + const float y = .5f * ((2 * p1_y) + (-p0_y + p2_y) * t + (2 * p0_y - 5 * p1_y + 4 * p2_y - p3_y) * t2 + (-p0_y + 3 * p1_y - 3 * p2_y + p3_y) * t3); - + if (x >= 0 && x < sz) data[x] = y; } } - + float last = 0; for (int i = 0; i < sz; i++) { @@ -207,10 +216,10 @@ void Map::loadSettings(QSettings& settings, const QString& title) { } settings.endGroup(); - + if (max == 0) points.append(QPointF(maxInput(), maxOutput())); - + cur.input = points; reload(); saved = cur; @@ -239,9 +248,9 @@ void Map::saveSettings(QSettings& settings, const QString& title) { settings.remove(x); settings.remove(QString("point-%1-y").arg(i)); } - + saved = cur; - + settings.endGroup(); } diff --git a/spline-widget/functionconfig.h b/spline-widget/functionconfig.h index 145ee14e..cac3c65c 100644 --- a/spline-widget/functionconfig.h +++ b/spline-widget/functionconfig.h @@ -39,23 +39,15 @@ private: MyMutex _mutex; QPointF last_input_value; - volatile bool activep; double max_x; double max_y; - + volatile bool activep; State cur, saved; public: double maxInput() const { return max_x; } double maxOutput() const { return max_y; } Map(); - Map(double maxx, double maxy) - { - setMaxInput(maxx); - setMaxOutput(maxy); - if (cur.input.size() == 0) - cur.input.push_back(QPointF(maxx, maxy)); - reload(); - } + Map(double maxx, double maxy); float getValue(float x); bool getLastPoint(QPointF& point); |