MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / arcToPolygon

Method arcToPolygon

src/frameworks/UBGeometryUtils.cpp:181–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179}
180
181QPolygonF UBGeometryUtils::arcToPolygon(const QLineF& startRadius, qreal spanAngleInDegrees, qreal width)
182{
183 qreal startAngleInDegrees = - startRadius.angle();
184 if (startAngleInDegrees > 180)
185 startAngleInDegrees -= 360;
186 else if (startAngleInDegrees < -180)
187 startAngleInDegrees += 360;
188
189 qreal radiusLength = startRadius.length();
190 qreal angle = 2 * asin(width / (2 * radiusLength)) * 180 / PI;
191 bool overlap = qAbs(spanAngleInDegrees) > 360 - angle;
192 if (overlap)
193 spanAngleInDegrees = spanAngleInDegrees < 0 ? -360 : 360;
194
195 qreal endAngleInDegrees = startAngleInDegrees + spanAngleInDegrees;
196
197 qreal innerRadius = radiusLength - width / 2;
198 QRectF innerSquare(
199 startRadius.p1().x() - innerRadius,
200 startRadius.p1().y() - innerRadius,
201 2 * innerRadius,
202 2 * innerRadius);
203 qreal outerRadius = radiusLength + width / 2;
204 QRectF outerSquare(
205 startRadius.p1().x() - outerRadius,
206 startRadius.p1().y() - outerRadius,
207 2 * outerRadius,
208 2 * outerRadius);
209 QRectF startSquare(
210 startRadius.p2().x() - width / 2,
211 startRadius.p2().y() - width / 2,
212 width,
213 width);
214 QRectF endSquare(
215 startRadius.p1().x() + radiusLength * cos(endAngleInDegrees * PI / 180.0) - width / 2,
216 startRadius.p1().y() + radiusLength * sin(endAngleInDegrees * PI / 180.0) - width / 2,
217 width,
218 width);
219
220 QPainterPath painterPath(
221 QPointF(
222 startRadius.p1().x() + innerRadius * cos(startAngleInDegrees * PI / 180.0),
223 startRadius.p1().y() + innerRadius * sin(startAngleInDegrees * PI / 180.0)));
224 startAngleInDegrees = - startAngleInDegrees;
225 endAngleInDegrees = - endAngleInDegrees;
226 spanAngleInDegrees = - spanAngleInDegrees;
227
228 painterPath.setFillRule(Qt::WindingFill);
229 painterPath.arcTo(innerSquare, startAngleInDegrees, spanAngleInDegrees);
230 painterPath.arcTo(endSquare, 180.0 + endAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0);
231 painterPath.arcTo(outerSquare, endAngleInDegrees, - spanAngleInDegrees);
232 painterPath.arcTo(startSquare, startAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0);
233 painterPath.closeSubpath();
234
235 return painterPath.toFillPolygon();
236}
237
238/**

Callers

nothing calls this directly

Calls 5

asinFunction · 0.85
cosFunction · 0.50
sinFunction · 0.50
angleMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected