[postgis-commits] svn - r3101 - trunk/lwgeom

postgis-commits at postgis.refractions.net postgis-commits at postgis.refractions.net
Tue Oct 14 10:42:15 PDT 2008


Author: pramsey
Date: 2008-10-14 10:42:15 -0700 (Tue, 14 Oct 2008)
New Revision: 3101

Modified:
   trunk/lwgeom/lwgeom_functions_analytic.c
   trunk/lwgeom/lwgeom_functions_basic.c
   trunk/lwgeom/lwgeom_gist.c
Log:
astyle style=ansi indent=tab=8


Modified: trunk/lwgeom/lwgeom_functions_analytic.c
===================================================================
--- trunk/lwgeom/lwgeom_functions_analytic.c	2008-10-14 11:44:18 UTC (rev 3100)
+++ trunk/lwgeom/lwgeom_functions_analytic.c	2008-10-14 17:42:15 UTC (rev 3101)
@@ -7,7 +7,7 @@
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU General Public Licence. See the COPYING file.
- * 
+ *
  **********************************************************************/
 
 #include "postgres.h"
@@ -19,7 +19,7 @@
 
 
 /***********************************************************************
- * Simple Douglas-Peucker line simplification. 
+ * Simple Douglas-Peucker line simplification.
  * No checks are done to avoid introduction of self-intersections.
  * No topology relations are considered.
  *
@@ -53,48 +53,48 @@
 void
 DP_findsplit2d(POINTARRAY *pts, int p1, int p2, int *split, double *dist)
 {
-   int k;
-   POINT2D pa, pb, pk;
-   double tmp;
+	int k;
+	POINT2D pa, pb, pk;
+	double tmp;
 
-   LWDEBUG(4, "DP_findsplit called");
+	LWDEBUG(4, "DP_findsplit called");
 
-   *dist = -1;
-   *split = p1;
+	*dist = -1;
+	*split = p1;
 
-   if (p1 + 1 < p2)
-   {
+	if (p1 + 1 < p2)
+	{
 
-      getPoint2d_p(pts, p1, &pa);
-      getPoint2d_p(pts, p2, &pb);
+		getPoint2d_p(pts, p1, &pa);
+		getPoint2d_p(pts, p2, &pb);
 
-      LWDEBUGF(4, "DP_findsplit: P%d(%f,%f) to P%d(%f,%f)",
-      p1, pa.x, pa.y, p2, pb.x, pb.y);
+		LWDEBUGF(4, "DP_findsplit: P%d(%f,%f) to P%d(%f,%f)",
+		         p1, pa.x, pa.y, p2, pb.x, pb.y);
 
-      for (k=p1+1; k<p2; k++)
-      {
-         getPoint2d_p(pts, k, &pk);
+		for (k=p1+1; k<p2; k++)
+		{
+			getPoint2d_p(pts, k, &pk);
 
-         LWDEBUGF(4, "DP_findsplit: P%d(%f,%f)", k, pk.x, pk.y);
+			LWDEBUGF(4, "DP_findsplit: P%d(%f,%f)", k, pk.x, pk.y);
 
-         /* distance computation */
-         tmp = distance2d_pt_seg(&pk, &pa, &pb);
+			/* distance computation */
+			tmp = distance2d_pt_seg(&pk, &pa, &pb);
 
-         if (tmp > *dist) 
-         {
-            *dist = tmp;	/* record the maximum */
-            *split = k;
+			if (tmp > *dist)
+			{
+				*dist = tmp;	/* record the maximum */
+				*split = k;
 
-            LWDEBUGF(4, "DP_findsplit: P%d is farthest (%g)", k, *dist);
-         }
-      }
+				LWDEBUGF(4, "DP_findsplit: P%d is farthest (%g)", k, *dist);
+			}
+		}
 
-   } /* length---should be redone if can == 0 */
+	} /* length---should be redone if can == 0 */
 
-   else
-   {
-      LWDEBUG(3, "DP_findsplit: segment too short, no split/no dist");
-   }
+	else
+	{
+		LWDEBUG(3, "DP_findsplit: segment too short, no split/no dist");
+	}
 
 }
 
@@ -104,7 +104,7 @@
 {
 	int *stack;			/* recursion stack */
 	int sp=-1;			/* recursion stack pointer */
-	int p1, split; 
+	int p1, split;
 	double dist;
 	POINTARRAY *outpts;
 	int ptsize = pointArray_ptsize(inpts);
@@ -123,7 +123,7 @@
 	outpts->npoints=1;
 	outpts->serialized_pointlist = palloc(ptsize*inpts->npoints);
 	memcpy(getPoint_internal(outpts, 0), getPoint_internal(inpts, 0),
-		ptsize);
+	       ptsize);
 
 	LWDEBUG(3, "DP_simplify: added P0 to simplified point array (size 1)");
 
@@ -134,13 +134,16 @@
 
 		LWDEBUGF(3, "DP_simplify: farthest point from P%d-P%d is P%d (dist. %g)", p1, stack[sp], split, dist);
 
-		if (dist > epsilon) {
+		if (dist > epsilon)
+		{
 			stack[++sp] = split;
-		} else {
+		}
+		else
+		{
 			outpts->npoints++;
 			memcpy(getPoint_internal(outpts, outpts->npoints-1),
-				getPoint_internal(inpts, stack[sp]),
-				ptsize);
+			       getPoint_internal(inpts, stack[sp]),
+			       ptsize);
 
 			LWDEBUGF(4, "DP_simplify: added P%d to simplified point array (size: %d)", stack[sp], outpts->npoints);
 
@@ -159,9 +162,10 @@
 	if ( outpts->npoints < inpts->npoints )
 	{
 		outpts->serialized_pointlist = repalloc(
-			outpts->serialized_pointlist,
-			ptsize*outpts->npoints);
-		if ( outpts->serialized_pointlist == NULL ) {
+		                                       outpts->serialized_pointlist,
+		                                       ptsize*outpts->npoints);
+		if ( outpts->serialized_pointlist == NULL )
+		{
 			elog(ERROR, "Out of virtual memory");
 		}
 	}
@@ -262,7 +266,7 @@
 	}
 
 	out = lwcollection_construct(TYPE_GETTYPE(igeom->type), igeom->SRID,
-		NULL, ngeoms, geoms);
+	                             NULL, ngeoms, geoms);
 
 	return out;
 }
@@ -270,25 +274,25 @@
 LWGEOM *
 simplify2d_lwgeom(const LWGEOM *igeom, double dist)
 {
-	switch(TYPE_GETTYPE(igeom->type))
+	switch (TYPE_GETTYPE(igeom->type))
 	{
-		case POINTTYPE:
-		case MULTIPOINTTYPE:
-			return lwgeom_clone(igeom);
-		case LINETYPE:
-			return (LWGEOM *)simplify2d_lwline(
-				(LWLINE *)igeom, dist);
-		case POLYGONTYPE:
-			return (LWGEOM *)simplify2d_lwpoly(
-				(LWPOLY *)igeom, dist);
-		case MULTILINETYPE:
-		case MULTIPOLYGONTYPE:
-		case COLLECTIONTYPE:
-			return (LWGEOM *)simplify2d_collection(
-				(LWCOLLECTION *)igeom, dist);
-		default:
-			lwerror("simplify2d_lwgeom: unknown geometry type: %d",
-				TYPE_GETTYPE(igeom->type));
+	case POINTTYPE:
+	case MULTIPOINTTYPE:
+		return lwgeom_clone(igeom);
+	case LINETYPE:
+		return (LWGEOM *)simplify2d_lwline(
+		               (LWLINE *)igeom, dist);
+	case POLYGONTYPE:
+		return (LWGEOM *)simplify2d_lwpoly(
+		               (LWPOLY *)igeom, dist);
+	case MULTILINETYPE:
+	case MULTIPOLYGONTYPE:
+	case COLLECTIONTYPE:
+		return (LWGEOM *)simplify2d_collection(
+		               (LWCOLLECTION *)igeom, dist);
+	default:
+		lwerror("simplify2d_lwgeom: unknown geometry type: %d",
+		        TYPE_GETTYPE(igeom->type));
 	}
 	return NULL;
 }
@@ -342,12 +346,14 @@
 	int nsegs, i;
 	double length, slength, tlength;
 
-	if( distance < 0 || distance > 1 ) {
+	if ( distance < 0 || distance > 1 )
+	{
 		elog(ERROR,"line_interpolate_point: 2nd arg isnt within [0,1]");
 		PG_RETURN_NULL();
 	}
 
-	if( lwgeom_getType(geom->type) != LINETYPE ) {
+	if ( lwgeom_getType(geom->type) != LINETYPE )
+	{
 		elog(ERROR,"line_interpolate_point: 1st arg isnt a line");
 		PG_RETURN_NULL();
 	}
@@ -366,9 +372,9 @@
 			getPoint4d_p(ipa, ipa->npoints-1, &pt);
 
 		opa = pointArray_construct((uchar *)&pt,
-			TYPE_HASZ(line->type),
-			TYPE_HASM(line->type),
-			1);
+		                           TYPE_HASZ(line->type),
+		                           TYPE_HASM(line->type),
+		                           1);
 		point = lwpoint_construct(line->SRID, 0, opa);
 		srl = lwpoint_serialize(point);
 		pfree_point(point);
@@ -379,11 +385,12 @@
 	nsegs = ipa->npoints - 1;
 	length = lwgeom_pointarray_length2d(ipa);
 	tlength = 0;
-	for( i = 0; i < nsegs; i++ ) {
+	for ( i = 0; i < nsegs; i++ )
+	{
 		POINT4D p1, p2;
 		POINT4D *p1ptr=&p1, *p2ptr=&p2; /* don't break
-		                                 * strict-aliasing rules
-		                                 */
+				                                 * strict-aliasing rules
+				                                 */
 
 		getPoint4d_p(ipa, i, &p1);
 		getPoint4d_p(ipa, i+1, &p2);
@@ -395,13 +402,14 @@
 		 * so far. create a new point some distance down the current
 		 * segment.
 		 */
-		if( distance < tlength + slength ) {
+		if ( distance < tlength + slength )
+		{
 			double dseg = (distance - tlength) / slength;
 			interpolate_point4d(&p1, &p2, &pt, dseg);
 			opa = pointArray_construct((uchar *)&pt,
-				TYPE_HASZ(line->type),
-				TYPE_HASM(line->type),
-				1);
+			                           TYPE_HASZ(line->type),
+			                           TYPE_HASM(line->type),
+			                           1);
 			point = lwpoint_construct(line->SRID, 0, opa);
 			srl = lwpoint_serialize(point);
 			pfree_point(point);
@@ -414,9 +422,9 @@
 	 * could if there's some floating point rounding errors. */
 	getPoint4d_p(ipa, ipa->npoints-1, &pt);
 	opa = pointArray_construct((uchar *)&pt,
-		TYPE_HASZ(line->type),
-		TYPE_HASM(line->type),
-		1);
+	                           TYPE_HASZ(line->type),
+	                           TYPE_HASM(line->type),
+	                           1);
 	point = lwpoint_construct(line->SRID, 0, opa);
 	srl = lwpoint_serialize(point);
 	pfree_point(point);
@@ -437,44 +445,44 @@
  *  You use it to stick all of a geometry points to
  *  a custom grid defined by its origin and cell size
  *  in geometry units.
- * 
+ *
  *  Points reduction is obtained by collapsing all
  *  consecutive points falling on the same grid node and
  *  removing all consecutive segments S1,S2 having
  *  S2.startpoint = S1.endpoint and S2.endpoint = S1.startpoint.
- * 
+ *
  *  ISSUES
  *  ------
- * 
+ *
  *  Only 2D is contemplated in grid application.
- * 
+ *
  *  Consecutive coincident segments removal does not work
  *  on first/last segments (They are not considered consecutive).
- * 
+ *
  *  Grid application occurs on a geometry subobject basis, thus no
  *  points reduction occurs for multipoint geometries.
  *
  *  USAGE TIPS
  *  ----------
- * 
+ *
  *  Run like this:
- * 
+ *
  *     SELECT SnapToGrid(<geometry>, <originX>, <originY>, <sizeX>, <sizeY>);
- * 
+ *
  *     Grid cells are not visible on a screen as long as the screen
  *     point size is equal or bigger then the grid cell size.
  *     This assumption may be used to reduce the number of points in
  *     a map for a given display scale.
- * 
+ *
  *     Keeping multiple resolution versions of the same data may be used
  *     in conjunction with MINSCALE/MAXSCALE keywords of mapserv to speed
  *     up rendering.
- * 
+ *
  *     Check also the use of DP simplification to reduce grid visibility.
  *     I'm still researching about the relationship between grid size and
  *     DP epsilon values - please tell me if you know more about this.
- * 
- * 
+ *
+ *
  * --strk at keybit.net;
  *
  ***********************************************************************/
@@ -482,16 +490,18 @@
 #define CHECK_RING_IS_CLOSE
 #define SAMEPOINT(a,b) ((a)->x==(b)->x&&(a)->y==(b)->y)
 
-typedef struct gridspec_t {
-   double ipx;
-   double ipy;
-   double ipz;
-   double ipm;
-   double xsize;
-   double ysize;
-   double zsize;
-   double msize;
-} gridspec;
+typedef struct gridspec_t
+{
+	double ipx;
+	double ipy;
+	double ipz;
+	double ipm;
+	double xsize;
+	double ysize;
+	double zsize;
+	double msize;
+}
+gridspec;
 
 
 /* Forward declarations */
@@ -504,7 +514,7 @@
 Datum LWGEOM_snaptogrid(PG_FUNCTION_ARGS);
 Datum LWGEOM_snaptogrid_pointoff(PG_FUNCTION_ARGS);
 static int grid_isNull(const gridspec *grid);
-#if POSTGIS_DEBUG_LEVEL > 0 
+#if POSTGIS_DEBUG_LEVEL > 0
 static void grid_print(const gridspec *grid);
 #endif
 
@@ -513,20 +523,20 @@
 grid_isNull(const gridspec *grid)
 {
 	if ( grid->xsize==0 &&
-		grid->ysize==0 &&
-		grid->zsize==0 &&
-		grid->msize==0 ) return 1;
+	                grid->ysize==0 &&
+	                grid->zsize==0 &&
+	                grid->msize==0 ) return 1;
 	else return 0;
 }
 
-#if POSTGIS_DEBUG_LEVEL > 0 
+#if POSTGIS_DEBUG_LEVEL > 0
 /* Print grid using given reporter */
 static void
 grid_print(const gridspec *grid)
 {
 	lwnotice("GRID(%g %g %g %g, %g %g %g %g)",
-		grid->ipx, grid->ipy, grid->ipz, grid->ipm,
-		grid->xsize, grid->ysize, grid->zsize, grid->msize);
+	         grid->ipx, grid->ipy, grid->ipz, grid->ipm,
+	         grid->xsize, grid->ysize, grid->zsize, grid->msize);
 }
 #endif
 
@@ -541,7 +551,7 @@
 POINTARRAY *
 ptarray_grid(POINTARRAY *pa, gridspec *grid)
 {
-	POINT4D pbuf; 
+	POINT4D pbuf;
 	int ipn, opn; /* point numbers (input/output) */
 	DYNPTARRAY *dpa;
 	POINTARRAY *opa;
@@ -557,19 +567,19 @@
 
 		if ( grid->xsize )
 			pbuf.x = rint((pbuf.x - grid->ipx)/grid->xsize) *
-				grid->xsize + grid->ipx;
+			         grid->xsize + grid->ipx;
 
 		if ( grid->ysize )
 			pbuf.y = rint((pbuf.y - grid->ipy)/grid->ysize) *
-				grid->ysize + grid->ipy;
+			         grid->ysize + grid->ipy;
 
 		if ( TYPE_HASZ(pa->dims) && grid->zsize )
 			pbuf.z = rint((pbuf.z - grid->ipz)/grid->zsize) *
-				grid->zsize + grid->ipz;
+			         grid->zsize + grid->ipz;
 
 		if ( TYPE_HASM(pa->dims) && grid->msize )
 			pbuf.m = rint((pbuf.m - grid->ipm)/grid->msize) *
-				grid->msize + grid->ipm;
+			         grid->msize + grid->ipm;
 
 		dynptarray_addPoint4d(dpa, &pbuf, 0);
 
@@ -618,7 +628,7 @@
 	nrings = 0;
 
 	LWDEBUGF(3, "grid_polygon3d: applying grid to polygon with %d rings",
-   		poly->nrings);
+	         poly->nrings);
 
 	for (ri=0; ri<poly->nrings; ri++)
 	{
@@ -654,18 +664,22 @@
 #endif
 
 		LWDEBUGF(3, "grid_polygon3d: ring%d simplified from %d to %d points", ri,
-			ring->npoints, newring->npoints);
+		         ring->npoints, newring->npoints);
 
 		/*
 		 * Add ring to simplified ring array
 		 * (TODO: dinamic allocation of pts_per_ring)
 		 */
-		if ( ! nrings ) {
+		if ( ! nrings )
+		{
 			newrings = palloc(sizeof(POINTARRAY *));
-		} else {
+		}
+		else
+		{
 			newrings = repalloc(newrings, sizeof(POINTARRAY *)*(nrings+1));
 		}
-		if ( ! newrings ) {
+		if ( ! newrings )
+		{
 			elog(ERROR, "Out of virtual memory");
 			return NULL;
 		}
@@ -714,29 +728,29 @@
 	if ( ! ngeoms ) return lwcollection_construct_empty(coll->SRID, 0, 0);
 
 	return lwcollection_construct(TYPE_GETTYPE(coll->type), coll->SRID,
-		NULL, ngeoms, geoms);
+	                              NULL, ngeoms, geoms);
 }
 
 LWGEOM *
 lwgeom_grid(LWGEOM *lwgeom, gridspec *grid)
 {
-	switch(TYPE_GETTYPE(lwgeom->type))
+	switch (TYPE_GETTYPE(lwgeom->type))
 	{
-		case POINTTYPE:
-			return (LWGEOM *)lwpoint_grid((LWPOINT *)lwgeom, grid);
-		case LINETYPE:
-			return (LWGEOM *)lwline_grid((LWLINE *)lwgeom, grid);
-		case POLYGONTYPE:
-			return (LWGEOM *)lwpoly_grid((LWPOLY *)lwgeom, grid);
-		case MULTIPOINTTYPE:
-		case MULTILINETYPE:
-		case MULTIPOLYGONTYPE:
-		case COLLECTIONTYPE:
-			return (LWGEOM *)lwcollection_grid((LWCOLLECTION *)lwgeom, grid);
-		default:
-			elog(ERROR, "lwgeom_grid: Unknown geometry type: %d",
-				TYPE_GETTYPE(lwgeom->type));
-			return NULL;
+	case POINTTYPE:
+		return (LWGEOM *)lwpoint_grid((LWPOINT *)lwgeom, grid);
+	case LINETYPE:
+		return (LWGEOM *)lwline_grid((LWLINE *)lwgeom, grid);
+	case POLYGONTYPE:
+		return (LWGEOM *)lwpoly_grid((LWPOLY *)lwgeom, grid);
+	case MULTIPOINTTYPE:
+	case MULTILINETYPE:
+	case MULTIPOLYGONTYPE:
+	case COLLECTIONTYPE:
+		return (LWGEOM *)lwcollection_grid((LWCOLLECTION *)lwgeom, grid);
+	default:
+		elog(ERROR, "lwgeom_grid: Unknown geometry type: %d",
+		     TYPE_GETTYPE(lwgeom->type));
+		return NULL;
 	}
 }
 
@@ -780,7 +794,7 @@
 
 	POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwgeom_typename(TYPE_GETTYPE(in_lwgeom->type)));
 
