[TASK] Step forward, step back. This is harder than expected.

This commit is contained in:
Jan Philipp Timme 2016-01-08 02:17:38 +01:00
parent b92850f4c9
commit c4f6ff5790
1 changed files with 67 additions and 10 deletions

View File

@ -120,6 +120,40 @@ class HoughMachine {
this->bresenham_orientation_sector = this->getOrientationSector(end_x - start_x, end_y - start_y);
// Now adapt input
// Output will be adapted in setPixel()
switch(this->bresenham_orientation_sector) {
case 0:
// Going right, nothing to do here
this->bresenham(start_x, start_y, end_x, end_y);
break;
case 1:
// Going right, but more up
this->bresenham(start_y, start_x, end_y, end_x);
break;
case 2:
// Going left, but more up
this->bresenham(start_y, end_x, end_y, start_x);
break;
case 3:
// Going left
this->bresenham(end_x, start_y, start_x, end_y);
break;
case 4:
// Going left
this->bresenham(end_x, end_y, start_x, start_y);
break;
case 5:
// Going left, but more down
this->bresenham(end_y, end_x, start_y, start_x);
break;
case 6:
// Going right, but more down
this->bresenham(end_y, start_x, start_y, end_x);
break;
case 7:
// Going right
this->bresenham(start_x, end_y, end_x, start_y);
break;
}
};
void bresenham(int start_x, int start_y, int end_x, int end_y) {
@ -158,34 +192,57 @@ class HoughMachine {
// Do matrix multiplication
double new_dx = dx * cosoct + dy * neg_sinoct;
double new_dy = dx * sinoct + dy * cosoct;
int orientation_sector = 0;
if(new_dy < 0) {
new_dx = -new_dx;
new_dy = -new_dy;
orientation_sector += 4;
}
int orientation_sector;
if(new_dx >= 0 && new_dx >= new_dy) orientation_sector = 0;
if(new_dx >= 0 && new_dx < new_dy) orientation_sector = 1;
if(new_dx < 0 && -new_dx < new_dy) orientation_sector = 2;
if(new_dx < 0 && -new_dx >= new_dy) orientation_sector = 3;
if(new_dx >= 0 && new_dx >= new_dy) orientation_sector += 0;
if(new_dx >= 0 && new_dx < new_dy) orientation_sector += 1;
if(new_dx < 0 && -new_dx < new_dy) orientation_sector += 2;
if(new_dx < 0 && -new_dx >= new_dy) orientation_sector += 3;
return orientation_sector;
};
void setPixel(int x, int y) {
int color = QColor::fromRgb(0, 255, 0).rgb();
//TODO: Fix this! This has to happen relative to the center point! :|
switch(this->bresenham_orientation_sector) {
case 0:
// Going right, nothing to do here
this->working_copy->getImage()->setPixel(x, y, color);
break;
case 1:
//TODO
// Going right, but more up
this->working_copy->getImage()->setPixel(y, x, color);
break;
case 2:
// Going left, but more up
this->working_copy->getImage()->setPixel(-y, x, color);
break;
case 3:
// Going left
this->working_copy->getImage()->setPixel(-x, y, color);
break;
case 4:
// Going left
this->working_copy->getImage()->setPixel(-x, -y, color);
break;
case 5:
// Going left, but more down
this->working_copy->getImage()->setPixel(-y, -x, color);
break;
case 6:
// Going right, but more down
this->working_copy->getImage()->setPixel(y, -x, color);
break;
case 7:
// Going right
this->working_copy->getImage()->setPixel(x, -y, color);
break;
}
this->working_copy->getImage()->setPixel(x, y, color);
};
void debugShow() {