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

Paul Ramsey pramsey at refractions.net
Fri Jan 25 00:47:02 EST 2008


Ben, does your patch also resolve this?

http://trac.osgeo.org/geos/ticket/171


On 24-Jan-08, at 2:20 PM, Ben Jubb wrote:

> 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<benjubb.vcf>_______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel



More information about the geos-devel mailing list