Guys i have a really weird problem. I am trying to implement a nested for loop which splits up a rectangle into smaller blocks and then checks to see which of these smaller blocks have points from an array i have defined in them(big rectangle is 320*240 btw):
int[,] edgetrunc = new int[edgeIndex, 2]; //edgeIndex is the number of points in the external array
Array.Copy(edgePoint, edgetrunc, edgeIndex*2);//truncates the nulls from the tail of my array
int delx = 16;//width of block
int dely = 12;//height of block
int blockIndex = new int();
bool[] block = new bool[(depthFrame.Width/delx)*(depthFrame.Height/dely)];
for (int ymin = 0;ymin < depthFrame.Height;ymin += dely)
{
for (int xmin = 0; xmin < depthFrame.Width; xmin += delx)
{
blockIndex = (xmin / delx) + (ymin / dely);
for (int i = 0; i < edgeIndex; i++)
{
if (edgetrunc[i, 0] >= xmin && edgetrunc[i, 0] < xmin++ && edgetrunc[i, 1] >= ymin && edgetrunc[i, 1] < ymin++)
{
block[blockIndex] = true;
break;
}
}
}
}
heres the problem though, i put a breakpoint on the second for loop(the xmin loop) and started to iterate it, and the value of xmin jumped from 0 to 320 on the first iteration, and after that stayed there and ymin alone changed on each iteration. Am i going cray? what did i do wrong?
PS i even tested this and i got the same problem:
for (int ymin = 0;ymin < depthFrame.Height;ymin += dely)
{
for (int xmin = 0; xmin < depthFrame.Width; xmin += delx)
{
}
}
EDIT:
figured it out, it was strange, apparantly it had to do with the way i was trying to find block index. To fix it, i initialized blockIndex to 0 outside the for loops and put blockIndex++ after the 3rd for loop, thanks for the help anyways =)
int blockIndex = 0;
bool[] block = new bool[(depthFrame.Width/delx)*(depthFrame.Height/dely)];
for (int ymin = 0;ymin < depthFrame.Height;ymin += dely)
{
for (int xmin = 0; xmin < depthFrame.Width; xmin += delx)
{
for (int i = 0; i < edgeIndex; i++)
{
if ((edgetrunc[i, 0] >= xmin) && (edgetrunc[i, 0] < (xmin + delx)) && (edgetrunc[i, 1] >= ymin) && (edgetrunc[i, 1] < (ymin + dely)))
{
block[blockIndex] = true;
break;
}
}
blockIndex++;
}
}