-   	out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
+	out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
 	if ( out_lwgeom == NULL ) PG_RETURN_NULL();
 
 	/* COMPUTE_BBOX TAINTING */
@@ -802,13 +816,13 @@
 		box2df_to_box3d_p(in_lwgeom->bbox, &box3d);
 
 		box3d.xmin = rint((box3d.xmin - grid.ipx)/grid.xsize)
-			* grid.xsize + grid.ipx;
+		             * grid.xsize + grid.ipx;
 		box3d.xmax = rint((box3d.xmax - grid.ipx)/grid.xsize)
-			* grid.xsize + grid.ipx;
+		             * grid.xsize + grid.ipx;
 		box3d.ymin = rint((box3d.ymin - grid.ipy)/grid.ysize)
-			* grid.ysize + grid.ipy;
+		             * grid.ysize + grid.ipy;
 		box3d.ymax = rint((box3d.ymax - grid.ipy)/grid.ysize)
-			* grid.ysize + grid.ipy;
+		             * grid.ysize + grid.ipy;
 
 		out_lwgeom->bbox = box3d_to_box2df(&box3d);
 	}
@@ -868,7 +882,7 @@
 	if (TYPE_HASM(in_lwpoint->type) ) grid.ipm = offsetpoint.m;
 	else grid.ipm=0;
 
-#if POSTGIS_DEBUG_LEVEL >= 4 
+#if POSTGIS_DEBUG_LEVEL >= 4
 	grid_print(&grid);
 #endif
 
@@ -882,7 +896,7 @@
 
 	POSTGIS_DEBUGF(3, "SnapToGrid got a %s", lwgeom_typename(TYPE_GETTYPE(in_lwgeom->type)));
 
-   	out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
+	out_lwgeom = lwgeom_grid(in_lwgeom, &grid);
 	if ( out_lwgeom == NULL ) PG_RETURN_NULL();
 
 	/* COMPUTE_BBOX TAINTING */
@@ -904,13 +918,13 @@
 		box2df_to_box3d_p(in_lwgeom->bbox, &box3d);
 
 		box3d.xmin = rint((box3d.xmin - grid.ipx)/grid.xsize)
-			* grid.xsize + grid.ipx;
+		             * grid.xsize + grid.ipx;
 		box3d.xmax = rint((box3d.xmax - grid.ipx)/grid.xsize)
-			* grid.xsize + grid.ipx;
+		             * grid.xsize + grid.ipx;
 		box3d.ymin = rint((box3d.ymin - grid.ipy)/grid.ysize)
-			* grid.ysize + grid.ipy;
+		             * grid.ysize + grid.ipy;
 		box3d.ymax = rint((box3d.ymax - grid.ipy)/grid.ysize)
-			* grid.ysize + grid.ipy;
+		             * grid.ysize + grid.ipy;
 
 		out_lwgeom->bbox = box3d_to_box2df(&box3d);
 	}
@@ -940,22 +954,26 @@
 	POINTARRAY *ipa, *opa;
 	PG_LWGEOM *ret;
 
-	if( from < 0 || from > 1 ) {
+	if ( from < 0 || from > 1 )
+	{
 		elog(ERROR,"line_interpolate_point: 2nd arg isnt within [0,1]");
 		PG_RETURN_NULL();
 	}
 
-	if( to < 0 || to > 1 ) {
+	if ( to < 0 || to > 1 )
+	{
 		elog(ERROR,"line_interpolate_point: 3rd arg isnt within [0,1]");
 		PG_RETURN_NULL();
 	}
 
-	if ( from > to ) {
+	if ( from > to )
+	{
 		elog(ERROR, "2nd arg must be smaller then 3rd arg");
 		PG_RETURN_NULL();
 	}
 
-	if( lwgeom_getType(geom->type) != LINETYPE ) {
+	if ( lwgeom_getType(geom->type) != LINETYPE )
+	{
 		elog(ERROR,"line_interpolate_point: 1st arg isnt a line");
 		PG_RETURN_NULL();
 	}
@@ -989,11 +1007,13 @@
 	POINT2D p;
 	double ret;
 
-	if( lwgeom_getType(geom1->type) != LINETYPE ) {
+	if ( lwgeom_getType(geom1->type) != LINETYPE )
+	{
 		elog(ERROR,"line_locate_point: 1st arg isnt a line");
 		PG_RETURN_NULL();
 	}
-	if( lwgeom_getType(geom2->type) != POINTTYPE ) {
+	if ( lwgeom_getType(geom2->type) != POINTTYPE )
+	{
 		elog(ERROR,"line_locate_point: 2st arg isnt a point");
 		PG_RETURN_NULL();
 	}
@@ -1015,73 +1035,73 @@
 }
 
 /*******************************************************************************
- * The following is based on the "Fast Winding Number Inclusion of a Point 
+ * The following is based on the "Fast Winding Number Inclusion of a Point
  * in a Polygon" algorithm by Dan Sunday.
  * http://www.geometryalgorithms.com/Archive/algorithm_0103/algorithm_0103.htm
  ******************************************************************************/
 
 /*
- * returns: >0 for a point to the left of the segment, 
+ * returns: >0 for a point to the left of the segment,
  *          <0 for a point to the right of the segment,
  *          0 for a point on the segment
  */
 double determineSide(POINT2D *seg1, POINT2D *seg2, POINT2D *point)
 {
-        return ((seg2->x-seg1->x)*(point->y-seg1->y)-(point->x-seg1->x)*(seg2->y-seg1->y));
+	return ((seg2->x-seg1->x)*(point->y-seg1->y)-(point->x-seg1->x)*(seg2->y-seg1->y));
 }
 
 /*
- * This function doesn't test that the point falls on the line defined by 
+ * This function doesn't test that the point falls on the line defined by
  * the two points.  It assumes that that has already been determined
  * by having determineSide return within the tolerance.  It simply checks
  * that if the point is on the line, it is within the endpoints.
  *
  * returns: 1 if the point is not outside the bounds of the segment
- *          0 if it is 
+ *          0 if it is
  */
 int isOnSegment(POINT2D *seg1, POINT2D *seg2, POINT2D *point)
 {
-        double maxX; 
-        double maxY;
-        double minX;
-        double minY;
+	double maxX;
+	double maxY;
+	double minX;
+	double minY;
 
-        if(seg1->x > seg2->x)
-        {
-                maxX = seg1->x;
-                minX = seg2->x;
-        }
-        else
-        {
-                maxX = seg2->x;
-                minX = seg1->x;
-        }
-        if(seg1->y > seg2->y)
-        {
-                maxY = seg1->y;
-                minY = seg2->y;
-        }
-        else
-        {
-                maxY = seg2->y;
-                minY = seg1->y;
-        }
+	if (seg1->x > seg2->x)
+	{
+		maxX = seg1->x;
+		minX = seg2->x;
+	}
+	else
+	{
+		maxX = seg2->x;
+		minX = seg1->x;
+	}
+	if (seg1->y > seg2->y)
+	{
+		maxY = seg1->y;
+		minY = seg2->y;
+	}
+	else
+	{
+		maxY = seg2->y;
+		minY = seg1->y;
+	}
 
-        LWDEBUGF(3, "maxX minX/maxY minY: %.8f %.8f/%.8f %.8f", maxX, minX, maxY, minY);
+	LWDEBUGF(3, "maxX minX/maxY minY: %.8f %.8f/%.8f %.8f", maxX, minX, maxY, minY);
 
-        if(maxX < point->x || minX > point->x)
-        {
-                LWDEBUGF(3, "X value %.8f falls outside the range %.8f-%.8f", point->x, minX, maxX);
+	if (maxX < point->x || minX > point->x)
+	{
+		LWDEBUGF(3, "X value %.8f falls outside the range %.8f-%.8f", point->x, minX, maxX);
 
-                return 0;
-        }
-        else if(maxY < point->y || minY > point->y)
-        {
-                LWDEBUGF(3, "Y value %.8f falls outside the range %.8f-%.8f", point->y, minY, maxY);
+		return 0;
+	}
+	else if (maxY < point->y || minY > point->y)
+	{
+		LWDEBUGF(3, "Y value %.8f falls outside the range %.8f-%.8f", point->y, minY, maxY);
 
-                return 0;
-        }
-        return 1;
+		return 0;
+	}
+	return 1;
 }
 
 /*
@@ -1091,78 +1111,78 @@
  */
 int point_in_ring_rtree(RTREE_NODE *root, POINT2D *point)
 {
-        int wn = 0;
-        int i;
-        double side;
-        POINT2D seg1;
-        POINT2D seg2;
-        LWMLINE *lines;
+	int wn = 0;
+	int i;
+	double side;
+	POINT2D seg1;
+	POINT2D seg2;
+	LWMLINE *lines;
 
-        LWDEBUG(2, "point_in_ring called.");
+	LWDEBUG(2, "point_in_ring called.");
 
-        lines = findLineSegments(root, point->y);
-        if(!lines)
-                return -1;
+	lines = findLineSegments(root, point->y);
+	if (!lines)
+		return -1;
 
-        for(i=0; i<lines->ngeoms; i++)
-        {
-                getPoint2d_p(lines->geoms[i]->points, 0, &seg1);
-                getPoint2d_p(lines->geoms[i]->points, 1, &seg2);
+	for (i=0; i<lines->ngeoms; i++)
+	{
+		getPoint2d_p(lines->geoms[i]->points, 0, &seg1);
+		getPoint2d_p(lines->geoms[i]->points, 1, &seg2);
 
 
-                side = determineSide(&seg1, &seg2, point);
+		side = determineSide(&seg1, &seg2, point);
 
-                LWDEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1.x, seg1.y, seg2.x, seg2.y);
-                LWDEBUGF(3, "side result: %.8f", side);
-                LWDEBUGF(3, "counterclockwise wrap %d, clockwise wrap %d", FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y), FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y));
+		LWDEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1.x, seg1.y, seg2.x, seg2.y);
+		LWDEBUGF(3, "side result: %.8f", side);
+		LWDEBUGF(3, "counterclockwise wrap %d, clockwise wrap %d", FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y), FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y));
 
-                /* zero length segments are ignored. */
-                if(((seg2.x-seg1.x)*(seg2.x-seg1.x)+(seg2.y-seg1.y)*(seg2.y-seg1.y)) < 1e-12*1e-12) 
-                {
-                        LWDEBUG(3, "segment is zero length... ignoring.");
+		/* zero length segments are ignored. */
+		if (((seg2.x-seg1.x)*(seg2.x-seg1.x)+(seg2.y-seg1.y)*(seg2.y-seg1.y)) < 1e-12*1e-12)
+		{
+			LWDEBUG(3, "segment is zero length... ignoring.");
 
-                        continue;
-                }
+			continue;
+		}
 
-                /* a point on the boundary of a ring is not contained. */
-                if(fabs(side) < 1e-12) 
-                {
-                        if(isOnSegment(&seg1, &seg2, point) == 1)
-                        {
-                                LWDEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
+		/* a point on the boundary of a ring is not contained. */
+		if (fabs(side) < 1e-12)
+		{
+			if (isOnSegment(&seg1, &seg2, point) == 1)
+			{
+				LWDEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
 
-                                return 0;
-                        }
-                }
-                /*
-                 * If the point is to the left of the line, and it's rising,
-                 * then the line is to the right of the point and 
-                 * circling counter-clockwise, so incremement.
-                 */
-                else if(FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y) && side>0)
-                {
-                        LWDEBUG(3, "incrementing winding number.");
+				return 0;
+			}
+		}
+		/*
+		 * If the point is to the left of the line, and it's rising,
+		 * then the line is to the right of the point and 
+		 * circling counter-clockwise, so incremement.
+		 */
+		else if (FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y) && side>0)
+		{
+			LWDEBUG(3, "incrementing winding number.");
 
-                        ++wn;
-                }
-                /*
-                 * If the point is to the right of the line, and it's falling,
-                 * then the line is to the right of the point and circling
-                 * clockwise, so decrement.
-                 */
-                else if(FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y) && side<0)
-                {
-                        LWDEBUG(3, "decrementing winding number.");
+			++wn;
+		}
+		/*
+		 * If the point is to the right of the line, and it's falling,
+		 * then the line is to the right of the point and circling
+		 * clockwise, so decrement.
+		 */
+		else if (FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y) && side<0)
+		{
+			LWDEBUG(3, "decrementing winding number.");
 
-                        --wn;
-                }
-        }
+			--wn;
+		}
+	}
 
-        LWDEBUGF(3, "winding number %d", wn);
+	LWDEBUGF(3, "winding number %d", wn);
 
-        if(wn == 0)
-        	return -1;
-        return 1;
+	if (wn == 0)
+		return -1;
+	return 1;
 }
 
 
@@ -1173,74 +1193,74 @@
  */
 int point_in_ring(POINTARRAY *pts, POINT2D *point)
 {
-        int wn = 0;
-        int i;
-        double side;
-        POINT2D seg1;
-        POINT2D seg2;
+	int wn = 0;
+	int i;
+	double side;
+	POINT2D seg1;
+	POINT2D seg2;
 
-        LWDEBUG(2, "point_in_ring called.");
+	LWDEBUG(2, "point_in_ring called.");
 
-        
-        for(i=0; i<pts->npoints-1; i++)
-        {
-                getPoint2d_p(pts, i, &seg1);
-                getPoint2d_p(pts, i+1, &seg2);
 
+	for (i=0; i<pts->npoints-1; i++)
+	{
+		getPoint2d_p(pts, i, &seg1);
+		getPoint2d_p(pts, i+1, &seg2);
 
-                side = determineSide(&seg1, &seg2, point);
 
-                LWDEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1.x, seg1.y, seg2.x, seg2.y);
-                LWDEBUGF(3, "side result: %.8f", side);
-                LWDEBUGF(3, "counterclockwise wrap %d, clockwise wrap %d", FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y), FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y));
+		side = determineSide(&seg1, &seg2, point);
 
-                /* zero length segments are ignored. */
-                if(((seg2.x-seg1.x)*(seg2.x-seg1.x)+(seg2.y-seg1.y)*(seg2.y-seg1.y)) < 1e-12*1e-12) 
-                {
-                        LWDEBUG(3, "segment is zero length... ignoring.");
+		LWDEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1.x, seg1.y, seg2.x, seg2.y);
+		LWDEBUGF(3, "side result: %.8f", side);
+		LWDEBUGF(3, "counterclockwise wrap %d, clockwise wrap %d", FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y), FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y));
 
-                        continue;
-                }
+		/* zero length segments are ignored. */
+		if (((seg2.x-seg1.x)*(seg2.x-seg1.x)+(seg2.y-seg1.y)*(seg2.y-seg1.y)) < 1e-12*1e-12)
+		{
+			LWDEBUG(3, "segment is zero length... ignoring.");
 
-                /* a point on the boundary of a ring is not contained. */
-                if(fabs(side) < 1e-12) 
-                {
-                        if(isOnSegment(&seg1, &seg2, point) == 1)
-                        {
-                                LWDEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
+			continue;
+		}
 
-                                return 0;
-                        }
-                }
-                /*
-                 * If the point is to the left of the line, and it's rising,
-                 * then the line is to the right of the point and 
-                 * circling counter-clockwise, so incremement.
-                 */
-                else if(FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y) && side>0)
-                {
-                        LWDEBUG(3, "incrementing winding number.");
+		/* a point on the boundary of a ring is not contained. */
+		if (fabs(side) < 1e-12)
+		{
+			if (isOnSegment(&seg1, &seg2, point) == 1)
+			{
+				LWDEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
 
-                        ++wn;
-                }
-                /*
-                 * If the point is to the right of the line, and it's falling,
-                 * then the line is to the right of the point and circling
-                 * clockwise, so decrement.
-                 */
-                else if(FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y) && side<0)
-                {
-                        LWDEBUG(3, "decrementing winding number.");
+				return 0;
+			}
+		}
+		/*
+		 * If the point is to the left of the line, and it's rising,
+		 * then the line is to the right of the point and 
+		 * circling counter-clockwise, so incremement.
+		 */
+		else if (FP_CONTAINS_BOTTOM(seg1.y,point->y,seg2.y) && side>0)
+		{
+			LWDEBUG(3, "incrementing winding number.");
 
-                        --wn;
-                }
-        }
+			++wn;
+		}
+		/*
+		 * If the point is to the right of the line, and it's falling,
+		 * then the line is to the right of the point and circling
+		 * clockwise, so decrement.
+		 */
+		else if (FP_CONTAINS_BOTTOM(seg2.y,point->y,seg1.y) && side<0)
+		{
+			LWDEBUG(3, "decrementing winding number.");
 
-        LWDEBUGF(3, "winding number %d", wn);
+			--wn;
+		}
+	}
 
-        if(wn == 0)
-        	return -1;
-        return 1;
+	LWDEBUGF(3, "winding number %d", wn);
+
+	if (wn == 0)
+		return -1;
+	return 1;
 }
 
 /*
@@ -1249,31 +1269,31 @@
  */
 int point_in_polygon_rtree(RTREE_NODE **root, int ringCount, LWPOINT *point)
 {
-        int i;
-        POINT2D pt;
+	int i;
+	POINT2D pt;
 
-        LWDEBUGF(2, "point_in_polygon called for %p %d %p.", root, ringCount, point);
+	LWDEBUGF(2, "point_in_polygon called for %p %d %p.", root, ringCount, point);
 
-        getPoint2d_p(point->point, 0, &pt);
-        /* assume bbox short-circuit has already been attempted */
-        
-        if(point_in_ring_rtree(root[0], &pt) != 1) 
-        {
-                LWDEBUG(3, "point_in_polygon_rtree: outside exterior ring.");
+	getPoint2d_p(point->point, 0, &pt);
+	/* assume bbox short-circuit has already been attempted */
 
-                return 0;
-        }
+	if (point_in_ring_rtree(root[0], &pt) != 1)
+	{
+		LWDEBUG(3, "point_in_polygon_rtree: outside exterior ring.");
 
-        for(i=1; i<ringCount; i++)
-        {
-                if(point_in_ring_rtree(root[i], &pt) != -1)
-                {
-                        LWDEBUGF(3, "point_in_polygon_rtree: within hole %d.", i);
+		return 0;
+	}
 
-                        return 0;
-                }
-        }
-        return 1;
+	for (i=1; i<ringCount; i++)
+	{
+		if (point_in_ring_rtree(root[i], &pt) != -1)
+		{
+			LWDEBUGF(3, "point_in_polygon_rtree: within hole %d.", i);
+
+			return 0;
+		}
+	}
+	return 1;
 }
 
 /*
@@ -1283,53 +1303,53 @@
  *
  * Expected **root order is all the exterior rings first, then all the holes
  *
- * TODO: this could be made slightly more efficient by ordering the rings in 
- * EIIIEIIIEIEI order (exterior/interior) and including list of exterior ring 
+ * TODO: this could be made slightly more efficient by ordering the rings in
+ * EIIIEIIIEIEI order (exterior/interior) and including list of exterior ring
  * positions on the cache object.
  */
 int point_in_multipolygon_rtree(RTREE_NODE **root, int polyCount, int ringCount, LWPOINT *point)
 {
-    int i;
-    POINT2D pt;
-    int result = -1;
+	int i;
+	POINT2D pt;
+	int result = -1;
 
-    LWDEBUGF(2, "point_in_multipolygon_rtree called for %p %d %d %p.", root, polyCount, ringCount, point);
+	LWDEBUGF(2, "point_in_multipolygon_rtree called for %p %d %d %p.", root, polyCount, ringCount, point);
 
-    getPoint2d_p(point->point, 0, &pt);
-    /* assume bbox short-circuit has already been attempted */
+	getPoint2d_p(point->point, 0, &pt);
+	/* assume bbox short-circuit has already been attempted */
 
 	/* is the point inside (not outside) any of the exterior rings? */
-    for( i = 0; i < polyCount; i++ )
-    {
+	for ( i = 0; i < polyCount; i++ )
+	{
 		int in_ring = point_in_ring_rtree(root[i], &pt);
 		LWDEBUGF(4, "point_in_multipolygon_rtree: exterior ring (%d), point_in_ring returned %d", i, in_ring);
-       	if( in_ring != -1 ) /* not outside this ring */
-       	{
-           	LWDEBUG(3, "point_in_multipolygon_rtree: inside exterior ring.");
-           	result = in_ring;
-           	break;
-       	}
-    }
-    
-    if( result == -1 ) /* strictly outside all rings */
-        return result;
+		if ( in_ring != -1 ) /* not outside this ring */
+		{
+			LWDEBUG(3, "point_in_multipolygon_rtree: inside exterior ring.");
+			result = in_ring;
+			break;
+		}
+	}
 
+	if ( result == -1 ) /* strictly outside all rings */
+		return result;
+
 	/* ok, it's in a ring, but if it's in a hole it's still outside */
-    for( i = polyCount; i < ringCount; i++ )
-    {
+	for ( i = polyCount; i < ringCount; i++ )
+	{
 		int in_ring = point_in_ring_rtree(root[i], &pt);
 		LWDEBUGF(4, "point_in_multipolygon_rtree: hole (%d), point_in_ring returned %d", i, in_ring);
-       	if( in_ring == 1 ) /* completely inside hole */
-       	{
-          	LWDEBUGF(3, "point_in_multipolygon_rtree: within hole %d.", i);
-          	return -1;
-       	}
-		if( in_ring == 0 ) /* on the boundary of a hole */
+		if ( in_ring == 1 ) /* completely inside hole */
 		{
+			LWDEBUGF(3, "point_in_multipolygon_rtree: within hole %d.", i);
+			return -1;
+		}
+		if ( in_ring == 0 ) /* on the boundary of a hole */
+		{
 			result = 0;
 		}
-    }
-    return result; /* -1 = outside, 0 = boundary, 1 = inside */
+	}
+	return result; /* -1 = outside, 0 = boundary, 1 = inside */
 
 }
 
@@ -1340,40 +1360,40 @@
  */
 int point_in_polygon(LWPOLY *polygon, LWPOINT *point)
 {
-        int i, result, in_ring;
-        POINTARRAY *ring;
-        POINT2D pt;
+	int i, result, in_ring;
+	POINTARRAY *ring;
+	POINT2D pt;
 
-        LWDEBUG(2, "point_in_polygon called.");
+	LWDEBUG(2, "point_in_polygon called.");
 
-        getPoint2d_p(point->point, 0, &pt);
-        /* assume bbox short-circuit has already been attempted */
-        
-        ring = polygon->rings[0];
-		in_ring = point_in_ring(polygon->rings[0], &pt);
-        if( in_ring == -1) /* outside the exterior ring */
-        {
-                LWDEBUG(3, "point_in_polygon: outside exterior ring.");
-                return -1;
-        }
-		result = in_ring;
+	getPoint2d_p(point->point, 0, &pt);
+	/* assume bbox short-circuit has already been attempted */
 
-        for(i=1; i<polygon->nrings; i++)
-        {
-                ring = polygon->rings[i];
-				in_ring = point_in_ring(polygon->rings[i], &pt);
-                if(in_ring == 1) /* inside a hole => outside the polygon */
-                {
-                	LWDEBUGF(3, "point_in_polygon: within hole %d.", i);
-                    return -1;
-                }
-				if(in_ring == 0) /* on the edge of a hole */
-				{
-                    LWDEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
-					return 0;
-				}
-        }
-        return result; /* -1 = outside, 0 = boundary, 1 = inside */
+	ring = polygon->rings[0];
+	in_ring = point_in_ring(polygon->rings[0], &pt);
+	if ( in_ring == -1) /* outside the exterior ring */
+	{
+		LWDEBUG(3, "point_in_polygon: outside exterior ring.");
+		return -1;
+	}
+	result = in_ring;
+
+	for (i=1; i<polygon->nrings; i++)
+	{
+		ring = polygon->rings[i];
+		in_ring = point_in_ring(polygon->rings[i], &pt);
+		if (in_ring == 1) /* inside a hole => outside the polygon */
+		{
+			LWDEBUGF(3, "point_in_polygon: within hole %d.", i);
+			return -1;
+		}
+		if (in_ring == 0) /* on the edge of a hole */
+		{
+			LWDEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
+			return 0;
+		}
+	}
+	return result; /* -1 = outside, 0 = boundary, 1 = inside */
 }
 
 /*
@@ -1383,57 +1403,57 @@
  */
 int point_in_multipolygon(LWMPOLY *mpolygon, LWPOINT *point)
 {
-        int i, j, result, in_ring;
-        POINTARRAY *ring;
-        POINT2D pt;
+	int i, j, result, in_ring;
+	POINTARRAY *ring;
+	POINT2D pt;
 
-        LWDEBUG(2, "point_in_polygon called.");
+	LWDEBUG(2, "point_in_polygon called.");
 
-        getPoint2d_p(point->point, 0, &pt);
-        /* assume bbox short-circuit has already been attempted */
+	getPoint2d_p(point->point, 0, &pt);
+	/* assume bbox short-circuit has already been attempted */
 
-		result = -1;
+	result = -1;
 
-		for(j = 0; j < mpolygon->ngeoms; j++ ) 
+	for (j = 0; j < mpolygon->ngeoms; j++ )
+	{
+
+		LWPOLY *polygon = mpolygon->geoms[j];
+		ring = polygon->rings[0];
+		in_ring = point_in_ring(polygon->rings[0], &pt);
+		if ( in_ring == -1) /* outside the exterior ring */
 		{
-		
-			LWPOLY *polygon = mpolygon->geoms[j];
-		   	ring = polygon->rings[0];
-			in_ring = point_in_ring(polygon->rings[0], &pt);
-       		if( in_ring == -1) /* outside the exterior ring */
-        	{
-                LWDEBUG(3, "point_in_polygon: outside exterior ring.");
-				continue;
-        	}
-			if( in_ring == 0 ) 
-			{
-				return 0;
-			}
+			LWDEBUG(3, "point_in_polygon: outside exterior ring.");
+			continue;
+		}
+		if ( in_ring == 0 )
+		{
+			return 0;
+		}
 
-			result = in_ring;
+		result = in_ring;
 
-        	for(i=1; i<polygon->nrings; i++)
-        	{
-                ring = polygon->rings[i];
-				in_ring = point_in_ring(polygon->rings[i], &pt);
-                if(in_ring == 1) /* inside a hole => outside the polygon */
-                {
-                	LWDEBUGF(3, "point_in_polygon: within hole %d.", i);
-					result = -1;
-                    break;
-                }
-				if(in_ring == 0) /* on the edge of a hole */
-				{
-                    LWDEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
-					return 0;
-				}
-        	}
-        	if( result != -1) 
+		for (i=1; i<polygon->nrings; i++)
+		{
+			ring = polygon->rings[i];
+			in_ring = point_in_ring(polygon->rings[i], &pt);
+			if (in_ring == 1) /* inside a hole => outside the polygon */
 			{
-				return result;
+				LWDEBUGF(3, "point_in_polygon: within hole %d.", i);
+				result = -1;
+				break;
 			}
+			if (in_ring == 0) /* on the edge of a hole */
+			{
+				LWDEBUGF(3, "point_in_polygon: on edge of hole %d.", i);
+				return 0;
+			}
 		}
-		return result;
+		if ( result != -1)
+		{
+			return result;
+		}
+	}
+	return result;
 }
 
 

Modified: trunk/lwgeom/lwgeom_functions_basic.c
===================================================================
--- trunk/lwgeom/lwgeom_functions_basic.c	2008-10-14 11:44:18 UTC (rev 3100)
+++ trunk/lwgeom/lwgeom_functions_basic.c	2008-10-14 17:42:15 UTC (rev 3101)
@@ -7,7 +7,7 @@
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU General Public Licence. See the COPYING file.
- * 
+ *
  **********************************************************************/
 
 #include <math.h>
@@ -75,10 +75,10 @@
 Datum optimistic_overlap(PG_FUNCTION_ARGS);
 
 void lwgeom_affine_ptarray(POINTARRAY *pa, double afac, double bfac, double cfac,
-	double dfac, double efac, double ffac, double gfac, double hfac, double ifac, double xoff, double yoff, double zoff);
+                           double dfac, double efac, double ffac, double gfac, double hfac, double ifac, double xoff, double yoff, double zoff);
 
 void lwgeom_affine_recursive(uchar *serialized, double afac, double bfac, double cfac,
-	double dfac, double efac, double ffac, double gfac, double hfac, double ifac, double xoff, double yoff, double zoff);
+                             double dfac, double efac, double ffac, double gfac, double hfac, double ifac, double xoff, double yoff, double zoff);
 
 /*------------------------------------------------------------------*/
 
@@ -93,8 +93,8 @@
 	if ( size != computed_size )
 	{
 		elog(NOTICE, "varlena size (%lu) != computed size+4 (%lu)",
-				(unsigned long)size,
-				(unsigned long)computed_size);
+		     (unsigned long)size,
+		     (unsigned long)computed_size);
 	}
 
 	PG_FREE_IF_COPY(geom,0);
@@ -240,7 +240,7 @@
 		}
 		else
 		{
-	elog(ERROR, "What ? lwgeom_getsubgeometry_inspected returned NULL??");
+			elog(ERROR, "What ? lwgeom_getsubgeometry_inspected returned NULL??");
 		}
 	}
 	return npoints;
@@ -323,8 +323,8 @@
 	PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	LWGEOM_INSPECTED *inspected = lwgeom_inspect(SERIALIZED_FORM(geom));
 	LWPOLY *poly;
-        LWCURVEPOLY *curvepoly;
-        LWGEOM *tmp;
+	LWCURVEPOLY *curvepoly;
+	LWGEOM *tmp;
 	double area = 0.0;
 	int i;
 
@@ -332,22 +332,22 @@
 
 	for (i=0; i<inspected->ngeometries; i++)
 	{
-                tmp = lwgeom_getgeom_inspected(inspected, i);
-                if(lwgeom_getType(tmp->type) == POLYGONTYPE)
-                {
-		        poly = (LWPOLY *)tmp;
-		        area += lwgeom_polygon_area(poly);
-                }
-                else if(lwgeom_getType(tmp->type) == CURVEPOLYTYPE)
-                {
-                        curvepoly = (LWCURVEPOLY *)tmp;
-                        area += lwgeom_curvepolygon_area(curvepoly);
-                }
-                lwgeom_release(tmp);
+		tmp = lwgeom_getgeom_inspected(inspected, i);
+		if (lwgeom_getType(tmp->type) == POLYGONTYPE)
+		{
+			poly = (LWPOLY *)tmp;
+			area += lwgeom_polygon_area(poly);
+		}
+		else if (lwgeom_getType(tmp->type) == CURVEPOLYTYPE)
+		{
+			curvepoly = (LWCURVEPOLY *)tmp;
+			area += lwgeom_curvepolygon_area(curvepoly);
+		}
+		lwgeom_release(tmp);
 
 		POSTGIS_DEBUGF(3, " LWGEOM_area_polygon found a poly (%f)", area);
 	}
-	
+
 	pfree_inspected(inspected);
 
 	PG_FREE_IF_COPY(geom, 0);
@@ -477,7 +477,7 @@
 
 /*
  * Write to already allocated memory 'optr' a 2d version of
- * the given serialized form. 
+ * the given serialized form.
  * Higher dimensions in input geometry are discarded.
  * Return number bytes written in given int pointer.
  */
@@ -492,14 +492,14 @@
 	uchar newtypefl;
 	LWPOINT *point = NULL;
 	LWLINE *line = NULL;
-        LWCURVE *curve = NULL;
+	LWCURVE *curve = NULL;
 	LWPOLY *poly = NULL;
 	POINTARRAY newpts;
 	POINTARRAY **nrings;
 	POINT2D p2d;
 	uchar *loc;
 
-		
+
 	LWDEBUG(2, "lwgeom_force2d_recursive: call");
 
 	type = lwgeom_getType(serialized[0]);
@@ -554,32 +554,32 @@
 		return;
 	}
 
