Commit 90a070f5 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix extrapolation in the backward 4-point interpolator

parent 46b755c4
......@@ -75,15 +75,18 @@ public:
m_qB_varY = y * m_d.x();
m_qC_varY = y * m_a.x();
m_py = y;
}
inline QPointF getValue() const {
static const qreal eps = 1e-10;
qreal qB = m_qB_const + m_qB_varX + m_qB_varY;
qreal qC = m_qC_varX + m_qC_varY;
qreal nu = 0.0;
if (qAbs(m_qA) < 1e-10) {
if (qAbs(m_qA) < eps) {
nu = -qC / qB;
} else {
qreal D = pow2(qB) - 4 * m_qA * qC;
......@@ -104,7 +107,15 @@ public:
}
}
qreal mu = (m_px - nu * m_c.x()) / (m_a.x() + nu * m_d.x());
qreal xBasedDenominator = m_a.x() + nu * m_d.x();
qreal mu;
if (qAbs(xBasedDenominator) > eps) {
mu = (m_px - nu * m_c.x()) / xBasedDenominator;
} else {
mu = (m_py - nu * m_c.y()) / (m_a.y() + nu * m_d.y());
}
return m_srcBase + QPointF(mu * m_xCoeff, nu * m_yCoeff);
}
......@@ -123,6 +134,7 @@ private:
qreal m_qC_varY; // quadratic equation C coeff, Y-dep part
qreal m_qD_div; // inverted divisor of the quadratic equation solution
qreal m_px; // saved relative X coordinate
qreal m_py; // saved relative Y coordinate
QPointF m_srcBase;
QPointF m_dstBase;
......
......@@ -285,4 +285,42 @@ void KisWarpTransformWorkerTest::testGridSize()
QCOMPARE(GridIterationTools::calcGridDimension(0, 300, 8), 39);
}
void KisWarpTransformWorkerTest::testBackwardInterpolatorExtrapolation()
{
QPolygonF src;
src << QPointF(0, 0);
src << QPointF(100, 0);
src << QPointF(100, 100);
src << QPointF(0, 100);
QPolygonF dst(src);
std::rotate(dst.begin(), dst.begin() + 1, dst.end());
KisFourPointInterpolatorBackward interp(src, dst);
// standard checks
QCOMPARE(interp.map(QPointF(0,0)), QPointF(0,100));
QCOMPARE(interp.map(QPointF(100,0)), QPointF(0,0));
QCOMPARE(interp.map(QPointF(100,100)), QPointF(100,0));
QCOMPARE(interp.map(QPointF(0,100)), QPointF(100,100));
// extrapolate!
QCOMPARE(interp.map(QPointF(-10,0)), QPointF(0,110));
QCOMPARE(interp.map(QPointF(0,-10)), QPointF(-10,100));
QCOMPARE(interp.map(QPointF(-10,-10)), QPointF(-10,110));
QCOMPARE(interp.map(QPointF(110,0)), QPointF(0,-10));
QCOMPARE(interp.map(QPointF(100,-10)), QPointF(-10,0));
QCOMPARE(interp.map(QPointF(110,-10)), QPointF(-10,-10));
QCOMPARE(interp.map(QPointF(110,100)), QPointF(100, -10));
QCOMPARE(interp.map(QPointF(100,110)), QPointF(110, 0));
QCOMPARE(interp.map(QPointF(110,110)), QPointF(110,-10));
QCOMPARE(interp.map(QPointF(-10,100)), QPointF(100, 110));
QCOMPARE(interp.map(QPointF(0,110)), QPointF(110, 100));
QCOMPARE(interp.map(QPointF(-10,110)), QPointF(110,110));
}
QTEST_KDEMAIN(KisWarpTransformWorkerTest, GUI)
......@@ -33,6 +33,7 @@ private slots:
void testBackwardInterpolatorXYShear();
void testBackwardInterpolatorRoundTrip();
void testGridSize();
void testBackwardInterpolatorExtrapolation();
};
#endif /* __KIS_WARP_TRANSFORM_WORKER_TEST_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment