Make st_summary at least return consistent results (#1254)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 1 Nov 2011 17:59:00 +0000 (17:59 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 1 Nov 2011 17:59:00 +0000 (17:59 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8076 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_libgeom.c
liblwgeom/cunit/cu_surface.c
liblwgeom/liblwgeom.h.in
liblwgeom/lwgeom_api.c
liblwgeom/lwsegmentize.c
liblwgeom/lwtin.c
liblwgeom/measures3d.c
postgis/lwgeom_debug.c

index c1f3e98d96f1e7c28bd40a521aa2e1f98ac8ba2e..625986e4e728ec93c500549e0b1a8a485aebdefc 100644 (file)
@@ -324,7 +324,7 @@ static void test_lwcollection_extract(void)
 
        geom = lwgeom_from_wkt("GEOMETRYCOLLECTION(POINT(0 0))", LW_PARSER_CHECK_NONE);
        col = lwcollection_extract((LWCOLLECTION*)geom, 1);
-       CU_ASSERT_EQUAL(TYPE_GETTYPE(col->type), MULTIPOINTTYPE);
+       CU_ASSERT_EQUAL(col->type, MULTIPOINTTYPE);
 
        /* How to properly release 'col' ? 
         * See http://http://trac.osgeo.org/postgis/ticket/1102
index 0323485aa767e4ba7bef7d43085ca8b999750f3d..fd2192b3e5993cc6f092e862d32fda6354bdd2b8 100644 (file)
@@ -196,7 +196,7 @@ void tin_parse(void)
        /*
          NOTA: Theses 3 ASSERT results will change a day cf #294
        */
-       CU_ASSERT_EQUAL(TYPE_GETTYPE(geom->type), TINTYPE);
+       CU_ASSERT_EQUAL(geom->type, TINTYPE);
 //     CU_ASSERT_STRING_EQUAL("GEOMETRYCOLLECTION EMPTY", lwgeom_to_ewkt(geom));
        lwgeom_free(geom);
 
@@ -250,7 +250,7 @@ check_tgeom(char *ewkt, int type, uint32_t srid, int is_solid)
        if (strlen(cu_error_msg)) printf("\n[%s], %s\n", ewkt, cu_error_msg);
        CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
 
-       if (TYPE_GETTYPE(g1->type) != type)
+       if (g1->type != type)
                printf("\n[%s], TYPE %s\n", ewkt, lwtype_name(g1->type));
        CU_ASSERT_EQUAL(g1->type, type);
        tgeom = tgeom_from_lwgeom(g1);
index a9e415c67bb0e0dfbfb80ae66f6b27bb55e79e24..f21a974b3b5719cfd2ccd26eabad7e6e581a45a3 100644 (file)
 #define WKBSRIDFLAG 0x20000000
 #define WKBBBOXFLAG 0x10000000
 
-/*
-* TODO: Remove these
-*/
-#define TYPE_HASZ(t) ( ((t)&0x20)>>5 )
-#define TYPE_NDIMS(t) ((((t)&0x20)>>5)+(((t)&0x10)>>4)+2)
-#define TYPE_GETTYPE(t) ((t)&0x0F)
-
 /**
 * Macros for manipulating the 'flags' byte. A uint8_t used as follows: 
 * ---RGBMZ
@@ -685,7 +678,7 @@ extern int lwtype_get_collectiontype(uint8_t type);
 /**
 * Return a char string with ASCII version of type flags 
 */
-extern const char *lwtype_zmflags(uint8_t type);
+extern char *lwtype_zmflags(uint8_t type);
 
 /**
 * Return the type name string associated with a type number 
index 08a39ad74ead48378f153ac43ecf7c1cc4d44b1d..77d6fd1852aa73a6145266031151bacc4441375e 100644 (file)
@@ -568,12 +568,12 @@ ptarray_isccw(const POINTARRAY *pa)
        else return 1;
 }
 
+static char tflags[4];
 
-const char *
+char *
 lwtype_zmflags(uint8_t flags)
 {
-       static char tflags[4];
-       int flagno=0;
+       int flagno = 0;
        if ( FLAGS_GET_Z(flags) ) tflags[flagno++] = 'Z';
        if ( FLAGS_GET_M(flags) ) tflags[flagno++] = 'M';
        if ( FLAGS_GET_BBOX(flags) ) tflags[flagno++] = 'B';
index 29091bebeebba31f4e351e029b17c7cbb134982c..1d1ca09e51fa5119814712b103b95c7ca13ded00 100644 (file)
@@ -389,7 +389,7 @@ lwmcurve_segmentize(LWMCURVE *mcurve, uint32_t perQuad)
        LWGEOM **lines;
        int i;
 
-       LWDEBUGF(2, "lwmcurve_segmentize called, geoms=%d, dim=%d.", mcurve->ngeoms, TYPE_NDIMS(mcurve->type));
+       LWDEBUGF(2, "lwmcurve_segmentize called, geoms=%d, dim=%d.", mcurve->ngeoms, FLAGS_NDIMS(mcurve->flags));
 
        lines = lwalloc(sizeof(LWGEOM *)*mcurve->ngeoms);
 
index 76654d5abe19c0ed00b6b2954dd40e45c7d2a80d..12149a94d228b61e158a4dfc943ebb5dfe8c7fa9 100644 (file)
@@ -88,7 +88,7 @@ int lwtin_is_closed(const LWTIN *tin)
        LWTRIANGLE *patch;
 
        /* If surface is not 3D, it's can't be closed */
-       if (!TYPE_HASZ(tin->type)) return 0;
+       if (!FLAGS_GET_Z(tin->flags)) return 0;
 
        /* Max theorical arcs number if no one is shared ... */
        narcs = 3 * tin->ngeoms;
index 341a6425cd7677b2e4c36a3fc420c211f004e118..ef67bcbebfd52b9c0505c5051c632f23423f8052 100644 (file)
@@ -201,7 +201,7 @@ int lw_dist3d_recursive(const LWGEOM *lwg1,const LWGEOM *lwg2, DISTPTS3D *dl)
        LWCOLLECTION *c1 = NULL;\r
        LWCOLLECTION *c2 = NULL;\r
 \r
-       LWDEBUGF(2, "lw_dist3d_recursive is called with type1=%d, type2=%d", TYPE_GETTYPE(lwg1->type), TYPE_GETTYPE(lwg2->type));\r
+       LWDEBUGF(2, "lw_dist3d_recursive is called with type1=%d, type2=%d", lwg1->type, lwg2->type);\r
 \r
        if (lwgeom_is_collection(lwg1))\r
        {\r
@@ -278,7 +278,7 @@ lw_dist3d_distribute_bruteforce(LWGEOM *lwg1, LWGEOM *lwg2, DISTPTS3D *dl)
        int     t1 = lwg1->type;\r
        int     t2 = lwg2->type;\r
 \r
-       LWDEBUGF(2, "lw_dist3d_distribute_bruteforce is called with typ1=%d, type2=%d", TYPE_GETTYPE(lwg1->type), TYPE_GETTYPE(lwg2->type));\r
+       LWDEBUGF(2, "lw_dist3d_distribute_bruteforce is called with typ1=%d, type2=%d", lwg1->type, lwg2->type);\r
 \r
        if  ( t1 == POINTTYPE )\r
        {\r
index a07166bfe05d58efa53689e7c449b79921b9f9b6..7aa486b42a03278e78ff1a31d59bbd25c65d5dd4 100644 (file)
@@ -44,7 +44,7 @@ lwgeom_summary(const LWGEOM *lwgeom, int offset)
        case COLLECTIONTYPE:
                return lwcollection_summary((LWCOLLECTION *)lwgeom, offset);
        default:
-               result = palloc(256);
+               result = lwalloc(256);
                sprintf(result, "Object is of unknown type: %d",
                        lwgeom->type);
                return result;
@@ -61,12 +61,13 @@ lwpoint_summary(LWPOINT *point, int offset)
 {
        char *result;
        char *pad="";
+       char *zmflags = lwtype_zmflags(point->flags);
 
        result = lwalloc(128+offset);
 
        sprintf(result, "%*.s%s[%s]\n",
                offset, pad, lwtype_name(point->type),
-               lwtype_zmflags(point->flags));
+               zmflags);
        return result;
 }
 
@@ -75,12 +76,13 @@ lwline_summary(LWLINE *line, int offset)
 {
        char *result;
        char *pad="";
+       char *zmflags = lwtype_zmflags(line->flags);
 
        result = lwalloc(128+offset);
 
        sprintf(result, "%*.s%s[%s] with %d points\n",
                offset, pad, lwtype_name(line->type),
-               lwtype_zmflags(line->flags),
+               zmflags,
                line->points->npoints);
        return result;
 }
@@ -94,6 +96,7 @@ lwcollection_summary(LWCOLLECTION *col, int offset)
        char *tmp;
        int i;
        char *pad="";
+       char *zmflags = lwtype_zmflags(col->flags);
 
        POSTGIS_DEBUG(2, "lwcollection_summary called");
 
@@ -101,7 +104,7 @@ lwcollection_summary(LWCOLLECTION *col, int offset)
 
        sprintf(result, "%*.s%s[%s] with %d elements\n",
                offset, pad, lwtype_name(col->type),
-               lwtype_zmflags(col->flags),
+               zmflags,
                col->ngeoms);
 
        for (i=0; i<col->ngeoms; i++)
@@ -129,6 +132,7 @@ lwpoly_summary(LWPOLY *poly, int offset)
        char *result;
        int i;
        char *pad="";
+       char *zmflags = lwtype_zmflags(poly->flags);
 
        POSTGIS_DEBUG(2, "lwpoly_summary called");
 
@@ -136,7 +140,7 @@ lwpoly_summary(LWPOLY *poly, int offset)
 
        sprintf(result, "%*.s%s[%s] with %i rings\n",
                offset, pad, lwtype_name(poly->type),
-               lwtype_zmflags(poly->flags),
+               zmflags,
                poly->nrings);
 
        for (i=0; i<poly->nrings; i++)