-        if( type == CURVETYPE )
-        {
-                curve = lwcurve_deserialize(serialized);
+	if ( type == CURVETYPE )
+	{
+		curve = lwcurve_deserialize(serialized);
 
-                LWDEBUGF(3, "lwgeom_force2d_recursize: it's a curve with %d points", curve->points->npoints);
+		LWDEBUGF(3, "lwgeom_force2d_recursize: it's a curve with %d points", curve->points->npoints);
 
-                TYPE_SETZM(newpts.dims, 0, 0);
-                newpts.npoints = curve->points->npoints;
-                newpts.serialized_pointlist = lwalloc(sizeof(POINT2D)*curve->points->npoints);
+		TYPE_SETZM(newpts.dims, 0, 0);
+		newpts.npoints = curve->points->npoints;
+		newpts.serialized_pointlist = lwalloc(sizeof(POINT2D)*curve->points->npoints);
 
 		LWDEBUGF(3, "lwgeom_force2d_recursive: %d bytes pointlist allocated", sizeof(POINT2D)*curve->points->npoints);
 
-                loc = newpts.serialized_pointlist;
-                for (j=0; j<curve->points->npoints; j++)
-                {
-                        getPoint2d_p(curve->points, j, &p2d);
-                        memcpy(loc, &p2d, sizeof(POINT2D));
-                        loc += sizeof(POINT2D);
-                }
-                curve->points = &newpts;
-                TYPE_SETZM(curve->type, 0, 0);
-                lwcurve_serialize_buf(curve, optr, retsize);
-                lwfree(newpts.serialized_pointlist);
-                lwfree(curve);
-                return;
-        }
+		loc = newpts.serialized_pointlist;
+		for (j=0; j<curve->points->npoints; j++)
+		{
+			getPoint2d_p(curve->points, j, &p2d);
+			memcpy(loc, &p2d, sizeof(POINT2D));
+			loc += sizeof(POINT2D);
+		}
+		curve->points = &newpts;
+		TYPE_SETZM(curve->type, 0, 0);
+		lwcurve_serialize_buf(curve, optr, retsize);
+		lwfree(newpts.serialized_pointlist);
+		lwfree(curve);
+		return;
+	}
 
 	if ( type == POLYGONTYPE )
 	{
@@ -596,7 +596,7 @@
 			TYPE_SETZM(nring->dims, 0, 0);
 			nring->npoints = ring->npoints;
 			nring->serialized_pointlist =
-				lwalloc(ring->npoints*sizeof(POINT2D));
+			        lwalloc(ring->npoints*sizeof(POINT2D));
 			loc = nring->serialized_pointlist;
 			for (k=0; k<ring->npoints; k++)
 			{
@@ -618,25 +618,25 @@
 	}
 
 	if ( type != MULTIPOINTTYPE && type != MULTIPOLYGONTYPE &&
-		type != MULTILINETYPE && type != COLLECTIONTYPE &&
-                type != COMPOUNDTYPE && type != CURVEPOLYTYPE &&
-                type != MULTICURVETYPE && type != MULTISURFACETYPE)
+	                type != MULTILINETYPE && type != COLLECTIONTYPE &&
+	                type != COMPOUNDTYPE && type != CURVEPOLYTYPE &&
+	                type != MULTICURVETYPE && type != MULTISURFACETYPE)
 	{
 		lwerror("lwgeom_force2d_recursive: unknown geometry: %d",
-			type);
+		        type);
 	}
 
- 	/*
-	 * OK, this is a collection, so we write down its metadata
-	 * first and then call us again
-	 */
+	/*
+	* OK, this is a collection, so we write down its metadata
+	* first and then call us again
+	*/
 
 	LWDEBUGF(3, "lwgeom_force2d_recursive: it's a collection (%s)", lwgeom_typename(type));
 
 
 	/* Add type */
 	newtypefl = lwgeom_makeType_full(0, 0, lwgeom_hasSRID(serialized[0]),
-		type, lwgeom_hasBBOX(serialized[0]));
+	                                 type, lwgeom_hasBBOX(serialized[0]));
 	optr[0] = newtypefl;
 	optr++;
 	totsize++;
@@ -691,7 +691,7 @@
 		optr += size;
 
 		LWDEBUGF(3, "lwgeom_force2d_recursive: added elem %d size: %d (tot: %d)",
-			i, size, totsize);
+		         i, size, totsize);
 	}
 	pfree_inspected(inspected);
 
@@ -702,7 +702,7 @@
 
 /*
  * Write to already allocated memory 'optr' a 3dz version of
- * the given serialized form. 
+ * the given serialized form.
  * Higher dimensions in input geometry are discarder.
  * If the given version is 2d Z is set to 0.
  * Return number bytes written in given int pointer.
@@ -717,14 +717,14 @@
 	int type;
 	LWPOINT *point = NULL;
 	LWLINE *line = NULL;
-        LWCURVE *curve = NULL;
+	LWCURVE *curve = NULL;
 	LWPOLY *poly = NULL;
 	POINTARRAY newpts;
 	POINTARRAY **nrings;
 	uchar *loc;
 	POINT3DZ point3dz;
 
-		
+
 	LWDEBUG(2, "lwgeom_force3dz_recursive: call");
 
 	type = lwgeom_getType(serialized[0]);
@@ -772,30 +772,30 @@
 		return;
 	}
 
-        if ( type == CURVETYPE )
-        {
-                curve = lwcurve_deserialize(serialized);
+	if ( type == CURVETYPE )
+	{
+		curve = lwcurve_deserialize(serialized);
 
-                LWDEBUG(3, "lwgeom_force3dz_recursize: it's a curve");
+		LWDEBUG(3, "lwgeom_force3dz_recursize: it's a curve");
 
-                TYPE_SETZM(newpts.dims, 1, 0);
-                newpts.npoints = curve->points->npoints;
-                newpts.serialized_pointlist = lwalloc(sizeof(POINT3DZ)*curve->points->npoints);
-                loc = newpts.serialized_pointlist;
-                for (j=0; j<curve->points->npoints; j++)
-                {
-                        getPoint3dz_p(curve->points, j, &point3dz);
-                        memcpy(loc, &point3dz, sizeof(POINT3DZ));
-                        loc+=sizeof(POINT3DZ);
-                }
-                curve->points = &newpts;
-                TYPE_SETZM(curve->type, 1, 0);
-                lwcurve_serialize_buf(curve, optr, retsize);
+		TYPE_SETZM(newpts.dims, 1, 0);
+		newpts.npoints = curve->points->npoints;
+		newpts.serialized_pointlist = lwalloc(sizeof(POINT3DZ)*curve->points->npoints);
+		loc = newpts.serialized_pointlist;
+		for (j=0; j<curve->points->npoints; j++)
+		{
+			getPoint3dz_p(curve->points, j, &point3dz);
+			memcpy(loc, &point3dz, sizeof(POINT3DZ));
+			loc+=sizeof(POINT3DZ);
+		}
+		curve->points = &newpts;
+		TYPE_SETZM(curve->type, 1, 0);
+		lwcurve_serialize_buf(curve, optr, retsize);
 
-                LWDEBUGF(3, "lwgeom_force3dz_recursive: it's a curve, size:%d", *retsize);
+		LWDEBUGF(3, "lwgeom_force3dz_recursive: it's a curve, size:%d", *retsize);
 
-                return;
-        }
+		return;
+	}
 
 	if ( type == POLYGONTYPE )
 	{
@@ -812,7 +812,7 @@
 			TYPE_SETZM(nring->dims, 1, 0);
 			nring->npoints = ring->npoints;
 			nring->serialized_pointlist =
-				lwalloc(ring->npoints*sizeof(POINT3DZ));
+			        lwalloc(ring->npoints*sizeof(POINT3DZ));
 			loc = nring->serialized_pointlist;
 			for (k=0; k<ring->npoints; k++)
 			{
@@ -831,16 +831,16 @@
 		return;
 	}
 
- 	/*
-	 * OK, this is a collection, so we write down its metadata
-	 * first and then call us again
-	 */
+	/*
+	* OK, this is a collection, so we write down its metadata
+	* first and then call us again
+	*/
 
 	LWDEBUGF(3, "lwgeom_force3dz_recursive: it's a collection (type:%d)", type);
 
 	/* Add type */
 	*optr = lwgeom_makeType_full(1, 0, lwgeom_hasSRID(serialized[0]),
-		type, lwgeom_hasBBOX(serialized[0]));
+	                             type, lwgeom_hasBBOX(serialized[0]));
 	optr++;
 	totsize++;
 	loc=serialized+1;
@@ -888,7 +888,7 @@
 
 /*
  * Write to already allocated memory 'optr' a 3dm version of
- * the given serialized form. 
+ * the given serialized form.
  * Higher dimensions in input geometry are discarder.
  * If the given version is 2d M is set to 0.
  * Return number bytes written in given int pointer.
@@ -904,14 +904,14 @@
 	uchar newtypefl;
 	LWPOINT *point = NULL;
 	LWLINE *line = NULL;
-        LWCURVE *curve = NULL;
+	LWCURVE *curve = NULL;
 	LWPOLY *poly = NULL;
 	POINTARRAY newpts;
 	POINTARRAY **nrings;
 	POINT3DM p3dm;
 	uchar *loc;
 
-		
+
 	LWDEBUG(2, "lwgeom_force3dm_recursive: call");
 
 	type = lwgeom_getType(serialized[0]);
@@ -966,30 +966,30 @@
 		return;
 	}
 
-        if ( type == CURVETYPE )
-        {
-                curve = lwcurve_deserialize(serialized);
+	if ( type == CURVETYPE )
+	{
+		curve = lwcurve_deserialize(serialized);
 
-                LWDEBUGF(3, "lwgeom_force3dm_recursize: it's a curve with %d points", curve->points->npoints);
+		LWDEBUGF(3, "lwgeom_force3dm_recursize: it's a curve with %d points", curve->points->npoints);
 
-                TYPE_SETZM(newpts.dims, 0, 1);
-                newpts.npoints = curve->points->npoints;
-                newpts.serialized_pointlist = lwalloc(sizeof(POINT3DM)*curve->points->npoints);
+		TYPE_SETZM(newpts.dims, 0, 1);
+		newpts.npoints = curve->points->npoints;
+		newpts.serialized_pointlist = lwalloc(sizeof(POINT3DM)*curve->points->npoints);
 
-                loc = newpts.serialized_pointlist;
-                for (j=0; j<curve->points->npoints; j++)
-                {
-                        getPoint3dm_p(curve->points, j, &p3dm);
-                        memcpy(loc, &p3dm, sizeof(POINT3DM));
-                        loc+=sizeof(POINT3DM);
-                }
-                curve->points = &newpts;
-                TYPE_SETZM(curve->type, 0, 1);
-                lwcurve_serialize_buf(curve, optr, retsize);
-                lwfree(newpts.serialized_pointlist);
-                lwfree(curve);
-                return;
-        }
+		loc = newpts.serialized_pointlist;
+		for (j=0; j<curve->points->npoints; j++)
+		{
+			getPoint3dm_p(curve->points, j, &p3dm);
+			memcpy(loc, &p3dm, sizeof(POINT3DM));
+			loc+=sizeof(POINT3DM);
+		}
+		curve->points = &newpts;
+		TYPE_SETZM(curve->type, 0, 1);
+		lwcurve_serialize_buf(curve, optr, retsize);
+		lwfree(newpts.serialized_pointlist);
+		lwfree(curve);
+		return;
+	}
 
 	if ( type == POLYGONTYPE )
 	{
@@ -1006,7 +1006,7 @@
 			TYPE_SETZM(nring->dims, 0, 1);
 			nring->npoints = ring->npoints;
 			nring->serialized_pointlist =
-				lwalloc(ring->npoints*sizeof(POINT3DM));
+			        lwalloc(ring->npoints*sizeof(POINT3DM));
 			loc = nring->serialized_pointlist;
 			for (k=0; k<ring->npoints; k++)
 			{
@@ -1028,25 +1028,25 @@
 	}
 
 	if ( type != MULTIPOINTTYPE && type != MULTIPOLYGONTYPE &&
-		type != MULTILINETYPE && type != COLLECTIONTYPE &&
-                type != COMPOUNDTYPE && type != CURVEPOLYTYPE &&
-                type != MULTICURVETYPE && type != MULTISURFACETYPE)
+	                type != MULTILINETYPE && type != COLLECTIONTYPE &&
+	                type != COMPOUNDTYPE && type != CURVEPOLYTYPE &&
+	                type != MULTICURVETYPE && type != MULTISURFACETYPE)
 	{
 		lwerror("lwgeom_force3dm_recursive: unknown geometry: %d",
-			type);
+		        type);
 	}
 
- 	/*
-	 * OK, this is a collection, so we write down its metadata
-	 * first and then call us again
-	 */
+	/*
+	* OK, this is a collection, so we write down its metadata
+	* first and then call us again
+	*/
 
 	LWDEBUGF(3, "lwgeom_force3dm_recursive: it's a collection (%s)", lwgeom_typename(type));
 
 
 	/* Add type */
 	newtypefl = lwgeom_makeType_full(0, 1, lwgeom_hasSRID(serialized[0]),
-		type, lwgeom_hasBBOX(serialized[0]));
+	                                 type, lwgeom_hasBBOX(serialized[0]));
 	optr[0] = newtypefl;
 	optr++;
 	totsize++;
@@ -1101,7 +1101,7 @@
 		optr += size;
 
 		LWDEBUGF(3, "lwgeom_force3dm_recursive: added elem %d size: %d (tot: %d)",
-			i, size, totsize);
+		         i, size, totsize);
 	}
 	pfree_inspected(inspected);
 
@@ -1113,7 +1113,7 @@
 
 /*
  * Write to already allocated memory 'optr' a 4d version of
- * the given serialized form. 
+ * the given serialized form.
  * Pad dimensions are set to 0 (this might be z, m or both).
  * Return number bytes written in given int pointer.
  */
@@ -1127,14 +1127,14 @@
 	int type;
 	LWPOINT *point = NULL;
 	LWLINE *line = NULL;
-        LWCURVE *curve = NULL;
+	LWCURVE *curve = NULL;
 	LWPOLY *poly = NULL;
 	POINTARRAY newpts;
 	POINTARRAY **nrings;
 	POINT4D p4d;
 	uchar *loc;
 
-		
+
 	LWDEBUG(2, "lwgeom_force4d_recursive: call");
 
 	type = lwgeom_getType(serialized[0]);
@@ -1181,27 +1181,27 @@
 		return;
 	}
 
-        if ( type == CURVETYPE )
-        {
-                curve = lwcurve_deserialize(serialized);
-                TYPE_SETZM(newpts.dims, 1, 1);
-                newpts.npoints = curve->points->npoints;
-                newpts.serialized_pointlist = lwalloc(sizeof(POINT4D)*curve->points->npoints);
-                loc = newpts.serialized_pointlist;
-                for (j=0; j<curve->points->npoints; j++)
-                {
-                        getPoint4d_p(curve->points, j, &p4d);
-                        memcpy(loc, &p4d, sizeof(POINT4D));
-                        loc+=sizeof(POINT4D);
-                }
-                curve->points = &newpts;
-                TYPE_SETZM(curve->type, 1, 1);
-                lwcurve_serialize_buf(curve, optr, retsize);
+	if ( type == CURVETYPE )
+	{
+		curve = lwcurve_deserialize(serialized);
+		TYPE_SETZM(newpts.dims, 1, 1);
+		newpts.npoints = curve->points->npoints;
+		newpts.serialized_pointlist = lwalloc(sizeof(POINT4D)*curve->points->npoints);
+		loc = newpts.serialized_pointlist;
+		for (j=0; j<curve->points->npoints; j++)
+		{
+			getPoint4d_p(curve->points, j, &p4d);
+			memcpy(loc, &p4d, sizeof(POINT4D));
+			loc+=sizeof(POINT4D);
+		}
+		curve->points = &newpts;
+		TYPE_SETZM(curve->type, 1, 1);
+		lwcurve_serialize_buf(curve, optr, retsize);
 
-                LWDEBUGF(3, "lwgeom_force4d_recursive: it's a curve, size:%d", *retsize);
+		LWDEBUGF(3, "lwgeom_force4d_recursive: it's a curve, size:%d", *retsize);
 
-                return;
-        }
+		return;
+	}
 
 	if ( type == POLYGONTYPE )
 	{
@@ -1218,7 +1218,7 @@
 			TYPE_SETZM(nring->dims, 1, 1);
 			nring->npoints = ring->npoints;
 			nring->serialized_pointlist =
-				lwalloc(ring->npoints*sizeof(POINT4D));
+			        lwalloc(ring->npoints*sizeof(POINT4D));
 			loc = nring->serialized_pointlist;
 			for (k=0; k<ring->npoints; k++)
 			{
@@ -1237,18 +1237,18 @@
 		return;
 	}
 
- 	/*
-	 * OK, this is a collection, so we write down its metadata
-	 * first and then call us again
-	 */
+	/*
+	* OK, this is a collection, so we write down its metadata
+	* first and then call us again
+	*/
 
 	LWDEBUGF(3, "lwgeom_force4d_recursive: it's a collection (type:%d)", type);
 
 	/* Add type */
 	*optr = lwgeom_makeType_full(
-		1, 1,
-		lwgeom_hasSRID(serialized[0]),
-		type, lwgeom_hasBBOX(serialized[0]));
+	                1, 1,
+	                lwgeom_hasSRID(serialized[0]),
+	                type, lwgeom_hasBBOX(serialized[0]));
 	optr++;
 	totsize++;
 	loc=serialized+1;
