Re: polygon && polygon and precision

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: pdowler(dot)cadc(at)gmail(dot)com
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: polygon && polygon and precision
Date: 2020-03-13 00:49:26
Message-ID: 20200313.094926.1670626366541216586.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello, Patrick.

At Thu, 12 Mar 2020 10:16:15 -0700, Patrick Dowler <pdowler(dot)cadc(at)gmail(dot)com> wrote in
> I am using polygon datatype with some very small values and discovered that
> the overlaps operator appears to break down and give false positives for
> values smaller than ~1e-6. I have tested this on 9.5 (.3 and .16) and 10.10.

For usability, geometric arithmetics is performed having 1.0E-6 of
tolerance. For example equalness between two floating point values is
defined as:

#define EPSILON 1.0E-06
#define FPeq(A, B) (fabs((A) - (B)) <= EPSILON)

Point-same-as is defined using the comparison, so the following
comparison gives true.

=# select '(1.5E-06, 0)'::point ~= '(1.0E-06, 0.5E-06)'::point;
?column?
----------
t

All comparisons are performed taking that degree of tolerance. By a
rough calculation, that tolerance in long-lat coordinate is
corresnponding to that of about 40 meters on the ground.

> To reproduce (these examples only differ in the x-axis exponents) and
> should be false but the first one is t(rue)
>
> select '((3.0e-07,-2),(9.0e-07,-2),(9.0e-07,1),(3.0e-07,1))'::polygon
> &&
> '((2.0e-07,-0.1),(2.0e-07,0.1),(2.01e-07,0.1),(2.01e-07,-0.1))'::polygon;
>
> select '((3.0e-06,-2),(9.0e-06,-2),(9.0e-06,1),(3.0e-06,1))'::polygon
> &&
> '((2.0e-06,-0.1),(2.0e-06,0.1),(2.01e-06,0.1),(2.01e-06,-0.1))'::polygon;
>
> Maybe suggests some single-precision floating point use in the
> calculations...

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2020-03-13 01:37:02 Re: plperl syntax question
Previous Message Rob Sargent 2020-03-12 22:45:58 Re: plperl syntax question