]> granicus.if.org Git - postgis/commitdiff
ST_CPAWithin precision fix
authorDarafei Praliaskouski <me@komzpa.net>
Tue, 27 Mar 2018 17:38:18 +0000 (17:38 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Tue, 27 Mar 2018 17:38:18 +0000 (17:38 +0000)
Closes #4032

git-svn-id: http://svn.osgeo.org/postgis/branches/2.3@16501 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/lwlinearreferencing.c

diff --git a/NEWS b/NEWS
index 2e01412d3d97b8b4783bfae79d3bcd4a8e30bb00..46b3d2582d3ef78990ced034340d8cef17ea2bbe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,7 +7,8 @@ PostGIS 2.3.7dev
   - #4003, lwpoly_construct_circle: Avoid division by zero (Raúl Marín Rodríguez)
   - #4020, Casting from box3d to geometry now returns correctly connected
            PolyhedralSurface (Matthias Bay)
-  - #4025, Incorrect answers for temporally "amost overlapping" ranges
+  - #4025, #4032 Incorrect answers for temporally "almost overlapping" ranges
+           (Paul Ramsey, Darafei Praliaskouski)
   - #4017, lwgeom lexer memory corruption (Peter E)
   - #4052, schema qualify several functions in geography
 
index 8580e1befafbabac10ffa62b207f46ccfc27658f..f0168378bf3d38e75bf476d20237561aa7928796 100644 (file)
@@ -23,7 +23,6 @@
  *
  **********************************************************************/
 
-
 #include "liblwgeom_internal.h"
 #include "lwgeom_log.h"
 #include "measures3d.h"
@@ -1239,7 +1238,7 @@ lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
 {
        LWLINE *l1, *l2;
        int i;
-       const GBOX *gbox1, *gbox2;
+       GBOX gbox1, gbox2;
        double tmin, tmax;
        double *mvals;
        int nmvals = 0;
@@ -1268,20 +1267,19 @@ lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
                return LW_FALSE;
        }
 
-       /* WARNING: these ranges may be wider than real ones */
-       gbox1 = lwgeom_get_bbox(g1);
-       gbox2 = lwgeom_get_bbox(g2);
-
-       assert(gbox1); /* or the npoints check above would have failed */
-       assert(gbox2); /* or the npoints check above would have failed */
+       /* We use lwgeom_calculate_gbox() instead of lwgeom_get_gbox() */
+       /* because we cannot afford the float rounding inaccuracy when */
+       /* we compare the ranges for overlap below */
+       lwgeom_calculate_gbox(g1, &gbox1);
+       lwgeom_calculate_gbox(g2, &gbox2);
 
        /*
         * Find overlapping M range
         * WARNING: may be larger than the real one
         */
 
-       tmin = FP_MAX(gbox1->mmin, gbox2->mmin);
-       tmax = FP_MIN(gbox1->mmax, gbox2->mmax);
+       tmin = FP_MAX(gbox1.mmin, gbox2.mmin);
+       tmax = FP_MIN(gbox1.mmax, gbox2.mmax);
 
        if ( tmax < tmin )
        {
@@ -1289,8 +1287,6 @@ lwgeom_cpa_within(const LWGEOM *g1, const LWGEOM *g2, double maxdist)
                return LW_FALSE;
        }
 
-       // lwnotice("Min:%g, Max:%g", tmin, tmax);
-
        /*
         * Collect M values in common time range from inputs
         */