@@ -1310,10 +1310,10 @@
 	srl = lwalloc(VARSIZE(geom));
 
 	lwgeom_force2d_recursive(SERIALIZED_FORM(geom),
-		srl, &size);
+	                         srl, &size);
 
 	result = PG_LWGEOM_construct(srl, pglwgeom_getSRID(geom),
-		lwgeom_hasBBOX(geom->type));
+	                             lwgeom_hasBBOX(geom->type));
 	PG_FREE_IF_COPY(geom, 0);
 
 	PG_RETURN_POINTER(result);
@@ -1330,22 +1330,25 @@
 	size_t size = 0;
 
 	olddims = lwgeom_ndims(geom->type);
-	
+
 	/* already 3d */
 	if ( olddims == 3 && TYPE_HASZ(geom->type) ) PG_RETURN_POINTER(geom);
 
-	if ( olddims > 3 ) {
+	if ( olddims > 3 )
+	{
 		srl = lwalloc(VARSIZE(geom));
-	} else {
+	}
+	else
+	{
 		/* allocate double as memory a larger for safety */
 		srl = lwalloc(VARSIZE(geom)*1.5);
 	}
 
 	lwgeom_force3dz_recursive(SERIALIZED_FORM(geom),
-		srl, &size);
+	                          srl, &size);
 
 	result = PG_LWGEOM_construct(srl, pglwgeom_getSRID(geom),
-		lwgeom_hasBBOX(geom->type));
+	                             lwgeom_hasBBOX(geom->type));
 
 	PG_FREE_IF_COPY(geom, 0);
 	PG_RETURN_POINTER(result);
@@ -1362,13 +1365,16 @@
 	size_t size = 0;
 
 	olddims = lwgeom_ndims(geom->type);
-	
+
 	/* already 3dm */
 	if ( olddims == 3 && TYPE_HASM(geom->type) ) PG_RETURN_POINTER(geom);
 
-	if ( olddims > 3 ) {
+	if ( olddims > 3 )
+	{
 		size = VARSIZE(geom);
-	} else {
+	}
+	else
+	{
 		/* allocate double as memory a larger for safety */
 		size = VARSIZE(geom) * 2;
 	}
@@ -1377,12 +1383,12 @@
 	POSTGIS_DEBUGF(3, "LWGEOM_force_3dm: allocated %d bytes for result", (int)size);
 
 	lwgeom_force3dm_recursive(SERIALIZED_FORM(geom),
-		srl, &size);
+	                          srl, &size);
 
 	POSTGIS_DEBUGF(3, "LWGEOM_force_3dm: lwgeom_force3dm_recursive returned a %d sized geom", (int)size);
 
 	result = PG_LWGEOM_construct(srl, pglwgeom_getSRID(geom),
-		lwgeom_hasBBOX(geom->type));
+	                             lwgeom_hasBBOX(geom->type));
 
 	PG_FREE_IF_COPY(geom, 0);
 
@@ -1400,7 +1406,7 @@
 	size_t size = 0;
 
 	olddims = lwgeom_ndims(geom->type);
-	
+
 	/* already 4d */
 	if ( olddims == 4 ) PG_RETURN_POINTER(geom);
 
@@ -1408,10 +1414,10 @@
 	srl = lwalloc(VARSIZE(geom)*2);
 
 	lwgeom_force4d_recursive(SERIALIZED_FORM(geom),
-		srl, &size);
+	                         srl, &size);
 
 	result = PG_LWGEOM_construct(srl, pglwgeom_getSRID(geom),
-		lwgeom_hasBBOX(geom->type));
+	                             lwgeom_hasBBOX(geom->type));
 
 	PG_FREE_IF_COPY(geom, 0);
 
@@ -1429,7 +1435,7 @@
 	int SRID;
 	BOX2DFLOAT4 *bbox;
 
-        POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
+	POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
 
 	/*
 	 * This funx is a no-op only if a bbox cache is already present
@@ -1437,7 +1443,7 @@
 	 * automatic bbox addition FOR_COMPLEX_GEOMS.
 	 */
 	if ( TYPE_GETTYPE(geom->type) == COLLECTIONTYPE &&
-		TYPE_HASBBOX(geom->type) )
+	                TYPE_HASBBOX(geom->type) )
 	{
 		PG_RETURN_POINTER(geom);
 	}
@@ -1461,8 +1467,8 @@
 		lwgeom->bbox = NULL;
 		lwgeoms[0] = lwgeom;
 		lwgeom = (LWGEOM *)lwcollection_construct(COLLECTIONTYPE,
-			SRID, bbox, 1,
-			lwgeoms);
+		                SRID, bbox, 1,
+		                lwgeoms);
 	}
 
 	result = pglwgeom_serialize(lwgeom);
@@ -1485,7 +1491,7 @@
 	int SRID=-1;
 	BOX2DFLOAT4 *box;
 
-        POSTGIS_DEBUG(2, "LWGEOM_force_multi called");
+	POSTGIS_DEBUG(2, "LWGEOM_force_multi called");
 
 	/*
 	 * This funx is a no-op only if a bbox cache is already present
@@ -1493,7 +1499,7 @@
 	 * automatic bbox addition FOR_COMPLEX_GEOMS.
 	 */
 	if ( TYPE_GETTYPE(geom->type) >= MULTIPOINTTYPE &&
-		TYPE_HASBBOX(geom->type) )
+	                TYPE_HASBBOX(geom->type) )
 	{
 		PG_RETURN_POINTER(geom);
 	}
@@ -1512,9 +1518,9 @@
 		lwgeom->SRID=-1;
 		lwgeom->bbox=NULL;
 		lwgeoms[0] = lwgeom;
-		
+
 		lwgeom = (LWGEOM *)lwcollection_construct(type,
-			SRID, box, 1, lwgeoms);
+		                SRID, box, 1, lwgeoms);
 	}
 
 
@@ -1548,7 +1554,7 @@
 	}
 
 	mindist = lwgeom_mindistance2d_recursive(SERIALIZED_FORM(geom1),
-		SERIALIZED_FORM(geom2));
+	                SERIALIZED_FORM(geom2));
 
 #ifdef PROFILE
 	profstop(PROF_QRUN);
@@ -1577,7 +1583,8 @@
 	geom2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
 	tolerance = PG_GETARG_FLOAT8(2);
 
-	if( tolerance < 0 ) {		
+	if ( tolerance < 0 )
+	{
 		elog(ERROR,"Tolerance cannot be less than zero\n");
 		PG_RETURN_NULL();
 	}
@@ -1589,10 +1596,10 @@
 	}
 
 	mindist = lwgeom_mindistance2d_recursive_tolerance(
-	            SERIALIZED_FORM(geom1),
-		          SERIALIZED_FORM(geom2), 
-		          tolerance
-		        );
+	                  SERIALIZED_FORM(geom1),
+	                  SERIALIZED_FORM(geom2),
+	                  tolerance
+	          );
 
 #ifdef PROFILE
 	profstop(PROF_QRUN);
@@ -1671,14 +1678,14 @@
 	LWGEOM *lwgeom;
 	PG_LWGEOM *ret;
 
-        POSTGIS_DEBUG(2, "LWGEOM_longitude_shift called.");
+	POSTGIS_DEBUG(2, "LWGEOM_longitude_shift called.");
 
 	geom = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
 	lwgeom = pglwgeom_deserialize(geom);
 
 	/* Drop bbox, will be recomputed */
 	lwgeom_dropBBOX(lwgeom);
-	
+
 	/* Modify geometry */
 	lwgeom_longitude_shift(lwgeom);
 
@@ -1706,7 +1713,8 @@
 
 	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	point = lwpoint_deserialize(SERIALIZED_FORM(geom));
-	if ( point == NULL ) {
+	if ( point == NULL )
+	{
 		PG_FREE_IF_COPY(geom, 0);
 		PG_RETURN_NULL(); /* not a point */
 	}
@@ -1736,7 +1744,7 @@
 	BOX2DFLOAT4 *box=NULL;
 	int SRID;
 
-        POSTGIS_DEBUG(2, "LWGEOM_collect called.");
+	POSTGIS_DEBUG(2, "LWGEOM_collect called.");
 
 	/* return null if both geoms are null */
 	if ( (geom1_ptr == NULL) && (geom2_ptr == NULL) )
@@ -1744,14 +1752,14 @@
 		PG_RETURN_NULL();
 	}
 
-        /* return a copy of the second geom if only first geom is null */
+	/* return a copy of the second geom if only first geom is null */
 	if (geom1_ptr == NULL)
 	{
 		result = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1));
 		PG_RETURN_POINTER(result);
 	}
 
-        /* return a copy of the first geom if only second geom is null */
+	/* return a copy of the first geom if only second geom is null */
 	if (geom2_ptr == NULL)
 	{
 		result = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
@@ -1763,7 +1771,7 @@
 	pglwgeom2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
 
 	POSTGIS_DEBUGF(3, "LWGEOM_collect(%s, %s): call", lwgeom_typename(TYPE_GETTYPE(pglwgeom1->type)), lwgeom_typename(TYPE_GETTYPE(pglwgeom2->type)));
-	
+
 #if 0
 	if ( pglwgeom_getSRID(pglwgeom1) != pglwgeom_getSRID(pglwgeom2) )
 	{
@@ -1802,8 +1810,8 @@
 	lwgeom_dropSRID(lwgeoms[1]);
 
 	outlwg = (LWGEOM *)lwcollection_construct(
-		outtype, SRID,
-		box, 2, lwgeoms);
+	                 outtype, SRID,
+	                 box, 2, lwgeoms);
 
 	result = pglwgeom_serialize(outlwg);
 
@@ -1837,12 +1845,15 @@
 	POSTGIS_DEBUG(2, "LWGEOM_accum called");
 
 	datum = PG_GETARG_DATUM(0);
-	if ( (Pointer *)datum == NULL ) {
+	if ( (Pointer *)datum == NULL )
+	{
 		array = NULL;
 		nelems = 0;
 
 		POSTGIS_DEBUG(3, "geom_accum: NULL array");
-	} else {
+	}
+	else
+	{
 		array = DatumGetArrayTypePCopy(datum);
 		/*array = PG_GETARG_ARRAYTYPE_P(0); */
 		nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
@@ -1871,11 +1882,12 @@
 	 * 		--strk(TODO);
 	 */
 	++nelems;
-	if ( nelems == 1 || ! array ) {
+	if ( nelems == 1 || ! array )
+	{
 		nbytes = ARR_OVERHEAD_NONULLS(1)+INTALIGN(VARSIZE(geom));
 
 		POSTGIS_DEBUGF(3, "geom_accum: adding %p (nelems=%d; nbytes=%d)",
-			(void*)geom, nelems, (int)nbytes);
+		               (void*)geom, nelems, (int)nbytes);
 
 		result = lwalloc(nbytes);
 		if ( ! result )
@@ -1896,7 +1908,9 @@
 
 		POSTGIS_DEBUGF(3, " %d bytes memcopied", VARSIZE(geom));
 
-	} else {
+	}
+	else
+	{
 		oldsize = VARSIZE(array);
 		nbytes = oldsize + INTALIGN(VARSIZE(geom));
 
@@ -1913,14 +1927,14 @@
 
 		POSTGIS_DEBUGF(3, " array start  @ %p", (void*)result);
 		POSTGIS_DEBUGF(3, " ARR_DATA_PTR @ %p (%ld)",
-			ARR_DATA_PTR(result), (uchar *)ARR_DATA_PTR(result)-(uchar *)result);
+		               ARR_DATA_PTR(result), (uchar *)ARR_DATA_PTR(result)-(uchar *)result);
 		POSTGIS_DEBUGF(3, " next element @ %p", (uchar *)result+oldsize);
 
 		SET_VARSIZE(result, nbytes);
 		memcpy(ARR_DIMS(result), &nelems, sizeof(int));
 
 		POSTGIS_DEBUGF(3, " writing next element starting @ %p",
-			(void*)(result+oldsize));
+		               (void*)(result+oldsize));
 
 		memcpy((uchar *)result+oldsize, geom, VARSIZE(geom));
 	}
@@ -1955,7 +1969,7 @@
 	size_t offset;
 	BOX2DFLOAT4 *box=NULL;
 
-        POSTGIS_DEBUG(2, "LWGEOM_collect_garray called.");
+	POSTGIS_DEBUG(2, "LWGEOM_collect_garray called.");
 
 	/* Get input datum */
 	datum = PG_GETARG_DATUM(0);
@@ -1971,7 +1985,7 @@
 	array = DatumGetArrayTypeP(datum);
 
 	POSTGIS_DEBUGF(3, " array is %d-bytes in size, %ld w/out header",
-		ARR_SIZE(array), ARR_SIZE(array)-ARR_OVERHEAD_NONULLS(ARR_NDIM(array)));
+	               ARR_SIZE(array), ARR_SIZE(array)-ARR_OVERHEAD_NONULLS(ARR_NDIM(array)));
 
 
 	/* Get number of geometries in array */
@@ -2007,10 +2021,11 @@
 		if ( ! i )
 		{
 			/* Get first geometry SRID */
-			SRID = lwgeoms[i]->SRID; 
+			SRID = lwgeoms[i]->SRID;
 
 			/* COMPUTE_BBOX WHEN_SIMPLE */
-			if ( lwgeoms[i]->bbox ) {
+			if ( lwgeoms[i]->bbox )
+			{
 				box = box2d_clone(lwgeoms[i]->bbox);
 			}
 		}
@@ -2020,7 +2035,7 @@
 			if ( lwgeoms[i]->SRID != SRID )
 			{
 				elog(ERROR,
-					"Operation on mixed SRID geometries");
+				     "Operation on mixed SRID geometries");
 				PG_RETURN_NULL();
 			}
 
@@ -2047,7 +2062,8 @@
 		lwgeom_dropBBOX(lwgeoms[i]);
 
 		/* Output type not initialized */
-		if ( ! outtype ) {
+		if ( ! outtype )
+		{
 			/* Input is single, make multi */
 			if ( intype < 4 ) outtype = intype+3;
 			/* Input is multi, make collection */
@@ -2066,8 +2082,8 @@
 	POSTGIS_DEBUGF(3, "LWGEOM_collect_garray: outtype = %d", outtype);
 
 	outlwg = (LWGEOM *)lwcollection_construct(
-		outtype, SRID,
-		box, nelems, lwgeoms);
+	                 outtype, SRID,
+	                 box, nelems, lwgeoms);
 
 	result = pglwgeom_serialize(outlwg);
 
@@ -2132,7 +2148,7 @@
 	size_t offset;
 	int SRID=-1;
 
-        POSTGIS_DEBUG(2, "LWGEOM_makeline_garray called.");
+	POSTGIS_DEBUG(2, "LWGEOM_makeline_garray called.");
 
 	/* Get input datum */
 	datum = PG_GETARG_DATUM(0);
@@ -2166,7 +2182,7 @@
 	 * lwpoints pointers array.
 	 * Count actual number of points.
 	 */
-	
+
 	/* possibly more then required */
 	lwpoints = palloc(sizeof(LWGEOM *)*nelems);
 	npoints = 0;
@@ -2179,23 +2195,26 @@
 		if ( TYPE_GETTYPE(geom->type) != POINTTYPE ) continue;
 
 		lwpoints[npoints++] =
-			lwpoint_deserialize(SERIALIZED_FORM(geom));
+		        lwpoint_deserialize(SERIALIZED_FORM(geom));
 
 		/* Check SRID homogeneity */
-		if ( npoints == 1 ) {
+		if ( npoints == 1 )
+		{
 			/* Get first geometry SRID */
-			SRID = lwpoints[npoints-1]->SRID; 
-		} else {
+			SRID = lwpoints[npoints-1]->SRID;
+		}
+		else
+		{
 			if ( lwpoints[npoints-1]->SRID != SRID )
 			{
 				elog(ERROR,
-					"Operation on mixed SRID geometries");
+				     "Operation on mixed SRID geometries");
 				PG_RETURN_NULL();
 			}
 		}
 
 		POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: element %d deserialized",
-			i);
+		               i);
 	}
 
 	/* Return null on 0-points input array */
@@ -2226,14 +2245,14 @@
 	LWPOINT *lwpoints[2];
 	LWLINE *outline;
 
-        POSTGIS_DEBUG(2, "LWGEOM_makeline called.");
+	POSTGIS_DEBUG(2, "LWGEOM_makeline called.");
 
 	/* Get input datum */
 	pglwg1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	pglwg2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
 
 	if ( ! TYPE_GETTYPE(pglwg1->type) == POINTTYPE ||
-		! TYPE_GETTYPE(pglwg2->type) == POINTTYPE )
+	                ! TYPE_GETTYPE(pglwg2->type) == POINTTYPE )
 	{
 		elog(ERROR, "Input geometries must be points");
 		PG_RETURN_NULL();
@@ -2257,7 +2276,7 @@
 }
 
 /*
- * makepoly( GEOMETRY, GEOMETRY[] ) returns a POLYGON 
+ * makepoly( GEOMETRY, GEOMETRY[] ) returns a POLYGON
  * formed by the given shell and holes geometries.
  */
 PG_FUNCTION_INFO_V1(LWGEOM_makepoly);
