C
oh na klar... das alte unsigned/signed problem...
inline int sqr(const int x){ return x*x; }
inline bool intersectsCircleLineX(const CIRCLE &c, const int x, const int y1,const int y2)
{
register int r2;
return ((r2=sqr(c.r)-sqr(c.x-x))>=0)&&(((r2-sqr(c.y-y1))*(r2-sqr(c.y-y2))<=0)||(((int)(c.y-y1)*(int)(c.y-y2)<=0)&&(r2-sqr(c.y-y1)<=0)));
}
inline bool intersectsCircleLineY(const CIRCLE &c, const int x1, const int x2,const int y)
{
register int r2;
return ((r2=sqr(c.r)-sqr(c.y-y))>=0)&&(((r2-sqr(c.x-x1))*(r2-sqr(c.x-x2))<=0)||(((int)(c.x-x1)*(int)(c.x-x2)<=0)&&(r2-sqr(c.x-x1)<=0)));
}
bool intersectsCircleRect(const RECTANGLE &r, const CIRCLE &c)
{
return intersectsCircleLineX(c,r.x,r.y,r.y+r.height)||
intersectsCircleLineX(c,r.x+r.width,r.y,r.y+r.height)||
intersectsCircleLineY(c,r.x,r.x+r.width,r.y)||
intersectsCircleLineY(c,r.x,r.x+r.width,r.y+r.height);
}
ich hatte es mit den definitionen, die oben angegeben waren getestet - und die waren signed; die windows strukturen benutzen aber unsigned - also hatten wir beide recht