]> granicus.if.org Git - postgis/commitdiff
#3049 Use getPoint_cp for read-only accesses
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 20 Feb 2015 17:48:41 +0000 (17:48 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 20 Feb 2015 17:48:41 +0000 (17:48 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13251 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/lwalgorithm.c
liblwgeom/lwgeom_api.c
liblwgeom/lwgeom_geos.c
liblwgeom/lwout_geojson.c
liblwgeom/lwout_gml.c
liblwgeom/measures.c
liblwgeom/measures.h
liblwgeom/ptarray.c

index 2e27fa6a81ae77c2a5c2dd61cdd59f274cdd7363..080fb68c79644478d7f7d59c4d24e88679f63af9 100644 (file)
@@ -808,13 +808,21 @@ extern POINT2D getPoint2d(const POINTARRAY *pa, int n);
 extern int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point);
 
 /**
-* Returns a pointer into the POINTARRAY serialized_ptlist, 
+* Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, 
 * suitable for reading from. This is very high performance
 * and declared const because you aren't allowed to muck with the 
 * values, only read them.
 */
 extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, int n);
 
+/**
+* Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, 
+* suitable for reading from. This is very high performance
+* and declared const because you aren't allowed to muck with the 
+* values, only read them.
+*/
+extern const POINT3DZ* getPoint3dz_cp(const POINTARRAY *pa, int n);
+
 /*
  * set point N to the given value
  * NOTE that the pointarray can be of any
index 0bb665b070c5cd548114609d01ce9c335b6108be..83205a36fe01e3bc94a71a21dfeb5f803d2785f7 100644 (file)
@@ -277,16 +277,15 @@ pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
 {
        int cn = 0;    /* the crossing number counter */
        int i;
-       POINT2D v1, v2;
+       const POINT2D *v1, *v2;
+       const POINT2D *first, *last;
 
-       POINT2D first, last;
-
-       getPoint2d_p(ring, 0, &first);
-       getPoint2d_p(ring, ring->npoints-1, &last);
-       if ( memcmp(&first, &last, sizeof(POINT2D)) )
+       first = getPoint2d_cp(ring, 0);
+       last = getPoint2d_cp(ring, ring->npoints-1);
+       if ( memcmp(first, last, sizeof(POINT2D)) )
        {
                lwerror("pt_in_ring_2d: V[n] != V[0] (%g %g != %g %g)",
-                       first.x, first.y, last.x, last.y);
+                       first->x, first->y, last->x, last->y);
                return LW_FALSE;
 
        }
@@ -295,28 +294,28 @@ pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring)
        /* printPA(ring); */
 
        /* loop through all edges of the polygon */
-       getPoint2d_p(ring, 0, &v1);
+       v1 = getPoint2d_cp(ring, 0);
        for (i=0; i<ring->npoints-1; i++)
        {
                double vt;
-               getPoint2d_p(ring, i+1, &v2);
+               v2 = getPoint2d_cp(ring, i+1);
 
                /* edge from vertex i to vertex i+1 */
                if
                (
                    /* an upward crossing */
-                   ((v1.y <= p->y) && (v2.y > p->y))
+                   ((v1->y <= p->y) && (v2->y > p->y))
                    /* a downward crossing */
-                   || ((v1.y > p->y) && (v2.y <= p->y))
+                   || ((v1->y > p->y) && (v2->y <= p->y))
                )
                {
 
-                       vt = (double)(p->y - v1.y) / (v2.y - v1.y);
+                       vt = (double)(p->y - v1->y) / (v2->y - v1->y);
 
-                       /* P.x <intersect */
-                       if (p->x < v1.x + vt * (v2.x - v1.x))
+                       /* P->x <intersect */
+                       if (p->x < v1->x + vt * (v2->x - v1->x))
                        {
-                               /* a valid crossing of y=p.y right of p.x */
+                               /* a valid crossing of y=p->y right of p->x */
                                ++cn;
                        }
                }
index deadea34a4e476a9ec71c36b8ac15d4438325e81..c35a1506e3141682ba6a2798a7fc83f5b1286226 100644 (file)
@@ -467,6 +467,27 @@ getPoint2d_cp(const POINTARRAY *pa, int n)
        return (const POINT2D*)getPoint_internal(pa, n);
 }
 
+const POINT3DZ*
+getPoint3dz_cp(const POINTARRAY *pa, int n)
+{
+       if ( ! pa ) return 0;
+       
+       if ( ! FLAGS_GET_Z(pa->flags) )
+       {
+               lwerror("getPoint3dz_cp: no Z coordinates in point array");
+               return 0; /*error */
+       }
+
+       if ( (n<0) || (n>=pa->npoints))
+       {
+               lwerror("getPoint3dz_cp: point offset out of range");
+               return 0; /*error */
+       }
+
+       return (const POINT3DZ*)getPoint_internal(pa, n);
+}
+
+
 
 /*
  * set point N to the given value
index 491984efa1fca60b1f32ed92d1f34c18ed502c85..ebf88581d5aaf61e6498bba95fb6d0557c99cd53 100644 (file)
@@ -202,34 +202,45 @@ GEOSCoordSeq
 ptarray_to_GEOSCoordSeq(const POINTARRAY *pa)
 {
        uint32_t dims = 2;
-       uint32_t size, i;
-       POINT3DZ p;
+       uint32_t i;
+       const POINT3DZ *p3d;
+       const POINT2D *p2d;
        GEOSCoordSeq sq;
 
-       if ( FLAGS_GET_Z(pa->flags) ) dims = 3;
-       size = pa->npoints;
+       if ( FLAGS_GET_Z(pa->flags) ) 
+               dims = 3;
 
-       sq = GEOSCoordSeq_create(size, dims);
-       if ( ! sq ) lwerror("Error creating GEOS Coordinate Sequence");
+       if ( ! (sq = GEOSCoordSeq_create(pa->npoints, dims)) ) 
+               lwerror("Error creating GEOS Coordinate Sequence");
 
-       for (i=0; i<size; i++)
+       for ( i=0; i < pa->npoints; i++ )
        {
-               getPoint3dz_p(pa, i, &p);
+               if ( dims == 3 )
+               {
+                       p3d = getPoint3dz_cp(pa, i);
+                       p2d = (const POINT2D *)p3d;
+               }
+               else
+               {
+                       p2d = getPoint2d_cp(pa, i);
+               }
 
-               LWDEBUGF(4, "Point: %g,%g,%g", p.x, p.y, p.z);
+               LWDEBUGF(4, "Point: %g,%g,%g", p2d->x, p2d->y, p3d->z);
 
 #if POSTGIS_GEOS_VERSION < 33
                /* Make sure we don't pass any infinite values down into GEOS */
                /* GEOS 3.3+ is supposed to  handle this stuff OK */
-               if ( isinf(p.x) || isinf(p.y) || (dims == 3 && isinf(p.z)) )
+               if ( isinf(p2d->x) || isinf(p2d->y) || (dims == 3 && isinf(p3d->z)) )
                        lwerror("Infinite coordinate value found in geometry.");
-               if ( isnan(p.x) || isnan(p.y) || (dims == 3 && isnan(p.z)) )
+               if ( isnan(p2d->x) || isnan(p2d->y) || (dims == 3 && isnan(p3d->z)) )
                        lwerror("NaN coordinate value found in geometry.");
 #endif
 
-               GEOSCoordSeq_setX(sq, i, p.x);
-               GEOSCoordSeq_setY(sq, i, p.y);
-               if ( dims == 3 ) GEOSCoordSeq_setZ(sq, i, p.z);
+               GEOSCoordSeq_setX(sq, i, p2d->x);
+               GEOSCoordSeq_setY(sq, i, p2d->y);
+               
+               if ( dims == 3 ) 
+                       GEOSCoordSeq_setZ(sq, i, p3d->z);
        }
        return sq;
 }
