Grid::snap now snaps points.

Fri, 03 Mar 2017 23:23:28 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 03 Mar 2017 23:23:28 +0200
changeset 1180
2005e4147ad6
parent 1179
1a9ffd5e0399
child 1181
ca6d0ef9aadb

Grid::snap now snaps points.

src/editmodes/abstractEditMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/circleMode.cpp file | annotate | diff | comparison | revisions
src/glcamera.cpp file | annotate | diff | comparison | revisions
src/grid.cpp file | annotate | diff | comparison | revisions
src/grid.h file | annotate | diff | comparison | revisions
--- a/src/editmodes/abstractEditMode.cpp	Fri Mar 03 23:16:14 2017 +0200
+++ b/src/editmodes/abstractEditMode.cpp	Fri Mar 03 23:23:28 2017 +0200
@@ -311,8 +311,9 @@
 		renderer()->getRelativeAxes(relativeX, relativeY);
 		QLineF line = {vertex0[relativeX], vertex0[relativeY], vertex1[relativeX], vertex1[relativeY]};
 		line.setAngle(roundToInterval<int>(line.angle(), 45));
-		result.setCoordinate(relativeX, grid()->snap(line.x2()));
-		result.setCoordinate(relativeY, grid()->snap(line.y2()));
+		QPointF point = grid()->snap(line.p2());
+		result.setCoordinate(relativeX, point.x());
+		result.setCoordinate(relativeY, point.y());
 	}
 
 	return result;
--- a/src/editmodes/circleMode.cpp	Fri Mar 03 23:16:14 2017 +0200
+++ b/src/editmodes/circleMode.cpp	Fri Mar 03 23:23:28 2017 +0200
@@ -56,7 +56,7 @@
 		renderer()->getRelativeAxes(localx, localy);
 		double dx = m_drawedVerts[0][localx] - v1[localx];
 		double dy = m_drawedVerts[0][localy] - v1[localy];
-		return grid()->snap(hypot(dx, dy));
+		return grid()->snap({hypot(dx, dy), 0}).x();
 	}
 
 	return 0.0;
--- a/src/glcamera.cpp	Fri Mar 03 23:16:14 2017 +0200
+++ b/src/glcamera.cpp	Fri Mar 03 23:23:28 2017 +0200
@@ -107,8 +107,9 @@
 		// If a grid was passed, snap coordinates to it.
 		if (grid)
 		{
-			cx = grid->snap(cx);
-			cy = grid->snap(cy);
+			QPointF snapped = grid->snap({cx, cy});
+			cx = snapped.x();
+			cy = snapped.y();
 		}
 
 		roundToDecimals(cx, 4);
--- a/src/grid.cpp	Fri Mar 03 23:16:14 2017 +0200
+++ b/src/grid.cpp	Fri Mar 03 23:23:28 2017 +0200
@@ -65,10 +65,10 @@
 }
 
 
-qreal Grid::snap(qreal value) const
+QPointF Grid::snap(QPointF point) const
 {
-	// First, extract the amount of grid steps the value is away from zero, round that to remove the remainder,
+	// For each co-ordinate, extract the amount of grid steps the value is away from zero, round that to remove the remainder,
 	// and multiply back by the the grid size.
 	double size = coordinateSnap();
-	return round(value / size) * size;
+	return {round(point.x() / size) * size, round(point.y() / size) * size};
 }
--- a/src/grid.h	Fri Mar 03 23:16:14 2017 +0200
+++ b/src/grid.h	Fri Mar 03 23:23:28 2017 +0200
@@ -41,6 +41,6 @@
 	qreal angleAsRadians() const;
 	int bezierCurveSegments() const;
 	qreal coordinateSnap() const;
-	qreal snap(qreal value) const;
+	QPointF snap(QPointF point) const;
 };
 

mercurial