Hi all,
I have sorted out my earlier problem but now have a different. I have defined an array of objects called LineArray. Each of these objects has an array called m_XYCoOrds[][] which hold ten x,y co-ordinate points. The 2nd dimension in the array holds x points at 0 and y points at 1. e.g. the first X point would be found by
m_XYCoOrds[0][0] and the y at
m_XYCoOrds[0][1].
The function ncrosses takes two points (x1,y1 and x2,y2) as arguments and checks to see if they cross any other lines that are defined as illegal in the map. The function ncrosses looks like
Code:
int ncrosses(int x1,int y1,int x2,int y2)
{
struct lineSeg *l1;
int i,j,count=0;
l1=coords2lineSeg(x1,y1,x2,y2);
for(i=0;i<MSIZE;i++)
{ for(j=0;j<NSIDES;j++)
if(crosses(l1,lmap[i].ln[j]))
{count++;
/*printf("hit %d ",i); */ /* only need to know about one line
crossed to know zone crossed or partially
crossed, could modify to get more info.*/
break;
}
}
free(l1);
return count;
}
the function crosses called in this function is the one that looks for the crossed lines. I know these functions work because, as you might be able to tell from the comments they are from an original piece of work in C. When I call ncrosses I want to store the value count in an object variable LineArray[0].m_LineCrosses.
And this is where the problem is coming from.
Because each line object has 10 different xy points it is necessary to call ncrosses 9 times for each object. I set up a simple for loop to do this when the document initialises.
Code:
int t=0;
while(t<9)
{
x1 = LineArray[i].m_XYCoOrds[0][0];
y1 = LineArray[i].m_XYCoOrds[0][1];
x2 = LineArray[i].m_XYCoOrds[1][0];
y2 = LineArray[i].m_XYCoOrds[1][1];
temp = ncrosses(x1,y1,x2,y2);//get the number of lines crossed
total = total + temp;
t++;
}
LineArray[i].m_LineCrosses = total;
the i in LineArray is simply because I am working my way through the array calling this for every line object.
The problem is that the value is always whatever I initialise total to be. e.g. if i set the line total=400; before calling this section of code LineArray[i].m_LineCrosses always equals 400. Its almost as thought the line LineArray[i].m_LineCrosses = total; does not exist. Any thoughts would be much appreciated.
Cheers
Dylan