Commit 7b53f2e4 authored by Kuntal  Majumder's avatar Kuntal Majumder 😟

Creates a bouding rectangle before searching

Ref T10894
parent b64a646d
......@@ -188,10 +188,11 @@ QRect KisMagneticWorker::calculateRect(QPoint p1, QPoint p2, int radius) const {
QVector<QPointF> KisMagneticWorker::computeEdge(int radius, QPoint begin, QPoint end) {
//QRect rect = calculateRect(begin, end, radius);
QRect rect = QPolygon(QVector<QPoint>{begin, end}).boundingRect();
rect.setSize(rect.size()*radius);
VertexDescriptor goal(end);
VertexDescriptor start(begin);
KisMagneticGraph g(m_dev, m_dev->exactBounds());
KisMagneticGraph g(m_dev, rect);
// How many maps does it require?
// Take a look here, if it doesn't make sense, https://www.boost.org/doc/libs/1_70_0/libs/graph/doc/astar_search.html
......
......@@ -96,7 +96,7 @@ void KisToolSelectMagnetic::mouseMoveEvent(KoPointerEvent *event)
m_lastCursorPos = convertToPixelCoord(event);
auto current = QPoint(m_lastCursorPos.x(), m_lastCursorPos.y());
//qDebug() << current;
m_points = m_worker.computeEdge(2, m_lastAnchor, current);
m_points = m_worker.computeEdge(10, m_lastAnchor, current);
m_paintPath = QPainterPath();
m_paintPath.moveTo(pixelToView(m_points[m_points.count()-1]));
for(int i=m_points.count()-2; i>0;i--){
......
......@@ -53,6 +53,9 @@ void KisMagneticWorkerTest::testWorker()
auto points = worker.computeEdge(10, startPos, endPos);
KIS_DUMP_DEVICE_2(grayscaleDev, rect, "draw", "dd");
/*
QVector<QPointF> result = { QPointF(50,65),
QPointF(49,64),
QPointF(48,63),
......@@ -112,6 +115,32 @@ void KisMagneticWorkerTest::testWorker()
QPointF(40,10)};
QCOMPARE(result, points);
*/
QImage img = dev->convertToQImage(0, rect);
img = img.convertToFormat(QImage::Format_ARGB32);
QPainter gc(&img);
QPainterPath path;
for (int i = 0; i < points.size(); i++) {
if (i == 0) {
path.moveTo(points[i]);
} else {
path.lineTo(points[i]);
}
}
gc.setPen(Qt::white);
gc.drawPath(path);
gc.setPen(Qt::green);
gc.drawEllipse(startPos, 3, 3);
gc.setPen(Qt::red);
gc.drawEllipse(endPos, 2, 2);
img.save("result.png");
}
QTEST_MAIN(KisMagneticWorkerTest)
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