/* This returns true if the circle intersects with the rectangle */
bool CircleRectangleIntersection(Scalar minx, Scalar minz, Scalar maxx, Scalar maxz, CVector C, Scalar Rad)
{
 double Rad2;

 Rad2 = Rad * Rad;
 /* Translate coordinates, placing C at the origin. */
 maxx -= C.x;  maxz -= C.z;
 minx -= C.x;  minz -= C.z;

 if (maxx < 0) 			/* R to left of circle center */
   	if (maxz < 0) 		/* R in lower left corner */
     		return ((maxx * maxx + maxz * maxz) < Rad2);
   	else if (minz > 0) 	/* R in upper left corner */
     		return ((maxx * maxx + minz * minz) < Rad2);
   	else 					/* R due West of circle */
     		return(MLabs(maxx) < Rad);
 	else if (minx > 0)  	/* R to right of circle center */
   		if (maxz < 0) 	/* R in lower right corner */
     			return ((minx * minx) < Rad2);
   	else if (minz > 0)  	/* R in upper right corner */
     		return ((minx * minx + minz + minz) < Rad2);
   	else 				/* R due East of circle */
     		return (minx < Rad);
 	else				/* R on circle vertical centerline */
   		if (maxz < 0) 	/* R due South of circle */
     		return (MLabs(maxz) < Rad);
   	else if (minz > 0)  	/* R due North of circle */
     		return (minz < Rad);
   	else 				/* R contains circle centerpoint */
     		return(true);
}
