QVector<Point> to QVector<Point*>

This commit is contained in:
2025-12-09 18:40:53 +03:00
parent 06a21821b4
commit 71a2a382f1
3 changed files with 15 additions and 8 deletions

View File

@@ -97,13 +97,15 @@ void Canvas::mousePressEvent(QMouseEvent* event)
params.push_back(x1); params.push_back(x1);
params.push_back(y1); params.push_back(y1);
points.push_back(Point(x1, y1, obj_count)); points.push_back(new Point(x1, y1, obj_count));
points.push_back(Point(x2, y2, obj_count)); points.push_back(new Point(x2, y2, obj_count));
current_line->p1.x = x1; current_line->p1.x = x1;
current_line->p1.y = y1; current_line->p1.y = y1;
current_line->p2.x = x2; current_line->p2.x = x2;
current_line->p2.y = y2; current_line->p2.y = y2;
current_line->p1_ref = points[points.size() - 2];
current_line->p2_ref = points[points.size() - 1];
} }
else { else {
*current_line->p2.x = scene.x(); *current_line->p2.x = scene.x();
@@ -115,7 +117,9 @@ void Canvas::mousePressEvent(QMouseEvent* event)
delete current_line; delete current_line;
current_line = nullptr; current_line = nullptr;
delete points.back();
points.pop_back(); points.pop_back();
delete points.back();
points.pop_back(); points.pop_back();
delete params.back(); delete params.back();
params.pop_back(); params.pop_back();
@@ -237,10 +241,10 @@ void Canvas::mouseMoveEvent(QMouseEvent* event)
{ {
if (draggedPoint) { if (draggedPoint) {
QPointF pos = event->pos() - dragOffset; QPointF pos = event->pos() - dragOffset;
for (Point pair : points) { for (Point* pair : points) {
if (areCoincident(draggedPoint, &pair)) { if (areCoincident(draggedPoint, pair)) {
*pair.x = pos.x(); *pair->x = pos.x();
*pair.y = pos.y(); *pair->y = pos.y();
} }
} }
*draggedPoint->x = pos.x(); *draggedPoint->x = pos.x();

View File

@@ -49,7 +49,7 @@ protected:
private: private:
// ====================== Поиск и выбор ====================== // ====================== Поиск и выбор ======================
Line* findAt(QPointF&); // ищет линию под курсором 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 areCoincident(Point*, Point*, bool mode = false);
// ====================== Параллельность ====================== // ====================== Параллельность ======================
bool areAlreadyParallel(Line* l1, Line* l2); // проверка на дубликат bool areAlreadyParallel(Line* l1, Line* l2); // проверка на дубликат
@@ -61,7 +61,7 @@ private:
// ====================== Данные сцены ====================== // ====================== Данные сцены ======================
System sys; // геометрический солвер System sys; // геометрический солвер
QVector<Line*> lines; // завершённые линии QVector<Line*> lines; // завершённые линии
QVector<Point> points; // все точки (для удобного доступа) QVector<Point*> points; // все точки (для удобного доступа)
std::vector<double*> params; // все параметры, передаваемые в солвер std::vector<double*> params; // все параметры, передаваемые в солвер
std::set<LinePair> parallelPairs; // уже запараллеленные пары (защита от дублей) std::set<LinePair> parallelPairs; // уже запараллеленные пары (защита от дублей)

View File

@@ -228,6 +228,8 @@ public:
{} {}
Point p1; Point p1;
Point p2; Point p2;
Point* p1_ref;
Point* p2_ref;
DeriVector2 CalculateNormal(const Point& p, const double* derivparam = nullptr) const override; DeriVector2 CalculateNormal(const Point& p, const double* derivparam = nullptr) const override;
DeriVector2 Value(double u, double du, const double* derivparam = nullptr) const override; DeriVector2 Value(double u, double du, const double* derivparam = nullptr) const override;
int PushOwnParams(VEC_pD& pvec) override; int PushOwnParams(VEC_pD& pvec) override;
@@ -237,6 +239,7 @@ public:
void set_tag(int); void set_tag(int);
int get_tag(); int get_tag();
bool contains(QPointF, qreal tol = 10.0) const; bool contains(QPointF, qreal tol = 10.0) const;
}; };
class Circle: public Curve class Circle: public Curve