154 void AlgorithmToolset::roundCoordinates() |
154 void AlgorithmToolset::roundCoordinates() |
155 { |
155 { |
156 setlocale (LC_ALL, "C"); |
156 setlocale (LC_ALL, "C"); |
157 int num = 0; |
157 int num = 0; |
158 |
158 |
159 for (LDObject* obj : selectedObjects()) |
159 for (LDObject* object : selectedObjects()) |
160 { |
160 { |
161 LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (obj); |
161 LDMatrixObject* mo = dynamic_cast<LDMatrixObject*> (object); |
162 |
162 |
163 if (mo) |
163 if (mo) |
164 { |
164 { |
165 Vertex v = mo->position(); |
165 Vertex position = mo->position(); |
166 Matrix t = mo->transformationMatrix(); |
166 Matrix matrix = mo->transformationMatrix(); |
167 |
167 |
168 v.apply ([&](Axis, double& a) |
168 for (Axis axis : {X, Y, Z}) |
169 { |
169 position[axis] = roundToDecimals(position[axis], config::roundPositionPrecision()); |
170 roundToDecimals (a, config::roundPositionPrecision()); |
170 |
171 }); |
171 for (int i : {0, 1, 2}) |
172 |
172 for (int j : {0, 1, 2}) |
173 applyToMatrix (t, [&](int, double& a) |
173 matrix(i, j) = roundToDecimals(matrix(i, j), config::roundMatrixPrecision()); |
174 { |
174 |
175 roundToDecimals (a, config::roundMatrixPrecision()); |
175 mo->setPosition(position); |
176 }); |
176 mo->setTransformationMatrix(matrix); |
177 |
|
178 mo->setPosition (v); |
|
179 mo->setTransformationMatrix (t); |
|
180 num += 12; |
177 num += 12; |
181 } |
178 } |
182 else |
179 else |
183 { |
180 { |
184 for (int i = 0; i < obj->numVertices(); ++i) |
181 for (int i = 0; i < object->numVertices(); ++i) |
185 { |
182 { |
186 Vertex v = obj->vertex (i); |
183 Vertex vertex = object->vertex (i); |
187 v.apply ([&](Axis, double& a) |
184 for (Axis axis : {X, Y, Z}) |
188 { |
185 vertex[axis] = roundToDecimals(vertex[axis], config::roundPositionPrecision()); |
189 roundToDecimals (a, config::roundPositionPrecision()); |
186 object->setVertex(i, vertex); |
190 }); |
|
191 obj->setVertex (i, v); |
|
192 num += 3; |
187 num += 3; |
193 } |
188 } |
194 } |
189 } |
195 } |
190 } |
196 |
191 |