X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fbeziercurve%2Fbpoint.cpp;h=d45488dfa63b9de7253b0e21ca56e19ab49b8288;hb=64834d517d243b2a7672080453324bf8872ed60d;hp=c335b4cd69d24560847167ba748cee1395a4403b;hpb=4228e3960b5e6d5ecda34529e7c34df86b0a7750;p=kdenlive diff --git a/src/beziercurve/bpoint.cpp b/src/beziercurve/bpoint.cpp index c335b4cd..d45488df 100644 --- a/src/beziercurve/bpoint.cpp +++ b/src/beziercurve/bpoint.cpp @@ -27,7 +27,7 @@ BPoint::BPoint() : { } -BPoint::BPoint(QPointF handle1, QPointF point, QPointF handle2) : +BPoint::BPoint(const QPointF &handle1, const QPointF &point, const QPointF &handle2) : h1(handle1), p(point), h2(handle2) @@ -35,6 +35,16 @@ BPoint::BPoint(QPointF handle1, QPointF point, QPointF handle2) : autoSetLinked(); } +QPointF &BPoint::operator[](int i) +{ + return i == 0 ? h1 : (i == 1 ? p : h2); +} + +const QPointF &BPoint::operator[](int i) const +{ + return i == 0 ? h1 : (i == 1 ? p : h2); +} + bool BPoint::operator==(const BPoint& point) const { return point.h1 == h1 && @@ -42,7 +52,7 @@ bool BPoint::operator==(const BPoint& point) const point.h2 == h2; } -void BPoint::setP(QPointF point, bool updateHandles) +void BPoint::setP(const QPointF &point, bool updateHandles) { QPointF offset = point - p; p = point; @@ -52,7 +62,7 @@ void BPoint::setP(QPointF point, bool updateHandles) } } -void BPoint::setH1(QPointF handle1) +void BPoint::setH1(const QPointF &handle1) { h1 = handle1; if (handlesLinked) { @@ -63,7 +73,7 @@ void BPoint::setH1(QPointF handle1) } } -void BPoint::setH2(QPointF handle2) +void BPoint::setH2(const QPointF &handle2) { h2 = handle2; if (handlesLinked) { @@ -76,9 +86,14 @@ void BPoint::setH2(QPointF handle2) void BPoint::keepInRange(qreal xMin, qreal xMax) { + Q_UNUSED(xMin) + Q_UNUSED(xMax) } void BPoint::autoSetLinked() { - handlesLinked = !QLineF(h1, p).angleTo(QLineF(p, h2)); + // sometimes the angle is returned as 360° + // due to rounding problems the angle is sometimes not quite 0 + qreal angle = QLineF(h1, p).angleTo(QLineF(p, h2)); + handlesLinked = angle < 1e-3 || qRound(angle) == 360; }