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++

Implement fuzzyComparePointsCyclic for VectorPath

Agata Cackoe264cd4d6875
diff --git a/libs/global/kis_algebra_2d.cpp b/libs/global/kis_algebra_2d.cpp
index 3398c6712f..e84a5ce25b 100644
--- a/libs/global/kis_algebra_2d.cpp
+++ b/libs/global/kis_algebra_2d.cpp
@@ -2610,10 +2610,58 @@ VectorPath VectorPath::reversed() const
return VectorPath(response);
}
-bool VectorPath::fuzzyCompareCyclic(const VectorPath &path, qreal eps) const
+bool VectorPath::fuzzyComparePointsCyclic(const VectorPath &path, qreal eps) const
{
- //
- return true;
+ using VPoint = VectorPath::VectorPathPoint;
+
+ if (segmentsCount() != path.segmentsCount()) {
+ return false;
+ }
+
+ bool fuzzy = qFuzzyIsNull(eps);
+
+ auto comparePoints = [fuzzy, eps] (QPointF left, QPointF right) {
+ if (fuzzy) {
+ return fuzzyPointCompare(left, right);
+ } else {
+ return fuzzyPointCompare(left, right, eps);
+ }
+ };
+
+
+ VPoint leftStart = path.pointAt(0);
+ QList<int> rightStartingPoints;
+ for (int i = 0; i < path.pointsCount(); i++) {
+ if (comparePoints(leftStart.endPoint, path.pointAt(i).endPoint)) {
+ rightStartingPoints << i;
+ }
+ }
+
+ Q_FOREACH(int startId, rightStartingPoints) {
+ bool isEqual = true;
+ for (int i = 0; i < pointsCount(); i++) {
+ int rightId = wrapValue(i + startId, 0, pointsCount());
+ if (!comparePoints(pointAt(i).endPoint, path.pointAt(rightId).endPoint)) {
+ isEqual = false;
+ break;
+ }
+ }
+ if (isEqual) {
+ return true;
+ }
+ for (int i = 0; i < pointsCount(); i++) {
+ int rightId = wrapValue(startId - i, 0, pointsCount());
+ if (!comparePoints(pointAt(i).endPoint, path.pointAt(rightId).endPoint)) {
+ isEqual = false;
+ break;
+ }
+ }
+ if (isEqual) {
+ return true;
+ }
+ }
+
+ return false;
}
QPainterPath VectorPath::asPainterPath() const
diff --git a/libs/global/kis_algebra_2d.h b/libs/global/kis_algebra_2d.h
index 2b16b7d20d..327f27faa1 100644
--- a/libs/global/kis_algebra_2d.h
+++ b/libs/global/kis_algebra_2d.h
@@ -624,7 +624,7 @@ public:
VectorPath reversed() const;
- bool fuzzyCompareCyclic(const VectorPath& path, qreal eps = 0.00001f) const;
+ bool fuzzyComparePointsCyclic(const VectorPath& path, qreal eps = 0.0f) const;
QPainterPath asPainterPath() const;