This is a loop I am using, which is part of a bigger code. The if statements in the loop are used to separate points on the screen into respective 16 screen rectangles. The prblem here is that all points are accumulated in the first rectangle, whereas they are supposed to be dispersed according to their x, y coordinates into the 16 rectangles. I am using code::blocks with Win XP. Here is the code:
But good god, this many &&s and if statements makes me want to scream. There must be a better way to do this...
It doesn't help that you numerically named your variables instead of using an array (isobox1, isobox2, isobox3, etc instead of just making an array named isobox)
/*
* I don't use code::blocks, but are you looking for something like this?
* (You can set the values in Rect's static fields based on the real width and height.)
*/
struct Rect {
int x, y;
staticconstint
WIDTH = 44,
HEIGHT = 74,
X_SEC = 4,
Y_SEC = 4;
};
Rect getRect(int pixel_x, int pixel_y) {
Rect where = {0, 0};
for( int x_num = 1; num <= Rect::X_SEC; ++x_num )
if( pixel_x <= x_num * Rect::WIDTH / Rect::X_SEC ) {
where.x = x_num - 1;
break;
}
for( int y_num = 1; num <= Rect::Y_SEC; ++y_num )
if( pixel_y <= y_num * Rect::HEIGHT / Rect::Y_SEC ) {
where.y = y_num - 1;
break;
}
return where;
}
1 2 3 4 5 6 7 8 9
//Also, this is not right.
0 < rightisosceles [dd][0][0] <= 11
//remeber that (a < b) evaluates to a bool, so this is really:
0 < a //return some bool b
b <= 11 //this doesn't make sence to a compiler
//what you wanted was
0 < a && a <= 11
//Sorry, no shortcuts (compound inequalities...)