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 */ |