//snip from ffc
if((isonline(curr.x, curr.y, curr.prevX, curr.prevY, changer.x, changer.y) || // Along the line, or...
(curr.x==changer.x && curr.y==changer.y)) && // At exactly the same position, and...
(curr.prevX>-10000000 && curr.prevY>-10000000)) // Whatever this means
//snip from tiles
/*
bool isonline(float x1, float y1, float x2, float y2, float x3, float y3)
{
float slope;
float intercept;
slope = (y2-y1)/(x2-x1);
intercept = y1 - (slope*x1);
return (y3 == (slope*x3)+intercept) && x3>zc_min(x1,x2) && x3<zc_max(x1,x2) && y3>zc_min(y1,y2) && y3<zc_max(y1,y2) ;
}
*/
//pixel-precise version of the above -DD
bool isonline(long x1, long y1, long x2, long y2, long x3, long y3)
{
long long dx = x2-x1;
long long dy = y2-y1;
long long qx = x3-x1;
long long qy = y3-y1;
//if (x3,y3) is on the line, qx,qy must be multiples of dx,dy. Check this without division.
if(qx*dy != qy*dx)
return false;
//check for degeneracy
if(dx == 0 && dy == 0)
return qx == 0 && qy == 0;
long long nondegend;
long long nondegenq;
if(dx == 0)
{
nondegend = dy;
nondegenq = qy;
}
else
{
nondegend = dx;
nondegenq = qx;
}
//flip negatives
if(nondegend < 0)
{
nondegend = -nondegend;
nondegenq = -nondegenq;
}
//and compare
return nondegenq >= 0 && nondegenq <= nondegend;
}