]> granicus.if.org Git - postgresql/commitdiff
Simplify box_overlap computations.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Feb 2013 23:26:08 +0000 (18:26 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Feb 2013 23:26:08 +0000 (18:26 -0500)
Given the assumption that a box's high coordinates are not less than its
low coordinates, the tests in box_ov() are overly complicated and can be
reduced to about half as much work.  Since many other functions in
geo_ops.c rely on that assumption, there doesn't seem to be a good reason
not to use it here.

Per discussion of Alexander Korotkov's GiST fix, which was already using
the simplified logic (in a non-fuzzy form, but the equivalence holds just
as well for fuzzy).

src/backend/utils/adt/geo_ops.c

index c899e80b35a96396dcd551c55d3d504ee475e356..ad18cf07e7d78956ce8db4b94d56cb50c3d4cad2 100644 (file)
@@ -558,15 +558,10 @@ box_overlap(PG_FUNCTION_ARGS)
 static bool
 box_ov(BOX *box1, BOX *box2)
 {
-       return ((FPge(box1->high.x, box2->high.x) &&
-                        FPle(box1->low.x, box2->high.x)) ||
-                       (FPge(box2->high.x, box1->high.x) &&
-                        FPle(box2->low.x, box1->high.x)))
-               &&
-               ((FPge(box1->high.y, box2->high.y) &&
-                 FPle(box1->low.y, box2->high.y)) ||
-                (FPge(box2->high.y, box1->high.y) &&
-                 FPle(box2->low.y, box1->high.y)));
+       return (FPle(box1->low.x, box2->high.x) &&
+                       FPle(box2->low.x, box1->high.x) &&
+                       FPle(box1->low.y, box2->high.y) &&
+                       FPle(box2->low.y, box1->high.y));
 }
 
 /*             box_left                -               is box1 strictly left of box2?