mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Fix wrong calculation of the bounding rect of an arc
This commit is contained in:
parent
45e3e92022
commit
092b18cefd
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user