94 |
94 |
95 switch (grid()->type()) |
95 switch (grid()->type()) |
96 { |
96 { |
97 case Grid::Cartesian: |
97 case Grid::Cartesian: |
98 { |
98 { |
99 qreal x0 = sign(topLeft.x()) * (fabs(topLeft.x()) - fmod(fabs(topLeft.x()), gridSize)); |
99 qreal x0 = sign(topLeft.x) * (fabs(topLeft.x) - fmod(fabs(topLeft.x), gridSize)); |
100 qreal y0 = sign(topLeft.y()) * (fabs(topLeft.y()) - fmod(fabs(topLeft.y()), gridSize)); |
100 qreal y0 = sign(topLeft.y) * (fabs(topLeft.y) - fmod(fabs(topLeft.y), gridSize)); |
101 |
101 |
102 static const auto prepareGridLine = [](qreal value) -> bool |
102 static const auto prepareGridLine = [](qreal value) -> bool |
103 { |
103 { |
104 if (not isZero(value)) |
104 if (not isZero(value)) |
105 { |
105 { |
114 { |
114 { |
115 return false; |
115 return false; |
116 } |
116 } |
117 }; |
117 }; |
118 |
118 |
119 for (qreal x = x0; x < bottomRight.x(); x += gridSize) |
119 for (qreal x = x0; x < bottomRight.x; x += gridSize) |
120 { |
120 { |
121 if (prepareGridLine(x)) |
121 if (prepareGridLine(x)) |
122 { |
122 { |
123 glVertex(currentCamera().realize({x, -10000, 999})); |
123 glVertex(currentCamera().realize({x, -10000, 999})); |
124 glVertex(currentCamera().realize({x, 10000, 999})); |
124 glVertex(currentCamera().realize({x, 10000, 999})); |
125 } |
125 } |
126 } |
126 } |
127 |
127 |
128 for (qreal y = y0; y < bottomRight.y(); y += gridSize) |
128 for (qreal y = y0; y < bottomRight.y; y += gridSize) |
129 { |
129 { |
130 if (prepareGridLine(y)) |
130 if (prepareGridLine(y)) |
131 { |
131 { |
132 glVertex(currentCamera().realize({-10000, y, 999})); |
132 glVertex(currentCamera().realize({-10000, y, 999})); |
133 glVertex(currentCamera().realize({10000, y, 999})); |
133 glVertex(currentCamera().realize({10000, y, 999})); |
140 { |
140 { |
141 const QPointF pole = grid()->pole(); |
141 const QPointF pole = grid()->pole(); |
142 const qreal size = grid()->coordinateSnap(); |
142 const qreal size = grid()->coordinateSnap(); |
143 Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); |
143 Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); |
144 Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()})); |
144 Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()})); |
145 QPointF topLeft2d {topLeft.x(), topLeft.y()}; |
145 QPointF topLeft2d {topLeft.x, topLeft.y}; |
146 QPointF bottomLeft2d {topLeft.x(), bottomRight.y()}; |
146 QPointF bottomLeft2d {topLeft.x, bottomRight.y}; |
147 QPointF bottomRight2d {bottomRight.x(), bottomRight.y()}; |
147 QPointF bottomRight2d {bottomRight.x, bottomRight.y}; |
148 QPointF topRight2d {bottomRight.x(), topLeft.y()}; |
148 QPointF topRight2d {bottomRight.x, topLeft.y}; |
149 qreal smallestRadius = distanceFromPointToRectangle(pole, QRectF{topLeft2d, bottomRight2d}); |
149 qreal smallestRadius = distanceFromPointToRectangle(pole, QRectF{topLeft2d, bottomRight2d}); |
150 qreal largestRadius = max(QLineF {topLeft2d, pole}.length(), |
150 qreal largestRadius = max(QLineF {topLeft2d, pole}.length(), |
151 QLineF {bottomLeft2d, pole}.length(), |
151 QLineF {bottomLeft2d, pole}.length(), |
152 QLineF {bottomRight2d, pole}.length(), |
152 QLineF {bottomRight2d, pole}.length(), |
153 QLineF {topRight2d, pole}.length()); |
153 QLineF {topRight2d, pole}.length()); |