Commit 59b693cf authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fixed two asserts in the Cage Transform

parent 13ca806d
......@@ -48,11 +48,32 @@ void adjustIfOnPolygonBoundary(const QPolygonF &poly, int polygonDirection, QPoi
isInRange(pt->y(), p0.y(), p1.y())) {
QPointF salt = 1.0e-3 * inwardUnitNormal(edge, polygonDirection);
*pt += salt;
QPointF adjustedPoint = *pt + salt;
// in case the polygon is self-intersecting, polygon direction
// might not help
if (kisDistanceToLine(adjustedPoint, QLineF(p0, p1)) < 1e-4) {
adjustedPoint = *pt - salt;
#ifdef SANITY_CHECKS
KIS_ASSERT_RECOVER_NOOP(kisDistanceToLine(*pt, QLineF(p0, p1)) > 1e-4);
if (kisDistanceToLine(adjustedPoint, QLineF(p0, p1)) < 1e-4) {
qDebug() << ppVar(*pt);
qDebug() << ppVar(adjustedPoint);
qDebug() << ppVar(QLineF(p0, p1));
qDebug() << ppVar(salt);
qDebug() << ppVar(poly.containsPoint(*pt, Qt::OddEvenFill));
qDebug() << ppVar(kisDistanceToLine(*pt, QLineF(p0, p1)));
qDebug() << ppVar(kisDistanceToLine(adjustedPoint, QLineF(p0, p1)));
}
*pt = adjustedPoint;
KIS_ASSERT_RECOVER_NOOP(kisDistanceToLine(*pt, QLineF(p0, p1)) > 1e-4);
#endif /* SANITY_CHECKS */
}
}
}
}
......
......@@ -205,6 +205,14 @@ QVector<QPointF> KisCageTransformWorker::Private::calculateTransformedPoints()
for (int i = 0; i < numValidPoints; i++) {
transformedPoints[i] = cage.transformedPoint(i, transfCage);
if (std::isnan(transformedPoints[i].x()) ||
std::isnan(transformedPoints[i].y())) {
qWarning() << "WARNING: One grid point has been removed from a consideration" << validPoints[i];
transformedPoints[i] = validPoints[i];
}
}
return transformedPoints;
......
......@@ -156,6 +156,61 @@ void KisCageTransformWorkerTest::testCageCounterclockwiseUnity()
testCage(false, true);
}
#include <QtGlobal>
QPointF generatePoint(const QRectF &rc)
{
qreal cx = qreal(qrand()) / RAND_MAX;
qreal cy = qreal(qrand()) / RAND_MAX;
QPointF diff = rc.bottomRight() - rc.topLeft();
QPointF pt = rc.topLeft() + QPointF(cx * diff.x(), cy * diff.y());
return pt;
}
void KisCageTransformWorkerTest::stressTestRandomCages()
{
TestUtil::TestProgressBar bar;
KoProgressUpdater pu(&bar);
KoUpdaterPtr updater = pu.startSubtask();
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8();
QImage image(TestUtil::fetchDataFileLazy("test_cage_transform.png"));
KisPaintDeviceSP dev = new KisPaintDevice(cs);
dev->convertFromQImage(image, 0);
const int pixelPrecision = 8;
QRectF bounds(dev->exactBounds());
qsrand(1);
for (int numPoints = 4; numPoints < 15; numPoints+=5) {
for (int j = 0; j < 200; j++) {
QVector<QPointF> origPoints;
QVector<QPointF> transfPoints;
qDebug() << ppVar(j);
for (int i = 0; i < numPoints; i++) {
origPoints << generatePoint(bounds);
transfPoints << generatePoint(bounds);
}
// no just hope it doesn't crash ;)
KisCageTransformWorker worker(dev,
origPoints,
updater,
pixelPrecision);
worker.prepareTransform();
worker.setTransformedCage(transfPoints);
worker.run();
}
}
}
#include "kis_green_coordinates_math.h"
void KisCageTransformWorkerTest::testUnityGreenCoordinates()
......
......@@ -33,6 +33,8 @@ private slots:
void testCageClockwiseUnity();
void testCageCounterclockwiseUnity();
void stressTestRandomCages();
void testUnityGreenCoordinates();
void testTransformAsBase();
......
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