I have been trying to speed up the following code. But, I can not think of a way to speed it up drastically. What the code does is that it goes through selected points (BINinfo[i].tpZ) in a set of points and then if any points fall within a set radius of a selected point then those points are then added to the selected point group(BINinfo[z].tepZ). The problem is that I am going through ~500,000 points and evaluating every single one of them. If there was a way to kick out of the loop when the distance was continuing to grow from the selected point in question that would significantly reduce the computation time.
Thank you any help is greatly appreciated.
A snip it of the code is below: (npts ~= 500,000, BINinfo[i].X are the X values, BINinfo[i].Y are the Y values and BINinfo[i].Z are the Z values)
int toomany=10; // if there are >10 returns than assume not road in a 2.5 ^2 circle
float size= 6.25; // buffer size "2.5^2" used to optimzie
if ( c > toomany && (BINinfo[z].tepZ != 0 ) && ((((x-x2)*(x-x2))+((y2-y)*(y2-y))) <= size))
BINinfo[z].tepZ = 0;
int returns=3; //number of returns to classify as road
if (c >= returns && (c <= toomany) && (BINinfo[z].tepZ == 0 ) && ((((x-x2)*(x-x2))+((y2-y)*(y2-y))) <= size) ) // if count is greater than return number and its in the circle and = 0 make it have its value back
BINinfo[z].tepZ = BINinfo[z].Z;
if (c < returns && BINinfo[z].tepZ != 0 && ((((x-x2)*(x-x2))+((y2-y)*(y2-y))) <= size)) //if count is less than return number and its in the circle and doesn't already = 0 make it 0