diff --git a/Canvas.cpp b/Canvas.cpp index b57d5d4..fe7af21 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -34,9 +34,9 @@ Point* Canvas::findPointAt(QPointF pos, qreal tolerance) QPointF p2(*line->p2.x, *line->p2.y); if (dist_P2P(p1, pos) <= tolerance) - temp = &line->p1; + temp = line->p1_ref; else if (dist_P2P(p2, pos) <= tolerance) - temp = &line->p2; + temp = line->p2_ref; } return temp; } @@ -97,13 +97,15 @@ void Canvas::mousePressEvent(QMouseEvent* event) params.push_back(x1); params.push_back(y1); - points.push_back(Point(x1, y1, obj_count)); - points.push_back(Point(x2, y2, obj_count)); + points.push_back(new Point(x1, y1, obj_count)); + points.push_back(new Point(x2, y2, obj_count)); current_line->p1.x = x1; current_line->p1.y = y1; current_line->p2.x = x2; current_line->p2.y = y2; + current_line->p1_ref = points[points.size() - 2]; + current_line->p2_ref = points[points.size() - 1]; } else { *current_line->p2.x = scene.x(); @@ -115,9 +117,13 @@ void Canvas::mousePressEvent(QMouseEvent* event) delete current_line; current_line = nullptr; + delete points.back(); points.pop_back(); + delete points.back(); points.pop_back(); + delete params.back(); params.pop_back(); + delete params.back(); params.pop_back(); mode = Mode::None; @@ -208,8 +214,8 @@ void Canvas::mousePressEvent(QMouseEvent* event) Line *l1 = nullptr, *l2 = nullptr; for (Line* l : lines) { - if (&l->p1 == firstPoint || &l->p2 == firstPoint) l1 = l; - if (&l->p1 == clickedPoint || &l->p2 == clickedPoint) l2 = l; + if (l->p1_ref == firstPoint || l->p2_ref == firstPoint) l1 = l; + if (l->p1_ref == clickedPoint || l->p2_ref == clickedPoint) l2 = l; } if (l1 == l2 || @@ -235,10 +241,10 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) { if (draggedPoint) { QPointF pos = event->pos() - dragOffset; - for (Point pair : points) { - if (areCoincident(draggedPoint, &pair)) { - *pair.x = pos.x(); - *pair.y = pos.y(); + for (Point* pair : points) { + if (areCoincident(draggedPoint, pair)) { + *pair->x = pos.x(); + *pair->y = pos.y(); } } *draggedPoint->x = pos.x(); diff --git a/Canvas.h b/Canvas.h index d750778..567652c 100644 --- a/Canvas.h +++ b/Canvas.h @@ -49,7 +49,7 @@ protected: private: // ====================== Поиск и выбор ====================== Line* findAt(QPointF&); // ищет линию под курсором - Point* findPointAt(QPointF, qreal tolerance = 10.0); + Point* findPointAt(QPointF, qreal tolerance = 5.0); bool areCoincident(Point*, Point*, bool mode = false); // ====================== Параллельность ====================== bool areAlreadyParallel(Line* l1, Line* l2); // проверка на дубликат @@ -61,7 +61,7 @@ private: // ====================== Данные сцены ====================== System sys; // геометрический солвер QVector lines; // завершённые линии - QVector points; // все точки (для удобного доступа) + QVector points; // все точки (для удобного доступа) std::vector params; // все параметры, передаваемые в солвер std::set parallelPairs; // уже запараллеленные пары (защита от дублей) diff --git a/GCS/Geo.h b/GCS/Geo.h index 229df9a..faf6efa 100644 --- a/GCS/Geo.h +++ b/GCS/Geo.h @@ -228,6 +228,8 @@ public: {} Point p1; Point p2; + Point* p1_ref; + Point* p2_ref; DeriVector2 CalculateNormal(const Point& p, const double* derivparam = nullptr) const override; DeriVector2 Value(double u, double du, const double* derivparam = nullptr) const override; int PushOwnParams(VEC_pD& pvec) override; @@ -237,6 +239,7 @@ public: void set_tag(int); int get_tag(); bool contains(QPointF, qreal tol = 10.0) const; + }; class Circle: public Curve