index 6de9b49e38d97d427729b4400f3629988e835b05..1e01fdc48c25bb1283984339f7fd0c75e31dfe46 100644 (file)
@@ -722,13 +722,13 @@ pointArray_to_geojson(POINTARRAY *pa, char *output, int precision)
        {
                for (i=0; i<pa->npoints; i++)
                {
-                       POINT2D pt;
-                       getPoint2d_p(pa, i, &pt);
+                       const POINT2D *pt;
+                       pt = getPoint2d_cp(pa, i);
 
-      lwprint_double(pt.x, precision, x, BUFSIZE);
-      trim_trailing_zeros(x);
-      lwprint_double(pt.y, precision, y, BUFSIZE);
-      trim_trailing_zeros(y);
+                       lwprint_double(pt->x, precision, x, BUFSIZE);
+                       trim_trailing_zeros(x);
+                       lwprint_double(pt->y, precision, y, BUFSIZE);
+                       trim_trailing_zeros(y);
 
                        if ( i ) ptr += sprintf(ptr, ",");
                        ptr += sprintf(ptr, "[%s,%s]", x, y);
@@ -738,15 +738,15 @@ pointArray_to_geojson(POINTARRAY *pa, char *output, int precision)
        {
                for (i=0; i<pa->npoints; i++)
                {
-                       POINT4D pt;
-                       getPoint4d_p(pa, i, &pt);
-
-      lwprint_double(pt.x, precision, x, BUFSIZE);
-      trim_trailing_zeros(x);
-      lwprint_double(pt.y, precision, y, BUFSIZE);
-      trim_trailing_zeros(y);
-      lwprint_double(pt.z, precision, z, BUFSIZE);
-      trim_trailing_zeros(z);
+                       const POINT3DZ *pt;
+                       pt = getPoint3dz_cp(pa, i);
+
+                       lwprint_double(pt->x, precision, x, BUFSIZE);
+                       trim_trailing_zeros(x);
+                       lwprint_double(pt->y, precision, y, BUFSIZE);
+                       trim_trailing_zeros(y);
+                       lwprint_double(pt->z, precision, z, BUFSIZE);
+                       trim_trailing_zeros(z);
 
                        if ( i ) ptr += sprintf(ptr, ",");
                        ptr += sprintf(ptr, "[%s,%s,%s]", x, y, z);
index 7304e83ad56c569d70d5954b60b3dccada3f88ec..fd6c47af211533b689e2f80d63689ac46f8be7a5 100644 (file)
@@ -661,19 +661,19 @@ pointArray_toGML2(POINTARRAY *pa, char *output, int precision)
        {
                for (i=0; i<pa->npoints; i++)
                {
-                       POINT2D pt;
-                       getPoint2d_p(pa, i, &pt);
+                       const POINT2D *pt;
+                       pt = getPoint2d_cp(pa, i);
 
-                       if (fabs(pt.x) < OUT_MAX_DOUBLE)
-                               sprintf(x, "%.*f", precision, pt.x);
+                       if (fabs(pt->x) < OUT_MAX_DOUBLE)
+                               sprintf(x, "%.*f", precision, pt->x);
                        else
-                               sprintf(x, "%g", pt.x);
+                               sprintf(x, "%g", pt->x);
                        trim_trailing_zeros(x);
 
-                       if (fabs(pt.y) < OUT_MAX_DOUBLE)
-                               sprintf(y, "%.*f", precision, pt.y);
+                       if (fabs(pt->y) < OUT_MAX_DOUBLE)
+                               sprintf(y, "%.*f", precision, pt->y);
                        else
-                               sprintf(y, "%g", pt.y);
+                               sprintf(y, "%g", pt->y);
                        trim_trailing_zeros(y);
 
                        if ( i ) ptr += sprintf(ptr, " ");
@@ -684,25 +684,25 @@ pointArray_toGML2(POINTARRAY *pa, char *output, int precision)
        {
                for (i=0; i<pa->npoints; i++)
                {
-                       POINT4D pt;
-                       getPoint4d_p(pa, i, &pt);
+                       const POINT3DZ *pt;
+                       pt = getPoint3dz_cp(pa, i);
 
-                       if (fabs(pt.x) < OUT_MAX_DOUBLE)
-                               sprintf(x, "%.*f", precision, pt.x);
+                       if (fabs(pt->x) < OUT_MAX_DOUBLE)
+                               sprintf(x, "%.*f", precision, pt->x);
                        else
-                               sprintf(x, "%g", pt.x);
+                               sprintf(x, "%g", pt->x);
                        trim_trailing_zeros(x);
 
-                       if (fabs(pt.y) < OUT_MAX_DOUBLE)
-                               sprintf(y, "%.*f", precision, pt.y);
+                       if (fabs(pt->y) < OUT_MAX_DOUBLE)
+                               sprintf(y, "%.*f", precision, pt->y);
                        else
-                               sprintf(y, "%g", pt.y);
+                               sprintf(y, "%g", pt->y);
                        trim_trailing_zeros(y);
 
-                       if (fabs(pt.z) < OUT_MAX_DOUBLE)
-                               sprintf(z, "%.*f", precision, pt.z);
+                       if (fabs(pt->z) < OUT_MAX_DOUBLE)
+                               sprintf(z, "%.*f", precision, pt->z);
                        else
-                               sprintf(z, "%g", pt.z);
+                               sprintf(z, "%g", pt->z);
                        trim_trailing_zeros(z);
 
                        if ( i ) ptr += sprintf(ptr, " ");
@@ -1908,19 +1908,19 @@ pointArray_toGML3(POINTARRAY *pa, char *output, int precision, int opts)
        {
                for (i=0; i<pa->npoints; i++)
                {
-                       POINT2D pt;
-                       getPoint2d_p(pa, i, &pt);
+                       const POINT2D *pt;
+                       pt = getPoint2d_cp(pa, i);
 
-                       if (fabs(pt.x) < OUT_MAX_DOUBLE)
-                               sprintf(x, "%.*f", precision, pt.x);
+                       if (fabs(pt->x) < OUT_MAX_DOUBLE)
+                               sprintf(x, "%.*f", precision, pt->x);
                        else
-                               sprintf(x, "%g", pt.x);
+                               sprintf(x, "%g", pt->x);
                        trim_trailing_zeros(x);
 
-                       if (fabs(pt.y) < OUT_MAX_DOUBLE)
-                               sprintf(y, "%.*f", precision, pt.y);
+                       if (fabs(pt->y) < OUT_MAX_DOUBLE)
+                               sprintf(y, "%.*f", precision, pt->y);
                        else
-                               sprintf(y, "%g", pt.y);
+                               sprintf(y, "%g", pt->y);
                        trim_trailing_zeros(y);
 
                        if ( i ) ptr += sprintf(ptr, " ");
@@ -1934,25 +1934,25 @@ pointArray_toGML3(POINTARRAY *pa, char *output, int precision, int opts)
        {
                for (i=0; i<pa->npoints; i++)
                {
-                       POINT4D pt;
-                       getPoint4d_p(pa, i, &pt);
+                       const POINT3DZ *pt;
+                       pt = getPoint3dz_cp(pa, i);
 
-                       if (fabs(pt.x) < OUT_MAX_DOUBLE)
-                               sprintf(x, "%.*f", precision, pt.x);
+                       if (fabs(pt->x) < OUT_MAX_DOUBLE)
+                               sprintf(x, "%.*f", precision, pt->x);
                        else
-                               sprintf(x, "%g", pt.x);
+                               sprintf(x, "%g", pt->x);
                        trim_trailing_zeros(x);
 
-                       if (fabs(pt.y) < OUT_MAX_DOUBLE)
-                               sprintf(y, "%.*f", precision, pt.y);
+                       if (fabs(pt->y) < OUT_MAX_DOUBLE)
+                               sprintf(y, "%.*f", precision, pt->y);
                        else
-                               sprintf(y, "%g", pt.y);
+                               sprintf(y, "%g", pt->y);
                        trim_trailing_zeros(y);
 
-                       if (fabs(pt.z) < OUT_MAX_DOUBLE)
-                               sprintf(z, "%.*f", precision, pt.z);
+                       if (fabs(pt->z) < OUT_MAX_DOUBLE)
+                               sprintf(z, "%.*f", precision, pt->z);
                        else
-                               sprintf(z, "%g", pt.z);
+                               sprintf(z, "%g", pt->z);
                        trim_trailing_zeros(z);
 
                        if ( i ) ptr += sprintf(ptr, " ");
index 70cc39eeb97c7a79d38d1b2bb4be572370e3ba6d..26567a179aca0e2eac4df95b73f24de2cea94d69 100644 (file)
@@ -559,13 +559,12 @@ point to point calculation
 int
 lw_dist2d_point_point(LWPOINT *point1, LWPOINT *point2, DISTPTS *dl)
 {
-       POINT2D p1;
-       POINT2D p2;
+       const POINT2D *p1, *p2;
 
-       getPoint2d_p(point1->point, 0, &p1);
-       getPoint2d_p(point2->point, 0, &p2);
+       p1 = getPoint2d_cp(point1->point, 0);
+       p2 = getPoint2d_cp(point2->point, 0);
 
-       return lw_dist2d_pt_pt(&p1, &p2,dl);
+       return lw_dist2d_pt_pt(p1, p2, dl);
 }
 /**
 
@@ -1117,8 +1116,8 @@ int
 lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2,DISTPTS *dl)
 {
        int t,u;
-       POINT2D start, end;
-       POINT2D start2, end2;
+       const POINT2D   *start, *end;
+       const POINT2D   *start2, *end2;
        int twist = dl->twisted;
 
        LWDEBUGF(2, "lw_dist2d_ptarray_ptarray called (points: %d-%d)",l1->npoints, l2->npoints);
@@ -1127,11 +1126,11 @@ lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2,DISTPTS *dl)
        {
                for (t=0; t<l1->npoints; t++) /*for each segment in L1 */
                {
-                       getPoint2d_p(l1, t, &start);
+                       start = getPoint2d_cp(l1, t);
                        for (u=0; u<l2->npoints; u++) /*for each segment in L2 */
                        {
-                               getPoint2d_p(l2, u, &start2);
-                               lw_dist2d_pt_pt(&start,&start2,dl);
+                               start2 = getPoint2d_cp(l2, u);
+                               lw_dist2d_pt_pt(start, start2, dl);
                                LWDEBUGF(4, "maxdist_ptarray_ptarray; seg %i * seg %i, dist = %g\n",t,u,dl->distance);
                                LWDEBUGF(3, " seg%d-seg%d dist: %f, mindist: %f",
                                         t, u, dl->distance, dl->tolerance);
@@ -1140,16 +1139,16 @@ lw_dist2d_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2,DISTPTS *dl)
        }
        else
        {
-               getPoint2d_p(l1, 0, &start);
+               start = getPoint2d_cp(l1, 0);
                for (t=1; t<l1->npoints; t++) /*for each segment in L1 */
                {
-                       getPoint2d_p(l1, t, &end);
-                       getPoint2d_p(l2, 0, &start2);
+                       end = getPoint2d_cp(l1, t);
+                       start2 = getPoint2d_cp(l2, 0);
                        for (u=1; u<l2->npoints; u++) /*for each segment in L2 */
                        {
-                               getPoint2d_p(l2, u, &end2);
+                               end2 = getPoint2d_cp(l2, u);
                                dl->twisted=twist;
-                               lw_dist2d_seg_seg(&start, &end, &start2, &end2,dl);
+                               lw_dist2d_seg_seg(start, end, start2, end2, dl);
                                LWDEBUGF(4, "mindist_ptarray_ptarray; seg %i * seg %i, dist = %g\n",t,u,dl->distance);
                                LWDEBUGF(3, " seg%d-seg%d dist: %f, mindist: %f",
                                         t, u, dl->distance, dl->tolerance);
@@ -1779,7 +1778,8 @@ lw_dist2d_fast_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2,DISTPTS *dl, GBOX
 
        double k, thevalue;
        float   deltaX, deltaY, c1m, c2m;
-       POINT2D theP,c1, c2;
+       POINT2D c1, c2;
+       const POINT2D *theP;
        float min1X, max1X, max1Y, min1Y,min2X, max2X, max2Y, min2Y;
        int t;
        int n1 = l1->npoints;
@@ -1816,16 +1816,16 @@ lw_dist2d_fast_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2,DISTPTS *dl, GBOX
                k = -deltaX/deltaY;
                for (t=0; t<n1; t++) /*for each segment in L1 */
                {
-                       getPoint2d_p(l1, t, &theP);
-                       thevalue = theP.y-(k*theP.x);
+                       theP = getPoint2d_cp(l1, t);
+                       thevalue = theP->y - (k * theP->x);
                        list1[t].themeasure=thevalue;
                        list1[t].pnr=t;
 
                }
                for (t=0; t<n2; t++) /*for each segment in L2*/
                {
-                       getPoint2d_p(l2, t, &theP);
-                       thevalue = theP.y-(k*theP.x);
+                       theP = getPoint2d_cp(l2, t);
+                       thevalue = theP->y - (k * theP->x);
                        list2[t].themeasure=thevalue;
                        list2[t].pnr=t;
 
@@ -1842,17 +1842,16 @@ lw_dist2d_fast_ptarray_ptarray(POINTARRAY *l1, POINTARRAY *l2,DISTPTS *dl, GBOX
                k = -deltaY/deltaX;
                for (t=0; t<n1; t++) /*for each segment in L1 */
                {
-                       getPoint2d_p(l1, t, &theP);
-                       thevalue = theP.x-(k*theP.y);
+                       theP = getPoint2d_cp(l1, t);
+                       thevalue = theP->x - (k * theP->y);
                        list1[t].themeasure=thevalue;
                        list1[t].pnr=t;
                        /* lwnotice("l1 %d, measure=%f",t,thevalue ); */
                }
                for (t=0; t<n2; t++) /*for each segment in L2*/
                {
-                       getPoint2d_p(l2, t, &theP);
-
-                       thevalue = theP.x-(k*theP.y);
+                       theP = getPoint2d_cp(l2, t);
+                       thevalue = theP->x - (k * theP->y);
                        list2[t].themeasure=thevalue;
                        list2[t].pnr=t;
                        /* lwnotice("l2 %d, measure=%f",t,thevalue ); */
@@ -1903,7 +1902,7 @@ struct_cmp_by_measure(const void *a, const void *b)
 int
 lw_dist2d_pre_seg_seg(POINTARRAY *l1, POINTARRAY *l2,LISTSTRUCT *list1, LISTSTRUCT *list2,double k, DISTPTS *dl)
 {
-       POINT2D p1, p2, p3, p4, p01, p02;
+       const POINT2D *p1, *p2, *p3, *p4, *p01, *p02;
        int pnr1,pnr2,pnr3,pnr4, n1, n2, i, u, r, twist;
        double maxmeasure;
        n1=     l1->npoints;
@@ -1911,9 +1910,9 @@ lw_dist2d_pre_seg_seg(POINTARRAY *l1, POINTARRAY *l2,LISTSTRUCT *list1, LISTSTRU
 
        LWDEBUG(2, "lw_dist2d_pre_seg_seg is called");
 
-       getPoint2d_p(l1, list1[0].pnr, &p1);
-       getPoint2d_p(l2, list2[0].pnr, &p3);
-       lw_dist2d_pt_pt(&p1, &p3,dl);
+       p1 = getPoint2d_cp(l1, list1[0].pnr);
+       p3 = getPoint2d_cp(l2, list2[0].pnr);
+       lw_dist2d_pt_pt(p1, p3, dl);
        maxmeasure = sqrt(dl->distance*dl->distance + (dl->distance*dl->distance*k*k));
        twist = dl->twisted; /*to keep the incomming order between iterations*/
        for (i =(n1-1); i>=0; --i)
@@ -1925,53 +1924,53 @@ lw_dist2d_pre_seg_seg(POINTARRAY *l1, POINTARRAY *l2,LISTSTRUCT *list1, LISTSTRU
                for (r=-1; r<=1; r +=2) /*because we are not iterating in the original pointorder we have to check the segment before and after every point*/
                {
                        pnr1 = list1[i].pnr;
-                       getPoint2d_p(l1, pnr1, &p1);
+                       p1 = getPoint2d_cp(l1, pnr1);
                        if (pnr1+r<0)
                        {
-                               getPoint2d_p(l1, (n1-1), &p01);
-                               if (( p1.x == p01.x) && (p1.y == p01.y)) pnr2 = (n1-1);
+                               p01 = getPoint2d_cp(l1, (n1-1));
+                               if (( p1->x == p01->x) && (p1->y == p01->y)) pnr2 = (n1-1);
                                else pnr2 = pnr1; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
                        }
 
                        else if (pnr1+r>(n1-1))
                        {
-                               getPoint2d_p(l1, 0, &p01);
-                               if (( p1.x == p01.x) && (p1.y == p01.y)) pnr2 = 0;
+                               p01 = getPoint2d_cp(l1, 0);
+                               if (( p1->x == p01->x) && (p1->y == p01->y)) pnr2 = 0;
                                else pnr2 = pnr1; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
                        }
                        else pnr2 = pnr1+r;
 
 
-                       getPoint2d_p(l1, pnr2, &p2);
+                       p2 = getPoint2d_cp(l1, pnr2);
                        for (u=0; u<n2; ++u)
                        {
                                if (((list2[u].themeasure-list1[i].themeasure)) >= maxmeasure) break;
                                pnr3 = list2[u].pnr;
-                               getPoint2d_p(l2, pnr3, &p3);
+                               p3 = getPoint2d_cp(l2, pnr3);
                                if (pnr3==0)
                                {
-                                       getPoint2d_p(l2, (n2-1), &p02);
-                                       if (( p3.x == p02.x) && (p3.y == p02.y)) pnr4 = (n2-1);
+                                       p02 = getPoint2d_cp(l2, (n2-1));
+                                       if (( p3->x == p02->x) && (p3->y == p02->y)) pnr4 = (n2-1);
                                        else pnr4 = pnr3; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
                                }
                                else pnr4 = pnr3-1;
 
-                               getPoint2d_p(l2, pnr4, &p4);
+                               p4 = getPoint2d_cp(l2, pnr4);
                                dl->twisted=twist;
-                               if (!lw_dist2d_selected_seg_seg(&p1, &p2, &p3, &p4, dl)) return LW_FALSE;
+                               if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl)) return LW_FALSE;
 
                                if (pnr3>=(n2-1))
                                {
-                                       getPoint2d_p(l2, 0, &p02);
-                                       if (( p3.x == p02.x) && (p3.y == p02.y)) pnr4 = 0;
+                                       p02 = getPoint2d_cp(l2, 0);
+                                       if (( p3->x == p02->x) && (p3->y == p02->y)) pnr4 = 0;
                                        else pnr4 = pnr3; /* if it is a line and the last and first point is not the same we avoid the edge between start and end this way*/
                                }
 
                                else pnr4 = pnr3+1;
 
-                               getPoint2d_p(l2, pnr4, &p4);
+                               p4 = getPoint2d_cp(l2, pnr4);
                                dl->twisted=twist; /*we reset the "twist" for each iteration*/
-                               if (!lw_dist2d_selected_seg_seg(&p1, &p2, &p3, &p4, dl)) return LW_FALSE;
+                               if (!lw_dist2d_selected_seg_seg(p1, p2, p3, p4, dl)) return LW_FALSE;
 
                                maxmeasure = sqrt(dl->distance*dl->distance + (dl->distance*dl->distance*k*k));/*here we "translate" the found mindistance so it can be compared to our "z"-values*/
                        }
@@ -1988,7 +1987,7 @@ lw_dist2d_pre_seg_seg(POINTARRAY *l1, POINTARRAY *l2,LISTSTRUCT *list1, LISTSTRU
        already know they do not intersect
 */
 int
-lw_dist2d_selected_seg_seg(POINT2D *A, POINT2D *B, POINT2D *C, POINT2D *D, DISTPTS *dl)
+lw_dist2d_selected_seg_seg(const POINT2D *A, const POINT2D *B, const POINT2D *C, const POINT2D *D, DISTPTS *dl)
 {
        LWDEBUGF(2, "lw_dist2d_selected_seg_seg [%g,%g]->[%g,%g] by [%g,%g]->[%g,%g]",
                 A->x,A->y,B->x,B->y, C->x,C->y, D->x, D->y);
index 9d3f138f7e1825fe6b58a67a69ba52e275b80d7f..de1df01b374cfd40a5bdb79aee62453a91b49649 100644 (file)
@@ -75,7 +75,7 @@ int lw_dist2d_curvepoly_curvepoly(LWCURVEPOLY *poly1, LWCURVEPOLY *poly2, DISTPT
 * New faster distance calculations
 */
 int lw_dist2d_pre_seg_seg(POINTARRAY *l1, POINTARRAY *l2,LISTSTRUCT *list1, LISTSTRUCT *list2,double k, DISTPTS *dl);
-int lw_dist2d_selected_seg_seg(POINT2D *A, POINT2D *B, POINT2D *C, POINT2D *D, DISTPTS *dl);
+int lw_dist2d_selected_seg_seg(const POINT2D *A, const POINT2D *B, const POINT2D *C, const POINT2D *D, DISTPTS *dl);
 int struct_cmp_by_measure(const void *a, const void *b);
 int lw_dist2d_fast_ptarray_ptarray(POINTARRAY *l1,POINTARRAY *l2, DISTPTS *dl,  GBOX *box1, GBOX *box2);
 
index 448692851c8574c4a71ffccec1112038c7b362b8..8330ce59a689eba98055e23ae5224568ba47fb64 100644 (file)
@@ -1272,7 +1272,8 @@ ptarray_locate_point(const POINTARRAY *pa, const POINT4D *p4d, double *mindistou
        double tlen, plen;
        int t, seg=-1;
        POINT4D start4d, end4d, projtmp;
-       POINT2D start, end, proj, p;
+       POINT2D proj, p;
+       const POINT2D *start, *end;
 
        /* Initialize our 2D copy of the input parameter */
        p.x = p4d->x;
@@ -1280,12 +1281,12 @@ ptarray_locate_point(const POINTARRAY *pa, const POINT4D *p4d, double *mindistou
        
        if ( ! proj4d ) proj4d = &projtmp;
 
-       getPoint2d_p(pa, 0, &start);
+       start = getPoint2d_cp(pa, 0);
        for (t=1; t<pa->npoints; t++)
        {
                double dist;
-               getPoint2d_p(pa, t, &end);
-               dist = distance2d_pt_seg(&p, &start, &end);
+               end = getPoint2d_cp(pa, t);
+               dist = distance2d_pt_seg(&p, start, end);
 
                if (t==1 || dist < mindist )
                {
@@ -1322,7 +1323,7 @@ ptarray_locate_point(const POINTARRAY *pa, const POINT4D *p4d, double *mindistou
        LWDEBUGF(3, "Closest segment:%d, npoints:%d", seg, pa->npoints);
 
        /* For robustness, force 1 when closest point == endpoint */
-       if ( (seg >= (pa->npoints-2)) && p2d_same(&proj, &end) )
+       if ( (seg >= (pa->npoints-2)) && p2d_same(&proj, end) )
        {
                return 1.0;
        }
@@ -1338,16 +1339,16 @@ ptarray_locate_point(const POINTARRAY *pa, const POINT4D *p4d, double *mindistou
        if ( tlen == 0 ) return 0;
 
        plen=0;
-       getPoint2d_p(pa, 0, &start);
+       start = getPoint2d_cp(pa, 0);
        for (t=0; t<seg; t++, start=end)
        {
-               getPoint2d_p(pa, t+1, &end);
-               plen += distance2d_pt_pt(&start, &end);
+               end = getPoint2d_cp(pa, t+1);
+               plen += distance2d_pt_pt(start, end);
 
                LWDEBUGF(4, "Segment %d made plen %g", t, plen);
        }
 
-       plen+=distance2d_pt_pt(&proj, &start);
+       plen+=distance2d_pt_pt(&proj, start);
 
        LWDEBUGF(3, "plen %g, tlen %g", plen, tlen);
 
@@ -1435,8 +1436,7 @@ static void
 ptarray_dp_findsplit(POINTARRAY *pts, int p1, int p2, int *split, double *dist)
 {
        int k;
-       POINT2D pa, pb;
-       const POINT2D* pk;
+       const POINT2D *pk, *pa, *pb;
        double tmp, d;
 
        LWDEBUG(4, "function called");
@@ -1447,11 +1447,11 @@ ptarray_dp_findsplit(POINTARRAY *pts, int p1, int p2, int *split, double *dist)
        if (p1 + 1 < p2)
        {
 
-               getPoint2d_p(pts, p1, &pa);
-               getPoint2d_p(pts, p2, &pb);
+               pa = getPoint2d_cp(pts, p1);
+               pb = getPoint2d_cp(pts, p2);
 
                LWDEBUGF(4, "P%d(%f,%f) to P%d(%f,%f)",
-                        p1, pa.x, pa.y, p2, pb.x, pb.y);
+                        p1, pa->x, pa->y, p2, pb->x, pb->y);
 
                for (k=p1+1; k<p2; k++)
                {
@@ -1460,7 +1460,7 @@ ptarray_dp_findsplit(POINTARRAY *pts, int p1, int p2, int *split, double *dist)
                        LWDEBUGF(4, "P%d(%f,%f)", k, pk->x, pk->y);
 
                        /* distance computation */
-                       tmp = distance2d_sqr_pt_seg(pk, &pa, &pb);
+                       tmp = distance2d_sqr_pt_seg(pk, pa, pb);
 
                        if (tmp > d)
                        {