[postgis-tickets] r16419 - Use more precise bounds when testing overlap of temporal ranges.

Paul Ramsey pramsey at cleverelephant.ca
Mon Feb 26 10:19:42 PST 2018


Author: pramsey
Date: 2018-02-26 10:19:42 -0800 (Mon, 26 Feb 2018)
New Revision: 16419

Modified:
   trunk/liblwgeom/lwlinearreferencing.c
Log:
Use more precise bounds when testing overlap of temporal ranges.
Fixes #4025


Modified: trunk/liblwgeom/lwlinearreferencing.c
===================================================================
--- trunk/liblwgeom/lwlinearreferencing.c	2018-02-26 17:55:03 UTC (rev 16418)
+++ trunk/liblwgeom/lwlinearreferencing.c	2018-02-26 18:19:42 UTC (rev 16419)
@@ -1072,7 +1072,7 @@
 {
 	LWLINE *l1, *l2;
 	int i;
-	const GBOX *gbox1, *gbox2;
+	GBOX gbox1, gbox2;
 	double tmin, tmax;
 	double *mvals;
 	int nmvals = 0;
@@ -1100,20 +1100,19 @@
 		return -1;
 	}
 
-	/* WARNING: these ranges may be wider than real ones */
-	gbox1 = lwgeom_get_bbox(g1);
-	gbox2 = lwgeom_get_bbox(g2);
+	/* 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);
 
-	assert(gbox1); /* or the npoints check above would have failed */
-	assert(gbox2); /* or the npoints check above would have failed */
-
 	/*
 	 * 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 )
 	{



More information about the postgis-tickets mailing list