From: Sandro Santilli Date: Thu, 8 Sep 2005 22:58:47 +0000 (+0000) Subject: minor speedups in distance() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=529300782e37a527eac11812f1c86f647eedf95b;p=postgis minor speedups in distance() git-svn-id: http://svn.osgeo.org/postgis/branches/pgis_1_0@1895 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/CHANGES b/CHANGES index af485f54f..dd18184b0 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ PostGIS 1.0.4 - Looser syntax acceptance in box3d parser - Documentation improvements - More robust selectivity estimator + - Minor speedup in distance() PostGIS 1.0.3 2005/08/08 diff --git a/lwgeom/measures.c b/lwgeom/measures.c index 7fa33a167..e0f5cc723 100644 --- a/lwgeom/measures.c +++ b/lwgeom/measures.c @@ -459,15 +459,21 @@ double distance2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2) // if intersect, return 0 for (i=0; inrings; i++) { - double dist = distance2d_ptarray_poly(poly1->rings[i], poly2); - if (i) mindist = LW_MIN(mindist, dist); - else mindist = dist; + int j; + for (j=0; jnrings; j++) + { + double d = distance2d_ptarray_ptarray(poly1->rings[i], + poly2->rings[j]); + if ( d <= 0 ) return 0.0; + + if (i) mindist = LW_MIN(mindist, d); + else mindist = d; + } #ifdef PGIS_DEBUG - lwnotice(" ring%d dist: %f, mindist: %f", i, dist, mindist); + lwnotice(" ring%d dist: %f, mindist: %f", i, d, mindist); #endif - if ( mindist <= 0 ) return 0.0; // intersection } // otherwise return closest approach of rings (no intersection)