From: Paul Ramsey Date: Fri, 20 Feb 2015 17:48:41 +0000 (+0000) Subject: #3049 Use getPoint_cp for read-only accesses X-Git-Tag: 2.2.0rc1~649 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18a9eb4e411cdac67f7b09c2cd7a1eb0a601e551;p=postgis #3049 Use getPoint_cp for read-only accesses git-svn-id: http://svn.osgeo.org/postgis/trunk@13251 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 2e27fa6a8..080fb68c7 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -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 diff --git a/liblwgeom/lwalgorithm.c b/liblwgeom/lwalgorithm.c index 0bb665b07..83205a36f 100644 --- a/liblwgeom/lwalgorithm.c +++ b/liblwgeom/lwalgorithm.c @@ -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; inpoints-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 x < v1.x + vt * (v2.x - v1.x)) + /* P->x 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; } } diff --git a/liblwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c index deadea34a..c35a1506e 100644 --- a/liblwgeom/lwgeom_api.c +++ b/liblwgeom/lwgeom_api.c @@ -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 diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index 491984efa..ebf88581d 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -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; inpoints; 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; } diff --git a/liblwgeom/lwout_geojson.c b/liblwgeom/lwout_geojson.c index 6de9b49e3..1e01fdc48 100644 --- a/liblwgeom/lwout_geojson.c +++ b/liblwgeom/lwout_geojson.c @@ -722,13 +722,13 @@ pointArray_to_geojson(POINTARRAY *pa, char *output, int precision) { for (i=0; inpoints; 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; inpoints; 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); diff --git a/liblwgeom/lwout_gml.c b/liblwgeom/lwout_gml.c index 7304e83ad..fd6c47af2 100644 --- a/liblwgeom/lwout_gml.c +++ b/liblwgeom/lwout_gml.c @@ -661,19 +661,19 @@ pointArray_toGML2(POINTARRAY *pa, char *output, int precision) { for (i=0; inpoints; 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; inpoints; 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; inpoints; 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; inpoints; 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, " "); diff --git a/liblwgeom/measures.c b/liblwgeom/measures.c index 70cc39eeb..26567a179 100644 --- a/liblwgeom/measures.c +++ b/liblwgeom/measures.c @@ -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; tnpoints; t++) /*for each segment in L1 */ { - getPoint2d_p(l1, t, &start); + start = getPoint2d_cp(l1, t); for (u=0; unpoints; 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; tnpoints; 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; unpoints; 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; ty - (k * theP->x); list1[t].themeasure=thevalue; list1[t].pnr=t; } for (t=0; ty - (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; tx - (k * theP->y); list1[t].themeasure=thevalue; list1[t].pnr=t; /* lwnotice("l1 %d, measure=%f",t,thevalue ); */ } for (t=0; tx - (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= 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); diff --git a/liblwgeom/measures.h b/liblwgeom/measures.h index 9d3f138f7..de1df01b3 100644 --- a/liblwgeom/measures.h +++ b/liblwgeom/measures.h @@ -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); diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index 448692851..8330ce59a 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -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; tnpoints; 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; tx, pa->y, p2, pb->x, pb->y); for (k=p1+1; kx, pk->y); /* distance computation */ - tmp = distance2d_sqr_pt_seg(pk, &pa, &pb); + tmp = distance2d_sqr_pt_seg(pk, pa, pb); if (tmp > d) {