# HG changeset patch # User Teemu Piippo # Date 1488585598 -7200 # Node ID 813d020f92d4e23f11e785bf9518c9296b4d3a17 # Parent ca6d0ef9aadbcf94abf118e9dcc8479e502765fc Added polar grid snapping code. diff -r ca6d0ef9aadb -r 813d020f92d4 src/canvas.cpp --- a/src/canvas.cpp Sat Mar 04 00:54:46 2017 +0200 +++ b/src/canvas.cpp Sat Mar 04 01:59:58 2017 +0200 @@ -95,7 +95,7 @@ */ void Canvas::drawFixedCameraBackdrop() { - static const enum { Cartesian, Polar } gridType = Cartesian; + static const enum { Cartesian, Polar } gridType = Polar; // Find the top left corner of the grid Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); diff -r ca6d0ef9aadb -r 813d020f92d4 src/grid.cpp --- a/src/grid.cpp Sat Mar 04 00:54:46 2017 +0200 +++ b/src/grid.cpp Sat Mar 04 01:59:58 2017 +0200 @@ -67,10 +67,23 @@ QPointF Grid::snap(QPointF point) const { - // 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(point.x() / size) * size, round(point.y() / size) * size}; + if (false) + { + // 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(point.x() / size) * size, round(point.y() / size) * size}; + } + else + { + qreal radius = hypot(point.x() - pole().x(), point.y() - -pole().y()); + qreal azimuth = atan2(point.y() - -pole().y(), point.x() - pole().x()); + double size = coordinateSnap(); + double angleStep = 2 * pi / polarDivisions(); + radius = round(radius / size) * size; + azimuth = round(azimuth / angleStep) * angleStep; + return {pole().x() + cos(azimuth) * radius, -pole().y() + sin(azimuth) * radius}; + } } /*