[geos-devel] Found a bug in contains().

Ben Jubb benjubb at refractions.net
Thu Jan 24 17:20:52 EST 2008


i all,
While doing some testing on the prepared geometry code in PostGIS, I 
found what appears to be a bug in
operation/predicate/RectangleContains.cpp.  This appeared while testing 
the contains() predicate, with input geometries like:

A] POINT (110 120)

and

B] POLYGON ((60 120, 60 40, 160 40, 160 120, 60 120))

(the point is on one of the horizontal edges of the polygon)

When testing B.contains(A), since the poly is a rectangle, there is a 
shortcut path for the test that ends up invoking 
isPointContainedInBoundary() in RectangleContains.cpp. This is supposed 
to test if the point lies on the boundary of the rectangle.  However, as 
coded, the test will prematurely return false, and thus the whole test 
errantly returns true.


Heres the patch.

Index: RectangleContains.cpp
===================================================================
--- RectangleContains.cpp    (revision 2111)
+++ RectangleContains.cpp    (working copy)
@@ -79,10 +79,9 @@
 {
     // we already know that the point is contained in the
     // rectangle envelope
-    if (! (pt.x == rectEnv.getMinX() || pt.x == rectEnv.getMaxX()) )
+    if (pt.x != rectEnv.getMinX() && pt.x != rectEnv.getMaxX() &&
+        pt.y != rectEnv.getMinY() && pt.y != rectEnv.getMaxY() )
         return false;
-    if (! (pt.y == rectEnv.getMinY() || pt.y == rectEnv.getMaxY()) )
-        return false;
 
     return true;
 }

cheers
b
-------------- next part --------------
A non-text attachment was scrubbed...
Name: benjubb.vcf
Type: text/x-vcard
Size: 255 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/geos-devel/attachments/20080124/0804605a/benjubb.vcf


More information about the geos-devel mailing list