[postgis-tickets] r17502 - Strip out direct calls to FLAGS macros where easy

Paul Ramsey pramsey at cleverelephant.ca
Tue Jun 11 01:49:13 PDT 2019


Author: pramsey
Date: 2019-06-11 13:49:13 -0700 (Tue, 11 Jun 2019)
New Revision: 17502

Added:
   trunk/liblwgeom/gserialized.c
   trunk/liblwgeom/gserialized.h
   trunk/liblwgeom/gserialized1.h
   trunk/liblwgeom/gserialized2.c
   trunk/liblwgeom/gserialized2.h
Modified:
   trunk/liblwgeom/liblwgeom.h.in
   trunk/liblwgeom/lwgeom.c
   trunk/postgis/geobuf.c
   trunk/postgis/gserialized_gist_2d.c
   trunk/postgis/lwgeom_dumppoints.c
   trunk/postgis/lwgeom_functions_analytic.c
   trunk/postgis/lwgeom_functions_basic.c
   trunk/postgis/lwgeom_ogc.c
   trunk/postgis/lwgeom_rtree.c
   trunk/postgis/lwgeom_sfcgal.c
Log:
Strip out direct calls to FLAGS macros where easy


Added: trunk/liblwgeom/gserialized.c
===================================================================
Added: trunk/liblwgeom/gserialized.h
===================================================================
Added: trunk/liblwgeom/gserialized1.h
===================================================================
Added: trunk/liblwgeom/gserialized2.c
===================================================================
Added: trunk/liblwgeom/gserialized2.h
===================================================================
Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/liblwgeom/liblwgeom.h.in	2019-06-11 20:49:13 UTC (rev 17502)
@@ -1429,6 +1429,11 @@
 extern int lwgeom_has_m(const LWGEOM *geom);
 
 /**
+* Return #LW_TRUE if geometry has SOLID flag.
+*/
+extern int lwgeom_is_solid(const LWGEOM *geom);
+
+/**
 * Return the number of dimensions (2, 3, 4) in a geometry
 */
 extern int lwgeom_ndims(const LWGEOM *geom);

Modified: trunk/liblwgeom/lwgeom.c
===================================================================
--- trunk/liblwgeom/lwgeom.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/liblwgeom/lwgeom.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -925,6 +925,13 @@
 }
 
 int
+lwgeom_is_solid(const LWGEOM *geom)
+{
+	if ( ! geom ) return LW_FALSE;
+	return FLAGS_GET_GEODETIC(geom->flags);
+}
+
+int
 lwgeom_ndims(const LWGEOM *geom)
 {
 	if ( ! geom ) return 0;
@@ -932,6 +939,8 @@
 }
 
 
