diff --git a/QT/scan-line/mywindow.cpp b/QT/scan-line/mywindow.cpp index 7a62965..9a2be79 100644 --- a/QT/scan-line/mywindow.cpp +++ b/QT/scan-line/mywindow.cpp @@ -56,10 +56,6 @@ MyWindow::MyWindow(QWidget *parent) : poczX = ui->rysujFrame->x(); poczY = ui->rysujFrame->y(); - segment_count = ui->segmentSlider->value(); - QString str(("Ilosc segmentow: " + std::to_string(segment_count)).c_str()); - ui->segmentLabel->setText(str); - shapes.push_back(Shape()); // Tworzymy obiekt klasy QImage, o odpowiedniej szerokosci @@ -89,17 +85,6 @@ void MyWindow::on_exitButton_clicked() qApp->quit(); } - -void MyWindow::on_segmentSlider_valueChanged(int val) -{ - segment_count = val; - QString str(("Ilosc segmentow: " + std::to_string(segment_count)).c_str()); - ui->segmentLabel->setText(str); - DrawShapes(); - update(); -} - - // Funkcja "odmalowujaca" komponent void MyWindow::paintEvent(QPaintEvent*) { @@ -305,9 +290,10 @@ void MyWindow::DrawShapes(){ DrawLine(p1.x, p1.y, p2.x, p2.y, img); } std::vector lines; - for(int j = 0; j < (int)shapes[i].points.size() - 1; j++){ + int points_n = (int)shapes[i].points.size(); + for(int j = 0; j < points_n; j++){ Point p1 = shapes[i].points[j]; - Point p2 = shapes[i].points[j+1]; + Point p2 = j == points_n - 1 ? shapes[i].points[0] : shapes[i].points[j+1]; lines.push_back(Line(p1, p2)); } for(int y = 0; y < wys; y++){ @@ -325,9 +311,7 @@ std::vector MyWindow::GetIntersectionsWithY(int y, std::vector lines) Line l = lines[i]; if(l.A.x < l.B.x) std::swap(l.A, l.B); -// if(l.A.x < l.B.x) -// std::swap(l.A, l.B); - if((l.A.y < y && l.B.y > y) || (l.A.y > y && l.B.y < y)){ + if((l.A.y <= y && l.B.y > y) || (l.A.y > y && l.B.y <= y)){ float d1 = (y - l.A.y); float d2 = (l.B.y - l.A.y); float dx = (l.B.x - l.A.x); @@ -336,7 +320,7 @@ std::vector MyWindow::GetIntersectionsWithY(int y, std::vector lines) res.push_back(x); } } - std::sort(res.begin(), res.end(), std::greater()); + std::sort(res.begin(), res.end(), std::less()); return res; } diff --git a/QT/scan-line/mywindow.h b/QT/scan-line/mywindow.h index 2634fc7..8954979 100644 --- a/QT/scan-line/mywindow.h +++ b/QT/scan-line/mywindow.h @@ -155,7 +155,6 @@ private: private slots: void on_cleanButton_clicked(); void on_exitButton_clicked(); - void on_segmentSlider_valueChanged(int val); void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void paintEvent(QPaintEvent*); diff --git a/QT/scan-line/mywindow.ui b/QT/scan-line/mywindow.ui index 35bbc7c..e3d6a20 100644 --- a/QT/scan-line/mywindow.ui +++ b/QT/scan-line/mywindow.ui @@ -42,7 +42,7 @@ 630 10 241 - 331 + 211 @@ -74,60 +74,19 @@ Wyjście - - - - 10 - 150 - 221 - 20 - - - - 1 - - - 100 - - - 10 - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 10 - - - - - - 10 - 120 - 131 - 20 - - - - TextLabel - - 10 - 186 + 100 221 - 131 + 101 Naciśnij lewy przycisk myszy by utworzyć punkt. Przytrzymaj lewy przycisk myszy przy punkcie by go przesunąć. -Naciśnij prawy przycisk myszy przy punkcie by go usunąć +Naciśnij na pierwszy punkt figury aby ją zamknąć Qt::PlainText