diff options
Diffstat (limited to 'imagealgos.cpp')
| -rw-r--r-- | imagealgos.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/imagealgos.cpp b/imagealgos.cpp index b4fba4b..267e4ae 100644 --- a/imagealgos.cpp +++ b/imagealgos.cpp @@ -303,7 +303,7 @@ Pixels& Pixels::operator/=(const float divider) QList<QLineF> pixelsToLines(const Pixels &rawProfile) { const auto& pixels = rawProfile.pixels; - QList<QPointF> points { pixels.size() }; + QList<QPointF> points(pixels.size()); for (int i = 0; i < pixels.size(); ++i) { @@ -320,7 +320,7 @@ QList<QLineF> pointsToLines(const QList<QPointF> &points) constexpr double maxDistanceFromLine { 3 }; constexpr double minLineLength { 10 }; - QList<int> lineAnchors { 0, points.size() - 1 }; + QList<int> lineAnchors{0, int(points.count() - 1)}; auto vecLength = [](const QPointF& vector) { return std::hypot(vector.x(), vector.y()); @@ -364,7 +364,7 @@ QList<QLineF> pointsToLines(const QList<QPointF> &points) // distance // qDebug() << "dist" << fabs(x*y2 - y*x2) / norm << point << line; - return fabs(x*y2 - y*x2) / norm; + return fabs(x * y2 - y * x2) / norm; }; // for (const auto& p : points) @@ -386,13 +386,21 @@ QList<QLineF> pointsToLines(const QList<QPointF> &points) const QLineF line { points.at(leftPointIdx), points.at(rightPointIdx) }; + // std::cout << "max between " << leftPointIdx + 1 << " and " + // << rightPointIdx - 1 << std::endl; + const auto farthest = std::max_element( // std::execution::par_unseq, points.cbegin() + leftPointIdx + 1, points.cbegin() + rightPointIdx - 1, [line, distanceToLine](const QPointF& a, const QPointF& b) { return distanceToLine(a, line) < distanceToLine(b, line); - }); + } + ); + + // std::cout << "done max" << std::endl; + // auto tmp = *farthest; + // std::cout << "done farthest" << std::endl; // qDebug() << "farthest point" << distanceToLine(*farthest, line); // qDebug() << "farthest dist" << distanceToLine(*farthest, line); @@ -400,7 +408,13 @@ QList<QLineF> pointsToLines(const QList<QPointF> &points) if (distanceToLine(*farthest, line) > maxDistanceFromLine) { + // std::cout << "try insert at " << i + 1 << ". lineAnchors.size is + // " + // << lineAnchors.size() + // << ". inserting this: " << farthest - points.cbegin() + // << std::endl; lineAnchors.insert(i + 1, farthest - points.cbegin()); + // std::cout << "done insert" << std::endl; --i; // qDebug() << "I'm here" << i; continue; |
