From: Paul Ramsey Date: Wed, 3 Jun 2015 13:50:28 +0000 (+0000) Subject: #3140, fix comparison function X-Git-Tag: 2.2.0rc1~411 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=318d910cba9747f6e08096d87f9b2d1b76a1fd0e;p=postgis #3140, fix comparison function git-svn-id: http://svn.osgeo.org/postgis/trunk@13604 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_measures.c b/liblwgeom/cunit/cu_measures.c index 9f9cfd4e9..2213c59f0 100644 --- a/liblwgeom/cunit/cu_measures.c +++ b/liblwgeom/cunit/cu_measures.c @@ -1076,7 +1076,6 @@ test_lwgeom_tcpa(void) ASSERT_DOUBLE_EQUAL(m, 20.0); ASSERT_DOUBLE_EQUAL(dist, 5.0); - /* G1 stops at t=1 until t=4 to let G2 pass by, then continues */ /* G2 passes at 1 meter from G1 t=3 */ @@ -1089,7 +1088,6 @@ test_lwgeom_tcpa(void) ASSERT_DOUBLE_EQUAL(m, 3.0); ASSERT_DOUBLE_EQUAL(dist, 1.0); - /* Test for https://trac.osgeo.org/postgis/ticket/3136 */ g1 = lwgeom_from_wkt("LINESTRING M (0 0 1432291464,2 0 1432291536) ", LW_PARSER_CHECK_NONE); diff --git a/liblwgeom/lwlinearreferencing.c b/liblwgeom/lwlinearreferencing.c index b7ede2359..9665717dd 100644 --- a/liblwgeom/lwlinearreferencing.c +++ b/liblwgeom/lwlinearreferencing.c @@ -974,11 +974,16 @@ ptarray_collect_mvals(const POINTARRAY *pa, double tmin, double tmax, double *mv } static int -compare_double(const void *a, const void *b) +compare_double(const void *pa, const void *pb) { - double *dpa = (double *)a; - double *dpb = (double *)b; - return *dpb < *dpa; + double a = *((double *)pa); + double b = *((double *)pb); + if ( a < b ) + return -1; + else if ( a > b ) + return 1; + else + return 0; } /* Return number of elements in unique array */ @@ -988,11 +993,11 @@ uniq(double *vals, int nvals) int i, last=0; for (i=1; ipoints, t0, &p0, 0); if ( -1 == seg ) continue; /* possible, if GBOX is approximated */ - /*lwnotice("Measure %g on segment %d of line 1: %g, %g, %g", t0, seg, p0.x, p0.y, p0.z);*/ + // lwnotice("Measure %g on segment %d of line 1: %g, %g, %g", t0, seg, p0.x, p0.y, p0.z); seg = ptarray_locate_along_linear(l1->points, t1, &p1, seg); if ( -1 == seg ) continue; /* possible, if GBOX is approximated */ - /*lwnotice("Measure %g on segment %d of line 1: %g, %g, %g", t1, seg, p1.x, p1.y, p1.z);*/ + // lwnotice("Measure %g on segment %d of line 1: %g, %g, %g", t1, seg, p1.x, p1.y, p1.z); seg = ptarray_locate_along_linear(l2->points, t0, &q0, 0); if ( -1 == seg ) continue; /* possible, if GBOX is approximated */ - /*lwnotice("Measure %g on segment %d of line 2: %g, %g, %g", t0, seg, q0.x, q0.y, q0.z);*/ + // lwnotice("Measure %g on segment %d of line 2: %g, %g, %g", t0, seg, q0.x, q0.y, q0.z); seg = ptarray_locate_along_linear(l2->points, t1, &q1, seg); if ( -1 == seg ) continue; /* possible, if GBOX is approximated */ - /*lwnotice("Measure %g on segment %d of line 2: %g, %g, %g", t1, seg, q1.x, q1.y, q1.z);*/ + // lwnotice("Measure %g on segment %d of line 2: %g, %g, %g", t1, seg, q1.x, q1.y, q1.z); t = segments_tcpa(&p0, &p1, &q0, &q1, t0, t1); -/* + /* lwnotice("Closest points: %g,%g,%g and %g,%g,%g at time %g", p0.x, p0.y, p0.z, q0.x, q0.y, q0.z, t); -*/ + */ dist2 = ( q0.x - p0.x ) * ( q0.x - p0.x ) + ( q0.y - p0.y ) * ( q0.y - p0.y ) + @@ -1162,7 +1167,7 @@ lwgeom_tcpa(const LWGEOM *g1, const LWGEOM *g2, double *mindist) { mindist2 = dist2; mintime = t; - /* lwnotice("MINTIME: %g", mintime); */ + // lwnotice("MINTIME: %g", mintime); } }