Skip to content

Commit 609d52a

Browse files
committed
use more permissive comparisons
1 parent 34e3a8d commit 609d52a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src_c/collisions.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pgIntersection_CircleCircle(pgCircleBase *A, pgCircleBase *B,
605605
return 0;
606606
}
607607

608-
if (d2 == 0 && A->r == B->r) {
608+
if (double_compare(d2, 0) && double_compare(A->r, B->r)) {
609609
return 0;
610610
}
611611

@@ -621,7 +621,7 @@ pgIntersection_CircleCircle(pgCircleBase *A, pgCircleBase *B,
621621
double xs2 = xm - h * (dy / d);
622622
double ys2 = ym + h * (dx / d);
623623

624-
if (d2 == r_sum2 || d2 == r_diff2) {
624+
if (double_compare(d2, r_sum2) || double_compare(d2, r_diff2)) {
625625
intersections[0] = xs1;
626626
intersections[1] = ys1;
627627
return 1;

src_c/include/geometry.h

+8
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,12 @@ PG_FREEPOLY_COND(pgPolygonBase *poly, int was_sequence)
147147
}
148148
}
149149

150+
static int
151+
double_compare(double a, double b)
152+
{
153+
/* Uses both a fixed epsilon and an adaptive epsilon */
154+
const double e = 1e-6;
155+
return fabs(a - b) < e || fabs(a - b) <= e * MAX(fabs(a), fabs(b));
156+
}
157+
150158
#endif /* ~_GEOMETRY_H */

0 commit comments

Comments
 (0)