Fixed scan-line, changed ui for project

This commit is contained in:
Dawid Pietrykowski 2023-01-15 16:35:45 +01:00
parent 9dc3611bc5
commit 2f5a2a1583
3 changed files with 9 additions and 67 deletions

View File

@ -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<Line> 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<int> MyWindow::GetIntersectionsWithY(int y, std::vector<Line> 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<int> MyWindow::GetIntersectionsWithY(int y, std::vector<Line> lines)
res.push_back(x);
}
}
std::sort(res.begin(), res.end(), std::greater<int>());
std::sort(res.begin(), res.end(), std::less<int>());
return res;
}

View File

@ -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*);

View File

@ -42,7 +42,7 @@
<x>630</x>
<y>10</y>
<width>241</width>
<height>331</height>
<height>211</height>
</rect>
</property>
<property name="title">
@ -74,60 +74,19 @@
<string>Wyjście</string>
</property>
</widget>
<widget class="QSlider" name="segmentSlider">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>221</width>
<height>20</height>
</rect>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
<widget class="QLabel" name="segmentLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>186</y>
<y>100</y>
<width>221</width>
<height>131</height>
<height>101</height>
</rect>
</property>
<property name="text">
<string>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ąć</string>
Naciśnij na pierwszy punkt figury aby ją zamknąć</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>