src/grid.cpp

changeset 1184
393babf1319d
parent 1182
813d020f92d4
child 1192
317f4ce38f3f
child 1323
05b3e173c900
equal deleted inserted replaced
1183:caa20ed02728 1184:393babf1319d
65 } 65 }
66 66
67 67
68 QPointF Grid::snap(QPointF point) const 68 QPointF Grid::snap(QPointF point) const
69 { 69 {
70 if (false) 70 switch (type())
71 { 71 {
72 // For each co-ordinate, extract the amount of grid steps the value is away from zero, round that to remove the remainder, 72 default:
73 // and multiply back by the the grid size. 73 case Cartesian:
74 double size = coordinateSnap(); 74 {
75 return {round(point.x() / size) * size, round(point.y() / size) * size}; 75 // For each co-ordinate, extract the amount of grid steps the value is away from zero, round that to remove the remainder,
76 } 76 // and multiply back by the the grid size.
77 else 77 double size = coordinateSnap();
78 { 78 return {round(point.x() / size) * size, round(point.y() / size) * size};
79 qreal radius = hypot(point.x() - pole().x(), point.y() - -pole().y()); 79 }
80 qreal azimuth = atan2(point.y() - -pole().y(), point.x() - pole().x()); 80
81 double size = coordinateSnap(); 81 case Polar:
82 double angleStep = 2 * pi / polarDivisions(); 82 {
83 radius = round(radius / size) * size; 83 qreal radius = hypot(point.x() - pole().x(), point.y() - -pole().y());
84 azimuth = round(azimuth / angleStep) * angleStep; 84 qreal azimuth = atan2(point.y() - -pole().y(), point.x() - pole().x());
85 return {pole().x() + cos(azimuth) * radius, -pole().y() + sin(azimuth) * radius}; 85 double size = coordinateSnap();
86 double angleStep = 2 * pi / polarDivisions();
87 radius = round(radius / size) * size;
88 azimuth = round(azimuth / angleStep) * angleStep;
89 return {pole().x() + cos(azimuth) * radius, -pole().y() + sin(azimuth) * radius};
90 }
86 } 91 }
87 } 92 }
88 93
89 /* 94 /*
90 * Returns the pole of the grid, in ideal X/Y co-ordinates. Z is left up for the caller to decide. 95 * Returns the pole of the grid, in ideal X/Y co-ordinates. Z is left up for the caller to decide.
91 */ 96 */
92 QPointF Grid::pole() const 97 QPointF Grid::pole() const
93 { 98 {
94 return {12, -17}; 99 return {0, 0};
95 } 100 }
96 101
97 /* 102 /*
98 * Returns the amount of divisions (slices) to be used in the polar grid. 103 * Returns the amount of divisions (slices) to be used in the polar grid.
99 */ 104 */
108 113
109 case Fine: 114 case Fine:
110 return HighResolution; 115 return HighResolution;
111 } 116 }
112 } 117 }
118
119 /*
120 * Returns whether to use a cartesian or polar grid.
121 */
122 Grid::Type Grid::type() const
123 {
124 return m_config->polarGrid() ? Polar : Cartesian;
125 }

mercurial