@@ -256,33 +256,26 @@ void WallItem::resizeWithGrid(QGraphicsSceneMouseEvent *event, int indexGrid)
256256 setY2 (y);
257257 reshapeEndWithGrid (indexGrid);
258258 } else {
259- const int coefX = static_cast <int >(pos ().x ()) / indexGrid;
260- const int coefY = static_cast <int >(pos ().y ()) / indexGrid;
261- auto newPos = QPointF (alignedCoordinate (pos ().x (), coefX, indexGrid),
262- alignedCoordinate (pos ().y (), coefY, indexGrid));
259+ auto newPos = QPointF (alignedCoordinate (pos ().x (), indexGrid),
260+ alignedCoordinate (pos ().y (), indexGrid));
263261 setPos (newPos);
264262 update ();
265263 }
266264}
267265
268266void WallItem::reshapeEndWithGrid (int indexGrid)
269267{
270- const int coefX = static_cast <int >(x2 ()) / indexGrid;
271- const int coefY = static_cast <int >(y2 ()) / indexGrid;
272-
273- setX2 (alignedCoordinate (x2 (), coefX, indexGrid));
274- setY2 (alignedCoordinate (y2 (), coefY, indexGrid));
268+ setX2 (alignedCoordinate (x2 (), indexGrid));
269+ setY2 (alignedCoordinate (y2 (), indexGrid));
275270
276271 mCellNumbX2 = x2 () / indexGrid;
277272 mCellNumbY2 = y2 () / indexGrid;
278273}
279274
280275void WallItem::reshapeBeginWithGrid (int indexGrid)
281276{
282- const int coefX = static_cast <int > (x1 ()) / indexGrid;
283- const int coefY = static_cast <int > (y1 ()) / indexGrid;
284- setX1 (alignedCoordinate (x1 (), coefX, indexGrid));
285- setY1 (alignedCoordinate (y1 (), coefY, indexGrid));
277+ setX1 (alignedCoordinate (x1 (), indexGrid));
278+ setY1 (alignedCoordinate (y1 (), indexGrid));
286279 mCellNumbX1 = x1 () / indexGrid;
287280 mCellNumbY1 = y1 () / indexGrid;
288281}
@@ -378,16 +371,3 @@ void WallItem::setDraggedEnd(qreal x, qreal y)
378371 setX2 (x1 () - x);
379372 setY2 (y1 () - y);
380373}
381-
382- qreal WallItem::alignedCoordinate (qreal coord, int coef, const int indexGrid) const
383- {
384- const int coefSign = coef ? coef / qAbs (coef) : 0 ;
385-
386- if (qAbs (qAbs (coord) - qAbs (coef) * indexGrid) <= indexGrid / 2.0 ) {
387- return coef * indexGrid;
388- } else if (qAbs (qAbs (coord) - (qAbs (coef) + 1 ) * indexGrid) <= indexGrid / 2.0 ) {
389- return (coef + coefSign) * indexGrid;
390- }
391-
392- return coord;
393- }
0 commit comments