de-duplicate definition

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-05 20:56:15 +03:00
parent 685768425f
commit 14dedd9435
6 changed files with 20 additions and 21 deletions

View file

@ -318,7 +318,7 @@ static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
};
for (int i = 0; i < 2; ++i) {
qreal kappa = qreal(2.0) * KAPPA * sign * offset * angles[i];
qreal kappa = qreal(2.0) * QT_PATH_KAPPA * sign * offset * angles[i];
o->x1 = circle[i].x();
o->y1 = circle[i].y();

View file

@ -631,20 +631,20 @@ void QPaintEngineEx::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yR
qreal pts[] = {
x1 + xRadius, y1, // MoveTo
x2 - xRadius, y1, // LineTo
x2 - (1 - KAPPA) * xRadius, y1, // CurveTo
x2, y1 + (1 - KAPPA) * yRadius,
x2 - (1 - QT_PATH_KAPPA) * xRadius, y1, // CurveTo
x2, y1 + (1 - QT_PATH_KAPPA) * yRadius,
x2, y1 + yRadius,
x2, y2 - yRadius, // LineTo
x2, y2 - (1 - KAPPA) * yRadius, // CurveTo
x2 - (1 - KAPPA) * xRadius, y2,
x2, y2 - (1 - QT_PATH_KAPPA) * yRadius, // CurveTo
x2 - (1 - QT_PATH_KAPPA) * xRadius, y2,
x2 - xRadius, y2,
x1 + xRadius, y2, // LineTo
x1 + (1 - KAPPA) * xRadius, y2, // CurveTo
x1, y2 - (1 - KAPPA) * yRadius,
x1 + (1 - QT_PATH_KAPPA) * xRadius, y2, // CurveTo
x1, y2 - (1 - QT_PATH_KAPPA) * yRadius,
x1, y2 - yRadius,
x1, y1 + yRadius, // LineTo
x1, y1 + (1 - KAPPA) * yRadius, // CurveTo
x1 + (1 - KAPPA) * xRadius, y1,
x1, y1 + (1 - QT_PATH_KAPPA) * yRadius, // CurveTo
x1 + (1 - QT_PATH_KAPPA) * xRadius, y1,
x1 + xRadius, y1
};

View file

@ -246,11 +246,6 @@ inline void QPainterPathPrivate::maybeMoveTo()
}
}
// This value is used to determine the length of control point vectors
// when approximating arc segments as curves. The factor is multiplied
// with the radius of the circle.
#define KAPPA qreal(0.5522847498)
QT_END_NAMESPACE
#endif // QPAINTERPATH_P_H

View file

@ -26,6 +26,7 @@
#include "qmath.h"
#include "qnumeric.h"
#include "qcorecommon_p.h"
#include "qguicommon_p.h"
QT_BEGIN_NAMESPACE
@ -743,18 +744,18 @@ template <class Iterator> bool qt_stroke_side(Iterator *it,
For a given angle in the range [0 .. 90], finds the corresponding parameter t
of the prototype cubic bezier arc segment
b = fromPoints(QPointF(1, 0), QPointF(1, KAPPA), QPointF(KAPPA, 1), QPointF(0, 1));
b = fromPoints(QPointF(1, 0), QPointF(1, QT_PATH_KAPPA), QPointF(QT_PATH_KAPPA, 1), QPointF(0, 1));
From the bezier equation:
b.pointAt(t).x() = (1-t)^3 + t*(1-t)^2 + t^2*(1-t)*KAPPA
b.pointAt(t).y() = t*(1-t)^2 * KAPPA + t^2*(1-t) + t^3
b.pointAt(t).x() = (1-t)^3 + t*(1-t)^2 + t^2*(1-t)*QT_PATH_KAPPA
b.pointAt(t).y() = t*(1-t)^2 * QT_PATH_KAPPA + t^2*(1-t) + t^3
Third degree coefficients:
b.pointAt(t).x() = at^3 + bt^2 + ct + d
where a = 2-3*KAPPA, b = 3*(KAPPA-1), c = 0, d = 1
where a = 2-3*QT_PATH_KAPPA, b = 3*(QT_PATH_KAPPA-1), c = 0, d = 1
b.pointAt(t).y() = at^3 + bt^2 + ct + d
where a = 3*KAPPA-2, b = 6*KAPPA+3, c = 3*KAPPA, d = 0
where a = 3*QT_PATH_KAPPA-2, b = 6*QT_PATH_KAPPA+3, c = 3*QT_PATH_KAPPA, d = 0
Newton's method to find the zero of a function:
given a function f(x) and initial guess x_0

View file

@ -47,8 +47,6 @@ struct qfixed2d
&& qFuzzyCompare(y, other.y); }
};
#define QT_PATH_KAPPA 0.5522847498
QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength,
QPointF *controlPoints, int *point_count);

View file

@ -9,6 +9,11 @@
QT_BEGIN_NAMESPACE
// This value is used to determine the length of control point vectors
// when approximating arc segments as curves. The factor is multiplied
// with the radius of the circle.
#define QT_PATH_KAPPA qreal(0.5522847498)
struct QRealRect {
qreal x1, y1, x2, y2;
};