@@ -2273,11 +2292,12 @@
 	unsigned int i;
 	size_t offset=0;
 
-        POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
+	POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
 
 	/* Get input shell */
 	pglwg1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-	if ( ! TYPE_GETTYPE(pglwg1->type) == LINETYPE ) {
+	if ( ! TYPE_GETTYPE(pglwg1->type) == LINETYPE )
+	{
 		lwerror("Shell is not a line");
 	}
 	shell = lwline_deserialize(SERIALIZED_FORM(pglwg1));
@@ -2293,7 +2313,8 @@
 			PG_LWGEOM *g = (PG_LWGEOM *)(ARR_DATA_PTR(array)+offset);
 			LWLINE *hole;
 			offset += INTALIGN(VARSIZE(g));
-			if ( TYPE_GETTYPE(g->type) != LINETYPE ) {
+			if ( TYPE_GETTYPE(g->type) != LINETYPE )
+			{
 				lwerror("Hole %d is not a line", i);
 			}
 			hole = lwline_deserialize(SERIALIZED_FORM(g));
@@ -2331,7 +2352,7 @@
 	int SRID;
 	PG_LWGEOM *result;
 
-        POSTGIS_DEBUG(2, "LWGEOM_expand called.");
+	POSTGIS_DEBUG(2, "LWGEOM_expand called.");
 
 	/* get geometry box  */
 	if ( ! getbox2d_p(SERIALIZED_FORM(geom), &box) )
@@ -2347,11 +2368,16 @@
 	expand_box2d(&box, d);
 
 	/* Assign coordinates to POINT2D array */
-	pts[0].x = box.xmin; pts[0].y = box.ymin;
-	pts[1].x = box.xmin; pts[1].y = box.ymax;
-	pts[2].x = box.xmax; pts[2].y = box.ymax;
-	pts[3].x = box.xmax; pts[3].y = box.ymin;
-	pts[4].x = box.xmin; pts[4].y = box.ymin;
+	pts[0].x = box.xmin;
+	pts[0].y = box.ymin;
+	pts[1].x = box.xmin;
+	pts[1].y = box.ymax;
+	pts[2].x = box.xmax;
+	pts[2].y = box.ymax;
+	pts[3].x = box.xmax;
+	pts[3].y = box.ymin;
+	pts[4].x = box.xmin;
+	pts[4].y = box.ymin;
 
 	/* Construct point array */
 	pa[0] = lwalloc(sizeof(POINTARRAY));
@@ -2366,7 +2392,7 @@
 	result = pglwgeom_serialize((LWGEOM *)poly);
 
 	PG_FREE_IF_COPY(geom, 0);
-	
+
 	PG_RETURN_POINTER(result);
 }
 
@@ -2411,12 +2437,12 @@
 		/* must be the EMPTY geometry */
 		PG_RETURN_POINTER(geom);
 	}
-	
+
 	/* get geometry SRID */
 	SRID = lwgeom_getsrid(SERIALIZED_FORM(geom));
 
-	
-	/* 
+
+	/*
 	 * Alter envelope type so that a valid geometry is always
 	 * returned depending upon the size of the geometry. The
 	 * code makes the following assumptions:
@@ -2429,53 +2455,60 @@
 
 
 	if (box.xmin == box.xmax &&
-	    box.ymin == box.ymax)
-        {
-                /* Construct and serialize point */
-                LWPOINT *point = make_lwpoint2d(SRID, box.xmin, box.ymin);
-                ser = lwpoint_serialize(point);
-        }
+	                box.ymin == box.ymax)
+	{
+		/* Construct and serialize point */
+		LWPOINT *point = make_lwpoint2d(SRID, box.xmin, box.ymin);
+		ser = lwpoint_serialize(point);
+	}
 	else if (box.xmin == box.xmax ||
-	         box.ymin == box.ymax)
-        {
-                LWLINE *line;
-                POINT2D *pts = palloc(sizeof(POINT2D)*2);
+	                box.ymin == box.ymax)
+	{
+		LWLINE *line;
+		POINT2D *pts = palloc(sizeof(POINT2D)*2);
 
-                /* Assign coordinates to POINT2D array */
-                pts[0].x = box.xmin; pts[0].y = box.ymin;
-                pts[1].x = box.xmax; pts[1].y = box.ymax;
+		/* Assign coordinates to POINT2D array */
+		pts[0].x = box.xmin;
+		pts[0].y = box.ymin;
+		pts[1].x = box.xmax;
+		pts[1].y = box.ymax;
 
-                /* Construct point array */
-                pa = pointArray_construct((uchar *)pts, 0, 0, 2);	  
+		/* Construct point array */
+		pa = pointArray_construct((uchar *)pts, 0, 0, 2);
 
-                /* Construct and serialize linestring */
-                line = lwline_construct(SRID, NULL, pa);
-                ser = lwline_serialize(line);
-        }
-        else
-        {
-                LWPOLY *poly;
-	        POINT2D *pts = lwalloc(sizeof(POINT2D)*5);
-                BOX2DFLOAT4 box2d;
-                getbox2d_p(SERIALIZED_FORM(geom), &box2d);
-  		
-                /* Assign coordinates to POINT2D array */
-                pts[0].x = box2d.xmin; pts[0].y = box2d.ymin;
-                pts[1].x = box2d.xmin; pts[1].y = box2d.ymax;
-                pts[2].x = box2d.xmax; pts[2].y = box2d.ymax;
-                pts[3].x = box2d.xmax; pts[3].y = box2d.ymin;
-                pts[4].x = box2d.xmin; pts[4].y = box2d.ymin;
+		/* Construct and serialize linestring */
+		line = lwline_construct(SRID, NULL, pa);
+		ser = lwline_serialize(line);
+	}
+	else
+	{
+		LWPOLY *poly;
+		POINT2D *pts = lwalloc(sizeof(POINT2D)*5);
+		BOX2DFLOAT4 box2d;
+		getbox2d_p(SERIALIZED_FORM(geom), &box2d);
 
-                /* Construct point array */
-                pa = pointArray_construct((uchar *)pts, 0, 0, 5);
+		/* Assign coordinates to POINT2D array */
+		pts[0].x = box2d.xmin;
+		pts[0].y = box2d.ymin;
+		pts[1].x = box2d.xmin;
+		pts[1].y = box2d.ymax;
+		pts[2].x = box2d.xmax;
+		pts[2].y = box2d.ymax;
+		pts[3].x = box2d.xmax;
+		pts[3].y = box2d.ymin;
+		pts[4].x = box2d.xmin;
+		pts[4].y = box2d.ymin;
 
-                /* Construct polygon  */
-                poly = lwpoly_construct(SRID, box2d_clone(&box2d), 1, &pa);
+		/* Construct point array */
+		pa = pointArray_construct((uchar *)pts, 0, 0, 5);
 
-                /* Serialize polygon */
-                ser = lwpoly_serialize(poly);
-        }
-			
+		/* Construct polygon  */
+		poly = lwpoly_construct(SRID, box2d_clone(&box2d), 1, &pa);
+
+		/* Serialize polygon */
+		ser = lwpoly_serialize(poly);
+	}
+
 	PG_FREE_IF_COPY(geom, 0);
 
 	/* Construct PG_LWGEOM  */
@@ -2500,7 +2533,7 @@
 
 
 /*
- *  Returns a modified geometry so that no segment is 
+ *  Returns a modified geometry so that no segment is
  *  longer then the given distance (computed using 2d).
  *  Every input point is kept.
  *  Z and M values for added points (if needed) are set to 0.
@@ -2512,14 +2545,14 @@
 	double dist;
 	LWGEOM *inlwgeom, *outlwgeom;
 
-        POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
+	POSTGIS_DEBUG(2, "LWGEOM_segmentize2d called");
 
 	ingeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	dist = PG_GETARG_FLOAT8(1);
 
 	/* Avoid deserialize/serialize steps */
 	if ( (TYPE_GETTYPE(ingeom->type) == POINTTYPE) ||
-		(TYPE_GETTYPE(ingeom->type) == MULTIPOINTTYPE) )
+	                (TYPE_GETTYPE(ingeom->type) == MULTIPOINTTYPE) )
 		PG_RETURN_POINTER(ingeom);
 
 	inlwgeom = lwgeom_deserialize(SERIALIZED_FORM(ingeom));
@@ -2545,7 +2578,7 @@
 	PG_LWGEOM *geom;
 	LWGEOM *lwgeom;
 
-        POSTGIS_DEBUG(2, "LWGEOM_reverse called");
+	POSTGIS_DEBUG(2, "LWGEOM_reverse called");
 
 	geom = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
 
@@ -2564,7 +2597,7 @@
 	PG_LWGEOM *ingeom, *outgeom;
 	LWGEOM *lwgeom;
 
-        POSTGIS_DEBUG(2, "LWGEOM_forceRHR_poly called");
+	POSTGIS_DEBUG(2, "LWGEOM_forceRHR_poly called");
 
 	ingeom = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
 
@@ -2586,7 +2619,7 @@
 	PG_LWGEOM *in, *out;
 	LWGEOM *lwgeom;
 
-        POSTGIS_DEBUG(2, "LWGEOM_noop called");
+	POSTGIS_DEBUG(2, "LWGEOM_noop called");
 
 	in = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 
@@ -2684,9 +2717,9 @@
 	lwgeom_release(lwg1);
 	lwgeom_release(lwg2);
 	PG_FREE_IF_COPY(g1, 0);
