]> granicus.if.org Git - postgis/commitdiff
some indentation fixes
authorSandro Santilli <strk@keybit.net>
Thu, 19 Aug 2004 13:16:16 +0000 (13:16 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 19 Aug 2004 13:16:16 +0000 (13:16 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@694 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_api.c
lwgeom/lwgeom_box2dfloat4.c

index 93ff710aedb53388906b19bb80e50d8c1490a30d..f465371c1d6c0358a071819bbbf0ec48f6825d47 100644 (file)
@@ -177,13 +177,17 @@ double nextUp_d(float d)
 
 
 
-//Connvert BOX3D to BOX2D
+// Convert BOX3D to BOX2D
+// returned box2d is allocated with 'palloc'
 BOX2DFLOAT4 *box3d_to_box2df(BOX3D *box)
 {
        BOX2DFLOAT4 *result = (BOX2DFLOAT4*) palloc(sizeof(BOX2DFLOAT4));
 
        if (box == NULL)
+       {
+               elog(NOTICE, "box3d_to_box2df got NUL box");
                return result;
+       }
 
        result->xmin = nextDown_f(box->xmin);
        result->ymin = nextDown_f(box->ymin);
@@ -313,32 +317,34 @@ BOX3D *combine_boxes(BOX3D *b1, BOX3D *b2)
 // otherwise we need to compute it.
 BOX2DFLOAT4 getbox2d(char *serialized_form)
 {
-               int     type = (unsigned char) serialized_form[0];
-               char    *loc;
-               BOX2DFLOAT4  result;
-               BOX3D   *box3d;
-               BOX2DFLOAT4     *box;
+       int type = (unsigned char) serialized_form[0];
+       char *loc;
+       BOX2DFLOAT4 result;
+       BOX3D *box3d;
+       BOX2DFLOAT4 *box;
 
-               loc = serialized_form+1;
+       loc = serialized_form+1;
 
-               if (lwgeom_hasBBOX(type))
-               {
-                       //woot - this is easy
+//elog(NOTICE,"getbox2d: type is %d", type);
+
+       if (lwgeom_hasBBOX(type))
+       {
+               //woot - this is easy
 //elog(NOTICE,"getbox2d has box");
-                       memcpy(&result,loc, sizeof(BOX2DFLOAT4));
-                       return result;
-               }
+               memcpy(&result,loc, sizeof(BOX2DFLOAT4));
+               return result;
+       }
 
-               //we have to actually compute it!
+       //we have to actually compute it!
 //elog(NOTICE,"getbox2d -- computing bbox");
-               box3d = lw_geom_getBB_simple(serialized_form);
-//elog(NOTICE,"getbox2d got bbox3d(%.15g %.15g,%.15g %.15g)",box3d->xmin,box3d->ymin,box3d->xmax,box3d->ymax);
-               box = box3d_to_box2df(box3d);
-//elog(NOTICE,"getbox2d made box2d(%.15g %.15g,%.15g %.15g)",box->xmin,box->ymin,box->xmax,box->ymax);
-               memcpy(&result,box, sizeof(BOX2DFLOAT4));
-               pfree(box3d);
-               pfree(box);
-               return result;
+       box3d = lw_geom_getBB_simple(serialized_form);
+//elog(NOTICE,"lw_geom_getBB_simple got bbox3d(%.15g %.15g,%.15g %.15g)",box3d->xmin,box3d->ymin,box3d->xmax,box3d->ymax);
+       box = box3d_to_box2df(box3d);
+//elog(NOTICE,"box3d made box2d(%.15g %.15g,%.15g %.15g)",box->xmin,box->ymin,box->xmax,box->ymax);
+       memcpy(&result,box, sizeof(BOX2DFLOAT4));
+       pfree(box3d);
+       pfree(box);
+       return result;
 }
 
 
@@ -475,23 +481,27 @@ void getPoint3d_p(POINTARRAY *pa, int n, char *point)
 {
        int size;
 
-        if ( (n<0) || (n>=pa->npoints))
-        {
-                return ; //error
-        }
+       if ( (n<0) || (n>=pa->npoints))
+       {
+               elog(NOTICE, "%d out of numpoint range (%d)", n, pa->npoints);
+               return ; //error
+       }
 
        size = pointArray_ptsize(pa);
 
-               // this does x,y
-        memcpy(point, &pa->serialized_pointlist[size*n],sizeof(double)*2 );
-        if (pa->ndims >2)
-               memcpy(point+16, &pa->serialized_pointlist[size*n + sizeof(double)*2],sizeof(double) );
-        else
-        {
-                double bad=NO_Z_VALUE;
+       // this does x,y
+       memcpy(point,
+               &pa->serialized_pointlist[size*n],
+               sizeof(double)*2 );
+
+       if (pa->ndims >2)
+               memcpy(point+16, &pa->serialized_pointlist[size*n + sizeof(double)*2],sizeof(double) );
+       else
+       {
+               double bad=NO_Z_VALUE;
                memcpy(point+16, &bad,sizeof(double) );
                //point->z = NO_Z_VALUE;
-        }
+       }
  }
 
 
@@ -565,7 +575,7 @@ BOX3D *pointArray_bbox(POINTARRAY *pa)
 
        result = (BOX3D*) palloc(sizeof(BOX3D));
 
-       if (pa->npoints ==0)
+       if (pa->npoints == 0)
                return result;
 
        getPoint3d_p(pa,0,(char*)&pt);
@@ -582,7 +592,8 @@ BOX3D *pointArray_bbox(POINTARRAY *pa)
                getPoint3d_p(pa,t,(char*)&pt);
                if (pt.x < result->xmin)
                        result->xmin = pt.x;
-               if (pt.y < result->ymin)
+               if (pt.y <
+                       result->ymin)
                        result->ymin = pt.y;
                if (pt.x > result->xmax)
                        result->xmax = pt.x;
@@ -1915,80 +1926,78 @@ BOX3D *lw_geom_getBB(char *serialized_form)
 //dont forget to pfree() result
 BOX3D *lw_geom_getBB_simple(char *serialized_form)
 {
-               char type = lwgeom_getType((unsigned char) serialized_form[0]);
-               int t;
-               char *loc;
-               uint32 ngeoms;
-               BOX3D *result;
-               BOX3D *b1,*b2;
-               int sub_size;
+       char type = lwgeom_getType((unsigned char) serialized_form[0]);
+       int t;
+       char *loc;
+       uint32 ngeoms;
+       BOX3D *result;
+       BOX3D *b1,*b2;
+       int sub_size;
 
+       if (type == POINTTYPE)
+       {
+               LWPOINT *pt = lwpoint_deserialize(serialized_form);
+               result = lwpoint_findbbox(pt);
+               pfree_point(pt);
+               return result;
+       /*
+               result = palloc(sizeof(BOX3D));
+               memcpy(result, serialized_form+1, sizeof(BOX2DFLOAT4));
+               memcpy(( (char *)result)+24, serialized_form+1, sizeof(BOX2DFLOAT4));
+               return result;
+       */
+       }
 
-               if (type == POINTTYPE)
-               {
+       else if (type == LINETYPE)
+       {
+               LWLINE *line = lwline_deserialize(serialized_form);
+               result = lwline_findbbox(line);
+               pfree_line(line);
+               return result;
 
-                       LWPOINT *pt = lwpoint_deserialize(serialized_form);
-                       result = lwpoint_findbbox(pt);
-                       pfree_point(pt);
-                       return result;
-               /*
-                       result = palloc(sizeof(BOX3D));
-                       memcpy(result, serialized_form+1, sizeof(BOX2DFLOAT4));
-                       memcpy(( (char *)result)+24, serialized_form+1, sizeof(BOX2DFLOAT4));
-                       return result;
-               */
-               }
+       }
+       else if (type == POLYGONTYPE)
+       {
+               LWPOLY *poly = lwpoly_deserialize(serialized_form);
+               result = lwpoly_findbbox(poly);
+               pfree_polygon(poly);
+               return result;
+       }
 
-               else if (type == LINETYPE)
-               {
-                       LWLINE *line = lwline_deserialize(serialized_form);
-                       result = lwline_findbbox(line);
-                       pfree_line(line);
-                       return result;
+          loc = serialized_form+1;
 
-               }
-               else if (type == POLYGONTYPE)
+               if (lwgeom_hasBBOX((unsigned char) serialized_form[0]))
                {
-                       LWPOLY *poly = lwpoly_deserialize(serialized_form);
-                       result = lwpoly_findbbox(poly);
-                       pfree_polygon(poly);
-                       return result;
+                       loc += sizeof(BOX2DFLOAT4);
                }
 
-                  loc = serialized_form+1;
+       if (lwgeom_hasSRID((unsigned char) serialized_form[0]) )
+       {
+               loc +=4;
+       }
 
-                       if (lwgeom_hasBBOX((unsigned char) serialized_form[0]))
-                       {
-                               loc += sizeof(BOX2DFLOAT4);
-                       }
+       ngeoms =  get_uint32(loc);
+       loc +=4;
 
-               if (lwgeom_hasSRID((unsigned char) serialized_form[0]) )
+       result = NULL;
+               // each sub-type
+       for (t=0;t<ngeoms;t++)
+       {
+               b1 = lw_geom_getBB_simple(loc);
+               sub_size = lwgeom_seralizedformlength_simple(loc);
+               loc += sub_size;
+               if (result != NULL)
                {
-                       loc +=4;
+                       b2= result;
+                       result = combine_boxes(b2, b1);
+                       pfree(b1);
+                       pfree(b2);
                }
-
-               ngeoms =  get_uint32(loc);
-               loc +=4;
-
-               result = NULL;
-                       // each sub-type
-               for (t=0;t<ngeoms;t++)
+               else
                {
-                       b1 = lw_geom_getBB_simple(loc);
-                       sub_size = lwgeom_seralizedformlength_simple(loc);
-                       loc += sub_size;
-                       if (result != NULL)
-                       {
-                               b2= result;
-                               result = combine_boxes(b2, b1);
-                               pfree(b1);
-                               pfree(b2);
-                       }
-                       else
-                       {
-                               result = b1;
-                       }
+                       result = b1;
                }
+       }
 
        return result;
 
index 4935fc47af4c57a8a4fc976b66ff4baf6943e227..e56ce1ece658ef4469bd1853dae5432cca2f08fe 100644 (file)
@@ -93,13 +93,13 @@ Datum BOX2DFLOAT4_out(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_to_BOX2DFLOAT4);
 Datum LWGEOM_to_BOX2DFLOAT4(PG_FUNCTION_ARGS)
 {
-       char                    *lwgeom = (char *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-       BOX2DFLOAT4                     box, *result;
+       char *lwgeom = (char *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       BOX2DFLOAT4 box, *result;
 
-                       box = getbox2d(lwgeom+4);
-                       result = palloc(sizeof(BOX2DFLOAT4));
-                       memcpy(result,&box, sizeof(BOX2DFLOAT4));
-                       PG_RETURN_POINTER(result);
+       box = getbox2d(lwgeom+4);
+       result = palloc(sizeof(BOX2DFLOAT4));
+       memcpy(result,&box, sizeof(BOX2DFLOAT4));
+       PG_RETURN_POINTER(result);
 }
 
 /*----------------------------------------------------------
@@ -257,20 +257,19 @@ Datum box2d_inter(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(box2d_union);
 Datum box2d_union(PG_FUNCTION_ARGS)
 {
-    BOX2DFLOAT4        *a = (BOX2DFLOAT4*) PG_GETARG_POINTER(0);
-    BOX2DFLOAT4        *b = (BOX2DFLOAT4*) PG_GETARG_POINTER(1);
-    BOX2DFLOAT4        *n;
-
-    n = (BOX2DFLOAT4 *) palloc(sizeof(BOX2DFLOAT4));
+       BOX2DFLOAT4        *a = (BOX2DFLOAT4*) PG_GETARG_POINTER(0);
+       BOX2DFLOAT4        *b = (BOX2DFLOAT4*) PG_GETARG_POINTER(1);
+       BOX2DFLOAT4        *n;
 
+       n = (BOX2DFLOAT4 *) palloc(sizeof(BOX2DFLOAT4));
 
        n->xmax = LWGEOM_Maxf(a->xmax, b->xmax);
-    n->ymax = LWGEOM_Maxf(a->ymax, b->ymax);
-    n->xmin = LWGEOM_Minf(a->xmin, b->xmin);
-    n->ymin = LWGEOM_Minf(a->ymin, b->ymin);
+       n->ymax = LWGEOM_Maxf(a->ymax, b->ymax);
+       n->xmin = LWGEOM_Minf(a->xmin, b->xmin);
+       n->ymin = LWGEOM_Minf(a->ymin, b->ymin);
 
 
-    PG_RETURN_POINTER(n);
+       PG_RETURN_POINTER(n);
 }