+
+
 void
 lwgeom_set_geodetic(LWGEOM *geom, int value)
 {

Modified: trunk/postgis/geobuf.c
===================================================================
--- trunk/postgis/geobuf.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/geobuf.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -490,11 +490,12 @@
 static void analyze_geometry_flags(struct geobuf_agg_context *ctx,
 	LWGEOM *lwgeom)
 {
-	if (!ctx->has_dimensions) {
-		if (FLAGS_GET_Z(lwgeom->flags) || FLAGS_GET_M(lwgeom->flags))
+	if (!ctx->has_dimensions)
+	{
+		if (lwgeom_has_z(lwgeom) && lwgeom_has_m(lwgeom))
+			ctx->dimensions = 4;
+		else if (lwgeom_has_z(lwgeom) || lwgeom_has_m(lwgeom))
 			ctx->dimensions = 3;
-		else if (FLAGS_GET_ZM(lwgeom->flags))
-			ctx->dimensions = 4;
 		else
 			ctx->dimensions = 2;
 		ctx->has_dimensions = 1;

Modified: trunk/postgis/gserialized_gist_2d.c
===================================================================
--- trunk/postgis/gserialized_gist_2d.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/gserialized_gist_2d.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -561,7 +561,6 @@
 gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
 {
 	GSERIALIZED *gpart;
-	uint8_t flags;
 	int result = LW_SUCCESS;
 
 	POSTGIS_DEBUG(4, "entered function");
@@ -577,12 +576,11 @@
 	** which makes slicing worthwhile.
 	*/
 	gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum);
-	flags = gpart->flags;
 
 	POSTGIS_DEBUGF(4, "got flags %d", gpart->flags);
 
 	/* Do we even have a serialized bounding box? */
-	if ( FLAGS_GET_BBOX(flags) )
+	if (gserialized_has_bbox(gpart))
 	{
 		/* Yes! Copy it out into the box! */
 		POSTGIS_DEBUG(4, "copying box out of serialization");

Modified: trunk/postgis/lwgeom_dumppoints.c
===================================================================
--- trunk/postgis/lwgeom_dumppoints.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/lwgeom_dumppoints.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -176,8 +176,8 @@
 					if (state->pt <= 3) {
 						getPoint4d_p(tri->points, state->pt, &pt);
 						lwpoint = lwpoint_make(tri->srid,
-								FLAGS_GET_Z(tri->points->flags),
-								FLAGS_GET_M(tri->points->flags),
+								lwgeom_has_z(lwgeom),
+								lwgeom_has_m(lwgeom),
 								&pt);
 					}
 					if (state->pt > 3) {
@@ -210,8 +210,8 @@
 					 */
 						getPoint4d_p(poly->rings[state->ring], state->pt, &pt);
 						lwpoint = lwpoint_make(poly->srid,
-								FLAGS_GET_Z(poly->rings[state->ring]->flags),
-								FLAGS_GET_M(poly->rings[state->ring]->flags),
+								lwgeom_has_z(lwgeom),
+								lwgeom_has_m(lwgeom),
 								&pt);
 					}
 					break;
@@ -291,21 +291,4 @@
 	}
 }
 
-/*
- * Geometry types of collection types for reference
- */
 
-#if 0
-        case MULTIPOINTTYPE:
-        case MULTILINETYPE:
-        case MULTIPOLYGONTYPE:
-        case COLLECTIONTYPE:
-        case CURVEPOLYTYPE:
-        case COMPOUNDTYPE:
-        case MULTICURVETYPE:
-        case MULTISURFACETYPE:
-        case POLYHEDRALSURFACETYPE:
-        case TINTYPE:
-
-#endif
-

Modified: trunk/postgis/lwgeom_functions_analytic.c
===================================================================
--- trunk/postgis/lwgeom_functions_analytic.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/lwgeom_functions_analytic.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -433,9 +433,9 @@
 	getPoint4d_p(in_lwpoint->point, 0, &offsetpoint);
 	grid.ipx = offsetpoint.x;
 	grid.ipy = offsetpoint.y;
-	if (FLAGS_GET_Z(in_lwpoint->flags) ) grid.ipz = offsetpoint.z;
+	if (lwgeom_has_z(in_lwpoint) ) grid.ipz = offsetpoint.z;
 	else grid.ipz=0;
-	if (FLAGS_GET_M(in_lwpoint->flags) ) grid.ipm = offsetpoint.m;
+	if (lwgeom_has_m(in_lwpoint) ) grid.ipm = offsetpoint.m;
 	else grid.ipm=0;
 
 #if POSTGIS_DEBUG_LEVEL >= 4

Modified: trunk/postgis/lwgeom_functions_basic.c
===================================================================
--- trunk/postgis/lwgeom_functions_basic.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/lwgeom_functions_basic.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -1151,7 +1151,8 @@
 		       lwtype_name(gserialized_get_type(gser1)),
 		       lwtype_name(gserialized_get_type(gser2)));
 
-	if (FLAGS_GET_ZM(gser1->flags) != FLAGS_GET_ZM(gser2->flags))
+	if ((gserialized_has_z(gser1) != gserialized_has_z(gser2)) ||
+		(gserialized_has_m(gser1) != gserialized_has_m(gser2)))
 	{
 		elog(ERROR, "Cannot ST_Collect geometries with differing dimensionality.");
 		PG_RETURN_NULL();
@@ -2675,7 +2676,7 @@
 		else
 		{
 			lwcol = lwgeom_construct_empty(
-			    type, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
+			    type, lwgeom->srid, lwgeom_has_z(lwgeom), lwgeom_has_m(lwgeom));
 		}
 	}
 	else
@@ -3092,7 +3093,7 @@
 
 	lwgeom_in = lwgeom_from_gserialized(geom_in);
 
-	hasm = FLAGS_GET_M(lwgeom_in->flags);
+	hasm = lwgeom_has_m(lwgeom_in);
 
 	if (!hasm)
 	{

Modified: trunk/postgis/lwgeom_ogc.c
===================================================================
--- trunk/postgis/lwgeom_ogc.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/lwgeom_ogc.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -697,12 +697,9 @@
 	lwgeom = lwgeom_from_gserialized(geom);
 	point = lwgeom_as_lwpoint(lwgeom);
 
-	if ( lwgeom_is_empty(lwgeom) )
+	if (lwgeom_is_empty(lwgeom) || !lwgeom_has_m(lwgeom))
 		PG_RETURN_NULL();
 
-	/* no M in input */
-	if ( ! FLAGS_GET_M(point->flags) ) PG_RETURN_NULL();
-
 	getPoint3dm_p(point->point, 0, &p);
 
 	PG_FREE_IF_COPY(geom, 0);

Modified: trunk/postgis/lwgeom_rtree.c
===================================================================
--- trunk/postgis/lwgeom_rtree.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/lwgeom_rtree.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -471,7 +471,7 @@
 		lwgeoms = lwalloc(sizeof(LWGEOM *));
 		lwgeoms[0] = (LWGEOM *)root->segment;
 
-		POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", root->segment, root->segment->type, FLAGS_GET_Z(root->segment->flags));
+		POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", root->segment, root->segment->type, lwgeom_has_z(root->segment));
 
 		result = (LWMLINE *)lwcollection_construct(MULTILINETYPE, SRID_UNKNOWN, NULL, 1, lwgeoms);
 	}
@@ -484,7 +484,7 @@
 		tmp = RTreeFindLineSegments(root->leftNode, value);
 		if (tmp)
 		{
-			POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, FLAGS_GET_Z(tmp->flags));
+			POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, lwgeom_has_z(tmp));
 
 			if (result)
 				result = RTreeMergeMultiLines(result, tmp);
@@ -501,7 +501,7 @@
 		tmp = RTreeFindLineSegments(root->rightNode, value);
 		if (tmp)
 		{
-			POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, FLAGS_GET_Z(tmp->flags));
+			POSTGIS_DEBUGF(3, "Found geom %p, type %d, dim %d", tmp, tmp->type, lwgeom_has_z(tmp));
 
 			if (result)
 				result = RTreeMergeMultiLines(result, tmp);

Modified: trunk/postgis/lwgeom_sfcgal.c
===================================================================
--- trunk/postgis/lwgeom_sfcgal.c	2019-06-11 20:13:13 UTC (rev 17501)
+++ trunk/postgis/lwgeom_sfcgal.c	2019-06-11 20:49:13 UTC (rev 17502)
@@ -503,7 +503,7 @@
 	if (!lwgeom)
 		elog(ERROR, "sfcgal_is_solid: Unable to deserialize input");
 
-	result = FLAGS_GET_SOLID(lwgeom->flags);
+	result = lwgeom_is_solid(lwgeom);
 
 	lwgeom_free(lwgeom);
 



More information about the postgis-tickets mailing list