-        PG_FREE_IF_COPY(g2, 1);
+	PG_FREE_IF_COPY(g2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 PG_FUNCTION_INFO_V1(LWGEOM_makepoint);
@@ -2696,24 +2729,27 @@
 	LWPOINT *point;
 	PG_LWGEOM *result;
 
-        POSTGIS_DEBUG(2, "LWGEOM_makepoint called");
+	POSTGIS_DEBUG(2, "LWGEOM_makepoint called");
 
 	x = PG_GETARG_FLOAT8(0);
 	y = PG_GETARG_FLOAT8(1);
 
 	if ( PG_NARGS() == 2 ) point = make_lwpoint2d(-1, x, y);
-	else if ( PG_NARGS() == 3 ) {
+	else if ( PG_NARGS() == 3 )
+	{
 		z = PG_GETARG_FLOAT8(2);
 		point = make_lwpoint3dz(-1, x, y, z);
 	}
-	else if ( PG_NARGS() == 4 ) {
+	else if ( PG_NARGS() == 4 )
+	{
 		z = PG_GETARG_FLOAT8(2);
 		m = PG_GETARG_FLOAT8(3);
 		point = make_lwpoint4d(-1, x, y, z, m);
 	}
-	else {
+	else
+	{
 		elog(ERROR, "LWGEOM_makepoint: unsupported number of args: %d",
-			PG_NARGS());
+		     PG_NARGS());
 		PG_RETURN_NULL();
 	}
 
@@ -2729,7 +2765,7 @@
 	LWPOINT *point;
 	PG_LWGEOM *result;
 
-        POSTGIS_DEBUG(2, "LWGEOM_makepoint3dm called.");
+	POSTGIS_DEBUG(2, "LWGEOM_makepoint3dm called.");
 
 	x = PG_GETARG_FLOAT8(0);
 	y = PG_GETARG_FLOAT8(1);
@@ -2749,12 +2785,13 @@
 	LWLINE *line, *outline;
 	int where = -1;
 
-        POSTGIS_DEBUG(2, "LWGEOM_addpoint called.");
+	POSTGIS_DEBUG(2, "LWGEOM_addpoint called.");
 
 	pglwg1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	pglwg2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
 
-	if ( PG_NARGS() > 2 ) {
+	if ( PG_NARGS() > 2 )
+	{
 		where = PG_GETARG_INT32(2);
 	}
 
@@ -2803,7 +2840,7 @@
 	LWLINE *line, *outline;
 	unsigned int which;
 
-        POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
+	POSTGIS_DEBUG(2, "LWGEOM_removepoint called.");
 
 	pglwg1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	which = PG_GETARG_INT32(1);
@@ -2851,7 +2888,7 @@
 	POINT4D newpoint;
 	unsigned int which;
 
-        POSTGIS_DEBUG(2, "LWGEOM_setpoint_linestring called.");
+	POSTGIS_DEBUG(2, "LWGEOM_setpoint_linestring called.");
 
 	/* we copy input as we're going to modify it */
 	pglwg1 = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
@@ -3016,63 +3053,65 @@
 Datum optimistic_overlap(PG_FUNCTION_ARGS)
 {
 
-  PG_LWGEOM                  *pg_geom1 = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-  PG_LWGEOM                  *pg_geom2 = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
-  double                  dist = PG_GETARG_FLOAT8(2);
-  BOX2DFLOAT4             g1_bvol;
-  double                  calc_dist;
+	PG_LWGEOM                  *pg_geom1 = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+	PG_LWGEOM                  *pg_geom2 = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+	double                  dist = PG_GETARG_FLOAT8(2);
+	BOX2DFLOAT4             g1_bvol;
+	double                  calc_dist;
 
-  LWGEOM                     *geom1;
-  LWGEOM                     *geom2;
+	LWGEOM                     *geom1;
+	LWGEOM                     *geom2;
 
 
-  /* deserialized PG_LEGEOM into their respective LWGEOM */
-  geom1 = lwgeom_deserialize(SERIALIZED_FORM(pg_geom1));
-  geom2 = lwgeom_deserialize(SERIALIZED_FORM(pg_geom2));
+	/* deserialized PG_LEGEOM into their respective LWGEOM */
+	geom1 = lwgeom_deserialize(SERIALIZED_FORM(pg_geom1));
+	geom2 = lwgeom_deserialize(SERIALIZED_FORM(pg_geom2));
 
-  if (geom1->SRID != geom2->SRID){
+	if (geom1->SRID != geom2->SRID)
+	{
 
-    elog(ERROR,"optimistic_overlap:Operation on two GEOMETRIES with different SRIDs\\n");
-    PG_RETURN_NULL();
-  }
+		elog(ERROR,"optimistic_overlap:Operation on two GEOMETRIES with different SRIDs\\n");
+		PG_RETURN_NULL();
+	}
 
-  if (TYPE_GETTYPE(geom1->type) != POLYGONTYPE){
-    elog(ERROR,"optimistic_overlap: first arg isnt a polygon\n");
-    PG_RETURN_NULL();
-  }
+	if (TYPE_GETTYPE(geom1->type) != POLYGONTYPE)
+	{
+		elog(ERROR,"optimistic_overlap: first arg isnt a polygon\n");
+		PG_RETURN_NULL();
+	}
 
-  if ( (TYPE_GETTYPE(geom2->type) != POLYGONTYPE) &&  (geom2->type != MULTIPOLYGONTYPE) )
-    {
-      elog(ERROR,"optimistic_overlap: 2nd arg isnt a [multi-]polygon\n");
-      PG_RETURN_NULL();
-    }
+	if ( (TYPE_GETTYPE(geom2->type) != POLYGONTYPE) &&  (geom2->type != MULTIPOLYGONTYPE) )
+	{
+		elog(ERROR,"optimistic_overlap: 2nd arg isnt a [multi-]polygon\n");
+		PG_RETURN_NULL();
+	}
 
-  /*bbox check */
+	/*bbox check */
 
-  getbox2d_p( SERIALIZED_FORM(pg_geom1), &g1_bvol );
+	getbox2d_p( SERIALIZED_FORM(pg_geom1), &g1_bvol );
 
 
-  g1_bvol.xmin = g1_bvol.xmin - dist;
-  g1_bvol.ymin = g1_bvol.ymin - dist;
-  g1_bvol.xmax = g1_bvol.xmax + dist;
-  g1_bvol.ymax = g1_bvol.ymax + dist;
+	g1_bvol.xmin = g1_bvol.xmin - dist;
+	g1_bvol.ymin = g1_bvol.ymin - dist;
+	g1_bvol.xmax = g1_bvol.xmax + dist;
+	g1_bvol.ymax = g1_bvol.ymax + dist;
 
-  if (  (g1_bvol.xmin > geom2->bbox->xmax) ||
-        (g1_bvol.xmax < geom2->bbox->xmin) ||
-        (g1_bvol.ymin > geom2->bbox->ymax) ||
-        (g1_bvol.ymax < geom2->bbox->ymin)
-        )
-    {
-      PG_RETURN_BOOL(FALSE);  /*bbox not overlap */
-    }
+	if (  (g1_bvol.xmin > geom2->bbox->xmax) ||
+	                (g1_bvol.xmax < geom2->bbox->xmin) ||
+	                (g1_bvol.ymin > geom2->bbox->ymax) ||
+	                (g1_bvol.ymax < geom2->bbox->ymin)
+	   )
+	{
+		PG_RETURN_BOOL(FALSE);  /*bbox not overlap */
+	}
 
-  /*
-   * compute distances
-   * should be a fast calc if they actually do intersect
-   */
-  calc_dist =     DatumGetFloat8 ( DirectFunctionCall2(LWGEOM_mindistance2d,   PointerGetDatum( pg_geom1 ),       PointerGetDatum( pg_geom2 )));
+	/*
+	 * compute distances
+	 * should be a fast calc if they actually do intersect
+	 */
+	calc_dist =     DatumGetFloat8 ( DirectFunctionCall2(LWGEOM_mindistance2d,   PointerGetDatum( pg_geom1 ),       PointerGetDatum( pg_geom2 )));
 
-  PG_RETURN_BOOL(calc_dist < dist);
+	PG_RETURN_BOOL(calc_dist < dist);
 }
 
 /*
@@ -3080,10 +3119,10 @@
  */
 void
 lwgeom_affine_ptarray(POINTARRAY *pa,
-	double afac, double bfac, double cfac,
-	double dfac, double efac, double ffac,
-	double gfac, double hfac, double ifac,
-	double xoff, double yoff, double zoff)
+                      double afac, double bfac, double cfac,
+                      double dfac, double efac, double ffac,
+                      double gfac, double hfac, double ifac,
+                      double xoff, double yoff, double zoff)
 {
 	int i;
 	double x,y,z;
@@ -3095,7 +3134,8 @@
 	{
 		LWDEBUG(3, " has z");
 
-		for (i=0; i<pa->npoints; i++) {
+		for (i=0; i<pa->npoints; i++)
+		{
 			getPoint4d_p(pa, i, &p4d);
 			x = p4d.x;
 			y = p4d.y;
@@ -3112,12 +3152,13 @@
 	{
 		LWDEBUG(3, " doesn't have z");
 
-		for (i=0; i<pa->npoints; i++) {
+		for (i=0; i<pa->npoints; i++)
+		{
 			getPoint4d_p(pa, i, &p4d);
-  			x = p4d.x;
-  			y = p4d.y;
-  			p4d.x = afac * x + bfac * y + xoff;
-  			p4d.y = dfac * x + efac * y + yoff;
+			x = p4d.x;
+			y = p4d.y;
+			p4d.x = afac * x + bfac * y + xoff;
+			p4d.y = dfac * x + efac * y + yoff;
 			setPoint4d(pa, i, &p4d);
 
 			LWDEBUGF(3, " POINT %g %g %g => %g %g %g", x, y, x, p4d.x, p4d.y, p4d.z);
@@ -3130,10 +3171,10 @@
 
 void
 lwgeom_affine_recursive(uchar *serialized,
-	double afac, double bfac, double cfac,
-	double dfac, double efac, double ffac,
-	double gfac, double hfac, double ifac,
-	double xoff, double yoff, double zoff)
+                        double afac, double bfac, double cfac,
+                        double dfac, double efac, double ffac,
+                        double gfac, double hfac, double ifac,
+                        double xoff, double yoff, double zoff)
 {
 	LWGEOM_INSPECTED *inspected;
 	int i, j;
@@ -3152,10 +3193,10 @@
 		if (point !=NULL)
 		{
 			lwgeom_affine_ptarray(point->point,
-				afac, bfac, cfac,
-				dfac, efac, ffac,
-				gfac, hfac, ifac,
-				xoff, yoff, zoff);
+			                      afac, bfac, cfac,
+			                      dfac, efac, ffac,
+			                      gfac, hfac, ifac,
+			                      xoff, yoff, zoff);
 			lwgeom_release((LWGEOM *)point);
 			continue;
 		}
@@ -3165,11 +3206,11 @@
 		{
 			for (j=0; j<poly->nrings; j++)
 			{
- 				lwgeom_affine_ptarray(poly->rings[j],
- 				afac, bfac, cfac,
- 				dfac, efac, ffac,
- 				gfac, hfac, ifac,
-  				xoff, yoff, zoff);
+				lwgeom_affine_ptarray(poly->rings[j],
+				                      afac, bfac, cfac,
+				                      dfac, efac, ffac,
+				                      gfac, hfac, ifac,
+				                      xoff, yoff, zoff);
 			}
 			lwgeom_release((LWGEOM *)poly);
 			continue;
@@ -3179,10 +3220,10 @@
 		if (line != NULL)
 		{
 			lwgeom_affine_ptarray(line->points,
-				afac, bfac, cfac,
-				dfac, efac, ffac,
-				gfac, hfac, ifac,
-				xoff, yoff, zoff);
+			                      afac, bfac, cfac,
+			                      dfac, efac, ffac,
+			                      gfac, hfac, ifac,
+			                      xoff, yoff, zoff);
 			lwgeom_release((LWGEOM *)line);
 			continue;
 		}
@@ -3194,10 +3235,10 @@
 		}
 
 		lwgeom_affine_recursive(subgeom,
-				afac, bfac, cfac,
-				dfac, efac, ffac,
-				gfac, hfac, ifac,
-				xoff, yoff, zoff);
+		                        afac, bfac, cfac,
+		                        dfac, efac, ffac,
+		                        gfac, hfac, ifac,
+		                        xoff, yoff, zoff);
 	}
 
 	pfree_inspected(inspected);
@@ -3225,13 +3266,13 @@
 	double yoff =  PG_GETARG_FLOAT8(11);
 	double zoff =  PG_GETARG_FLOAT8(12);
 
-        POSTGIS_DEBUG(2, "LWGEOM_affine called.");
-	
+	POSTGIS_DEBUG(2, "LWGEOM_affine called.");
+
 	lwgeom_affine_recursive(srl,
-		afac, bfac, cfac,
-		dfac, efac, ffac,
-		gfac, hfac, ifac,
-		xoff, yoff, zoff);
+	                        afac, bfac, cfac,
+	                        dfac, efac, ffac,
+	                        gfac, hfac, ifac,
+	                        xoff, yoff, zoff);
 
 	/* COMPUTE_BBOX TAINTING */
 	tmp = pglwgeom_deserialize(geom);

Modified: trunk/lwgeom/lwgeom_gist.c
===================================================================
--- trunk/lwgeom/lwgeom_gist.c	2008-10-14 11:44:18 UTC (rev 3100)
+++ trunk/lwgeom/lwgeom_gist.c	2008-10-14 17:42:15 UTC (rev 3101)
@@ -88,45 +88,81 @@
 PG_FUNCTION_INFO_V1(LWGEOM_overlap);
 Datum LWGEOM_overlap(PG_FUNCTION_ARGS)
 {
+	/*
 	PG_LWGEOM *lwgeom1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	PG_LWGEOM *lwgeom2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+	*/
+
+	PG_LWGEOM *lwgeom1 = (PG_LWGEOM*)PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, VARHDRSZ + 1 + sizeof(BOX2DFLOAT4) );
+	PG_LWGEOM *lwgeom2 = (PG_LWGEOM*)PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(1), 0, VARHDRSZ + 1 + sizeof(BOX2DFLOAT4) );
 	bool result;
 	BOX2DFLOAT4 box1;
 	BOX2DFLOAT4 box2;
+	uchar *ser1;
+	uchar *ser2;
 
-	POSTGIS_DEBUG(2, "GIST: LWGEOM_overlap --entry");
-
-	if ( pglwgeom_getSRID(lwgeom1) != pglwgeom_getSRID(lwgeom2) )
+	ser1 = SERIALIZED_FORM(lwgeom1);
+	ser2 = SERIALIZED_FORM(lwgeom2);
+	if ( lwgeom_hasBBOX(ser1[0]) )
 	{
-		PG_FREE_IF_COPY(lwgeom1, 0);
-        	PG_FREE_IF_COPY(lwgeom2, 1);
-		elog(ERROR, "Operation on two geometries with different SRIDs");
-		PG_RETURN_NULL();
+		memcpy(&box1, ser1 + 1, sizeof(BOX2DFLOAT4));
 	}
-
-
-	if ( ! (getbox2d_p(SERIALIZED_FORM(lwgeom1), &box1) && getbox2d_p(SERIALIZED_FORM(lwgeom2), &box2)) )
+	else
 	{
-		PG_FREE_IF_COPY(lwgeom1, 0);
-        	PG_FREE_IF_COPY(lwgeom2, 1);
-		/* One or both are empty geoms */
-        	PG_RETURN_BOOL(FALSE);
+		lwgeom1 = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+		if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom1), &box1) )
+		{
+			PG_FREE_IF_COPY(lwgeom1, 0);
+			PG_RETURN_BOOL(FALSE);
+		}
 	}
+	if ( lwgeom_hasBBOX(ser2[0]) )
+	{
+		memcpy(&box2, ser2 + 1, sizeof(BOX2DFLOAT4));
+	}
+	else
+	{
+		lwgeom2 = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+		if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom2), &box2) )
+		{
+			PG_FREE_IF_COPY(lwgeom2, 0);
+			PG_RETURN_BOOL(FALSE);
+		}
+	}
 
+	POSTGIS_DEBUG(2, "GIST: LWGEOM_overlap --entry");
+	/*
+		if ( pglwgeom_getSRID(lwgeom1) != pglwgeom_getSRID(lwgeom2) )
+		{
+			PG_FREE_IF_COPY(lwgeom1, 0);
+	        	PG_FREE_IF_COPY(lwgeom2, 1);
+			elog(ERROR, "Operation on two geometries with different SRIDs");
+			PG_RETURN_NULL();
+		}
 
+
+		if ( ! (getbox2d_p(SERIALIZED_FORM(lwgeom1), &box1) && getbox2d_p(SERIALIZED_FORM(lwgeom2), &box2)) )
+		{
+			PG_FREE_IF_COPY(lwgeom1, 0);
+	        	PG_FREE_IF_COPY(lwgeom2, 1);
+			/* One or both are empty geoms */
+	/*        	PG_RETURN_BOOL(FALSE);
+		}
+	*/
+
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_overlap,
-		PointerGetDatum(&box1), PointerGetDatum(&box2)));
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
 	POSTGIS_DEBUGF(3, "GIST: lwgeom_overlap:\n(%f %f, %f %f) (%f %f %f %f) = %i",
-		box1.xmin, box1.ymax, box1.xmax, box1.ymax,
-		box2.xmin, box2.ymax, box2.xmax, box2.ymax,
-		result
-		);
+	               box1.xmin, box1.ymax, box1.xmax, box1.ymax,
+	               box2.xmin, box2.ymax, box2.xmax, box2.ymax,
+	               result
+	              );
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -158,12 +194,12 @@
 
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_overleft,
-		PointerGetDatum(&box1), PointerGetDatum(&box2))); 
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 PG_FUNCTION_INFO_V1(LWGEOM_left);
@@ -187,12 +223,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_left,
-		PointerGetDatum(&box1), PointerGetDatum(&box2))); 
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -217,12 +253,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_right,
-		PointerGetDatum(&box1), PointerGetDatum(&box2)));
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -247,12 +283,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_overright,
-		PointerGetDatum(&box1), PointerGetDatum(&box2)));
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -278,12 +314,12 @@
 
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_overbelow,
-		PointerGetDatum(&box1), PointerGetDatum(&box2))); 
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 PG_FUNCTION_INFO_V1(LWGEOM_below);
@@ -307,12 +343,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_below,
-		PointerGetDatum(&box1), PointerGetDatum(&box2))); 
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -337,12 +373,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_above,
-		PointerGetDatum(&box1), PointerGetDatum(&box2)));
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -367,12 +403,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_overabove,
-		PointerGetDatum(&box1), PointerGetDatum(&box2)));
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -397,12 +433,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_contained,
-		PointerGetDatum(&box1), PointerGetDatum(&box2)));
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -427,12 +463,12 @@
 	}
 
 	result = DatumGetBool(DirectFunctionCall2(BOX2D_contain,
-		PointerGetDatum(&box1), PointerGetDatum(&box2)));
+	                      PointerGetDatum(&box1), PointerGetDatum(&box2)));
 
 	PG_FREE_IF_COPY(lwgeom1, 0);
-        PG_FREE_IF_COPY(lwgeom2, 1);
+	PG_FREE_IF_COPY(lwgeom2, 1);
 
-        PG_RETURN_BOOL(result);
+	PG_RETURN_BOOL(result);
 }
 
 
@@ -472,8 +508,8 @@
 #if POSTGIS_DEBUG_LEVEL > 0
 			result = serialized_lwgeom_to_ewkt(&lwg_unparser_result, (uchar *)in+VARHDRSZ, PARSER_CHECK_NONE);
 			POSTGIS_DEBUGF(4, "GIST: LWGEOM_gist_compress detoasted entry->key: %s", lwg_unparser_result.wkoutput);
-#endif		
-	
+#endif
+
 			if (in == NULL)
 			{
 				elog(ERROR, "PG_DETOAST_DATUM(<notnull>) returned NULL ??");
@@ -483,10 +519,10 @@
 			rr = (BOX2DFLOAT4*) palloc(sizeof(BOX2DFLOAT4));
 
 			if (	! getbox2d_p(SERIALIZED_FORM(in), rr) ||
-				! finite(rr->xmin) ||
-				! finite(rr->ymin) ||
-				! finite(rr->xmax) ||
-				! finite(rr->ymax) )
+			                ! finite(rr->xmin) ||
+			                ! finite(rr->ymin) ||
+			                ! finite(rr->xmax) ||
+			                ! finite(rr->ymax) )
 			{
 
 				POSTGIS_DEBUG(4, "found empty or infinite geometry");
@@ -506,14 +542,14 @@
 
 #if POSTGIS_PGSQL_VERSION >= 82
 			gistentryinit(*retval, PointerGetDatum(rr),
-				entry->rel, entry->page,
-				entry->offset,
-				FALSE);
+			              entry->rel, entry->page,
+			              entry->offset,
+			              FALSE);
 #else
 			gistentryinit(*retval, PointerGetDatum(rr),
-				entry->rel, entry->page,
-				entry->offset, sizeof(BOX2DFLOAT4),
-				FALSE);
+			              entry->rel, entry->page,
+			              entry->offset, sizeof(BOX2DFLOAT4),
+			              FALSE);
 #endif
 
 
@@ -524,10 +560,10 @@
 
 #if POSTGIS_PGSQL_VERSION >= 82
 			gistentryinit(*retval, (Datum) 0, entry->rel,
-				entry->page, entry->offset, FALSE);
+			              entry->page, entry->offset, FALSE);
 #else
 			gistentryinit(*retval, (Datum) 0, entry->rel,
-				entry->page, entry->offset, 0, FALSE);
+			              entry->page, entry->offset, 0, FALSE);
 #endif
 
 		}
@@ -572,7 +608,7 @@
 		PG_RETURN_BOOL(false); /* null query - this is screwy! */
 	}
 
-	/* 
+	/*
 	** First pull only a small amount of the tuple, enough to 
 	** get the bounding box, if one exists.
 	*/
@@ -591,13 +627,13 @@
 	** retrieval function, which will calculate the box from scratch.
 	*/
 	serialized_lwgeom = SERIALIZED_FORM(query);
-	if( lwgeom_hasBBOX(serialized_lwgeom[0]) ) 
+	if ( lwgeom_hasBBOX(serialized_lwgeom[0]) )
 	{
 		memcpy(&box, serialized_lwgeom + 1, sizeof(BOX2DFLOAT4));
-	} 
-	else 
+	}
+	else
 	{
-		query = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); 
+		query = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
 		if ( ! getbox2d_p(SERIALIZED_FORM(query), &box) )
 		{
 			PG_FREE_IF_COPY(query, 1);
@@ -607,11 +643,11 @@
 
 	if (GIST_LEAF(entry))
 		result = lwgeom_rtree_leaf_consistent((BOX2DFLOAT4 *)
-			DatumGetPointer(entry->key), &box, strategy );
+		                                      DatumGetPointer(entry->key), &box, strategy );
 	else
 		result = lwgeom_rtree_internal_consistent(
-			(BOX2DFLOAT4 *) DatumGetPointer(entry->key),
-			&box, strategy );
+		                 (BOX2DFLOAT4 *) DatumGetPointer(entry->key),
+		                 &box, strategy );
 
 	PG_FREE_IF_COPY(query, 1);
 	PG_RETURN_BOOL(result);
