From: Nicklas Avén Date: Mon, 6 Apr 2015 09:46:00 +0000 (+0000) Subject: effectivearea: force qsort to always return the same ordering when comparing identica... X-Git-Tag: 2.2.0rc1~559 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d26edb0720fa566c50ba862a600a79e9487f864;p=postgis effectivearea: force qsort to always return the same ordering when comparing identical area. Prevents different result cross platforms. git-svn-id: http://svn.osgeo.org/postgis/trunk@13423 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/effectivearea.c b/liblwgeom/effectivearea.c index b89fd2cb3..ddcd19cbb 100644 --- a/liblwgeom/effectivearea.c +++ b/liblwgeom/effectivearea.c @@ -90,10 +90,15 @@ We create the minheap by ordering the minheap array by the areas in the areanode */ static int cmpfunc (const void * a, const void * b) { -// LWDEBUG(2, "cmpfunc entered"); double v1 = (*(areanode**)a)->area; double v2 = (*(areanode**)b)->area; - return (v1>v2 ) ? 1 : -1; + /*qsort gives unpredictable results when comaping identical values. + If two values is the same we force returning the last point in hte point array. + That way we get the same ordering on diffreent machines and pllatforms*/ + if (v1==v2) + return (*(areanode**)a)-(*(areanode**)b); + else + return (v1>v2 ) ? 1 : -1; } @@ -246,6 +251,7 @@ static void tune_areas(EFFECTIVE_AREAS *ea, int avoid_collaps, int set_area, dou for (i=0;itreeindex=i; + LWDEBUGF(4,"Check ordering qsort gives, area=%lf and belong to point %d",((areanode*) tree.key_array[i])->area, tree.key_array[i]-ea->initial_arealist); } /*Ok, now we have a minHeap, just need to keep it*/