Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix rendering of nearly-perfect Liquify mask squares

Agata Cacko265ea46eae45
diff --git a/libs/global/kis_algebra_2d.h b/libs/global/kis_algebra_2d.h
index c8c9fad99b..ab00aef1f5 100644
--- a/libs/global/kis_algebra_2d.h
+++ b/libs/global/kis_algebra_2d.h
@@ -876,6 +876,20 @@ bool isPolygonRect(const Polygon &poly, Difference tolerance) {
return true;
}
return sameHoriz(poly[0], poly[1]) && sameVert(poly[1], poly[2]) && sameHoriz(poly[2], poly[3]) && sameVert(poly[3], poly[0]);
+}
+
+template<class Polygon, typename Difference = decltype(Polygon::first())>
+bool isPolygonPixelAlignedRect(const Polygon &poly, Difference tolerance) {
+ if (!isPolygonRect(poly, tolerance)) {
+ return false;
+ }
+
+ for (int i = 0; i < poly.length(); i++) {
+ if (!fuzzyPointCompare(poly[i], QPointF(poly[i].toPoint()), tolerance)) {
+ return false;
+ }
+ }
+ return true;
}
diff --git a/libs/image/kis_grid_interpolation_tools.h b/libs/image/kis_grid_interpolation_tools.h
index 74ed1d018b..c7c1511b5d 100644
--- a/libs/image/kis_grid_interpolation_tools.h
+++ b/libs/image/kis_grid_interpolation_tools.h
@@ -176,7 +176,7 @@ struct PaintDevicePolygonOp
QRect boundRect = areaToCopy.boundingRect().toAlignedRect();
if (boundRect.isEmpty()) return;
- bool isItRect = KisAlgebra2D::isPolygonRect(areaToCopy, m_epsilon); // no need for lower tolerance
+ bool isItRect = KisAlgebra2D::isPolygonPixelAlignedRect(areaToCopy, m_epsilon);
#ifdef DEBUG_PAINTING_POLYGONS
isItRect = false; // force to use the code below, to not have to rewrite it for a workaround for copyAreaOptimized
@@ -233,12 +233,13 @@ struct PaintDevicePolygonOp
QRect boundRect = clipDstPolygon.boundingRect().toAlignedRect();
if (boundRect.isEmpty()) return;
- bool samePolygon = (m_dstDev->colorSpace() == m_srcDev->colorSpace()) && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon);
+ bool samePolygon = (m_dstDev->colorSpace() == m_srcDev->colorSpace())
+ && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon)
+ && KisAlgebra2D::fuzzyPointCompare(srcPolygon, clipDstPolygon, m_epsilon);
- if (samePolygon) {
- // we can use clipDstPolygon here, because it will be smaller than dstPolygon and srcPolygon, because of how IncompletePolicy works
- // we could also calculate intersection here if we're worried whether that fact is always true
- fastCopyArea(clipDstPolygon);
+ if (samePolygon && KisAlgebra2D::isPolygonPixelAlignedRect(dstPolygon, m_epsilon)) {
+ QRect boundRect = dstPolygon.boundingRect().toAlignedRect();
+ fastCopyArea(boundRect);
return;
}
@@ -330,7 +331,7 @@ struct PaintDevicePolygonOp
KisPaintDeviceSP m_srcDev;
KisPaintDeviceSP m_dstDev;
- const qreal m_epsilon {0.1};
+ const qreal m_epsilon {0.001};
#ifdef DEBUG_PAINTING_POLYGONS
QColor m_debugColor {Qt::red};
@@ -364,7 +365,7 @@ struct QImagePolygonOp
if (boundRect.isEmpty()) return;
- bool isItRect = KisAlgebra2D::isPolygonRect(areaToCopy, m_epsilon); // no need for lower tolerance
+ bool isItRect = KisAlgebra2D::isPolygonPixelAlignedRect(areaToCopy, m_epsilon);
if (isItRect) {
fastCopyArea(boundRect);
return;
@@ -451,12 +452,13 @@ struct QImagePolygonOp
void operator() (const QPolygonF &srcPolygon, const QPolygonF &dstPolygon, const QPolygonF &clipDstPolygon) {
QRect boundRect = clipDstPolygon.boundingRect().toAlignedRect();
- bool samePolygon = m_dstImage.format() == m_srcImage.format() && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon);
+ bool samePolygon = (m_dstImage.format() == m_srcImage.format())
+ && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon)
+ && KisAlgebra2D::fuzzyPointCompare(srcPolygon, clipDstPolygon, m_epsilon);
- if (samePolygon) {
- // we can use clipDstPolygon here, because it will be smaller than dstPolygon and srcPolygon, because of how IncompletePolicy works
- // we could also calculate intersection here if we're worried whether that fact is always true
- fastCopyArea(clipDstPolygon);
+ if (samePolygon && KisAlgebra2D::isPolygonPixelAlignedRect(dstPolygon, m_epsilon)) {
+ QRect boundRect = dstPolygon.boundingRect().toAlignedRect();
+ fastCopyArea(boundRect);
return;
}
@@ -529,7 +531,7 @@ struct QImagePolygonOp
QRect m_srcImageRect;
QRect m_dstImageRect;
- const qreal m_epsilon {0.1};
+ const qreal m_epsilon {0.001};
private:
bool m_canMergeRects {true};