Fix wrong calculation of the bounding rect of an arc

This commit is contained in:
joshua 2023-01-27 19:39:53 +01:00
parent 45e3e92022
commit 092b18cefd

View File

@ -195,41 +195,10 @@ QRectF QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(
*/
QRectF QetGraphicsHandlerUtility::rectForArc(const QRectF &rect, qreal start_angle, qreal span_angle)
{
auto point = pointsForArc (rect, start_angle, span_angle);
auto end_angle =start_angle + span_angle;
auto normalized_end_angle = end_angle;
if (normalized_end_angle > 360)
normalized_end_angle -= 360;
QPointF top_left;
if ((start_angle <= 180 && normalized_end_angle >= 180) ||
(end_angle > 360 && normalized_end_angle >= 180)) {
top_left.setX(rect.left());
} else {
top_left.setX(std::min(point[0].x(), point[1].x()));
}
if ((start_angle <= 90 && end_angle >= 90) ||
(start_angle > 90 && end_angle > 360 && normalized_end_angle >= 90)) {
top_left.setY(rect.top());
} else {
top_left.setY(std::min(point[0].y(), point[1].y()));
}
QPointF bottom_right;
if (end_angle >= 360) {
bottom_right.setX(rect.right());
} else {
bottom_right.setX(std::max(point[0].x(), point[1].x()));
}
if ((start_angle <= 270 && end_angle >= 270) ||
(end_angle > 360 && normalized_end_angle >= 270)) {
bottom_right.setY(rect.bottom());
} else {
bottom_right.setY(std::max(point[0].y(), point[1].y()));
}
return QRectF(top_left, bottom_right);
QPainterPath path;
path.arcMoveTo(rect, start_angle);
path.arcTo(rect, start_angle, span_angle);
return path.boundingRect();
}
/**