Index: trunk/src/misc.c =================================================================== --- trunk/src/misc.c (revision 955) +++ trunk/src/misc.c (revision 956) @@ -112,6 +112,17 @@ return sqrt(delta_x * delta_x + delta_y * delta_y); } +/* Distance2() should be used so that there is only one + * place to deal with overflow/precision errors + */ +double +Distance2 (double x1, double y1, double x2, double y2) +{ + double delta_x = (x2 - x1); + double delta_y = (y2 - y1); + return delta_x * delta_x + delta_y * delta_y; +} + /* Bring an angle into [0, 360) range */ Angle NormalizeAngle (Angle a) Index: trunk/src/misc.h =================================================================== --- trunk/src/misc.h (revision 955) +++ trunk/src/misc.h (revision 956) @@ -45,6 +45,7 @@ } UnitList[]; double Distance (double x1, double y1, double x2, double y2); +double Distance2 (double x1, double y1, double x2, double y2); /* distance square */ Angle NormalizeAngle (Angle a); char *pcb_author (void); Index: trunk/src/search.h =================================================================== --- trunk/src/search.h (revision 955) +++ trunk/src/search.h (revision 956) @@ -72,14 +72,14 @@ /* == the same but accept if any part of the object touches the box == */ #define POINT_IN_CIRCLE(x, y, cx, cy, r) \ - (((x)-(cx)) * ((x)-(cx)) + ((y)-(cy)) * ((y)-(cy)) <= (r)*(r)) + (Distance2(x, y, cx, cy) <= (double)(r) * (double)(r)) -#define CIRCLE_TOUCH_BOX(cx, cy, r, b) \ +#define CIRCLE_TOUCHES_BOX(cx, cy, r, b) \ ( POINT_IN_BOX((cx)-(r),(cy),(b)) || POINT_IN_BOX((cx)+(r),(cy),(b)) || POINT_IN_BOX((cx),(cy)-(r),(b)) || POINT_IN_BOX((cx),(cy)+(r),(b)) \ || POINT_IN_CIRCLE((b)->X1, (b)->Y1, (cx), (cy), (r)) || POINT_IN_CIRCLE((b)->X2, (b)->Y1, (cx), (cy), (r)) || POINT_IN_CIRCLE((b)->X1, (b)->Y2, (cx), (cy), (r)) || POINT_IN_CIRCLE((b)->X2, (b)->Y2, (cx), (cy), (r))) #define VIA_OR_PIN_TOUCHES_BOX(v,b) \ - CIRCLE_TOUCH_BOX((v)->X,(v)->Y,((v)->Thickness + (v)->DrillingHole/2),(b)) + CIRCLE_TOUCHES_BOX((v)->X,(v)->Y,((v)->Thickness + (v)->DrillingHole/2),(b)) #define LINE_TOUCHES_BOX(l,b) \ ( lines_intersect((l)->Point1.X,(l)->Point1.Y,(l)->Point2.X,(l)->Point2.Y, (b)->X1, (b)->Y1, (b)->X2, (b)->Y1) \