@@ -620,78 +656,79 @@
 
 static bool
 lwgeom_rtree_internal_consistent(BOX2DFLOAT4 *key, BOX2DFLOAT4 *query,
-	StrategyNumber strategy)
+                                 StrategyNumber strategy)
 {
 	bool retval;
 
 	POSTGIS_DEBUGF(2, "GIST: lwgeom_rtree_internal_consistent called with strategy=%i", strategy);
 
-	switch(strategy) {
-		case RTLeftStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overright, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTOverLeftStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_right, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTOverlapStrategyNumber:  /*optimized for speed */
+	switch (strategy)
+	{
+	case RTLeftStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overright, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTOverLeftStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_right, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTOverlapStrategyNumber:  /*optimized for speed */
 
-		        retval = (((key->xmax>= query->xmax) &&
-				 (key->xmin <= query->xmax)) ||
-				((query->xmax>= key->xmax) &&
-				 (query->xmin<= key->xmax)))
-				&&
-				(((key->ymax>= query->ymax) &&
-		  		(key->ymin<= query->ymax)) ||
-		 		((query->ymax>= key->ymax) &&
-		  		(query->ymin<= key->ymax)));
+		retval = (((key->xmax>= query->xmax) &&
+		           (key->xmin <= query->xmax)) ||
+		          ((query->xmax>= key->xmax) &&
+		           (query->xmin<= key->xmax)))
+		         &&
+		         (((key->ymax>= query->ymax) &&
+		           (key->ymin<= query->ymax)) ||
+		          ((query->ymax>= key->ymax) &&
+		           (query->ymin<= key->ymax)));
 
 
 #if POSTGIS_DEBUG_LEVEL >=4
-			/*keep track and report info about how many times this is called */
-			if (counter_intern == 0)
-			{
-				POSTGIS_DEBUGF(4, "search bounding box is: <%.16g %.16g,%.16g %.16g> - size box2d= %ld",
-				 	query->xmin,query->ymin,query->xmax,query->ymax,sizeof(BOX2DFLOAT4));
+		/*keep track and report info about how many times this is called */
+		if (counter_intern == 0)
+		{
+			POSTGIS_DEBUGF(4, "search bounding box is: <%.16g %.16g,%.16g %.16g> - size box2d= %ld",
+			               query->xmin,query->ymin,query->xmax,query->ymax,sizeof(BOX2DFLOAT4));
 
-			}
+		}
 
 
-			POSTGIS_DEBUGF(4, "%i:(int)<%.8g %.8g,%.8g %.8g>&&<%.8g %.8g,%.8g %.8g> %i",counter_intern,key->xmin,key->ymin,key->xmax,key->ymax,
-		  			query->xmin,query->ymin,query->xmax,query->ymax,   (int) retval);
-		
-			counter_intern++;
+		POSTGIS_DEBUGF(4, "%i:(int)<%.8g %.8g,%.8g %.8g>&&<%.8g %.8g,%.8g %.8g> %i",counter_intern,key->xmin,key->ymin,key->xmax,key->ymax,
+		               query->xmin,query->ymin,query->xmax,query->ymax,   (int) retval);
+
+		counter_intern++;
 #endif
 
-			return(retval);
-			break;
+		return(retval);
+		break;
 
-		case RTOverRightStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_left, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTRightStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overleft, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTOverBelowStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_above, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTBelowStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overabove, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTAboveStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overbelow, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTOverAboveStrategyNumber:
-			retval = !DatumGetBool( DirectFunctionCall2( BOX2D_below, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTSameStrategyNumber:
-		case RTContainsStrategyNumber:
-			retval = DatumGetBool( DirectFunctionCall2( BOX2D_contain, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		case RTContainedByStrategyNumber:
-			retval = DatumGetBool( DirectFunctionCall2( BOX2D_overlap, PointerGetDatum(key), PointerGetDatum(query) ) );
-			break;
-		default:
-			retval = FALSE;
+	case RTOverRightStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_left, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTRightStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overleft, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTOverBelowStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_above, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTBelowStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overabove, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTAboveStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_overbelow, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTOverAboveStrategyNumber:
+		retval = !DatumGetBool( DirectFunctionCall2( BOX2D_below, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTSameStrategyNumber:
+	case RTContainsStrategyNumber:
+		retval = DatumGetBool( DirectFunctionCall2( BOX2D_contain, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	case RTContainedByStrategyNumber:
+		retval = DatumGetBool( DirectFunctionCall2( BOX2D_overlap, PointerGetDatum(key), PointerGetDatum(query) ) );
+		break;
+	default:
+		retval = FALSE;
 	}
 	return(retval);
 }
@@ -699,7 +736,7 @@
 
 static bool
 lwgeom_rtree_leaf_consistent(BOX2DFLOAT4 *key,
-	BOX2DFLOAT4 *query, StrategyNumber strategy)
+                             BOX2DFLOAT4 *query, StrategyNumber strategy)
 {
 	bool retval;
 
@@ -707,62 +744,62 @@
 
 	switch (strategy)
 	{
-		case RTLeftStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_left, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTOverLeftStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_overleft, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTOverlapStrategyNumber: /*optimized for speed */
-			retval = (((key->xmax>= query->xmax) &&
-				 (key->xmin <= query->xmax)) ||
-				 ((query->xmax>= key->xmax) &&
-	   			 (query->xmin<= key->xmax)))
-			   	 &&
-				 (((key->ymax>= query->ymax) &&
-				 (key->ymin<= query->ymax)) ||
-				 ((query->ymax>= key->ymax) &&
-				 (query->ymin<= key->ymax)));
+	case RTLeftStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_left, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTOverLeftStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_overleft, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTOverlapStrategyNumber: /*optimized for speed */
+		retval = (((key->xmax>= query->xmax) &&
+		           (key->xmin <= query->xmax)) ||
+		          ((query->xmax>= key->xmax) &&
+		           (query->xmin<= key->xmax)))
+		         &&
+		         (((key->ymax>= query->ymax) &&
+		           (key->ymin<= query->ymax)) ||
+		          ((query->ymax>= key->ymax) &&
+		           (query->ymin<= key->ymax)));
 
 #if POSTGIS_DEBUG_LEVEL >= 4
-			/*keep track and report info about how many times this is called */
-			POSTGIS_DEBUGF(4, "%i:gist test (leaf) <%.6g %.6g,%.6g %.6g> &&  <%.6g %.6g,%.6g %.6g> --> %i",
-				counter_leaf,key->xmin,key->ymin,key->xmax,key->ymax,
-				query->xmin,query->ymin,query->xmax,query->ymax,   (int) retval);
-			counter_leaf++;
+		/*keep track and report info about how many times this is called */
+		POSTGIS_DEBUGF(4, "%i:gist test (leaf) <%.6g %.6g,%.6g %.6g> &&  <%.6g %.6g,%.6g %.6g> --> %i",
+		               counter_leaf,key->xmin,key->ymin,key->xmax,key->ymax,
+		               query->xmin,query->ymin,query->xmax,query->ymax,   (int) retval);
+		counter_leaf++;
 #endif
-			return(retval);
+		return(retval);
 
-			break;
-		case RTOverRightStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_overright, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTRightStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_right, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTOverBelowStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_overbelow, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTBelowStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_below, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTAboveStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_above, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTOverAboveStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_overabove, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTSameStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_same, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTContainsStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_contain, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		case RTContainedByStrategyNumber:
-			retval = DatumGetBool(DirectFunctionCall2(BOX2D_contained, PointerGetDatum(key), PointerGetDatum(query)));
-			break;
-		default:
-			retval = FALSE;
+		break;
+	case RTOverRightStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_overright, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTRightStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_right, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTOverBelowStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_overbelow, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTBelowStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_below, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTAboveStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_above, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTOverAboveStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_overabove, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTSameStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_same, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTContainsStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_contain, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	case RTContainedByStrategyNumber:
+		retval = DatumGetBool(DirectFunctionCall2(BOX2D_contained, PointerGetDatum(key), PointerGetDatum(query)));
+		break;
+	default:
+		retval = FALSE;
 	}
 	return (retval);
 }
@@ -790,17 +827,17 @@
 PG_FUNCTION_INFO_V1(LWGEOM_gist_union);
 Datum LWGEOM_gist_union(PG_FUNCTION_ARGS)
 {
- 	GistEntryVector	*entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+	GistEntryVector	*entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 
 	int		   *sizep = (int *) PG_GETARG_POINTER(1);
 	int			numranges,
-				i;
+	i;
 	BOX2DFLOAT4 *cur,
-			   *pageunion;
+	*pageunion;
 
 	POSTGIS_DEBUG(2, "GIST: LWGEOM_gist_union called\n");
 
-  	numranges = entryvec->n;
+	numranges = entryvec->n;
 	cur = (BOX2DFLOAT4 *) DatumGetPointer(entryvec->vector[0].key);
 
 	pageunion = (BOX2DFLOAT4 *) palloc(sizeof(BOX2DFLOAT4));
@@ -938,13 +975,16 @@
 	PG_RETURN_POINTER(result);
 }
 
-typedef struct {
+typedef struct
+{
 	BOX2DFLOAT4 	*key;
 	int 	pos;
-} KBsort;
+}
+KBsort;
 
 static int
-compare_KB(const void* a, const void* b) {
+compare_KB(const void* a, const void* b)
+{
 	BOX2DFLOAT4 *abox = ((KBsort*)a)->key;
 	BOX2DFLOAT4 *bbox = ((KBsort*)b)->key;
 	float sa = (abox->xmax - abox->xmin) * (abox->ymax - abox->ymin);
@@ -983,7 +1023,7 @@
 PG_FUNCTION_INFO_V1(LWGEOM_gist_picksplit);
 Datum LWGEOM_gist_picksplit(PG_FUNCTION_ARGS)
 {
-  	GistEntryVector	*entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+	GistEntryVector	*entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 
 	GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
 	OffsetNumber i;
@@ -1001,8 +1041,8 @@
 
 	posL = posR = posB = posT = 0;
 
-  	maxoff = entryvec->n - 1;
-  	cur = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[FirstOffsetNumber].key);
+	maxoff = entryvec->n - 1;
+	cur = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[FirstOffsetNumber].key);
 
 	memcpy((void *) &pageunion, (void *) cur, sizeof(BOX2DFLOAT4));
 
@@ -1012,14 +1052,14 @@
 	/* find MBR */
 	for (i = OffsetNumberNext(FirstOffsetNumber); i <= maxoff; i = OffsetNumberNext(i))
 	{
-  		cur = (BOX2DFLOAT4 *) DatumGetPointer(entryvec->vector[i].key);
+		cur = (BOX2DFLOAT4 *) DatumGetPointer(entryvec->vector[i].key);
 
 		if ( allisequal == true &&  (
-				pageunion.xmax != cur->xmax ||
-				pageunion.ymax != cur->ymax ||
-				pageunion.xmin != cur->xmin ||
-				pageunion.ymin != cur->ymin
-			) )
+		                        pageunion.xmax != cur->xmax ||
+		                        pageunion.ymax != cur->ymax ||
+		                        pageunion.xmin != cur->xmin ||
+		                        pageunion.ymin != cur->ymin
+		                ) )
 			allisequal = false;
 
 		if (pageunion.xmax < cur->xmax)
@@ -1044,7 +1084,7 @@
 	{
 		POSTGIS_DEBUG(4, " AllIsEqual!");
 
-  		cur = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[OffsetNumberNext(FirstOffsetNumber)].key);
+		cur = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[OffsetNumberNext(FirstOffsetNumber)].key);
 
 
 		if (memcmp((void *) cur, (void *) &pageunion, sizeof(BOX2DFLOAT4)) == 0)
@@ -1096,7 +1136,7 @@
 
 	for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
 	{
-  		cur = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[i].key);
+		cur = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[i].key);
 
 		if (cur->xmin - pageunion.xmin < pageunion.xmax - cur->xmax)
 			ADDLIST(listL, unionL, posL,i);
@@ -1116,34 +1156,41 @@
 
 
 	/* bad disposition, sort by ascending and resplit */
-	if ( (posR==0 || posL==0) && (posT==0 || posB==0) ) {
+	if ( (posR==0 || posL==0) && (posT==0 || posB==0) )
+	{
 		KBsort *arr = (KBsort*)palloc( sizeof(KBsort) * maxoff );
 		posL = posR = posB = posT = 0;
-		for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) {
-  			arr[i-1].key = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[i].key);
+		for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+		{
+			arr[i-1].key = (BOX2DFLOAT4*) DatumGetPointer(entryvec->vector[i].key);
 			arr[i-1].pos = i;
 		}
 		qsort( arr, maxoff, sizeof(KBsort), compare_KB );
-		for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) {
+		for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+		{
 			cur = arr[i-1].key;
 			if (cur->xmin - pageunion.xmin < pageunion.xmax - cur->xmax)
 				ADDLIST(listL, unionL, posL,arr[i-1].pos);
-			else if ( cur->xmin - pageunion.xmin == pageunion.xmax - cur->xmax ) {
+			else if ( cur->xmin - pageunion.xmin == pageunion.xmax - cur->xmax )
+			{
 				if ( posL>posR )
 					ADDLIST(listR, unionR, posR,arr[i-1].pos);
 				else
 					ADDLIST(listL, unionL, posL,arr[i-1].pos);
-			} else
+			}
+			else
 				ADDLIST(listR, unionR, posR,arr[i-1].pos);
 
 			if (cur->ymin - pageunion.ymin < pageunion.ymax - cur->ymax)
 				ADDLIST(listB, unionB, posB,arr[i-1].pos);
-			else if ( cur->ymin - pageunion.ymin == pageunion.ymax - cur->ymax ) {
+			else if ( cur->ymin - pageunion.ymin == pageunion.ymax - cur->ymax )
+			{
 				if ( posB>posT )
 					ADDLIST(listT, unionT, posT,arr[i-1].pos);
 				else
 					ADDLIST(listB, unionB, posB,arr[i-1].pos);
-			} else
+			}
+			else
 				ADDLIST(listT, unionT, posT,arr[i-1].pos);
 		}
 		pfree(arr);
@@ -1157,9 +1204,9 @@
 	else
 	{
 		Datum interLR = DirectFunctionCall2(BOX2D_intersects,
-			PointerGetDatum(unionL), PointerGetDatum(unionR));
+		                                    PointerGetDatum(unionL), PointerGetDatum(unionR));
 		Datum interBT = DirectFunctionCall2(BOX2D_intersects,
-			PointerGetDatum(unionB), PointerGetDatum(unionT));
+		                                    PointerGetDatum(unionB), PointerGetDatum(unionT));
 		float sizeLR, sizeBT;
 
 		/*elog(NOTICE,"direction is abigeous"); */
@@ -1193,29 +1240,29 @@
 		v->spl_rdatum = PointerGetDatum(unionR);
 
 #if POSTGIS_DEBUG_LEVEL >= 4
-	{
-		char aaa[5000],bbb[100];
-		aaa[0] = 0;
+		{
+			char aaa[5000],bbb[100];
+			aaa[0] = 0;
 
-		POSTGIS_DEBUGF(4, "   split direction was '%c'", direction);
-		POSTGIS_DEBUGF(4, "   posL = %i, posR=%i", posL,posR);
-		POSTGIS_DEBUG(4, "   posL's (nleft) offset numbers:");
+			POSTGIS_DEBUGF(4, "   split direction was '%c'", direction);
+			POSTGIS_DEBUGF(4, "   posL = %i, posR=%i", posL,posR);
+			POSTGIS_DEBUG(4, "   posL's (nleft) offset numbers:");
 
-		for (i=0;i<posL;i++)
-		{
-			sprintf(bbb," %i", listL[i]);
-			strcat(aaa,bbb);
+			for (i=0;i<posL;i++)
+			{
+				sprintf(bbb," %i", listL[i]);
+				strcat(aaa,bbb);
+			}
+			POSTGIS_DEBUGF(4, "%s", aaa);
+			aaa[0]=0;
+			POSTGIS_DEBUG(4, "   posR's (nright) offset numbers:");
+			for (i=0;i<posR;i++)
+			{
+				sprintf(bbb," %i", listR[i]);
+				strcat(aaa,bbb);
+			}
+			POSTGIS_DEBUGF(4, "%s", aaa);
 		}
-		POSTGIS_DEBUGF(4, "%s", aaa);
-		aaa[0]=0;
-		POSTGIS_DEBUG(4, "   posR's (nright) offset numbers:");
-		for (i=0;i<posR;i++)
-		{
-			sprintf(bbb," %i", listR[i]);
-			strcat(aaa,bbb);
-		}
-		POSTGIS_DEBUGF(4, "%s", aaa);
-	}
 #endif
 
 
@@ -1234,30 +1281,30 @@
 		v->spl_ldatum = PointerGetDatum(unionB);
 		v->spl_rdatum = PointerGetDatum(unionT);
 
-#if POSTGIS_DEBUG_LEVEL >= 4 
-	{
-		char aaa[5000],bbb[100];
-		aaa[0]=0;
+#if POSTGIS_DEBUG_LEVEL >= 4
+		{
+			char aaa[5000],bbb[100];
+			aaa[0]=0;
 
-		POSTGIS_DEBUGF(4, "   split direction was '%c'", direction);
-		POSTGIS_DEBUGF(4, "   posB = %i, posT=%i", posB,posT);
-		POSTGIS_DEBUG(4, "   posB's (nleft) offset numbers:");
+			POSTGIS_DEBUGF(4, "   split direction was '%c'", direction);
+			POSTGIS_DEBUGF(4, "   posB = %i, posT=%i", posB,posT);
+			POSTGIS_DEBUG(4, "   posB's (nleft) offset numbers:");
 
-		for (i=0;i<posB;i++)
-		{
-			sprintf(bbb," %i", listB[i]);
-			strcat(aaa,bbb);
+			for (i=0;i<posB;i++)
+			{
+				sprintf(bbb," %i", listB[i]);
+				strcat(aaa,bbb);
+			}
+			POSTGIS_DEBUGF(4, "%s", aaa);
+			aaa[0]=0;
+			POSTGIS_DEBUG(4, "   posT's (nright) offset numbers:");
+			for (i=0;i<posT;i++)
+			{
+				sprintf(bbb," %i", listT[i]);
+				strcat(aaa,bbb);
+			}
+			POSTGIS_DEBUGF(4, "%s", aaa);
 		}
-		POSTGIS_DEBUGF(4, "%s", aaa);
-		aaa[0]=0;
-		POSTGIS_DEBUG(4, "   posT's (nright) offset numbers:");
-		for (i=0;i<posT;i++)
-		{
-			sprintf(bbb," %i", listT[i]);
-			strcat(aaa,bbb);
-		}
-		POSTGIS_DEBUGF(4, "%s", aaa);
-	}
 #endif
 
 



More information about the postgis-commits mailing list