pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: postgresql@eric.brechemier.name
To: pgsql-bugs@postgresql.org
Cc: postgresql@eric.brechemier.name
Subject: BUG #14971: point outside polygon is reported inside polygon
Date: Wed, 13 Dec 2017 17:28:06 +0000
Message-ID: <20171213172806.20142.73638@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      14971
Logged by:          Eric Bréchemier
Email address:      postgresql@eric.brechemier.name
PostgreSQL version: 9.5.0
Operating system:   macos
Description:        

Using GPS positions with 5 decimals, which corresponds to an accuracy of
approximately 1 meter, we noticed that the operators '<@' and '@>' which
check whether a polygon contains a given point sometimes give an incorrect
result.

Here is a minimum example which shows the issue:

select '((30E-5,-15E-5),(60E-5,90E-5),(-30E-5,150E-5))'::polygon @>
point(0,0);

This query returns TRUE instead of FALSE.

The same query, scaled to integer values correctly returns FALSE:

select '((30,-15),(60,90),(-30,150))'::polygon @> point(0,0);

I simulated the algorithm used in the implementation step by step in a
spreadsheet, and found that the discrepancy occurs in the computation of
FPzero(z) called by lseg_crossing() called by point_inside() called by
poly_contain_pt().

With the floating point values, z becomes smaller than the EPSILON of
1.0E-6, which is not the case with integer values.

Changing EPSILON to a lower value solves the issue. It appears that the
current value of EPSILON was chosen with single precision floating point
values in mind rather than the double precision values stored in points and
polygons.



Message-ID: <20171213172806.20142.73638@wrigleys.postgresql.org>
Permalink:  ../20171213172806.20142.73638@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20171213172806.20142.73638@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: postgresql@eric.brechemier.name
  Subject: Re: BUG #14971: point outside polygon is reported inside polygon
  In-Reply-To: <20171213172806.20142.73638@wrigleys.postgresql.org>
  References: <20171213172806.20142.73638@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox