mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Fix wrong calculation of the bounding rect of an arc
This commit is contained in:
@@ -195,41 +195,10 @@ QRectF QetGraphicsHandlerUtility::mirrorRectForPosAtIndex(
|
|||||||
*/
|
*/
|
||||||
QRectF QetGraphicsHandlerUtility::rectForArc(const QRectF &rect, qreal start_angle, qreal span_angle)
|
QRectF QetGraphicsHandlerUtility::rectForArc(const QRectF &rect, qreal start_angle, qreal span_angle)
|
||||||
{
|
{
|
||||||
auto point = pointsForArc (rect, start_angle, span_angle);
|
QPainterPath path;
|
||||||
auto end_angle =start_angle + span_angle;
|
path.arcMoveTo(rect, start_angle);
|
||||||
auto normalized_end_angle = end_angle;
|
path.arcTo(rect, start_angle, span_angle);
|
||||||
if (normalized_end_angle > 360)
|
return path.boundingRect();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user