From eed4a3088d04120a6f443714ce0200eb90e5ffa6 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Mon, 22 Dec 2025 20:31:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B0=D0=B6=D0=BD=D1=8B=D0=B9=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Наконец-то можно двигать нормально вершины без риска блокировки --- Canvas.cpp | 64 +++++++++++++++++++++++------------------------------- Canvas.h | 2 +- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/Canvas.cpp b/Canvas.cpp index b185cad..dc3205c 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -2,6 +2,8 @@ #define WIDGET_POSITION event->pos() #define UCS_POSITION screenToLogical(WIDGET_POSITION) +std::set groups; + // =================================================================== // Вспомогательные функции // =================================================================== @@ -185,6 +187,7 @@ void Canvas::mousePressEvent(QMouseEvent* event) Point* p = findPointAt(scene); if (p) { draggedPoint = p; + getCoincidentGroup(draggedPoint); dragOffset = scene - QPointF(*p->x, *p->y); return; } @@ -480,25 +483,12 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) // ====================== Перемещение точки ====================== if (draggedPoint) { QPointF pos = UCS_POSITION - dragOffset; - - *draggedPoint->x = pos.x(); - *draggedPoint->y = pos.y(); - - // TODO - for (Point* pair : points) { - if (areCoincident(draggedPoint, pair)) { - *pair->x = pos.x(); - *pair->y = pos.y(); - } - } - - auto coincidentGroup = getCoincidentGroup(draggedPoint); - for (Point* pt : coincidentGroup) { + for (Point* pt : groups) { *pt->x = pos.x(); *pt->y = pos.y(); } - for (Point* basePt : coincidentGroup) { + for (Point* basePt : groups) { for (Point* other : points) { if (areHorizontalVertical(basePt, other, true)) { *other->x = pos.x(); @@ -509,15 +499,6 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) } } - for (Point* other : points) { - if (areHorizontalVertical(draggedPoint, other, true)) { - *other->x = pos.x(); - } - if (areHorizontalVertical(draggedPoint, other, false)) { - *other->y = pos.y(); - } - } - solve_for_canvas(); } @@ -571,6 +552,8 @@ void Canvas::mouseReleaseEvent(QMouseEvent* event) draggedLine = nullptr; solve_for_canvas(); } + + groups.clear(); } // =================================================================== @@ -683,19 +666,17 @@ void Canvas::keyPressEvent(QKeyEvent* event) mode = Mode::None; current_line = nullptr; firstPoint = nullptr; + groups.clear(); update(); } break; } case Qt::Key_Z: { - if (event->modifiers() & Qt::ControlModifier) { - // Ctrl+Z - отмена последнего ограничения - if (constraints_count > 0) { - remove_constraint(constraints_count - 1); - constraints_count--; - solve_for_canvas(); - } + if (constraints_count > 0) { + remove_constraint(constraints_count - 1); + constraints_count--; + solve_for_canvas(); } break; } @@ -741,17 +722,23 @@ QPointF Canvas::screenToLogical(const QPointF& screenPos) const return logical; } -std::vector Canvas::getCoincidentGroup(Point* p) +void Canvas::getCoincidentGroup(Point* p) { - std::vector group; - group.push_back(p); - for (Point* other : points) { if (other != p && areCoincident(p, other)) { - group.push_back(other); + groups.insert(other); + break; } } - return group; + + for (size_t i = 0; i < points.size(); ++i) { + for (size_t j = i + 1; j < points.size(); j++) { + if (*points[i] == *points[j] && groups.contains(points[j])) { + groups.insert(points[i]); + } + } + } + groups.insert(p); } void Canvas::solve_for_canvas() @@ -775,6 +762,7 @@ void Canvas::solve_for_canvas() if (flag) { QMessageBox::warning(this, QString("Error!"), QString("Last constraint is unavailable!")); remove_constraint(constraints_count - 1); + C_Info.erase(constraints_count - 1); constraints_count--; } after_constraint = false; @@ -841,4 +829,6 @@ void Canvas::clearCanvas() // Обновление отображения update(); + + groups.clear(); } \ No newline at end of file diff --git a/Canvas.h b/Canvas.h index a6b996a..323bf49 100644 --- a/Canvas.h +++ b/Canvas.h @@ -70,7 +70,7 @@ private: #endif QPointF screenToLogical(const QPointF& screenPos) const; - std::vector getCoincidentGroup(Point* p); + void getCoincidentGroup(Point* p); // ====================== Методы поиска и выбора ====================== /// Найти линию под указанной позицией