]> granicus.if.org Git - postgis/commitdiff
fixed bugs in non-GEOS centroid function
authorSandro Santilli <strk@keybit.net>
Mon, 20 Sep 2004 09:21:29 +0000 (09:21 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 20 Sep 2004 09:21:29 +0000 (09:21 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@841 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_functions_basic.c

index 162e3a37d1ac49e221f52db19041ef1e80de4ed1..c3264caf8fff7274a5fb947e18693c6ab371547e 100644 (file)
@@ -2338,6 +2338,7 @@ Datum LWGEOM_isempty(PG_FUNCTION_ARGS)
 
 
 #if ! USE_GEOS
+Datum centroid(PG_FUNCTION_ARGS);
 PG_FUNCTION_INFO_V1(centroid);
 Datum centroid(PG_FUNCTION_ARGS)
 {
@@ -2349,12 +2350,13 @@ Datum centroid(PG_FUNCTION_ARGS)
        LWPOLY *poly;
        LWPOINT *point;
        LWGEOM *result;
-       POINTARRAY *ring;
+       POINTARRAY *ring, *pa;
        POINT3D *p, cent;
        int i,j,k;
        uint32 num_points_tot = 0;
        char *srl;
        char wantbbox = 0;
+       double tot_x=0, tot_y=0, tot_z=0;
 
        if  (type != POLYGONTYPE && type != MULTIPOLYGONTYPE)
                PG_RETURN_NULL();
@@ -2369,9 +2371,9 @@ Datum centroid(PG_FUNCTION_ARGS)
                        for (k=0; k<ring->npoints-1; k++)
                        {
                                p = (POINT3D *)getPoint(ring, k);
-                               tot_x += p.x;
-                               tot_y += p.y;
-                               if ( ring->ndims > 2 ) tot_z += p.z;
+                               tot_x += p->x;
+                               tot_y += p->y;
+                               if ( ring->ndims > 2 ) tot_z += p->z;
                        }
                        num_points_tot += ring->npoints-1;
                }