Sat, 24 Mar 2018 12:46:40 +0200
roundToDecimals no longer needs an lvalue. applyToMatrix removed.
src/basics.cpp | file | annotate | diff | comparison | revisions | |
src/basics.h | file | annotate | diff | comparison | revisions | |
src/glcamera.cpp | file | annotate | diff | comparison | revisions | |
src/toolsets/algorithmtoolset.cpp | file | annotate | diff | comparison | revisions | |
src/types/vertex.h | file | annotate | diff | comparison | revisions |
--- a/src/basics.cpp Sat Mar 24 12:34:20 2018 +0200 +++ b/src/basics.cpp Sat Mar 24 12:46:40 2018 +0200 @@ -56,32 +56,19 @@ } -void roundToDecimals(double& value, int decimals) +double roundToDecimals(double value, int decimals) { if (decimals == 0) { - value = round(value); + return round(value); } else if (decimals > 0) { qreal coefficient = pow(10, decimals); - value = round(value * coefficient) / coefficient; + return round(value * coefficient) / coefficient; } } - -void applyToMatrix(Matrix& a, ApplyToMatrixFunction func) -{ - for (int i = 0; i < 9; ++i) - func(i, a.value(i)); -} - -void applyToMatrix(const Matrix& a, ApplyToMatrixConstFunction func) -{ - for (int i = 0; i < 9; ++i) - func(i, a.value(i)); -} - QString formatFileSize(qint64 size) { static const QString suffixes[] = {" bytes", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
--- a/src/basics.h Sat Mar 24 12:34:20 2018 +0200 +++ b/src/basics.h Sat Mar 24 12:46:40 2018 +0200 @@ -94,14 +94,9 @@ return vector.length(); } -using ApplyToMatrixFunction = std::function<void(int, double&)>; -using ApplyToMatrixConstFunction = std::function<void(int, double)>; - -void applyToMatrix(class Matrix& a, ApplyToMatrixFunction func); -void applyToMatrix(const class Matrix& a, ApplyToMatrixConstFunction func); QString formatFileSize(qint64 size); int gcd(int a, int b); QString joinStrings(const QList<class StringFormatArg>& values, QString delimeter = " "); -void roundToDecimals(double& value, int decimals); +double roundToDecimals(double value, int decimals); class QSettings& settingsObject(); void simplify(int& numerator, int& denominator);
--- a/src/glcamera.cpp Sat Mar 24 12:34:20 2018 +0200 +++ b/src/glcamera.cpp Sat Mar 24 12:46:40 2018 +0200 @@ -111,8 +111,8 @@ cy = snapped.y(); } - roundToDecimals(cx, 4); - roundToDecimals(cy, 4); + cx = roundToDecimals(cx, 4); + cy = roundToDecimals(cy, 4); // Create the vertex from the coordinates position3d.setCoordinate(axisX(), cx * signX);
--- a/src/toolsets/algorithmtoolset.cpp Sat Mar 24 12:34:20 2018 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Sat Mar 24 12:46:40 2018 +0200 @@ -156,39 +156,34 @@ setlocale (LC_ALL, "C"); int num = 0; - for (LDObject* obj : selectedObjects()) + for (LDObject* object : selectedObjects()) { - LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj); + LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (object); if (mo) { - Vertex v = mo->position(); - Matrix t = mo->transformationMatrix(); + Vertex position = mo->position(); + Matrix matrix = mo->transformationMatrix(); - v.apply ([&](Axis, double& a) - { - roundToDecimals (a, config::roundPositionPrecision()); - }); + for (Axis axis : {X, Y, Z}) + position[axis] = roundToDecimals(position[axis], config::roundPositionPrecision()); - applyToMatrix (t, [&](int, double& a) - { - roundToDecimals (a, config::roundMatrixPrecision()); - }); + for (int i : {0, 1, 2}) + for (int j : {0, 1, 2}) + matrix(i, j) = roundToDecimals(matrix(i, j), config::roundMatrixPrecision()); - mo->setPosition (v); - mo->setTransformationMatrix (t); + mo->setPosition(position); + mo->setTransformationMatrix(matrix); num += 12; } else { - for (int i = 0; i < obj->numVertices(); ++i) + for (int i = 0; i < object->numVertices(); ++i) { - Vertex v = obj->vertex (i); - v.apply ([&](Axis, double& a) - { - roundToDecimals (a, config::roundPositionPrecision()); - }); - obj->setVertex (i, v); + Vertex vertex = object->vertex (i); + for (Axis axis : {X, Y, Z}) + vertex[axis] = roundToDecimals(vertex[axis], config::roundPositionPrecision()); + object->setVertex(i, vertex); num += 3; } }
--- a/src/types/vertex.h Sat Mar 24 12:34:20 2018 +0200 +++ b/src/types/vertex.h Sat Mar 24 12:46:40 2018 +0200 @@ -32,7 +32,7 @@ void apply(ApplyConstFunction func) const; QString toString(bool mangled = false) const; QVector3D toVector() const; - void transform(const Matrix& matr, const Vertex& pos); + void transform(const class Matrix& matrix, const Vertex& pos); Vertex transformed(const GLRotationMatrix& matrix) const; void setCoordinate(Axis ax, qreal value);