fix: graph jitter on load + format
This commit is contained in:
@@ -8,8 +8,8 @@ namespace ZShell::internal {
|
||||
|
||||
qreal snapLine(qreal logical, qint64 widthDev, qreal dpr) {
|
||||
const qreal half = qreal(widthDev) / 2.0;
|
||||
return (static_cast<qreal>(std::llround(logical * dpr - half)) + half)
|
||||
/ dpr;
|
||||
return (static_cast<qreal>(std::llround(logical * dpr - half)) + half) /
|
||||
dpr;
|
||||
}
|
||||
|
||||
void segmentControls(
|
||||
@@ -51,8 +51,8 @@ qreal cubicY(
|
||||
for (int it = 0; it < 16; ++it) {
|
||||
const qreal t = (lo + hi) / 2.0;
|
||||
const qreal u = 1.0 - t;
|
||||
const qreal x = u * u * u * p1.x() + 3 * u * u * t * c1.x()
|
||||
+ 3 * u * t * t * c2.x() + t * t * t * p2.x();
|
||||
const qreal x = u * u * u * p1.x() + 3 * u * u * t * c1.x() +
|
||||
3 * u * t * t * c2.x() + t * t * t * p2.x();
|
||||
if (x < targetX)
|
||||
lo = t;
|
||||
else
|
||||
@@ -61,8 +61,8 @@ qreal cubicY(
|
||||
|
||||
const qreal t = (lo + hi) / 2.0;
|
||||
const qreal u = 1.0 - t;
|
||||
return u * u * u * p1.y() + 3 * u * u * t * c1.y()
|
||||
+ 3 * u * t * t * c2.y() + t * t * t * p2.y();
|
||||
return u * u * u * p1.y() + 3 * u * u * t * c1.y() +
|
||||
3 * u * t * t * c2.y() + t * t * t * p2.y();
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -72,17 +72,14 @@ namespace {
|
||||
int segmentIndexAt(const QVector<QPointF>& points, qreal targetX) {
|
||||
const int last = points.size() - 2;
|
||||
for (int i = 0; i < points.size() - 1; ++i) {
|
||||
if (targetX <= points[i + 1].x())
|
||||
return i;
|
||||
if (targetX <= points[i + 1].x()) return i;
|
||||
}
|
||||
return qMax(0, last);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
QPointF pointAtX(
|
||||
const QVector<QPointF>& points,
|
||||
qreal targetX,
|
||||
bool curveSmoothing) {
|
||||
const QVector<QPointF>& points, qreal targetX, bool curveSmoothing) {
|
||||
const int j = segmentIndexAt(points, targetX);
|
||||
QPointF c1;
|
||||
QPointF c2;
|
||||
@@ -93,9 +90,8 @@ QPointF pointAtX(
|
||||
for (int it = 0; it < 24; ++it) {
|
||||
const qreal t = (lo + hi) / 2.0;
|
||||
const qreal u = 1.0 - t;
|
||||
const qreal x = u * u * u * points[j].x()
|
||||
+ 3 * u * u * t * c1.x() + 3 * u * t * t * c2.x()
|
||||
+ t * t * t * points[j + 1].x();
|
||||
const qreal x = u * u * u * points[j].x() + 3 * u * u * t * c1.x() +
|
||||
3 * u * t * t * c2.x() + t * t * t * points[j + 1].x();
|
||||
if (x < targetX)
|
||||
lo = t;
|
||||
else
|
||||
@@ -104,18 +100,15 @@ QPointF pointAtX(
|
||||
|
||||
const qreal t = (lo + hi) / 2.0;
|
||||
const qreal u = 1.0 - t;
|
||||
const qreal y = u * u * u * points[j].y() + 3 * u * u * t * c1.y()
|
||||
+ 3 * u * t * t * c2.y() + t * t * t * points[j + 1].y();
|
||||
const qreal y = u * u * u * points[j].y() + 3 * u * u * t * c1.y() +
|
||||
3 * u * t * t * c2.y() + t * t * t * points[j + 1].y();
|
||||
return QPointF(targetX, y);
|
||||
}
|
||||
|
||||
QVector<QPointF> curveVertices(
|
||||
const QVector<QPointF>& points,
|
||||
qreal dpr,
|
||||
bool curveSmoothing) {
|
||||
const QVector<QPointF>& points, qreal dpr, bool curveSmoothing) {
|
||||
QVector<QPointF> out;
|
||||
if (points.size() < 2)
|
||||
return out;
|
||||
if (points.size() < 2) return out;
|
||||
|
||||
out.reserve(points.size());
|
||||
out.append(points.first());
|
||||
|
||||
Reference in New Issue
Block a user