]> granicus.if.org Git - postgis/commitdiff
[format] clang-format files touched in SFCGAL relayout
authorDarafei Praliaskouski <me@komzpa.net>
Fri, 30 Nov 2018 18:00:34 +0000 (18:00 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Fri, 30 Nov 2018 18:00:34 +0000 (18:00 +0000)
References #4258

git-svn-id: http://svn.osgeo.org/postgis/trunk@17093 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_sfcgal.c
liblwgeom/lwgeom_sfcgal.c
liblwgeom/lwgeom_sfcgal.h
postgis/lwgeom_backend_api.c
postgis/lwgeom_functions_basic.c
postgis/lwgeom_sfcgal.c
postgis/lwgeom_sfcgal.h

index 523562f0e78844d2b1a2a245cdb130602e5c9a0f..0cba17319b06fa711238f8c68a381cb8560f0f0b 100644 (file)
 #include "cu_tester.h"
 #include "liblwgeom.h"
 
-extern LWGEOM* lwgeom_sfcgal_noop( const LWGEOM* geom_in );
+extern LWGEOM *lwgeom_sfcgal_noop(const LWGEOM *geom_in);
 
-static void test_sfcgal_noop(void)
+static void
+test_sfcgal_noop(void)
 {
        size_t i;
 
-       char *ewkt[] =
-       {
-               "POINT(0 0.2)",
-               "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
-               "TRIANGLE((0 0,-1 1,0 -1,0 0))",
-               "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
-               "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
-               "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
-               "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
-               "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
-               "SRID=4326;POLYGON((-1 -1 1,-1 2.5 1,2 2 2,2 -1 2,-1 -1 2),(0 0 1,0 1 1,1 1 1,1 0 2,0 0 2))",
-               "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
-               "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
-               "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
-               "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
-               "POLYHEDRALSURFACE(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
-               "POLYHEDRALSURFACE(((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)),((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)))",
-               "TIN(((0 0,0 -1,-1 1,0 0)),((0 0,1 0,0 -1,0 0)))",
+       char *ewkt[] = {
+           "POINT(0 0.2)",
+           "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
+           "TRIANGLE((0 0,-1 1,0 -1,0 0))",
+           "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
+           "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+           "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+           "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+           "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+           "SRID=4326;POLYGON((-1 -1 1,-1 2.5 1,2 2 2,2 -1 2,-1 -1 2),(0 0 1,0 1 1,1 1 1,1 0 2,0 0 2))",
+           "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
+           "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
+           "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
+           "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
+           "POLYHEDRALSURFACE(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
+           "POLYHEDRALSURFACE(((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)),((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)))",
+           "TIN(((0 0,0 -1,-1 1,0 0)),((0 0,1 0,0 -1,0 0)))",
        };
 
-       char *expected_ewkt[] =
-       {
-               "POINT(0 0.2)",
-               "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
-               "TRIANGLE((0 0,-1 1,0 -1,0 0))",
-               "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
-               "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
-               "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
-               "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
-               "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
-               "SRID=4326;POLYGON((-1 -1 1,-1 2.5 1,2 2 2,2 -1 2,-1 -1 2),(0 0 1,0 1 1,1 1 1,1 0 2,0 0 2))",
-               "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
-               "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
-               "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
-               "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
-               "POLYHEDRALSURFACE(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
-               "POLYHEDRALSURFACE(((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)),((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)))",
-               "TIN(((0 0,0 -1,-1 1,0 0)),((0 0,1 0,0 -1,0 0)))",
+       char *expected_ewkt[] = {
+           "POINT(0 0.2)",
+           "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
+           "TRIANGLE((0 0,-1 1,0 -1,0 0))",
+           "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
+           "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+           "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+           "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+           "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+           "SRID=4326;POLYGON((-1 -1 1,-1 2.5 1,2 2 2,2 -1 2,-1 -1 2),(0 0 1,0 1 1,1 1 1,1 0 2,0 0 2))",
+           "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
+           "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
+           "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
+           "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
+           "POLYHEDRALSURFACE(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
+           "POLYHEDRALSURFACE(((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)),((-1 -1 1,-1 2.5 1,2 2 1,2 -1 1,-1 -1 1),(0 0 1,0 1 1,1 1 1,1 0 1,0 0 1),(-0.5 -0.5 1,-0.5 -0.4 1,-0.4 -0.4 1,-0.4 -0.5 1,-0.5 -0.5 1)))",
+           "TIN(((0 0,0 -1,-1 1,0 0)),((0 0,1 0,0 -1,0 0)))",
        };
 
-       for ( i = 0; i < (sizeof ewkt/sizeof(char *)); i++ )
+       for (i = 0; i < (sizeof ewkt / sizeof(char *)); i++)
        {
                LWGEOM *geom_in, *geom_out;
                char *in_ewkt;
@@ -72,7 +71,8 @@ static void test_sfcgal_noop(void)
                in_ewkt = ewkt[i];
                geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
                geom_out = lwgeom_sfcgal_noop(geom_in);
-               if ( ! geom_out ) {
+               if (!geom_out)
+               {
                        fprintf(stderr, "\nNull return from lwgeom_sfcgal_noop with wkt:   %s\n", in_ewkt);
                        lwgeom_free(geom_in);
                        continue;
@@ -87,12 +87,12 @@ static void test_sfcgal_noop(void)
        }
 }
 
-
 /*
 ** Used by test harness to register the tests in this file.
 */
 void sfcgal_suite_setup(void);
-void sfcgal_suite_setup(void)
+void
+sfcgal_suite_setup(void)
 {
        CU_pSuite suite = CU_add_suite("sfcgal", NULL, NULL);
        PG_ADD_TEST(suite, test_sfcgal_noop);
index ac9760016ddef238d6583a391c105f4d2385d7f1..bf4c93db08832f8e24d22261f6c2263812931815 100644 (file)
  *
  **********************************************************************/
 
-
 #include "lwgeom_sfcgal.h"
 
 static int SFCGAL_type_to_lwgeom_type(sfcgal_geometry_type_t type);
-static POINTARRAY* ptarray_from_SFCGAL(const sfcgal_geometry_t* geom, int force3D);
-static sfcgal_geometry_t* ptarray_to_SFCGAL(const POINTARRAY* pa, int type);
-
-
+static POINTARRAY *ptarray_from_SFCGAL(const sfcgal_geometry_t *geom, int force3D);
+static sfcgal_geometry_t *ptarray_to_SFCGAL(const POINTARRAY *pa, int type);
 
 /* Return SFCGAL version string */
-const char*
+const char *
 lwgeom_sfcgal_version()
 {
-        const char *version = sfcgal_version();
-        return version;
+       const char *version = sfcgal_version();
+       return version;
 }
 
-
 /*
  * Mapping between SFCGAL and PostGIS types
  *
@@ -69,9 +65,9 @@ SFCGAL_type_to_lwgeom_type(sfcgal_geometry_type_t type)
                return MULTIPOLYGONTYPE;
 
        case SFCGAL_TYPE_MULTISOLID:
-               return COLLECTIONTYPE;  /* Nota: PolyhedralSurface closed inside
-                                          aim is to use true solid type as soon
-                                          as available in OGC SFS */
+               return COLLECTIONTYPE; /* Nota: PolyhedralSurface closed inside
+                                         aim is to use true solid type as soon
+                                         as available in OGC SFS */
 
        case SFCGAL_TYPE_GEOMETRYCOLLECTION:
                return COLLECTIONTYPE;
@@ -108,19 +104,18 @@ SFCGAL_type_to_lwgeom_type(sfcgal_geometry_type_t type)
        }
 }
 
-
 /*
  * Return a PostGIS pointarray from a simple SFCGAL geometry:
  * POINT, LINESTRING or TRIANGLE
  *
  * Throw an error on others types
  */
-static POINTARRAY*
-ptarray_from_SFCGAL(const sfcgal_geometry_tgeom, int want3d)
+static POINTARRAY *
+ptarray_from_SFCGAL(const sfcgal_geometry_t *geom, int want3d)
 {
        POINT4D point;
        uint32_t i, npoints;
-       POINTARRAYpa = NULL;
+       POINTARRAY *pa = NULL;
 
        assert(geom);
 
@@ -148,7 +143,7 @@ ptarray_from_SFCGAL(const sfcgal_geometry_t* geom, int want3d)
 
                for (i = 0; i < npoints; i++)
                {
-                       const sfcgal_geometry_tpt = sfcgal_linestring_point_n(geom, i);
+                       const sfcgal_geometry_t *pt = sfcgal_linestring_point_n(geom, i);
                        point.x = sfcgal_point_x(pt);
                        point.y = sfcgal_point_y(pt);
 
@@ -168,11 +163,11 @@ ptarray_from_SFCGAL(const sfcgal_geometry_t* geom, int want3d)
 
                for (i = 0; i < 4; i++)
                {
-                       const sfcgal_geometry_t* pt = sfcgal_triangle_vertex(geom, (i%3));
+                       const sfcgal_geometry_t *pt = sfcgal_triangle_vertex(geom, (i % 3));
                        point.x = sfcgal_point_x(pt);
                        point.y = sfcgal_point_y(pt);
 
-                       if ( sfcgal_geometry_is_3d(geom))
+                       if (sfcgal_geometry_is_3d(geom))
                                point.z = sfcgal_point_z(pt);
                        else if (want3d)
                                point.z = 0.0;
@@ -190,15 +185,14 @@ ptarray_from_SFCGAL(const sfcgal_geometry_t* geom, int want3d)
        return pa;
 }
 
-
 /*
  * Convert a PostGIS pointarray to SFCGAL structure
  *
  * Used for simple LWGEOM geometry POINT, LINESTRING, TRIANGLE
  * and POLYGON rings
  */
-static sfcgal_geometry_t*
-ptarray_to_SFCGAL(const POINTARRAYpa, int type)
+static sfcgal_geometry_t *
+ptarray_to_SFCGAL(const POINTARRAY *pa, int type)
 {
        POINT3DZ point;
        int is_3d;
@@ -213,14 +207,16 @@ ptarray_to_SFCGAL(const POINTARRAY* pa, int type)
        case POINTTYPE:
        {
                getPoint3dz_p(pa, 0, &point);
-               if (is_3d) return sfcgal_point_create_from_xyz(point.x, point.y, point.z);
-               else       return sfcgal_point_create_from_xy(point.x, point.y);
+               if (is_3d)
+                       return sfcgal_point_create_from_xyz(point.x, point.y, point.z);
+               else
+                       return sfcgal_point_create_from_xy(point.x, point.y);
        }
        break;
 
        case LINETYPE:
        {
-               sfcgal_geometry_tline = sfcgal_linestring_create();
+               sfcgal_geometry_t *line = sfcgal_linestring_create();
 
                for (i = 0; i < pa->npoints; i++)
                {
@@ -228,12 +224,11 @@ ptarray_to_SFCGAL(const POINTARRAY* pa, int type)
                        if (is_3d)
                        {
                                sfcgal_linestring_add_point(line,
-                                                           sfcgal_point_create_from_xyz(point.x, point.y, point.z));
+                                                           sfcgal_point_create_from_xyz(point.x, point.y, point.z));
                        }
                        else
                        {
-                               sfcgal_linestring_add_point(line,
-                                                           sfcgal_point_create_from_xy(point.x, point.y));
+                               sfcgal_linestring_add_point(line, sfcgal_point_create_from_xy(point.x, point.y));
                        }
                }
 
@@ -243,19 +238,25 @@ ptarray_to_SFCGAL(const POINTARRAY* pa, int type)
 
        case TRIANGLETYPE:
        {
-               sfcgal_geometry_ttriangle = sfcgal_triangle_create();
+               sfcgal_geometry_t *triangle = sfcgal_triangle_create();
 
                getPoint3dz_p(pa, 0, &point);
-               if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 0, point.x, point.y, point.z);
-               else       sfcgal_triangle_set_vertex_from_xy (triangle, 0, point.x, point.y);
+               if (is_3d)
+                       sfcgal_triangle_set_vertex_from_xyz(triangle, 0, point.x, point.y, point.z);
+               else
+                       sfcgal_triangle_set_vertex_from_xy(triangle, 0, point.x, point.y);
 
                getPoint3dz_p(pa, 1, &point);
-               if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 1, point.x, point.y, point.z);
-               else       sfcgal_triangle_set_vertex_from_xy (triangle, 1, point.x, point.y);
+               if (is_3d)
+                       sfcgal_triangle_set_vertex_from_xyz(triangle, 1, point.x, point.y, point.z);
+               else
+                       sfcgal_triangle_set_vertex_from_xy(triangle, 1, point.x, point.y);
 
                getPoint3dz_p(pa, 2, &point);
-               if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 2, point.x, point.y, point.z);
-               else       sfcgal_triangle_set_vertex_from_xy (triangle, 2, point.x, point.y);
+               if (is_3d)
+                       sfcgal_triangle_set_vertex_from_xyz(triangle, 2, point.x, point.y, point.z);
+               else
+                       sfcgal_triangle_set_vertex_from_xy(triangle, 2, point.x, point.y);
 
                return triangle;
        }
@@ -268,14 +269,13 @@ ptarray_to_SFCGAL(const POINTARRAY* pa, int type)
        }
 }
 
-
 /*
  * Convert a SFCGAL structure to PostGIS LWGEOM
  *
  * Throws an error on unsupported type
  */
-LWGEOM*
-SFCGAL2LWGEOM(const sfcgal_geometry_tgeom, int force3D, int srid)
+LWGEOM *
+SFCGAL2LWGEOM(const sfcgal_geometry_t *geom, int force3D, int srid)
 {
        uint32_t ngeoms, nshells, nsolids;
        uint32_t i, j, k;
@@ -290,43 +290,43 @@ SFCGAL2LWGEOM(const sfcgal_geometry_t* geom, int force3D, int srid)
        case SFCGAL_TYPE_POINT:
        {
                if (sfcgal_geometry_is_empty(geom))
-                       return (LWGEOM*) lwpoint_construct_empty(srid, want3d, 0);
+                       return (LWGEOM *)lwpoint_construct_empty(srid, want3d, 0);
 
-               POINTARRAYpa = ptarray_from_SFCGAL(geom, want3d);
-               return (LWGEOM*) lwpoint_construct(srid, NULL, pa);
+               POINTARRAY *pa = ptarray_from_SFCGAL(geom, want3d);
+               return (LWGEOM *)lwpoint_construct(srid, NULL, pa);
        }
 
        case SFCGAL_TYPE_LINESTRING:
        {
                if (sfcgal_geometry_is_empty(geom))
-                       return (LWGEOM*) lwline_construct_empty(srid, want3d, 0);
+                       return (LWGEOM *)lwline_construct_empty(srid, want3d, 0);
 
-               POINTARRAYpa = ptarray_from_SFCGAL(geom, want3d);
-               return (LWGEOM*) lwline_construct(srid, NULL, pa);
+               POINTARRAY *pa = ptarray_from_SFCGAL(geom, want3d);
+               return (LWGEOM *)lwline_construct(srid, NULL, pa);
        }
 
        case SFCGAL_TYPE_TRIANGLE:
        {
                if (sfcgal_geometry_is_empty(geom))
-                       return (LWGEOM*) lwtriangle_construct_empty(srid, want3d, 0);
+                       return (LWGEOM *)lwtriangle_construct_empty(srid, want3d, 0);
 
-               POINTARRAYpa = ptarray_from_SFCGAL(geom, want3d);
-               return (LWGEOM*) lwtriangle_construct(srid, NULL, pa);
+               POINTARRAY *pa = ptarray_from_SFCGAL(geom, want3d);
+               return (LWGEOM *)lwtriangle_construct(srid, NULL, pa);
        }
 
        case SFCGAL_TYPE_POLYGON:
        {
                if (sfcgal_geometry_is_empty(geom))
-                       return (LWGEOM*) lwpoly_construct_empty(srid, want3d, 0);
+                       return (LWGEOM *)lwpoly_construct_empty(srid, want3d, 0);
 
                uint32_t nrings = sfcgal_polygon_num_interior_rings(geom) + 1;
-               POINTARRAY** pa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*) * nrings);
+               POINTARRAY **pa = (POINTARRAY **)lwalloc(sizeof(POINTARRAY *) * nrings);
 
                pa[0] = ptarray_from_SFCGAL(sfcgal_polygon_exterior_ring(geom), want3d);
                for (i = 1; i < nrings; i++)
-                       pa[i] = ptarray_from_SFCGAL(sfcgal_polygon_interior_ring_n(geom, i-1), want3d);
+                       pa[i] = ptarray_from_SFCGAL(sfcgal_polygon_interior_ring_n(geom, i - 1), want3d);
 
-               return (LWGEOM*) lwpoly_construct(srid, NULL, nrings, pa);
+               return (LWGEOM *)lwpoly_construct(srid, NULL, nrings, pa);
        }
 
        case SFCGAL_TYPE_MULTIPOINT:
@@ -336,25 +336,29 @@ SFCGAL2LWGEOM(const sfcgal_geometry_t* geom, int force3D, int srid)
        case SFCGAL_TYPE_GEOMETRYCOLLECTION:
        {
                ngeoms = sfcgal_geometry_collection_num_geometries(geom);
-               LWGEOM** geoms = NULL;
+               LWGEOM **geoms = NULL;
                if (ngeoms)
                {
                        nsolids = 0;
-                       geoms = (LWGEOM**) lwalloc(sizeof(LWGEOM*) * ngeoms);
+                       geoms = (LWGEOM **)lwalloc(sizeof(LWGEOM *) * ngeoms);
                        for (i = 0; i < ngeoms; i++)
                        {
-                               const sfcgal_geometry_tg = sfcgal_geometry_collection_geometry_n(geom, i);
+                               const sfcgal_geometry_t *g = sfcgal_geometry_collection_geometry_n(geom, i);
                                geoms[i] = SFCGAL2LWGEOM(g, 0, srid);
-                               if ( FLAGS_GET_SOLID( geoms[i]->flags ) ) ++nsolids;
+                               if (FLAGS_GET_SOLID(geoms[i]->flags))
+                                       ++nsolids;
                        }
-                       geoms = (LWGEOM**) lwrealloc(geoms, sizeof(LWGEOM*) * ngeoms);
+                       geoms = (LWGEOM **)lwrealloc(geoms, sizeof(LWGEOM *) * ngeoms);
                }
-               LWGEOM* rgeom = (LWGEOM*) lwcollection_construct(SFCGAL_type_to_lwgeom_type(
-                               sfcgal_geometry_type_id(geom)), srid, NULL, ngeoms, geoms);
-               if ( ngeoms )
+               LWGEOM *rgeom = (LWGEOM *)lwcollection_construct(
+                   SFCGAL_type_to_lwgeom_type(sfcgal_geometry_type_id(geom)), srid, NULL, ngeoms, geoms);
+               if (ngeoms)
                {
-                       if ( ngeoms == nsolids ) FLAGS_SET_SOLID( rgeom->flags, 1);
-                       else if ( nsolids ) lwnotice("SFCGAL2LWGEOM: SOLID in heterogeneous collection will be treated as a POLYHEDRALSURFACETYPE");
+                       if (ngeoms == nsolids)
+                               FLAGS_SET_SOLID(rgeom->flags, 1);
+                       else if (nsolids)
+                               lwnotice(
+                                   "SFCGAL2LWGEOM: SOLID in heterogeneous collection will be treated as a POLYHEDRALSURFACETYPE");
                }
                return rgeom;
        }
@@ -375,17 +379,17 @@ SFCGAL2LWGEOM(const sfcgal_geometry_t* geom, int force3D, int srid)
        {
                ngeoms = sfcgal_polyhedral_surface_num_polygons(geom);
 
-               LWGEOM** geoms = NULL;
+               LWGEOM **geoms = NULL;
                if (ngeoms)
                {
-                       geoms = (LWGEOM**) lwalloc(sizeof(LWGEOM*) * ngeoms);
+                       geoms = (LWGEOM **)lwalloc(sizeof(LWGEOM *) * ngeoms);
                        for (i = 0; i < ngeoms; i++)
                        {
-                               const sfcgal_geometry_t* g = sfcgal_polyhedral_surface_polygon_n( geom, i );
+                               const sfcgal_geometry_t *g = sfcgal_polyhedral_surface_polygon_n(geom, i);
                                geoms[i] = SFCGAL2LWGEOM(g, 0, srid);
                        }
                }
-               return (LWGEOM*)lwcollection_construct(POLYHEDRALSURFACETYPE, srid, NULL, ngeoms, geoms);
+               return (LWGEOM *)lwcollection_construct(POLYHEDRALSURFACETYPE, srid, NULL, ngeoms, geoms);
        }
 
        /* Solid is map as a closed PolyhedralSurface (for now) */
@@ -396,42 +400,43 @@ SFCGAL2LWGEOM(const sfcgal_geometry_t* geom, int force3D, int srid)
                for (ngeoms = 0, i = 0; i < nshells; i++)
                        ngeoms += sfcgal_polyhedral_surface_num_polygons(sfcgal_solid_shell_n(geom, i));
 
-               LWGEOM** geoms = 0;
+               LWGEOM **geoms = 0;
                if (ngeoms)
                {
-                       geoms = (LWGEOM**) lwalloc( sizeof(LWGEOM*) * ngeoms);
-                       for (i = 0, k =; i < nshells; i++)
+                       geoms = (LWGEOM **)lwalloc(sizeof(LWGEOM *) * ngeoms);
+                       for (i = 0, k = 0; i < nshells; i++)
                        {
-                               const sfcgal_geometry_tshell = sfcgal_solid_shell_n(geom, i);
+                               const sfcgal_geometry_t *shell = sfcgal_solid_shell_n(geom, i);
                                ngeoms = sfcgal_polyhedral_surface_num_polygons(shell);
 
                                for (j = 0; j < ngeoms; j++)
                                {
-                                       const sfcgal_geometry_tg = sfcgal_polyhedral_surface_polygon_n(shell, j);
+                                       const sfcgal_geometry_t *g = sfcgal_polyhedral_surface_polygon_n(shell, j);
                                        geoms[k] = SFCGAL2LWGEOM(g, 1, srid);
                                        k++;
                                }
                        }
                }
-               LWGEOM* rgeom =  (LWGEOM*) lwcollection_construct(POLYHEDRALSURFACETYPE, srid, NULL, ngeoms, geoms);
-               if (ngeoms) FLAGS_SET_SOLID( rgeom->flags, 1);
+               LWGEOM *rgeom = (LWGEOM *)lwcollection_construct(POLYHEDRALSURFACETYPE, srid, NULL, ngeoms, geoms);
+               if (ngeoms)
+                       FLAGS_SET_SOLID(rgeom->flags, 1);
                return rgeom;
        }
 
        case SFCGAL_TYPE_TRIANGULATEDSURFACE:
        {
                ngeoms = sfcgal_triangulated_surface_num_triangles(geom);
-               LWGEOM** geoms = NULL;
+               LWGEOM **geoms = NULL;
                if (ngeoms)
                {
-                       geoms = (LWGEOM**) lwalloc(sizeof(LWGEOM*) * ngeoms);
+                       geoms = (LWGEOM **)lwalloc(sizeof(LWGEOM *) * ngeoms);
                        for (i = 0; i < ngeoms; i++)
                        {
-                               const sfcgal_geometry_tg = sfcgal_triangulated_surface_triangle_n(geom, i);
+                               const sfcgal_geometry_t *g = sfcgal_triangulated_surface_triangle_n(geom, i);
                                geoms[i] = SFCGAL2LWGEOM(g, 0, srid);
                        }
                }
-               return (LWGEOM*) lwcollection_construct(TINTYPE, srid, NULL, ngeoms, geoms);
+               return (LWGEOM *)lwcollection_construct(TINTYPE, srid, NULL, ngeoms, geoms);
        }
 
        default:
@@ -440,12 +445,11 @@ SFCGAL2LWGEOM(const sfcgal_geometry_t* geom, int force3D, int srid)
        }
 }
 
-
-sfcgal_geometry_t*
-LWGEOM2SFCGAL(const LWGEOM* geom)
+sfcgal_geometry_t *
+LWGEOM2SFCGAL(const LWGEOM *geom)
 {
        uint32_t i;
-       sfcgal_geometry_tret_geom = NULL;
+       sfcgal_geometry_t *ret_geom = NULL;
 
        assert(geom);
 
@@ -453,8 +457,9 @@ LWGEOM2SFCGAL(const LWGEOM* geom)
        {
        case POINTTYPE:
        {
-               const LWPOINT* lwp = (const LWPOINT*) geom;
-               if (lwgeom_is_empty(geom)) return sfcgal_point_create();
+               const LWPOINT *lwp = (const LWPOINT *)geom;
+               if (lwgeom_is_empty(geom))
+                       return sfcgal_point_create();
 
                return ptarray_to_SFCGAL(lwp->point, POINTTYPE);
        }
@@ -462,8 +467,9 @@ LWGEOM2SFCGAL(const LWGEOM* geom)
 
        case LINETYPE:
        {
-               const LWLINE* line = (const LWLINE*) geom;
-               if (lwgeom_is_empty(geom)) return sfcgal_linestring_create();
+               const LWLINE *line = (const LWLINE *)geom;
+               if (lwgeom_is_empty(geom))
+                       return sfcgal_linestring_create();
 
                return ptarray_to_SFCGAL(line->points, LINETYPE);
        }
@@ -471,25 +477,27 @@ LWGEOM2SFCGAL(const LWGEOM* geom)
 
        case TRIANGLETYPE:
        {
-               const LWTRIANGLE* triangle = (const LWTRIANGLE*) geom;
-               if (lwgeom_is_empty(geom)) return sfcgal_triangle_create();
+               const LWTRIANGLE *triangle = (const LWTRIANGLE *)geom;
+               if (lwgeom_is_empty(geom))
+                       return sfcgal_triangle_create();
                return ptarray_to_SFCGAL(triangle->points, TRIANGLETYPE);
        }
        break;
 
        case POLYGONTYPE:
        {
-               const LWPOLY* poly = (const LWPOLY*) geom;
+               const LWPOLY *poly = (const LWPOLY *)geom;
                uint32_t nrings = poly->nrings - 1;
 
-               if (lwgeom_is_empty(geom)) return sfcgal_polygon_create();
+               if (lwgeom_is_empty(geom))
+                       return sfcgal_polygon_create();
 
-               sfcgal_geometry_texterior_ring = ptarray_to_SFCGAL(poly->rings[0], LINETYPE);
+               sfcgal_geometry_t *exterior_ring = ptarray_to_SFCGAL(poly->rings[0], LINETYPE);
                ret_geom = sfcgal_polygon_create_from_exterior_ring(exterior_ring);
 
                for (i = 0; i < nrings; i++)
                {
-                       sfcgal_geometry_tring = ptarray_to_SFCGAL(poly->rings[i + 1], LINETYPE);
+                       sfcgal_geometry_t *ring = ptarray_to_SFCGAL(poly->rings[i + 1], LINETYPE);
                        sfcgal_polygon_add_interior_ring(ret_geom, ring);
                }
                return ret_geom;
@@ -501,15 +509,19 @@ LWGEOM2SFCGAL(const LWGEOM* geom)
        case MULTIPOLYGONTYPE:
        case COLLECTIONTYPE:
        {
-               if (geom->type == MULTIPOINTTYPE)        ret_geom = sfcgal_multi_point_create();
-               else if (geom->type == MULTILINETYPE)    ret_geom = sfcgal_multi_linestring_create();
-               else if (geom->type == MULTIPOLYGONTYPE) ret_geom = sfcgal_multi_polygon_create();
-               else                                     ret_geom = sfcgal_geometry_collection_create();
-
-               const LWCOLLECTION* lwc = (const LWCOLLECTION*)geom;
+               if (geom->type == MULTIPOINTTYPE)
+                       ret_geom = sfcgal_multi_point_create();
+               else if (geom->type == MULTILINETYPE)
+                       ret_geom = sfcgal_multi_linestring_create();
+               else if (geom->type == MULTIPOLYGONTYPE)
+                       ret_geom = sfcgal_multi_polygon_create();
+               else
+                       ret_geom = sfcgal_geometry_collection_create();
+
+               const LWCOLLECTION *lwc = (const LWCOLLECTION *)geom;
                for (i = 0; i < lwc->ngeoms; i++)
                {
-                       sfcgal_geometry_tg = LWGEOM2SFCGAL(lwc->geoms[i]);
+                       sfcgal_geometry_t *g = LWGEOM2SFCGAL(lwc->geoms[i]);
                        sfcgal_geometry_collection_add_geometry(ret_geom, g);
                }
 
@@ -519,12 +531,12 @@ LWGEOM2SFCGAL(const LWGEOM* geom)
 
        case POLYHEDRALSURFACETYPE:
        {
-               const LWPSURFACE* lwp = (const LWPSURFACE*) geom;
+               const LWPSURFACE *lwp = (const LWPSURFACE *)geom;
                ret_geom = sfcgal_polyhedral_surface_create();
 
                for (i = 0; i < lwp->ngeoms; i++)
                {
-                       sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
+                       sfcgal_geometry_t *g = LWGEOM2SFCGAL((const LWGEOM *)lwp->geoms[i]);
                        sfcgal_polyhedral_surface_add_polygon(ret_geom, g);
                }
                /* We treat polyhedral surface as the only exterior shell,
@@ -540,12 +552,12 @@ LWGEOM2SFCGAL(const LWGEOM* geom)
 
        case TINTYPE:
        {
-               const LWTIN* lwp = (const LWTIN*) geom;
+               const LWTIN *lwp = (const LWTIN *)geom;
                ret_geom = sfcgal_triangulated_surface_create();
 
                for (i = 0; i < lwp->ngeoms; i++)
                {
-                       sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
+                       sfcgal_geometry_t *g = LWGEOM2SFCGAL((const LWGEOM *)lwp->geoms[i]);
                        sfcgal_triangulated_surface_add_triangle(ret_geom, g);
                }
 
@@ -559,21 +571,21 @@ LWGEOM2SFCGAL(const LWGEOM* geom)
        }
 }
 
-
 /*
  * No Operation SFCGAL function, used (only) for cunit tests
  * Take a PostGIS geometry, send it to SFCGAL and return it unchanged (in theory)
  */
-LWGEOM* lwgeom_sfcgal_noop(const LWGEOM* geom_in)
+LWGEOM *
+lwgeom_sfcgal_noop(const LWGEOM *geom_in)
 {
-       sfcgal_geometry_tconverted;
+       sfcgal_geometry_t *converted;
 
        assert(geom_in);
 
        converted = LWGEOM2SFCGAL(geom_in);
        assert(converted);
 
-       LWGEOMgeom_out = SFCGAL2LWGEOM(converted, 0, SRID_UNKNOWN);
+       LWGEOM *geom_out = SFCGAL2LWGEOM(converted, 0, SRID_UNKNOWN);
        sfcgal_geometry_delete(converted);
 
        /* copy SRID (SFCGAL does not store the SRID) */
index 30d359a1b639a031a3371c85edd2707b86f926d7..5efb393d167345555f49dda72ebe5334f309b231 100644 (file)
  *
  **********************************************************************/
 
-
-
 #include "liblwgeom_internal.h"
 #include <SFCGAL/capi/sfcgal_c.h>
 
-
 /* return SFCGAL version string */
-const char*
-lwgeom_sfcgal_version(void);
+const char *lwgeom_sfcgal_version(void);
 
 /* Convert SFCGAL structure to lwgeom PostGIS */
-LWGEOM*
-SFCGAL2LWGEOM(const sfcgal_geometry_t* geom, int force3D, int SRID);
+LWGEOM *SFCGAL2LWGEOM(const sfcgal_geometry_t *geom, int force3D, int SRID);
 
 /* Convert lwgeom PostGIS to SFCGAL structure */
-sfcgal_geometry_t*
-LWGEOM2SFCGAL(const LWGEOM* geom);
+sfcgal_geometry_t *LWGEOM2SFCGAL(const LWGEOM *geom);
 
 /* No Operation SFCGAL function, used (only) for cunit tests
  * Take a PostGIS geometry, send it to SFCGAL and return it unchanged
  */
-LWGEOM*
-lwgeom_sfcgal_noop(const LWGEOM* geom_in);
+LWGEOM *lwgeom_sfcgal_noop(const LWGEOM *geom_in);
index 82e69bd519dc79645561b82ed16c0b0ec9840dc3..716cd3a2fa5f02d5b96a515d4849eb7a340048a4 100644 (file)
@@ -22,7 +22,6 @@
  *
  **********************************************************************/
 
-
 #include "postgres.h"
 #include "fmgr.h"
 #include "utils/guc.h" /* for custom variables */
@@ -48,69 +47,71 @@ Datum distance3d(PG_FUNCTION_ARGS);
 
 Datum intersects3d_dwithin(PG_FUNCTION_ARGS);
 
-
 struct lwgeom_backend_definition
 {
-    const char* name;
-    Datum (*intersects_fn)    (PG_FUNCTION_ARGS);
-    Datum (*intersects3d_fn)  (PG_FUNCTION_ARGS);
-    Datum (*intersection_fn)  (PG_FUNCTION_ARGS);
-    Datum (*difference_fn)    (PG_FUNCTION_ARGS);
-    Datum (*union_fn)         (PG_FUNCTION_ARGS);
-    Datum (*distance_fn)      (PG_FUNCTION_ARGS);
-    Datum (*distance3d_fn)    (PG_FUNCTION_ARGS);
+       const char *name;
+       Datum (*intersects_fn)(PG_FUNCTION_ARGS);
+       Datum (*intersects3d_fn)(PG_FUNCTION_ARGS);
+       Datum (*intersection_fn)(PG_FUNCTION_ARGS);
+       Datum (*difference_fn)(PG_FUNCTION_ARGS);
+       Datum (*union_fn)(PG_FUNCTION_ARGS);
+       Datum (*distance_fn)(PG_FUNCTION_ARGS);
+       Datum (*distance3d_fn)(PG_FUNCTION_ARGS);
 };
 
 #if HAVE_SFCGAL
-#define LWGEOM_NUM_BACKENDS   2
+#define LWGEOM_NUM_BACKENDS 2
 #else
-#define LWGEOM_NUM_BACKENDS   1
+#define LWGEOM_NUM_BACKENDS 1
 #endif
 
-struct lwgeom_backend_definition lwgeom_backends[LWGEOM_NUM_BACKENDS] = {
-    { .name = "geos",
-      .intersects_fn    = geos_intersects,
-      .intersects3d_fn  = intersects3d_dwithin,
-      .intersection_fn  = geos_intersection,
-      .difference_fn    = geos_difference,
-      .union_fn         = geos_geomunion,
-      .distance_fn      = LWGEOM_mindistance2d,
-      .distance3d_fn    = LWGEOM_mindistance3d
-    },
+struct lwgeom_backend_definition lwgeom_backends[LWGEOM_NUM_BACKENDS] = {{.name = "geos",
+                                                                         .intersects_fn = geos_intersects,
+                                                                         .intersects3d_fn = intersects3d_dwithin,
+                                                                         .intersection_fn = geos_intersection,
+                                                                         .difference_fn = geos_difference,
+                                                                         .union_fn = geos_geomunion,
+                                                                         .distance_fn = LWGEOM_mindistance2d,
+                                                                         .distance3d_fn = LWGEOM_mindistance3d},
 #if HAVE_SFCGAL
-    { .name = "sfcgal",
-      .intersects_fn    = sfcgal_intersects,
-      .intersects3d_fn  = sfcgal_intersects3D,
-      .intersection_fn  = sfcgal_intersection,
-      .difference_fn    = sfcgal_difference,
-      .union_fn         = sfcgal_union,
-      .distance_fn      = sfcgal_distance,
-      .distance3d_fn    = sfcgal_distance3D
-    }
+                                                                        {.name = "sfcgal",
+                                                                         .intersects_fn = sfcgal_intersects,
+                                                                         .intersects3d_fn = sfcgal_intersects3D,
+                                                                         .intersection_fn = sfcgal_intersection,
+                                                                         .difference_fn = sfcgal_difference,
+                                                                         .union_fn = sfcgal_union,
+                                                                         .distance_fn = sfcgal_distance,
+                                                                         .distance3d_fn = sfcgal_distance3D}
 #endif
 };
 
-
 /* Geometry Backend */
-charlwgeom_backend_name;
-struct lwgeom_backend_definitionlwgeom_backend = &lwgeom_backends[0];
+char *lwgeom_backend_name;
+struct lwgeom_backend_definition *lwgeom_backend = &lwgeom_backends[0];
 
-static void lwgeom_backend_switch( const char* newvalue, __attribute__((__unused__)) void* extra )
+static void
+lwgeom_backend_switch(const char *newvalue, __attribute__((__unused__)) void *extra)
 {
-    int i;
+       int i;
 
-    if (!newvalue) { return; }
+       if (!newvalue)
+       {
+               return;
+       }
 
-    for ( i = 0; i < LWGEOM_NUM_BACKENDS; ++i ) {
-       if ( !strcmp(lwgeom_backends[i].name, newvalue) ) {
-           lwgeom_backend = &lwgeom_backends[i];
-           return;
+       for (i = 0; i < LWGEOM_NUM_BACKENDS; ++i)
+       {
+               if (!strcmp(lwgeom_backends[i].name, newvalue))
+               {
+                       lwgeom_backend = &lwgeom_backends[i];
+                       return;
+               }
        }
-    }
-    lwpgerror("Can't find %s geometry backend", newvalue );
+       lwpgerror("Can't find %s geometry backend", newvalue);
 }
 
-void lwgeom_init_backend()
+void
+lwgeom_init_backend()
 {
        /* #2382 Before trying to create a user GUC, make sure */
        /* that the name is not already in use. Why would it be in use? */
@@ -125,7 +126,7 @@ void lwgeom_init_backend()
        /* callback to change which backend is in use by flipping a global variable */
        /* over. This saves the overhead of looking up the engine every time, at */
        /* the expense of the extra complexity. */
-       if ( postgis_guc_find_option(guc_name) )
+       if (postgis_guc_find_option(guc_name))
        {
                /* In this narrow case the previously installed GUC is tied to the callback in */
                /* the previously loaded library. Probably this is happening during an */
@@ -136,17 +137,18 @@ void lwgeom_init_backend()
 
        /* Good, the GUC name is not already in use, so this must be a fresh */
        /* and clean new load of the library, and we can define the user GUC */
-       DefineCustomStringVariable( guc_name, /* name */
-                               "Sets the PostGIS Geometry Backend.", /* short_desc */
-                               "Sets the PostGIS Geometry Backend (allowed values are 'geos' or 'sfcgal')", /* long_desc */
-                               &lwgeom_backend_name, /* valueAddr */
-                               (char *)lwgeom_backends[0].name, /* bootValue */
-                               PGC_USERSET, /* GucContext context */
-                               0, /* int flags */
-                               NULL, /* GucStringCheckHook check_hook */
-                               lwgeom_backend_switch, /* GucStringAssignHook assign_hook */
-                               NULL  /* GucShowHook show_hook */
-                               );
+       DefineCustomStringVariable(
+           guc_name,                                                                    /* name */
+           "Sets the PostGIS Geometry Backend.",                                        /* short_desc */
+           "Sets the PostGIS Geometry Backend (allowed values are 'geos' or 'sfcgal')", /* long_desc */
+           &lwgeom_backend_name,                                                        /* valueAddr */
+           (char *)lwgeom_backends[0].name,                                             /* bootValue */
+           PGC_USERSET,                                                                 /* GucContext context */
+           0,                                                                           /* int flags */
+           NULL,                  /* GucStringCheckHook check_hook */
+           lwgeom_backend_switch, /* GucStringAssignHook assign_hook */
+           NULL                   /* GucShowHook show_hook */
+       );
 }
 
 #if 0
@@ -157,74 +159,69 @@ int GetNumConfigOptions(void) returns num_guc_variables
 backend/utils/misc/guc_tables.h
 struct config_generic ** get_guc_variables(void)
 
-
-
-
 #endif
 
 PG_FUNCTION_INFO_V1(intersects);
 Datum intersects(PG_FUNCTION_ARGS)
 {
-    return (*lwgeom_backend->intersects_fn)( fcinfo );
+       return (*lwgeom_backend->intersects_fn)(fcinfo);
 }
 
 PG_FUNCTION_INFO_V1(intersection);
 Datum intersection(PG_FUNCTION_ARGS)
 {
-    return (*lwgeom_backend->intersection_fn)( fcinfo );
+       return (*lwgeom_backend->intersection_fn)(fcinfo);
 }
 
 PG_FUNCTION_INFO_V1(difference);
 Datum difference(PG_FUNCTION_ARGS)
 {
-    return (*lwgeom_backend->difference_fn)( fcinfo );
+       return (*lwgeom_backend->difference_fn)(fcinfo);
 }
 
 PG_FUNCTION_INFO_V1(geomunion);
 Datum geomunion(PG_FUNCTION_ARGS)
 {
-    return (*lwgeom_backend->union_fn)( fcinfo );
+       return (*lwgeom_backend->union_fn)(fcinfo);
 }
 
 PG_FUNCTION_INFO_V1(distance);
 Datum distance(PG_FUNCTION_ARGS)
 {
-    return (*lwgeom_backend->distance_fn)( fcinfo );
+       return (*lwgeom_backend->distance_fn)(fcinfo);
 }
 
 PG_FUNCTION_INFO_V1(distance3d);
 Datum distance3d(PG_FUNCTION_ARGS)
 {
-    return (*lwgeom_backend->distance3d_fn)( fcinfo );
+       return (*lwgeom_backend->distance3d_fn)(fcinfo);
 }
 
 PG_FUNCTION_INFO_V1(intersects3d);
 Datum intersects3d(PG_FUNCTION_ARGS)
 {
-    return (*lwgeom_backend->intersects3d_fn)( fcinfo );
+       return (*lwgeom_backend->intersects3d_fn)(fcinfo);
 }
 
-
-
 /* intersects3d through dwithin
  * used by the 'geos' backend
  */
 PG_FUNCTION_INFO_V1(intersects3d_dwithin);
 Datum intersects3d_dwithin(PG_FUNCTION_ARGS)
 {
-    double mindist;
-    GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
-    GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
-    LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
-    LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
+       double mindist;
+       GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
+       GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
+       LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
+       LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
        error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
-    mindist = lwgeom_mindistance3d_tolerance(lwgeom1,lwgeom2,0.0);
+       mindist = lwgeom_mindistance3d_tolerance(lwgeom1, lwgeom2, 0.0);
 
-    PG_FREE_IF_COPY(geom1, 0);
-    PG_FREE_IF_COPY(geom2, 1);
-    /*empty geometries cases should be right handled since return from underlying
-      functions should be FLT_MAX which causes false as answer*/
-    PG_RETURN_BOOL(0.0 == mindist);
+       PG_FREE_IF_COPY(geom1, 0);
+       PG_FREE_IF_COPY(geom2, 1);
+       /*empty geometries cases should be right handled since return from underlying
+         functions should be FLT_MAX which causes false as answer*/
+       PG_RETURN_BOOL(0.0 == mindist);
 }
index 4d2be7ceb039b056fc360320b7fef318c1dd0e83..73341347e78b0b54ddf1ee707191e8600482152e 100644 (file)
@@ -23,7 +23,6 @@
  *
  **********************************************************************/
 
-
 #include "postgres.h"
 #include "fmgr.h"
 #include "utils/array.h"
@@ -124,7 +123,7 @@ Datum LWGEOM_mem_size(PG_FUNCTION_ARGS)
 {
        GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
        size_t size = VARSIZE(geom);
-       PG_FREE_IF_COPY(geom,0);
+       PG_FREE_IF_COPY(geom, 0);
        PG_RETURN_INT32(size);
 }
 
@@ -145,7 +144,7 @@ Datum LWGEOM_summary(PG_FUNCTION_ARGS)
        mytext = cstring_to_text(result);
        lwfree(result);
 
-       PG_FREE_IF_COPY(geom,0);
+       PG_FREE_IF_COPY(geom, 0);
        PG_RETURN_TEXT_P(mytext);
 }
 
@@ -178,7 +177,7 @@ Datum postgis_svn_version(PG_FUNCTION_ARGS)
 {
        static int rev = POSTGIS_SVN_REVISION;
        char ver[32];
-       if ( rev > 0 )
+       if (rev > 0)
        {
                snprintf(ver, 32, "%d", rev);
                PG_RETURN_TEXT_P(cstring_to_text(ver));
@@ -224,7 +223,6 @@ Datum postgis_autocache_bbox(PG_FUNCTION_ARGS)
 #endif
 }
 
-
 PG_FUNCTION_INFO_V1(postgis_libxml_version);
 Datum postgis_libxml_version(PG_FUNCTION_ARGS)
 {
@@ -358,7 +356,6 @@ Datum LWGEOM_perimeter2d_poly(PG_FUNCTION_ARGS)
        PG_RETURN_FLOAT8(perimeter);
 }
 
-
 /* transform input geometry to 2d if not 2d already */
 PG_FUNCTION_INFO_V1(LWGEOM_force_2d);
 Datum LWGEOM_force_2d(PG_FUNCTION_ARGS)
@@ -368,7 +365,8 @@ Datum LWGEOM_force_2d(PG_FUNCTION_ARGS)
        LWGEOM *lwg_in, *lwg_out;
 
        /* already 2d */
-       if ( gserialized_ndims(pg_geom_in) == 2 ) PG_RETURN_POINTER(pg_geom_in);
+       if (gserialized_ndims(pg_geom_in) == 2)
+               PG_RETURN_POINTER(pg_geom_in);
 
        lwg_in = lwgeom_from_gserialized(pg_geom_in);
        lwg_out = lwgeom_force_2d(lwg_in);
@@ -389,7 +387,7 @@ Datum LWGEOM_force_3dz(PG_FUNCTION_ARGS)
        LWGEOM *lwg_in, *lwg_out;
 
        /* already 3d */
-       if ( gserialized_ndims(pg_geom_in) == 3 && gserialized_has_z(pg_geom_in) )
+       if (gserialized_ndims(pg_geom_in) == 3 && gserialized_has_z(pg_geom_in))
                PG_RETURN_POINTER(pg_geom_in);
 
        lwg_in = lwgeom_from_gserialized(pg_geom_in);
@@ -411,7 +409,7 @@ Datum LWGEOM_force_3dm(PG_FUNCTION_ARGS)
        LWGEOM *lwg_in, *lwg_out;
 
        /* already 3d */
-       if ( gserialized_ndims(pg_geom_in) == 3 && gserialized_has_m(pg_geom_in) )
+       if (gserialized_ndims(pg_geom_in) == 3 && gserialized_has_m(pg_geom_in))
                PG_RETURN_POINTER(pg_geom_in);
 
        lwg_in = lwgeom_from_gserialized(pg_geom_in);
@@ -433,7 +431,7 @@ Datum LWGEOM_force_4d(PG_FUNCTION_ARGS)
        LWGEOM *lwg_in, *lwg_out;
 
        /* already 4d */
-       if ( gserialized_ndims(pg_geom_in) == 4 )
+       if (gserialized_ndims(pg_geom_in) == 4)
                PG_RETURN_POINTER(pg_geom_in);
 
        lwg_in = lwgeom_from_gserialized(pg_geom_in);
@@ -464,8 +462,7 @@ Datum LWGEOM_force_collection(PG_FUNCTION_ARGS)
         * in input. If bbox cache is not there we'll need to handle
         * automatic bbox addition FOR_COMPLEX_GEOMS.
         */
-       if ( gserialized_get_type(geom) == COLLECTIONTYPE &&
-               gserialized_has_bbox(geom) )
+       if (gserialized_get_type(geom) == COLLECTIONTYPE && gserialized_has_bbox(geom))
        {
                PG_RETURN_POINTER(geom);
        }
@@ -474,7 +471,7 @@ Datum LWGEOM_force_collection(PG_FUNCTION_ARGS)
        lwgeom = lwgeom_from_gserialized(geom);
 
        /* alread a multi*, just make it a collection */
-       if ( lwgeom_is_collection(lwgeom) )
+       if (lwgeom_is_collection(lwgeom))
        {
                lwgeom->type = COLLECTIONTYPE;
        }
@@ -487,11 +484,9 @@ Datum LWGEOM_force_collection(PG_FUNCTION_ARGS)
                bbox = lwgeom->bbox;
                lwgeom->srid = SRID_UNKNOWN;
                lwgeom->bbox = NULL;
-               lwgeoms = palloc(sizeof(LWGEOM*));
+               lwgeoms = palloc(sizeof(LWGEOM *));
                lwgeoms[0] = lwgeom;
-               lwgeom = (LWGEOM *)lwcollection_construct(COLLECTIONTYPE,
-                        srid, bbox, 1,
-                        lwgeoms);
+               lwgeom = (LWGEOM *)lwcollection_construct(COLLECTIONTYPE, srid, bbox, 1, lwgeoms);
        }
 
        result = geometry_serialize(lwgeom);
@@ -517,19 +512,20 @@ Datum LWGEOM_force_multi(PG_FUNCTION_ARGS)
        ** in input. If bbox cache is not there we'll need to handle
        ** automatic bbox addition FOR_COMPLEX_GEOMS.
        */
-       if ( gserialized_has_bbox(geom) ) {
+       if (gserialized_has_bbox(geom))
+       {
                switch (gserialized_get_type(geom))
                {
-                       case MULTIPOINTTYPE:
-                       case MULTILINETYPE:
-                       case MULTIPOLYGONTYPE:
-                       case COLLECTIONTYPE:
-                       case MULTICURVETYPE:
-                       case MULTISURFACETYPE:
-                       case TINTYPE:
-                               PG_RETURN_POINTER(geom);
-                       default:
-                               break;
+               case MULTIPOINTTYPE:
+               case MULTILINETYPE:
+               case MULTIPOLYGONTYPE:
+               case COLLECTIONTYPE:
+               case MULTICURVETYPE:
+               case MULTISURFACETYPE:
+               case TINTYPE:
+                       PG_RETURN_POINTER(geom);
+               default:
+                       break;
                }
        }
 
@@ -555,7 +551,7 @@ Datum LWGEOM_force_curve(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "LWGEOM_force_curve called");
 
-  /* TODO: early out if input is already a curve */
+       /* TODO: early out if input is already a curve */
 
        lwgeom = lwgeom_from_gserialized(geom);
        ogeom = lwgeom_as_curve(lwgeom);
@@ -575,21 +571,21 @@ Datum LWGEOM_force_sfs(PG_FUNCTION_ARGS)
        GSERIALIZED *result;
        LWGEOM *lwgeom;
        LWGEOM *ogeom;
-       text * ver;
+       text *ver;
        int version = 110; /* default version is SFS 1.1 */
 
        POSTGIS_DEBUG(2, "LWGEOM_force_sfs called");
 
-        /* If user specified version, respect it */
-        if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
-        {
-                ver = PG_GETARG_TEXT_P(1);
+       /* If user specified version, respect it */
+       if ((PG_NARGS() > 1) && (!PG_ARGISNULL(1)))
+       {
+               ver = PG_GETARG_TEXT_P(1);
 
-                if  ( ! strncmp(VARDATA(ver), "1.2", 3))
-                {
-                        version = 120;
-                }
-        }
+               if (!strncmp(VARDATA(ver), "1.2", 3))
+               {
+                       version = 120;
+               }
+       }
 
        lwgeom = lwgeom_from_gserialized(geom);
        ogeom = lwgeom_force_sfs(lwgeom, version);
@@ -714,7 +710,7 @@ Datum LWGEOM_mindistance2d(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(geom2, 1);
 
        /*if called with empty geometries the ingoing mindistance is untouched, and makes us return NULL*/
-       if (mindist<FLT_MAX)
+       if (mindist < FLT_MAX)
                PG_RETURN_FLOAT8(mindist);
 
        PG_RETURN_NULL();
@@ -735,15 +731,15 @@ Datum LWGEOM_dwithin(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if ( tolerance < 0 )
+       if (tolerance < 0)
        {
-               elog(ERROR,"Tolerance cannot be less than zero\n");
+               elog(ERROR, "Tolerance cannot be less than zero\n");
                PG_RETURN_NULL();
        }
 
        error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
-       mindist = lwgeom_mindistance2d_tolerance(lwgeom1,lwgeom2,tolerance);
+       mindist = lwgeom_mindistance2d_tolerance(lwgeom1, lwgeom2, tolerance);
 
        PG_FREE_IF_COPY(geom1, 0);
        PG_FREE_IF_COPY(geom2, 1);
@@ -767,9 +763,9 @@ Datum LWGEOM_dfullywithin(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if ( tolerance < 0 )
+       if (tolerance < 0)
        {
-               elog(ERROR,"Tolerance cannot be less than zero\n");
+               elog(ERROR, "Tolerance cannot be less than zero\n");
                PG_RETURN_NULL();
        }
 
@@ -781,7 +777,7 @@ Datum LWGEOM_dfullywithin(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(geom2, 1);
 
        /*If function is feed with empty geometries we should return false*/
-       if (maxdist>-1)
+       if (maxdist > -1)
                PG_RETURN_BOOL(tolerance >= maxdist);
 
        PG_RETURN_BOOL(LW_FALSE);
@@ -807,7 +803,7 @@ Datum LWGEOM_maxdistance2d_linestring(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(geom2, 1);
 
        /*if called with empty geometries the ingoing mindistance is untouched, and makes us return NULL*/
-       if (maxdist>-1)
+       if (maxdist > -1)
                PG_RETURN_FLOAT8(maxdist);
 
        PG_RETURN_NULL();
@@ -929,7 +925,7 @@ Datum LWGEOM_mindistance3d(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(geom2, 1);
 
        /*if called with empty geometries the ingoing mindistance is untouched, and makes us return NULL*/
-       if (mindist<FLT_MAX)
+       if (mindist < FLT_MAX)
                PG_RETURN_FLOAT8(mindist);
 
        PG_RETURN_NULL();
@@ -950,15 +946,15 @@ Datum LWGEOM_dwithin3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if ( tolerance < 0 )
+       if (tolerance < 0)
        {
-               elog(ERROR,"Tolerance cannot be less than zero\n");
+               elog(ERROR, "Tolerance cannot be less than zero\n");
                PG_RETURN_NULL();
        }
 
        error_if_srid_mismatch(lwgeom1->srid, lwgeom2->srid);
 
-       mindist = lwgeom_mindistance3d_tolerance(lwgeom1,lwgeom2,tolerance);
+       mindist = lwgeom_mindistance3d_tolerance(lwgeom1, lwgeom2, tolerance);
 
        PG_FREE_IF_COPY(geom1, 0);
        PG_FREE_IF_COPY(geom2, 1);
@@ -983,9 +979,9 @@ Datum LWGEOM_dfullywithin3d(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom1 = lwgeom_from_gserialized(geom1);
        LWGEOM *lwgeom2 = lwgeom_from_gserialized(geom2);
 
-       if ( tolerance < 0 )
+       if (tolerance < 0)
        {
-               elog(ERROR,"Tolerance cannot be less than zero\n");
+               elog(ERROR, "Tolerance cannot be less than zero\n");
                PG_RETURN_NULL();
        }
 
@@ -996,7 +992,7 @@ Datum LWGEOM_dfullywithin3d(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(geom2, 1);
 
        /*If function is feed with empty geometries we should return false*/
-       if (maxdist>-1)
+       if (maxdist > -1)
                PG_RETURN_BOOL(tolerance >= maxdist);
 
        PG_RETURN_BOOL(LW_FALSE);
@@ -1022,13 +1018,12 @@ Datum LWGEOM_maxdistance3d(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(geom2, 1);
 
        /*if called with empty geometries the ingoing mindistance is untouched, and makes us return NULL*/
-       if (maxdist>-1)
+       if (maxdist > -1)
                PG_RETURN_FLOAT8(maxdist);
 
        PG_RETURN_NULL();
 }
 
-
 PG_FUNCTION_INFO_V1(LWGEOM_longitude_shift);
 Datum LWGEOM_longitude_shift(PG_FUNCTION_ARGS)
 {
@@ -1075,7 +1070,7 @@ Datum ST_WrapX(PG_FUNCTION_ARGS)
        cutx = PG_GETARG_FLOAT8(1);
        amount = PG_GETARG_FLOAT8(2);
 
-       //if ( ! amount ) PG_RETURN_DATUM(gdatum);
+       // if ( ! amount ) PG_RETURN_DATUM(gdatum);
 
        geom_in = ((GSERIALIZED *)PG_DETOAST_DATUM(gdatum));
        lwgeom_in = lwgeom_from_gserialized(geom_in);
@@ -1104,7 +1099,7 @@ Datum LWGEOM_inside_circle_point(PG_FUNCTION_ARGS)
        geom = PG_GETARG_GSERIALIZED_P(0);
        lwgeom = lwgeom_from_gserialized(geom);
        lwpoint = lwgeom_as_lwpoint(lwgeom);
-       if ( lwpoint == NULL || lwgeom_is_empty(lwgeom) )
+       if (lwpoint == NULL || lwgeom_is_empty(lwgeom))
        {
                PG_FREE_IF_COPY(geom, 0);
                PG_RETURN_NULL(); /* not a point */
@@ -1129,14 +1124,14 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
 {
        GSERIALIZED *gser1, *gser2, *result;
        LWGEOM *lwgeoms[2], *outlwg;
-    uint32 type1, type2;
-    uint8_t outtype;
+       uint32 type1, type2;
+       uint8_t outtype;
        int srid;
 
        POSTGIS_DEBUG(2, "LWGEOM_collect called.");
 
        /* return null if both geoms are null */
-       if ( PG_ARGISNULL(0) && PG_ARGISNULL(1) )
+       if (PG_ARGISNULL(0) && PG_ARGISNULL(1))
                PG_RETURN_NULL();
 
        /* Return the second geom if the first geom is null */
@@ -1150,11 +1145,14 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
        gser1 = PG_GETARG_GSERIALIZED_P(0);
        gser2 = PG_GETARG_GSERIALIZED_P(1);
 
-       POSTGIS_DEBUGF(3, "LWGEOM_collect(%s, %s): call", lwtype_name(gserialized_get_type(gser1)), lwtype_name(gserialized_get_type(gser2)));
+       POSTGIS_DEBUGF(3,
+                      "LWGEOM_collect(%s, %s): call",
+                      lwtype_name(gserialized_get_type(gser1)),
+                      lwtype_name(gserialized_get_type(gser2)));
 
-       if ( FLAGS_GET_ZM(gser1->flags) != FLAGS_GET_ZM(gser2->flags) )
+       if (FLAGS_GET_ZM(gser1->flags) != FLAGS_GET_ZM(gser2->flags))
        {
-               elog(ERROR,"Cannot ST_Collect geometries with differing dimensionality.");
+               elog(ERROR, "Cannot ST_Collect geometries with differing dimensionality.");
                PG_RETURN_NULL();
        }
 
@@ -1167,7 +1165,7 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
        type1 = lwgeoms[0]->type;
        type2 = lwgeoms[1]->type;
 
-       if ( (type1 == type2) && (!lwgeom_is_collection(lwgeoms[0])) )
+       if ((type1 == type2) && (!lwgeom_is_collection(lwgeoms[0])))
                outtype = lwtype_get_collectiontype(type1);
        else
                outtype = COLLECTIONTYPE;
@@ -1192,7 +1190,6 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(result);
 }
 
-
 /**
  * @brief collect_garray ( GEOMETRY[] ) returns a geometry which contains
  *             all the sub_objects from all of the geometries in given array.
@@ -1221,27 +1218,29 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
 
        POSTGIS_DEBUG(2, "LWGEOM_collect_garray called.");
 
-       if ( PG_ARGISNULL(0) )
+       if (PG_ARGISNULL(0))
                PG_RETURN_NULL();
 
        /* Get actual ArrayType */
        array = PG_GETARG_ARRAYTYPE_P(0);
        nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
 
-       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)));
+       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)));
 
        POSTGIS_DEBUGF(3, "LWGEOM_collect_garray: array has %d elements", nelems);
 
        /* Return null on 0-elements input array */
-       if ( nelems == 0 )
+       if (nelems == 0)
                PG_RETURN_NULL();
 
        /*
         * Deserialize all geometries in array into the lwgeoms pointers
         * array. Check input types to form output type.
         */
-       lwgeoms = palloc(sizeof(LWGEOM*) * nelems);
+       lwgeoms = palloc(sizeof(LWGEOM *) * nelems);
        count = 0;
        outtype = 0;
 
@@ -1251,13 +1250,13 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
        iterator = array_create_iterator(array, 0);
 #endif
 
-       while( array_iterate(iterator, &value, &isnull) )
+       while (array_iterate(iterator, &value, &isnull))
        {
                GSERIALIZED *geom;
                uint8_t intype;
 
                /* Don't do anything for NULL values */
-               if ( isnull )
+               if (isnull)
                        continue;
 
                geom = (GSERIALIZED *)DatumGetPointer(value);
@@ -1267,13 +1266,13 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
 
                POSTGIS_DEBUGF(3, "%s: geom %d deserialized", __func__, count);
 
-               if ( ! count )
+               if (!count)
                {
                        /* Get first geometry SRID */
                        srid = lwgeoms[count]->srid;
 
                        /* COMPUTE_BBOX WHEN_SIMPLE */
-                       if ( lwgeoms[count]->bbox )
+                       if (lwgeoms[count]->bbox)
                        {
                                box = gbox_copy(lwgeoms[count]->bbox);
                        }
@@ -1284,9 +1283,9 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
                        error_if_srid_mismatch(lwgeoms[count]->srid, srid);
 
                        /* COMPUTE_BBOX WHEN_SIMPLE */
-                       if ( box )
+                       if (box)
                        {
-                               if ( lwgeoms[count]->bbox )
+                               if (lwgeoms[count]->bbox)
                                {
                                        gbox_merge(lwgeoms[count]->bbox, box);
                                }
@@ -1302,23 +1301,21 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
                lwgeom_drop_bbox(lwgeoms[count]);
 
                /* Output type not initialized */
-               if ( ! outtype )
+               if (!outtype)
                {
                        outtype = lwtype_get_collectiontype(intype);
                }
                /* Input type not compatible with output */
                /* make output type a collection */
-               else if ( outtype != COLLECTIONTYPE && lwtype_get_collectiontype(intype) != outtype )
+               else if (outtype != COLLECTIONTYPE && lwtype_get_collectiontype(intype) != outtype)
                {
                        outtype = COLLECTIONTYPE;
                }
 
                count++;
-
        }
        array_free_iterator(iterator);
 
-
        POSTGIS_DEBUGF(3, "LWGEOM_collect_garray: outtype = %d", outtype);
 
        /* If we have been passed a complete set of NULLs then return NULL */
@@ -1328,9 +1325,7 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
        }
        else
        {
-               outlwg = (LWGEOM *)lwcollection_construct(
-                            outtype, srid,
-                            box, count, lwgeoms);
+               outlwg = (LWGEOM *)lwcollection_construct(outtype, srid, box, count, lwgeoms);
 
                result = geometry_serialize(outlwg);
 
@@ -1354,7 +1349,7 @@ Datum LWGEOM_line_from_mpoint(PG_FUNCTION_ARGS)
        /* Get input GSERIALIZED and deserialize it */
        ingeom = PG_GETARG_GSERIALIZED_P(0);
 
-       if ( gserialized_get_type(ingeom) != MULTIPOINTTYPE )
+       if (gserialized_get_type(ingeom) != MULTIPOINTTYPE)
        {
                elog(ERROR, "makeline: input must be a multipoint");
                PG_RETURN_NULL(); /* input is not a multipoint */
@@ -1362,7 +1357,7 @@ Datum LWGEOM_line_from_mpoint(PG_FUNCTION_ARGS)
 
        mpoint = lwgeom_as_lwmpoint(lwgeom_from_gserialized(ingeom));
        lwline = lwline_from_lwmpoint(mpoint->srid, mpoint);
-       if ( ! lwline )
+       if (!lwline)
        {
                PG_FREE_IF_COPY(ingeom, 0);
                elog(ERROR, "makeline: lwline_from_lwmpoint returned NULL");
@@ -1400,7 +1395,7 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
        POSTGIS_DEBUGF(2, "%s called", __func__);
 
        /* Return null on null input */
-       if ( PG_ARGISNULL(0) )
+       if (PG_ARGISNULL(0))
                PG_RETURN_NULL();
 
        /* Get actual ArrayType */
@@ -1412,10 +1407,9 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
        POSTGIS_DEBUGF(3, "%s: array has %d elements", __func__, nelems);
 
        /* Return null on 0-elements input array */
-       if ( nelems == 0 )
+       if (nelems == 0)
                PG_RETURN_NULL();
 
-
        /*
         * Deserialize all point geometries in array into the
         * geoms pointers array.
@@ -1432,18 +1426,17 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
        iterator = array_create_iterator(array, 0);
 #endif
 
-       while( array_iterate(iterator, &value, &isnull) )
+       while (array_iterate(iterator, &value, &isnull))
        {
                GSERIALIZED *geom;
 
-               if ( isnull )
+               if (isnull)
                        continue;
 
                geom = (GSERIALIZED *)DatumGetPointer(value);
 
-               if ( gserialized_get_type(geom) != POINTTYPE &&
-                    gserialized_get_type(geom) != LINETYPE &&
-                    gserialized_get_type(geom) != MULTIPOINTTYPE)
+               if (gserialized_get_type(geom) != POINTTYPE && gserialized_get_type(geom) != LINETYPE &&
+                   gserialized_get_type(geom) != MULTIPOINTTYPE)
                {
                        continue;
                }
@@ -1451,15 +1444,15 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
                geoms[ngeoms++] = lwgeom_from_gserialized(geom);
 
                /* Check SRID homogeneity */
-               if ( ngeoms == 1 )
+               if (ngeoms == 1)
                {
                        /* Get first geometry SRID */
-                       srid = geoms[ngeoms-1]->srid;
+                       srid = geoms[ngeoms - 1]->srid;
                        /* TODO: also get ZMflags */
                }
                else
                {
-                       error_if_srid_mismatch(geoms[ngeoms-1]->srid, srid);
+                       error_if_srid_mismatch(geoms[ngeoms - 1]->srid, srid);
                }
 
                POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
@@ -1467,7 +1460,7 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
        array_free_iterator(iterator);
 
        /* Return null on 0-points input array */
-       if ( ngeoms == 0 )
+       if (ngeoms == 0)
        {
                /* TODO: should we return LINESTRING EMPTY here ? */
                elog(NOTICE, "No points or linestrings in input array");
@@ -1491,7 +1484,7 @@ PG_FUNCTION_INFO_V1(LWGEOM_makeline);
 Datum LWGEOM_makeline(PG_FUNCTION_ARGS)
 {
        GSERIALIZED *pglwg1, *pglwg2;
-       GSERIALIZED *result=NULL;
+       GSERIALIZED *result = NULL;
        LWGEOM *lwgeoms[2];
        LWLINE *outline;
 
@@ -1501,8 +1494,8 @@ Datum LWGEOM_makeline(PG_FUNCTION_ARGS)
        pglwg1 = PG_GETARG_GSERIALIZED_P(0);
        pglwg2 = PG_GETARG_GSERIALIZED_P(1);
 
-       if ( (gserialized_get_type(pglwg1) != POINTTYPE && gserialized_get_type(pglwg1) != LINETYPE) ||
-            (gserialized_get_type(pglwg2) != POINTTYPE && gserialized_get_type(pglwg2) != LINETYPE) )
+       if ((gserialized_get_type(pglwg1) != POINTTYPE && gserialized_get_type(pglwg1) != LINETYPE) ||
+           (gserialized_get_type(pglwg2) != POINTTYPE && gserialized_get_type(pglwg2) != LINETYPE))
        {
                elog(ERROR, "Input geometries must be points or lines");
                PG_RETURN_NULL();
@@ -1533,40 +1526,40 @@ PG_FUNCTION_INFO_V1(LWGEOM_makepoly);
 Datum LWGEOM_makepoly(PG_FUNCTION_ARGS)
 {
        GSERIALIZED *pglwg1;
-       ArrayType *array=NULL;
-       GSERIALIZED *result=NULL;
-       const LWLINE *shell=NULL;
-       const LWLINE **holes=NULL;
+       ArrayType *array = NULL;
+       GSERIALIZED *result = NULL;
+       const LWLINE *shell = NULL;
+       const LWLINE **holes = NULL;
        LWPOLY *outpoly;
-       uint32 nholes=0;
+       uint32 nholes = 0;
        uint32 i;
-       size_t offset=0;
+       size_t offset = 0;
 
        POSTGIS_DEBUG(2, "LWGEOM_makepoly called.");
 
        /* Get input shell */
        pglwg1 = PG_GETARG_GSERIALIZED_P(0);
-       if ( gserialized_get_type(pglwg1) != LINETYPE )
+       if (gserialized_get_type(pglwg1) != LINETYPE)
        {
                lwpgerror("Shell is not a line");
        }
        shell = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
 
        /* Get input holes if any */
-       if ( PG_NARGS() > 1 )
+       if (PG_NARGS() > 1)
        {
                array = PG_GETARG_ARRAYTYPE_P(1);
                nholes = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
-               holes = lwalloc(sizeof(LWLINE *)*nholes);
-               for (i=0; i<nholes; i++)
+               holes = lwalloc(sizeof(LWLINE *) * nholes);
+               for (i = 0; i < nholes; i++)
                {
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wsign-compare"
-                       GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
+                       GSERIALIZED *g = (GSERIALIZED *)(ARR_DATA_PTR(array) + offset);
 #pragma GCC diagnostic pop
                        LWLINE *hole;
                        offset += INTALIGN(VARSIZE(g));
-                       if ( gserialized_get_type(g) != LINETYPE )
+                       if (gserialized_get_type(g) != LINETYPE)
                        {
                                lwpgerror("Hole %d is not a line", i);
                        }
@@ -1576,15 +1569,15 @@ Datum LWGEOM_makepoly(PG_FUNCTION_ARGS)
        }
 
        outpoly = lwpoly_from_lwlines(shell, nholes, holes);
-       POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM*)outpoly, 0));
+       POSTGIS_DEBUGF(3, "%s", lwgeom_summary((LWGEOM *)outpoly, 0));
        result = geometry_serialize((LWGEOM *)outpoly);
 
-       lwline_free((LWLINE*)shell);
+       lwline_free((LWLINE *)shell);
        PG_FREE_IF_COPY(pglwg1, 0);
 
-       for (i=0; i<nholes; i++)
+       for (i = 0; i < nholes; i++)
        {
-               lwline_free((LWLINE*)holes[i]);
+               lwline_free((LWLINE *)holes[i]);
        }
 
        PG_RETURN_POINTER(result);
@@ -1608,14 +1601,14 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS)
        POSTGIS_DEBUG(2, "LWGEOM_expand called.");
 
        /* Can't expand an empty */
-       if ( lwgeom_is_empty(lwgeom) )
+       if (lwgeom_is_empty(lwgeom))
        {
                lwgeom_free(lwgeom);
                PG_RETURN_POINTER(geom);
        }
 
        /* Can't expand something with no gbox! */
-       if ( LW_FAILURE == lwgeom_calculate_gbox(lwgeom, &gbox) )
+       if (LW_FAILURE == lwgeom_calculate_gbox(lwgeom, &gbox))
        {
                lwgeom_free(lwgeom);
                PG_RETURN_POINTER(geom);
@@ -1638,10 +1631,10 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS)
        }
 
        {
-               POINT4D p1 = { gbox.xmin, gbox.ymin, gbox.zmin, gbox.mmin };
-               POINT4D p2 = { gbox.xmin, gbox.ymax, gbox.zmin, gbox.mmin };
-               POINT4D p3 = { gbox.xmax, gbox.ymax, gbox.zmax, gbox.mmax };
-               POINT4D p4 = { gbox.xmax, gbox.ymin, gbox.zmax, gbox.mmax };
+               POINT4D p1 = {gbox.xmin, gbox.ymin, gbox.zmin, gbox.mmin};
+               POINT4D p2 = {gbox.xmin, gbox.ymax, gbox.zmin, gbox.mmin};
+               POINT4D p3 = {gbox.xmax, gbox.ymax, gbox.zmax, gbox.mmax};
+               POINT4D p4 = {gbox.xmax, gbox.ymin, gbox.zmax, gbox.mmax};
 
                poly = lwpoly_construct_rectangle(lwgeom_has_z(lwgeom), lwgeom_has_m(lwgeom), &p1, &p2, &p3, &p4);
        }
@@ -1680,10 +1673,10 @@ Datum LWGEOM_to_BOX(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(pg_lwgeom, 0);
 
        /* Null on failure */
-       if ( ! result )
+       if (!result)
                PG_RETURN_NULL();
 
-    out = lwalloc(sizeof(BOX));
+       out = lwalloc(sizeof(BOX));
        out->low.x = gbox.xmin;
        out->low.y = gbox.ymin;
        out->high.x = gbox.xmax;
@@ -1707,14 +1700,13 @@ Datum LWGEOM_envelope(PG_FUNCTION_ARGS)
        POINTARRAY *pa;
        GSERIALIZED *result;
 
-
-       if ( lwgeom_is_empty(lwgeom) )
+       if (lwgeom_is_empty(lwgeom))
        {
                /* must be the EMPTY geometry */
                PG_RETURN_POINTER(geom);
        }
 
-       if ( lwgeom_calculate_gbox(lwgeom, &box) == LW_FAILURE )
+       if (lwgeom_calculate_gbox(lwgeom, &box) == LW_FAILURE)
        {
                /* must be the EMPTY geometry */
                PG_RETURN_POINTER(geom);
@@ -1731,14 +1723,14 @@ Datum LWGEOM_envelope(PG_FUNCTION_ARGS)
         *     - Otherwise return a POLYGON
         */
 
-       if ( (box.xmin == box.xmax) && (box.ymin == box.ymax) )
+       if ((box.xmin == box.xmax) && (box.ymin == box.ymax))
        {
                /* Construct and serialize point */
                LWPOINT *point = lwpoint_make2d(srid, box.xmin, box.ymin);
                result = geometry_serialize(lwpoint_as_lwgeom(point));
                lwpoint_free(point);
        }
-       else if ( (box.xmin == box.xmax) || (box.ymin == box.ymax) )
+       else if ((box.xmin == box.xmax) || (box.ymin == box.ymax))
        {
                LWLINE *line;
                /* Construct point array */
@@ -1760,7 +1752,7 @@ Datum LWGEOM_envelope(PG_FUNCTION_ARGS)
        else
        {
                LWPOLY *poly;
-               POINTARRAY **ppa = lwalloc(sizeof(POINTARRAY*));
+               POINTARRAY **ppa = lwalloc(sizeof(POINTARRAY *));
                pa = ptarray_construct_empty(0, 0, 5);
                ppa[0] = pa;
 
@@ -1804,7 +1796,6 @@ Datum LWGEOM_isempty(PG_FUNCTION_ARGS)
        PG_RETURN_BOOL(empty);
 }
 
-
 /**
  *  @brief Returns a modified geometry so that no segment is
  *     longer then the given distance (computed using 2d).
@@ -1826,16 +1817,14 @@ Datum LWGEOM_segmentize2d(PG_FUNCTION_ARGS)
        type = gserialized_get_type(ingeom);
 
        /* Avoid types we cannot segmentize. */
-       if ( (type == POINTTYPE) ||
-            (type == MULTIPOINTTYPE) ||
-            (type == TRIANGLETYPE) ||
-            (type == TINTYPE) ||
-            (type == POLYHEDRALSURFACETYPE) )
+       if ((type == POINTTYPE) || (type == MULTIPOINTTYPE) || (type == TRIANGLETYPE) || (type == TINTYPE) ||
+           (type == POLYHEDRALSURFACETYPE))
        {
                PG_RETURN_POINTER(ingeom);
        }
 
-       if ( dist <= 0 ) {
+       if (dist <= 0)
+       {
                /* Protect from knowingly infinite loops, see #1799 */
                /* Note that we'll end out of memory anyway for other small distances */
                elog(ERROR, "ST_Segmentize: invalid max_distance %g (must be >= 0)", dist);
@@ -1845,7 +1834,7 @@ Datum LWGEOM_segmentize2d(PG_FUNCTION_ARGS)
        LWGEOM_INIT();
 
        inlwgeom = lwgeom_from_gserialized(ingeom);
-       if ( lwgeom_is_empty(inlwgeom) )
+       if (lwgeom_is_empty(inlwgeom))
        {
                /* Should only happen on interruption */
                lwgeom_free(inlwgeom);
@@ -1853,19 +1842,20 @@ Datum LWGEOM_segmentize2d(PG_FUNCTION_ARGS)
        }
 
        outlwgeom = lwgeom_segmentize2d(inlwgeom, dist);
-       if ( ! outlwgeom ) {
+       if (!outlwgeom)
+       {
                /* Should only happen on interruption */
                PG_FREE_IF_COPY(ingeom, 0);
                PG_RETURN_NULL();
        }
 
        /* Copy input bounding box if any */
-       if ( inlwgeom->bbox )
+       if (inlwgeom->bbox)
                outlwgeom->bbox = gbox_copy(inlwgeom->bbox);
 
        outgeom = geometry_serialize(outlwgeom);
 
-       //lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
+       // lwgeom_free(outlwgeom); /* TODO fix lwgeom_clone / ptarray_clone_deep for consistent semantics */
        lwgeom_free(inlwgeom);
 
        PG_FREE_IF_COPY(ingeom, 0);
@@ -1962,7 +1952,6 @@ Datum ST_Normalize(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(out);
 }
 
-
 /**
  *  @return:
  *   0==2d
@@ -1977,8 +1966,10 @@ Datum LWGEOM_zmflag(PG_FUNCTION_ARGS)
        int ret = 0;
 
        in = PG_GETARG_GSERIALIZED_P(0);
-       if ( gserialized_has_z(in) ) ret += 2;
-       if ( gserialized_has_m(in) ) ret += 1;
+       if (gserialized_has_z(in))
+               ret += 2;
+       if (gserialized_has_m(in))
+               ret += 1;
        PG_FREE_IF_COPY(in, 0);
        PG_RETURN_INT16(ret);
 }
@@ -1997,7 +1988,6 @@ Datum LWGEOM_hasm(PG_FUNCTION_ARGS)
        PG_RETURN_BOOL(gserialized_has_m(in));
 }
 
-
 PG_FUNCTION_INFO_V1(LWGEOM_hasBBOX);
 Datum LWGEOM_hasBBOX(PG_FUNCTION_ARGS)
 {
@@ -2029,14 +2019,14 @@ Datum LWGEOM_same(PG_FUNCTION_ARGS)
        LWGEOM *lwg1, *lwg2;
        bool result;
 
-       if ( gserialized_get_type(g1) != gserialized_get_type(g2) )
+       if (gserialized_get_type(g1) != gserialized_get_type(g2))
        {
                PG_FREE_IF_COPY(g1, 0);
                PG_FREE_IF_COPY(g2, 1);
                PG_RETURN_BOOL(false); /* different types */
        }
 
-       if ( gserialized_get_zm(g1) != gserialized_get_zm(g2) )
+       if (gserialized_get_zm(g1) != gserialized_get_zm(g2))
        {
                PG_FREE_IF_COPY(g1, 0);
                PG_FREE_IF_COPY(g2, 1);
@@ -2073,7 +2063,8 @@ Datum ST_MakeEnvelope(PG_FUNCTION_ARGS)
        y1 = PG_GETARG_FLOAT8(1);
        x2 = PG_GETARG_FLOAT8(2);
        y2 = PG_GETARG_FLOAT8(3);
-       if ( PG_NARGS() > 4 ) {
+       if (PG_NARGS() > 4)
+       {
                srid = PG_GETARG_INT32(4);
        }
 
@@ -2105,7 +2096,7 @@ Datum ST_IsCollection(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_makepoint);
 Datum LWGEOM_makepoint(PG_FUNCTION_ARGS)
 {
-       double x,y,z,m;
+       double x, y, z, m;
        LWPOINT *point;
        GSERIALIZED *result;
 
@@ -2114,13 +2105,14 @@ Datum LWGEOM_makepoint(PG_FUNCTION_ARGS)
        x = PG_GETARG_FLOAT8(0);
        y = PG_GETARG_FLOAT8(1);
 
-       if ( PG_NARGS() == 2 ) point = lwpoint_make2d(SRID_UNKNOWN, x, y);
-       else if ( PG_NARGS() == 3 )
+       if (PG_NARGS() == 2)
+               point = lwpoint_make2d(SRID_UNKNOWN, x, y);
+       else if (PG_NARGS() == 3)
        {
                z = PG_GETARG_FLOAT8(2);
                point = lwpoint_make3dz(SRID_UNKNOWN, x, y, z);
        }
-       else if ( PG_NARGS() == 4 )
+       else if (PG_NARGS() == 4)
        {
                z = PG_GETARG_FLOAT8(2);
                m = PG_GETARG_FLOAT8(3);
@@ -2128,8 +2120,7 @@ Datum LWGEOM_makepoint(PG_FUNCTION_ARGS)
        }
        else
        {
-               elog(ERROR, "LWGEOM_makepoint: unsupported number of args: %d",
-                    PG_NARGS());
+               elog(ERROR, "LWGEOM_makepoint: unsupported number of args: %d", PG_NARGS());
                PG_RETURN_NULL();
        }
 
@@ -2141,7 +2132,7 @@ Datum LWGEOM_makepoint(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_makepoint3dm);
 Datum LWGEOM_makepoint3dm(PG_FUNCTION_ARGS)
 {
-       double x,y,m;
+       double x, y, m;
        LWPOINT *point;
        GSERIALIZED *result;
 
@@ -2170,14 +2161,13 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
        pglwg1 = PG_GETARG_GSERIALIZED_P(0);
        pglwg2 = PG_GETARG_GSERIALIZED_P(1);
 
-
-       if ( gserialized_get_type(pglwg1) != LINETYPE )
+       if (gserialized_get_type(pglwg1) != LINETYPE)
        {
                elog(ERROR, "First argument must be a LINESTRING");
                PG_RETURN_NULL();
        }
 
-       if ( gserialized_get_type(pglwg2) != POINTTYPE )
+       if (gserialized_get_type(pglwg2) != POINTTYPE)
        {
                elog(ERROR, "Second argument must be a POINT");
                PG_RETURN_NULL();
@@ -2185,7 +2175,7 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
 
        line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
 
-       if ( PG_NARGS() > 2 )
+       if (PG_NARGS() > 2)
        {
                where = PG_GETARG_INT32(2);
        }
@@ -2194,7 +2184,7 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
                where = line->points->npoints;
        }
 
-       if ( where < 0 || where > (int32) line->points->npoints )
+       if (where < 0 || where > (int32)line->points->npoints)
        {
                elog(ERROR, "Invalid offset");
                PG_RETURN_NULL();
@@ -2204,7 +2194,7 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
        linecopy = lwgeom_as_lwline(lwgeom_clone_deep(lwline_as_lwgeom(line)));
        lwline_free(line);
 
-       if ( lwline_add_lwpoint(linecopy, point, (uint32_t) where) == LW_FAILURE )
+       if (lwline_add_lwpoint(linecopy, point, (uint32_t)where) == LW_FAILURE)
        {
                elog(ERROR, "Point insert failed");
                PG_RETURN_NULL();
@@ -2218,7 +2208,6 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
        lwpoint_free(point);
 
        PG_RETURN_POINTER(result);
-
 }
 
 PG_FUNCTION_INFO_V1(LWGEOM_removepoint);
@@ -2233,7 +2222,7 @@ Datum LWGEOM_removepoint(PG_FUNCTION_ARGS)
        pglwg1 = PG_GETARG_GSERIALIZED_P(0);
        which = PG_GETARG_INT32(1);
 
-       if ( gserialized_get_type(pglwg1) != LINETYPE )
+       if (gserialized_get_type(pglwg1) != LINETYPE)
        {
                elog(ERROR, "First argument must be a LINESTRING");
                PG_RETURN_NULL();
@@ -2241,13 +2230,13 @@ Datum LWGEOM_removepoint(PG_FUNCTION_ARGS)
 
        line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
 
-       if ( which > line->points->npoints-1 )
+       if (which > line->points->npoints - 1)
        {
-               elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints-1);
+               elog(ERROR, "Point index out of range (%d..%d)", 0, line->points->npoints - 1);
                PG_RETURN_NULL();
        }
 
-       if ( line->points->npoints < 3 )
+       if (line->points->npoints < 3)
        {
                elog(ERROR, "Can't remove points from a single segment line");
                PG_RETURN_NULL();
@@ -2282,11 +2271,10 @@ Datum LWGEOM_setpoint_linestring(PG_FUNCTION_ARGS)
        which = PG_GETARG_INT32(1);
        pglwg2 = PG_GETARG_GSERIALIZED_P(2);
 
-
        /* Extract a POINT4D from the point */
        lwg = lwgeom_from_gserialized(pglwg2);
        lwpoint = lwgeom_as_lwpoint(lwg);
-       if ( ! lwpoint )
+       if (!lwpoint)
        {
                elog(ERROR, "Third argument must be a POINT");
                PG_RETURN_NULL();
@@ -2297,18 +2285,19 @@ Datum LWGEOM_setpoint_linestring(PG_FUNCTION_ARGS)
 
        lwg = lwgeom_from_gserialized(pglwg1);
        line = lwgeom_as_lwline(lwg);
-       if ( ! line )
+       if (!line)
        {
                elog(ERROR, "First argument must be a LINESTRING");
                PG_RETURN_NULL();
        }
-       if(which < 0){
+       if (which < 0)
+       {
                /* Use backward indexing for negative values */
-               which = which + line->points->npoints ;
+               which = which + line->points->npoints;
        }
-       if ( (uint32_t)which + 1 > line->points->npoints )
+       if ((uint32_t)which + 1 > line->points->npoints)
        {
-               elog(ERROR, "abs(Point index) out of range (-)(%d..%d)", 0, line->points->npoints-1);
+               elog(ERROR, "abs(Point index) out of range (-)(%d..%d)", 0, line->points->npoints - 1);
                PG_RETURN_NULL();
        }
 
@@ -2371,14 +2360,14 @@ Datum LWGEOM_azimuth(PG_FUNCTION_ARGS)
        /* Extract first point */
        geom = PG_GETARG_GSERIALIZED_P(0);
        lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
-       if ( ! lwpoint )
+       if (!lwpoint)
        {
                PG_FREE_IF_COPY(geom, 0);
                lwpgerror("Argument must be POINT geometries");
                PG_RETURN_NULL();
        }
        srid = lwpoint->srid;
-       if ( ! getPoint2d_p(lwpoint->point, 0, &p1) )
+       if (!getPoint2d_p(lwpoint->point, 0, &p1))
        {
                PG_FREE_IF_COPY(geom, 0);
                lwpgerror("Error extracting point");
@@ -2390,19 +2379,19 @@ Datum LWGEOM_azimuth(PG_FUNCTION_ARGS)
        /* Extract second point */
        geom = PG_GETARG_GSERIALIZED_P(1);
        lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
-       if ( ! lwpoint )
+       if (!lwpoint)
        {
                PG_FREE_IF_COPY(geom, 1);
                lwpgerror("Argument must be POINT geometries");
                PG_RETURN_NULL();
        }
-       if ( lwpoint->srid != srid )
+       if (lwpoint->srid != srid)
        {
                PG_FREE_IF_COPY(geom, 1);
                lwpgerror("Operation on mixed SRID geometries");
                PG_RETURN_NULL();
        }
-       if ( ! getPoint2d_p(lwpoint->point, 0, &p2) )
+       if (!getPoint2d_p(lwpoint->point, 0, &p2))
        {
                PG_FREE_IF_COPY(geom, 1);
                lwpgerror("Error extracting point");
@@ -2412,13 +2401,13 @@ Datum LWGEOM_azimuth(PG_FUNCTION_ARGS)
        PG_FREE_IF_COPY(geom, 1);
 
        /* Standard return value for equality case */
-       if ( (p1.x == p2.x) && (p1.y == p2.y) )
+       if ((p1.x == p2.x) && (p1.y == p2.y))
        {
                PG_RETURN_NULL();
        }
 
        /* Compute azimuth */
-       if ( ! azimuth_pt_pt(&p1, &p2, &result) )
+       if (!azimuth_pt_pt(&p1, &p2, &result))
        {
                PG_RETURN_NULL();
        }
@@ -2436,86 +2425,88 @@ Datum LWGEOM_azimuth(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(LWGEOM_angle);
 Datum LWGEOM_angle(PG_FUNCTION_ARGS)
 {
-       GSERIALIZED * seri_geoms[4];
+       GSERIALIZED *seri_geoms[4];
        LWGEOM *geom_unser;
        LWPOINT *lwpoint;
        POINT2D points[4];
-       double az1,az2 ;
+       double az1, az2;
        double result;
        int srids[4];
-       int i = 0 ;
+       int i = 0;
        int j = 0;
        int err_code = 0;
        int n_args = PG_NARGS();
 
        /* no deserialize, checking for common error first*/
-       for(i=0; i<n_args; i++)
+       for (i = 0; i < n_args; i++)
        {
                seri_geoms[i] = PG_GETARG_GSERIALIZED_P(i);
-               if (gserialized_is_empty(seri_geoms[i]) )
-               {/* empty geom */
-                       if (i==3)
+               if (gserialized_is_empty(seri_geoms[i]))
+               { /* empty geom */
+                       if (i == 3)
                        {
-                               n_args = 3 ;
+                               n_args = 3;
                        }
                        else
                        {
-                               err_code = 1 ;
-                               break ;
+                               err_code = 1;
+                               break;
                        }
-               } else
+               }
+               else
                {
-                       if(gserialized_get_type(seri_geoms[i]) != POINTTYPE)
-                       {/* geom type */
-                               err_code = 2 ;
+                       if (gserialized_get_type(seri_geoms[i]) != POINTTYPE)
+                       { /* geom type */
+                               err_code = 2;
                                break;
                        }
                        else
                        {
-                               srids[i] = gserialized_get_srid(seri_geoms[i]) ;
-                               if(srids[0] != srids[i])
-                               {/* error on srid*/
-                                       err_code = 3 ;
+                               srids[i] = gserialized_get_srid(seri_geoms[i]);
+                               if (srids[0] != srids[i])
+                               { /* error on srid*/
+                                       err_code = 3;
                                        break;
                                }
                        }
                }
        }
-       if (err_code >0)
-               switch (err_code){
-                       default: /*always executed*/
-                       for (j=0;j<=i;j++)
+       if (err_code > 0)
+               switch (err_code)
+               {
+               default: /*always executed*/
+                       for (j = 0; j <= i; j++)
                                PG_FREE_IF_COPY(seri_geoms[j], j);
-                       /*FALLTHROUGH*/
-                       case 1:
+               /*FALLTHROUGH*/
+               case 1:
                        lwpgerror("Empty geometry");
-                       PG_RETURN_NULL() ;
+                       PG_RETURN_NULL();
                        break;
 
-                       case 2:
+               case 2:
                        lwpgerror("Argument must be POINT geometries");
                        PG_RETURN_NULL();
                        break;
 
-                       case 3:
+               case 3:
                        lwpgerror("Operation on mixed SRID geometries");
                        PG_RETURN_NULL();
                        break;
                }
        /* extract points */
-       for(i=0; i<n_args; i++)
+       for (i = 0; i < n_args; i++)
        {
-               geom_unser = lwgeom_from_gserialized(seri_geoms[i]) ;
+               geom_unser = lwgeom_from_gserialized(seri_geoms[i]);
                lwpoint = lwgeom_as_lwpoint(geom_unser);
                if (!lwpoint)
                {
-                       for (j=0;j<n_args;j++)
+                       for (j = 0; j < n_args; j++)
                                PG_FREE_IF_COPY(seri_geoms[j], j);
                        lwpgerror("Error unserializing geometry");
-                       PG_RETURN_NULL() ;
+                       PG_RETURN_NULL();
                }
 
-               if ( ! getPoint2d_p(lwpoint->point, 0, &points[i]) )
+               if (!getPoint2d_p(lwpoint->point, 0, &points[i]))
                {
                        /* // can't free serialized geom, it might be needed by lw
                        for (j=0;j<n_args;j++)
@@ -2533,24 +2524,24 @@ Datum LWGEOM_angle(PG_FUNCTION_ARGS)
        /* compute azimuth for the 2 pairs of points
         * note that angle is not defined identically for 3 points or 4 points*/
        if (n_args == 3)
-       {/* we rely on azimuth to complain if points are identical */
-               if ( ! azimuth_pt_pt(&points[0], &points[1], &az1) )
+       { /* we rely on azimuth to complain if points are identical */
+               if (!azimuth_pt_pt(&points[0], &points[1], &az1))
                        PG_RETURN_NULL();
-               if ( ! azimuth_pt_pt(&points[2], &points[1], &az2) )
+               if (!azimuth_pt_pt(&points[2], &points[1], &az2))
                        PG_RETURN_NULL();
-       } else
+       }
+       else
        {
-               if ( ! azimuth_pt_pt(&points[0], &points[1], &az1) )
+               if (!azimuth_pt_pt(&points[0], &points[1], &az1))
                        PG_RETURN_NULL();
-               if ( ! azimuth_pt_pt(&points[2], &points[3], &az2) )
+               if (!azimuth_pt_pt(&points[2], &points[3], &az2))
                        PG_RETURN_NULL();
        }
-       result = az2-az1 ;
-       result += (result<0) * 2 * M_PI ; /* we dont want negative angle*/
+       result = az2 - az1;
+       result += (result < 0) * 2 * M_PI; /* we dont want negative angle*/
        PG_RETURN_FLOAT8(result);
 }
 
-
 /*
  * optimistic_overlap(Polygon P1, Multipolygon MP2, double dist)
  * returns true if P1 overlaps MP2
@@ -2574,42 +2565,40 @@ Datum optimistic_overlap(PG_FUNCTION_ARGS)
 
        if (geom1->type != POLYGONTYPE)
        {
-               elog(ERROR,"optimistic_overlap: first arg isn't a polygon\n");
+               elog(ERROR, "optimistic_overlap: first arg isn't a polygon\n");
                PG_RETURN_NULL();
        }
 
-       if (geom2->type != POLYGONTYPE &&  geom2->type != MULTIPOLYGONTYPE)
+       if (geom2->type != POLYGONTYPE && geom2->type != MULTIPOLYGONTYPE)
        {
-               elog(ERROR,"optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
+               elog(ERROR, "optimistic_overlap: 2nd arg isn't a [multi-]polygon\n");
                PG_RETURN_NULL();
        }
 
        /*bbox check */
-       gserialized_get_gbox_p(pg_geom1, &g1_bvol );
+       gserialized_get_gbox_p(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;
 
-       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) )
+       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 */
+               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 )));
+       calc_dist = DatumGetFloat8(
+           DirectFunctionCall2(LWGEOM_mindistance2d, PointerGetDatum(pg_geom1), PointerGetDatum(pg_geom2)));
 
        PG_RETURN_BOOL(calc_dist < dist);
 }
 
-
 /*affine transform geometry */
 PG_FUNCTION_INFO_V1(LWGEOM_affine);
 Datum LWGEOM_affine(PG_FUNCTION_ARGS)
@@ -2619,25 +2608,25 @@ Datum LWGEOM_affine(PG_FUNCTION_ARGS)
        GSERIALIZED *ret;
        AFFINE affine;
 
-       affine.afac =  PG_GETARG_FLOAT8(1);
-       affine.bfac =  PG_GETARG_FLOAT8(2);
-       affine.cfac =  PG_GETARG_FLOAT8(3);
-       affine.dfac =  PG_GETARG_FLOAT8(4);
-       affine.efac =  PG_GETARG_FLOAT8(5);
-       affine.ffac =  PG_GETARG_FLOAT8(6);
-       affine.gfac =  PG_GETARG_FLOAT8(7);
-       affine.hfac =  PG_GETARG_FLOAT8(8);
-       affine.ifac =  PG_GETARG_FLOAT8(9);
-       affine.xoff =  PG_GETARG_FLOAT8(10);
-       affine.yoff =  PG_GETARG_FLOAT8(11);
-       affine.zoff =  PG_GETARG_FLOAT8(12);
+       affine.afac = PG_GETARG_FLOAT8(1);
+       affine.bfac = PG_GETARG_FLOAT8(2);
+       affine.cfac = PG_GETARG_FLOAT8(3);
+       affine.dfac = PG_GETARG_FLOAT8(4);
+       affine.efac = PG_GETARG_FLOAT8(5);
+       affine.ffac = PG_GETARG_FLOAT8(6);
+       affine.gfac = PG_GETARG_FLOAT8(7);
+       affine.hfac = PG_GETARG_FLOAT8(8);
+       affine.ifac = PG_GETARG_FLOAT8(9);
+       affine.xoff = PG_GETARG_FLOAT8(10);
+       affine.yoff = PG_GETARG_FLOAT8(11);
+       affine.zoff = PG_GETARG_FLOAT8(12);
 
        POSTGIS_DEBUG(2, "LWGEOM_affine called.");
 
        lwgeom_affine(lwgeom, &affine);
 
        /* COMPUTE_BBOX TAINTING */
-       if ( lwgeom->bbox )
+       if (lwgeom->bbox)
        {
                lwgeom_refresh_bbox(lwgeom);
        }
@@ -2659,21 +2648,21 @@ Datum ST_GeoHash(PG_FUNCTION_ARGS)
        char *geohash = NULL;
        text *result = NULL;
 
-       if ( PG_ARGISNULL(0) )
+       if (PG_ARGISNULL(0))
        {
                PG_RETURN_NULL();
        }
 
        geom = PG_GETARG_GSERIALIZED_P(0);
 
-       if ( ! PG_ARGISNULL(1) )
+       if (!PG_ARGISNULL(1))
        {
                precision = PG_GETARG_INT32(1);
        }
 
-       geohash = lwgeom_geohash((LWGEOM*)(lwgeom_from_gserialized(geom)), precision);
+       geohash = lwgeom_geohash((LWGEOM *)(lwgeom_from_gserialized(geom)), precision);
 
-       if ( ! geohash )
+       if (!geohash)
                PG_RETURN_NULL();
 
        result = cstring_to_text(geohash);
@@ -2693,7 +2682,7 @@ Datum ST_CollectionExtract(PG_FUNCTION_ARGS)
        int lwgeom_type = lwgeom->type;
 
        /* Ensure the right type was input */
-       if ( ! ( type == POINTTYPE || type == LINETYPE || type == POLYGONTYPE ) )
+       if (!(type == POINTTYPE || type == LINETYPE || type == POLYGONTYPE))
        {
                lwgeom_free(lwgeom);
                elog(ERROR, "ST_CollectionExtract: only point, linestring and polygon may be extracted");
@@ -2701,10 +2690,10 @@ Datum ST_CollectionExtract(PG_FUNCTION_ARGS)
        }
 
        /* Mirror non-collections right back */
-       if ( ! lwgeom_is_collection(lwgeom) )
+       if (!lwgeom_is_collection(lwgeom))
        {
                /* Non-collections of the matching type go back */
-               if(lwgeom_type == type)
+               if (lwgeom_type == type)
                {
                        lwgeom_free(lwgeom);
                        PG_RETURN_POINTER(input);
@@ -2712,15 +2701,16 @@ Datum ST_CollectionExtract(PG_FUNCTION_ARGS)
                /* Others go back as EMPTY */
                else
                {
-                       lwcol = lwgeom_construct_empty(type, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
+                       lwcol = lwgeom_construct_empty(
+                           type, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
                }
        }
        else
        {
-               lwcol = lwcollection_as_lwgeom(lwcollection_extract((LWCOLLECTION*)lwgeom, type));
+               lwcol = lwcollection_as_lwgeom(lwcollection_extract((LWCOLLECTION *)lwgeom, type));
        }
 
-       output = geometry_serialize((LWGEOM*)lwcol);
+       output = geometry_serialize((LWGEOM *)lwcol);
        lwgeom_free(lwgeom);
        lwgeom_free(lwcol);
 
@@ -2763,17 +2753,17 @@ Datum ST_RemoveRepeatedPoints(PG_FUNCTION_ARGS)
        double tolerance = 0.0;
 
        /* Don't even start to think about points */
-       if ( type == POINTTYPE )
+       if (type == POINTTYPE)
                PG_RETURN_POINTER(g_in);
 
-       if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
+       if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
                tolerance = PG_GETARG_FLOAT8(1);
 
        lwgeom_in = lwgeom_from_gserialized(g_in);
        lwgeom_out = lwgeom_remove_repeated_points(lwgeom_in, tolerance);
        g_out = geometry_serialize(lwgeom_out);
 
-       if ( lwgeom_out != lwgeom_in )
+       if (lwgeom_out != lwgeom_in)
        {
                lwgeom_free(lwgeom_out);
        }
@@ -2801,60 +2791,68 @@ Datum ST_FlipCoordinates(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(out);
 }
 
-static LWORD ordname2ordval(char n)
+static LWORD
+ordname2ordval(char n)
 {
-  if ( n == 'x' || n == 'X' ) return LWORD_X;
-  if ( n == 'y' || n == 'Y' ) return LWORD_Y;
-  if ( n == 'z' || n == 'Z' ) return LWORD_Z;
-  if ( n == 'm' || n == 'M' ) return LWORD_M;
-  lwpgerror("Invalid ordinate name '%c'. Expected x,y,z or m", n);
-  return (LWORD)-1;
+       if (n == 'x' || n == 'X')
+               return LWORD_X;
+       if (n == 'y' || n == 'Y')
+               return LWORD_Y;
+       if (n == 'z' || n == 'Z')
+               return LWORD_Z;
+       if (n == 'm' || n == 'M')
+               return LWORD_M;
+       lwpgerror("Invalid ordinate name '%c'. Expected x,y,z or m", n);
+       return (LWORD)-1;
 }
 
 Datum ST_SwapOrdinates(PG_FUNCTION_ARGS);
 PG_FUNCTION_INFO_V1(ST_SwapOrdinates);
 Datum ST_SwapOrdinates(PG_FUNCTION_ARGS)
 {
-  GSERIALIZED *in;
-  GSERIALIZED *out;
-  LWGEOM *lwgeom;
-  const char *ospec;
-  LWORD o1, o2;
-
-  ospec = PG_GETARG_CSTRING(1);
-  if ( strlen(ospec) != 2 )
-  {
-    lwpgerror("Invalid ordinate specification. "
-            "Need two letters from the set (x,y,z,m). "
-            "Got '%s'", ospec);
-    PG_RETURN_NULL();
-  }
-  o1 = ordname2ordval( ospec[0] );
-  o2 = ordname2ordval( ospec[1] );
-
-  in = PG_GETARG_GSERIALIZED_P_COPY(0);
-
-  /* Check presence of given ordinates */
-  if ( ( o1 == LWORD_M || o2 == LWORD_M ) && ! gserialized_has_m(in) )
-  {
-    lwpgerror("Geometry does not have an M ordinate");
-    PG_RETURN_NULL();
-  }
-  if ( ( o1 == LWORD_Z || o2 == LWORD_Z ) && ! gserialized_has_z(in) )
-  {
-    lwpgerror("Geometry does not have a Z ordinate");
-    PG_RETURN_NULL();
-  }
-
-  /* Nothing to do if swapping the same ordinate, pity for the copy... */
-  if ( o1 == o2 ) PG_RETURN_POINTER(in);
-
-  lwgeom = lwgeom_from_gserialized(in);
-  lwgeom_swap_ordinates(lwgeom, o1, o2);
-  out = geometry_serialize(lwgeom);
-  lwgeom_free(lwgeom);
-  PG_FREE_IF_COPY(in, 0);
-  PG_RETURN_POINTER(out);
+       GSERIALIZED *in;
+       GSERIALIZED *out;
+       LWGEOM *lwgeom;
+       const char *ospec;
+       LWORD o1, o2;
+
+       ospec = PG_GETARG_CSTRING(1);
+       if (strlen(ospec) != 2)
+       {
+               lwpgerror(
+                   "Invalid ordinate specification. "
+                   "Need two letters from the set (x,y,z,m). "
+                   "Got '%s'",
+                   ospec);
+               PG_RETURN_NULL();
+       }
+       o1 = ordname2ordval(ospec[0]);
+       o2 = ordname2ordval(ospec[1]);
+
+       in = PG_GETARG_GSERIALIZED_P_COPY(0);
+
+       /* Check presence of given ordinates */
+       if ((o1 == LWORD_M || o2 == LWORD_M) && !gserialized_has_m(in))
+       {
+               lwpgerror("Geometry does not have an M ordinate");
+               PG_RETURN_NULL();
+       }
+       if ((o1 == LWORD_Z || o2 == LWORD_Z) && !gserialized_has_z(in))
+       {
+               lwpgerror("Geometry does not have a Z ordinate");
+               PG_RETURN_NULL();
+       }
+
+       /* Nothing to do if swapping the same ordinate, pity for the copy... */
+       if (o1 == o2)
+               PG_RETURN_POINTER(in);
+
+       lwgeom = lwgeom_from_gserialized(in);
+       lwgeom_swap_ordinates(lwgeom, o1, o2);
+       out = geometry_serialize(lwgeom);
+       lwgeom_free(lwgeom);
+       PG_FREE_IF_COPY(in, 0);
+       PG_RETURN_POINTER(out);
 }
 
 /*
@@ -2864,52 +2862,53 @@ Datum ST_BoundingDiagonal(PG_FUNCTION_ARGS);
 PG_FUNCTION_INFO_V1(ST_BoundingDiagonal);
 Datum ST_BoundingDiagonal(PG_FUNCTION_ARGS)
 {
-  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
-  GSERIALIZED *geom_out;
-  bool fits = PG_GETARG_BOOL(1);
-  LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
-  LWGEOM *lwgeom_out;
-  const GBOX *gbox;
-  int hasz = FLAGS_GET_Z(lwgeom_in->flags);
-  int hasm = FLAGS_GET_M(lwgeom_in->flags);
-  int srid = lwgeom_in->srid;
-  POINT4D pt;
-  POINTARRAY *pa;
-
-  if ( fits ) {
-    /* unregister any cached bbox to ensure it's recomputed */
-    lwgeom_in->bbox = NULL;
-  }
-
-  gbox = lwgeom_get_bbox(lwgeom_in);
-
-  if ( ! gbox )
-  {
-    lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
-  }
-  else
-  {
-    pa = ptarray_construct_empty(hasz, hasm, 2);
-    pt.x = gbox->xmin;
-    pt.y = gbox->ymin;
-    pt.z = gbox->zmin;
-    pt.m = gbox->mmin;
-    ptarray_append_point(pa, &pt, LW_TRUE);
-    pt.x = gbox->xmax;
-    pt.y = gbox->ymax;
-    pt.z = gbox->zmax;
-    pt.m = gbox->mmax;
-    ptarray_append_point(pa, &pt, LW_TRUE);
-    lwgeom_out = lwline_as_lwgeom( lwline_construct(srid, NULL, pa) );
-  }
-
-  lwgeom_free(lwgeom_in);
-  PG_FREE_IF_COPY(geom_in, 0);
-
-  geom_out = geometry_serialize(lwgeom_out);
-  lwgeom_free(lwgeom_out);
-
-  PG_RETURN_POINTER(geom_out);
+       GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
+       GSERIALIZED *geom_out;
+       bool fits = PG_GETARG_BOOL(1);
+       LWGEOM *lwgeom_in = lwgeom_from_gserialized(geom_in);
+       LWGEOM *lwgeom_out;
+       const GBOX *gbox;
+       int hasz = FLAGS_GET_Z(lwgeom_in->flags);
+       int hasm = FLAGS_GET_M(lwgeom_in->flags);
+       int srid = lwgeom_in->srid;
+       POINT4D pt;
+       POINTARRAY *pa;
+
+       if (fits)
+       {
+               /* unregister any cached bbox to ensure it's recomputed */
+               lwgeom_in->bbox = NULL;
+       }
+
+       gbox = lwgeom_get_bbox(lwgeom_in);
+
+       if (!gbox)
+       {
+               lwgeom_out = lwgeom_construct_empty(LINETYPE, srid, hasz, hasm);
+       }
+       else
+       {
+               pa = ptarray_construct_empty(hasz, hasm, 2);
+               pt.x = gbox->xmin;
+               pt.y = gbox->ymin;
+               pt.z = gbox->zmin;
+               pt.m = gbox->mmin;
+               ptarray_append_point(pa, &pt, LW_TRUE);
+               pt.x = gbox->xmax;
+               pt.y = gbox->ymax;
+               pt.z = gbox->zmax;
+               pt.m = gbox->mmax;
+               ptarray_append_point(pa, &pt, LW_TRUE);
+               lwgeom_out = lwline_as_lwgeom(lwline_construct(srid, NULL, pa));
+       }
+
+       lwgeom_free(lwgeom_in);
+       PG_FREE_IF_COPY(geom_in, 0);
+
+       geom_out = geometry_serialize(lwgeom_out);
+       lwgeom_free(lwgeom_out);
+
+       PG_RETURN_POINTER(geom_out);
 }
 
 Datum ST_Scale(PG_FUNCTION_ARGS);
@@ -2954,8 +2953,10 @@ Datum ST_Scale(PG_FUNCTION_ARGS)
        /* Once we read the scale data into local static point, we can */
        /* free the lwgeom */
        lwpoint_getPoint4d_p(lwpt_scale, &factors);
-       if (!lwgeom_has_z(lwg_scale)) factors.z = 1.0;
-       if (!lwgeom_has_m(lwg_scale)) factors.m = 1.0;
+       if (!lwgeom_has_z(lwg_scale))
+               factors.z = 1.0;
+       if (!lwgeom_has_m(lwg_scale))
+               factors.m = 1.0;
        lwgeom_free(lwg_scale);
 
        /* Do we have the optional false origin? */
@@ -3017,10 +3018,10 @@ Datum ST_Points(PG_FUNCTION_ARGS)
        }
        else
        {
-               GSERIALIZEDgeom = PG_GETARG_GSERIALIZED_P(0);
-               GSERIALIZEDret;
-               LWGEOMlwgeom = lwgeom_from_gserialized(geom);
-               LWMPOINTresult = lwmpoint_from_lwgeom(lwgeom);
+               GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
+               GSERIALIZED *ret;
+               LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
+               LWMPOINT *result = lwmpoint_from_lwgeom(lwgeom);
 
                lwgeom_free(lwgeom);
 
@@ -3033,9 +3034,9 @@ Datum ST_Points(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(ST_QuantizeCoordinates);
 Datum ST_QuantizeCoordinates(PG_FUNCTION_ARGS)
 {
-       GSERIALIZEDinput;
-       GSERIALIZEDresult;
-       LWGEOMg;
+       GSERIALIZED *input;
+       GSERIALIZED *result;
+       LWGEOM *g;
        int32_t prec_x;
        int32_t prec_y;
        int32_t prec_z;
@@ -3068,7 +3069,6 @@ Datum ST_QuantizeCoordinates(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(result);
 }
 
-
 /*
  * ST_FilterByM(in geometry, val double precision)
  */
@@ -3083,7 +3083,7 @@ Datum LWGEOM_FilterByM(PG_FUNCTION_ARGS)
        int returnm;
        int hasm;
 
-       if ( PG_NARGS() > 0 && ! PG_ARGISNULL(0))
+       if (PG_NARGS() > 0 && !PG_ARGISNULL(0))
        {
                geom_in = PG_GETARG_GSERIALIZED_P(0);
        }
@@ -3092,28 +3092,28 @@ Datum LWGEOM_FilterByM(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
 
-       if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1))
+       if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
                min = PG_GETARG_FLOAT8(1);
        else
        {
                min = DBL_MIN;
        }
-       if ( PG_NARGS() > 2  && ! PG_ARGISNULL(2))
+       if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
                max = PG_GETARG_FLOAT8(2);
        else
        {
                max = DBL_MAX;
        }
-       if ( PG_NARGS() > 3  && ! PG_ARGISNULL(3) && PG_GETARG_BOOL(3))
+       if (PG_NARGS() > 3 && !PG_ARGISNULL(3) && PG_GETARG_BOOL(3))
                returnm = 1;
        else
        {
-               returnm=0;
+               returnm = 0;
        }
 
-       if(min>max)
+       if (min > max)
        {
-               elog(ERROR,"Min-value cannot be larger than Max value\n");
+               elog(ERROR, "Min-value cannot be larger than Max value\n");
                PG_RETURN_NULL();
        }
 
@@ -3121,16 +3121,15 @@ Datum LWGEOM_FilterByM(PG_FUNCTION_ARGS)
 
        hasm = FLAGS_GET_M(lwgeom_in->flags);
 
-       if(!hasm)
+       if (!hasm)
        {
-               elog(NOTICE,"No M-value, No vertex removed\n");
+               elog(NOTICE, "No M-value, No vertex removed\n");
                PG_RETURN_POINTER(geom_in);
        }
 
-       lwgeom_out = lwgeom_filter_m(lwgeom_in, min, max,returnm);
+       lwgeom_out = lwgeom_filter_m(lwgeom_in, min, max, returnm);
 
        geom_out = geometry_serialize(lwgeom_out);
        lwgeom_free(lwgeom_out);
        PG_RETURN_POINTER(geom_out);
-
 }
index 2b28e3fa041bfa4657a6a50086d7295f732d1247..bb23dc0c56cb1844b565f4bbb410eb7498fda8f5 100644 (file)
@@ -22,7 +22,6 @@
  *
  **********************************************************************/
 
-
 #include "postgres.h"
 #include "fmgr.h"
 #include "utils/builtins.h"
@@ -32,7 +31,6 @@
 #include "lwgeom_sfcgal.h"
 #include "../postgis_config.h"
 
-
 Datum postgis_sfcgal_version(PG_FUNCTION_ARGS);
 
 Datum sfcgal_from_ewkt(PG_FUNCTION_ARGS);
@@ -60,30 +58,31 @@ Datum sfcgal_minkowski_sum(PG_FUNCTION_ARGS);
 Datum sfcgal_make_solid(PG_FUNCTION_ARGS);
 Datum sfcgal_is_solid(PG_FUNCTION_ARGS);
 
-
 GSERIALIZED *geometry_serialize(LWGEOM *lwgeom);
-chartext_to_cstring(const text *textptr);
+char *text_to_cstring(const text *textptr);
 
 static int __sfcgal_init = 0;
 
-void sfcgal_postgis_init(void)
+void
+sfcgal_postgis_init(void)
 {
-    if ( ! __sfcgal_init ) {
-       sfcgal_init();
-       sfcgal_set_error_handlers((sfcgal_error_handler_t) lwpgnotice, (sfcgal_error_handler_t) lwpgerror);
-       sfcgal_set_alloc_handlers(lwalloc, lwfree);
-       __sfcgal_init = 1;
-    }
+       if (!__sfcgal_init)
+       {
+               sfcgal_init();
+               sfcgal_set_error_handlers((sfcgal_error_handler_t)lwpgnotice, (sfcgal_error_handler_t)lwpgerror);
+               sfcgal_set_alloc_handlers(lwalloc, lwfree);
+               __sfcgal_init = 1;
+       }
 }
 
-
 /* Conversion from GSERIALIZED* to SFCGAL::Geometry */
-sfcgal_geometry_t* POSTGIS2SFCGALGeometry(GSERIALIZED *pglwgeom)
+sfcgal_geometry_t *
+POSTGIS2SFCGALGeometry(GSERIALIZED *pglwgeom)
 {
-       sfcgal_geometry_tg;
+       sfcgal_geometry_t *g;
        LWGEOM *lwgeom = lwgeom_from_gserialized(pglwgeom);
 
-       if (! lwgeom)
+       if (!lwgeom)
        {
                lwpgerror("POSTGIS2SFCGALGeometry: Unable to deserialize input");
        }
@@ -93,11 +92,11 @@ sfcgal_geometry_t* POSTGIS2SFCGALGeometry(GSERIALIZED *pglwgeom)
        return g;
 }
 
-
 /* Conversion from GSERIALIZED* to SFCGAL::PreparedGeometry */
-sfcgal_prepared_geometry_t* POSTGIS2SFCGALPreparedGeometry(GSERIALIZED *pglwgeom)
+sfcgal_prepared_geometry_t *
+POSTGIS2SFCGALPreparedGeometry(GSERIALIZED *pglwgeom)
 {
-       sfcgal_geometry_tg;
+       sfcgal_geometry_t *g;
        LWGEOM *lwgeom = lwgeom_from_gserialized(pglwgeom);
 
        if (!lwgeom)
@@ -111,12 +110,12 @@ sfcgal_prepared_geometry_t* POSTGIS2SFCGALPreparedGeometry(GSERIALIZED *pglwgeom
        return sfcgal_prepared_geometry_create_from_geometry(g, gserialized_get_srid(pglwgeom));
 }
 
-
 /* Conversion from SFCGAL::Geometry to GSERIALIZED */
-GSERIALIZED* SFCGALGeometry2POSTGIS(const sfcgal_geometry_t* geom, int force3D, int SRID)
+GSERIALIZED *
+SFCGALGeometry2POSTGIS(const sfcgal_geometry_t *geom, int force3D, int SRID)
 {
        GSERIALIZED *result;
-       LWGEOMlwgeom = SFCGAL2LWGEOM(geom, force3D, SRID);
+       LWGEOM *lwgeom = SFCGAL2LWGEOM(geom, force3D, SRID);
 
        if (lwgeom_needs_bbox(lwgeom) == LW_TRUE)
                lwgeom_add_bbox(lwgeom);
@@ -127,37 +126,35 @@ GSERIALIZED* SFCGALGeometry2POSTGIS(const sfcgal_geometry_t* geom, int force3D,
        return result;
 }
 
-
 /* Conversion from SFCGAL::PreparedGeometry to GSERIALIZED */
-GSERIALIZED* SFCGALPreparedGeometry2POSTGIS(const sfcgal_prepared_geometry_t* geom, int force3D)
+GSERIALIZED *
+SFCGALPreparedGeometry2POSTGIS(const sfcgal_prepared_geometry_t *geom, int force3D)
 {
-    return SFCGALGeometry2POSTGIS(sfcgal_prepared_geometry_geometry(geom),
-               force3D, sfcgal_prepared_geometry_srid(geom));
+       return SFCGALGeometry2POSTGIS(
+           sfcgal_prepared_geometry_geometry(geom), force3D, sfcgal_prepared_geometry_srid(geom));
 }
 
-
 /* Conversion from EWKT to GSERIALIZED */
 PG_FUNCTION_INFO_V1(sfcgal_from_ewkt);
 Datum sfcgal_from_ewkt(PG_FUNCTION_ARGS)
 {
-       GSERIALIZEDresult;
-       sfcgal_prepared_geometry_tg;
+       GSERIALIZED *result;
+       sfcgal_prepared_geometry_t *g;
        text *wkttext = PG_GETARG_TEXT_P(0);
        char *cstring = text_to_cstring(wkttext);
 
        sfcgal_postgis_init();
 
-       g = sfcgal_io_read_ewkt( cstring, strlen(cstring) );
+       g = sfcgal_io_read_ewkt(cstring, strlen(cstring));
 
-       result = SFCGALPreparedGeometry2POSTGIS( g, 0 );
-       sfcgal_prepared_geometry_delete( g );
+       result = SFCGALPreparedGeometry2POSTGIS(g, 0);
+       sfcgal_prepared_geometry_delete(g);
        PG_RETURN_POINTER(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_area3D);
 Datum sfcgal_area3D(PG_FUNCTION_ARGS)
-    {
+{
        GSERIALIZED *input;
        sfcgal_geometry_t *geom;
        double result;
@@ -175,7 +172,6 @@ Datum sfcgal_area3D(PG_FUNCTION_ARGS)
        PG_RETURN_FLOAT8(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_is_planar);
 Datum sfcgal_is_planar(PG_FUNCTION_ARGS)
 {
@@ -196,7 +192,6 @@ Datum sfcgal_is_planar(PG_FUNCTION_ARGS)
        PG_RETURN_BOOL(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_orientation);
 Datum sfcgal_orientation(PG_FUNCTION_ARGS)
 {
@@ -217,7 +212,6 @@ Datum sfcgal_orientation(PG_FUNCTION_ARGS)
        PG_RETURN_INT32(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_intersects);
 Datum sfcgal_intersects(PG_FUNCTION_ARGS)
 {
@@ -241,7 +235,6 @@ Datum sfcgal_intersects(PG_FUNCTION_ARGS)
        PG_RETURN_BOOL(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_intersects3D);
 Datum sfcgal_intersects3D(PG_FUNCTION_ARGS)
 {
@@ -265,7 +258,6 @@ Datum sfcgal_intersects3D(PG_FUNCTION_ARGS)
        PG_RETURN_BOOL(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_distance);
 Datum sfcgal_distance(PG_FUNCTION_ARGS)
 {
@@ -289,7 +281,6 @@ Datum sfcgal_distance(PG_FUNCTION_ARGS)
        PG_RETURN_FLOAT8(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_distance3D);
 Datum sfcgal_distance3D(PG_FUNCTION_ARGS)
 {
@@ -313,7 +304,6 @@ Datum sfcgal_distance3D(PG_FUNCTION_ARGS)
        PG_RETURN_FLOAT8(result);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_tesselate);
 Datum sfcgal_tesselate(PG_FUNCTION_ARGS)
 {
@@ -338,7 +328,6 @@ Datum sfcgal_tesselate(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(output);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_triangulate);
 Datum sfcgal_triangulate(PG_FUNCTION_ARGS)
 {
@@ -363,7 +352,6 @@ Datum sfcgal_triangulate(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(output);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_force_lhr);
 Datum sfcgal_force_lhr(PG_FUNCTION_ARGS)
 {
@@ -388,7 +376,6 @@ Datum sfcgal_force_lhr(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(output);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_straight_skeleton);
 Datum sfcgal_straight_skeleton(PG_FUNCTION_ARGS)
 {
@@ -417,12 +404,13 @@ PG_FUNCTION_INFO_V1(sfcgal_approximate_medial_axis);
 Datum sfcgal_approximate_medial_axis(PG_FUNCTION_ARGS)
 {
 #if POSTGIS_SFCGAL_VERSION < 12
-       lwpgerror("The SFCGAL version this PostGIS binary "
-               "was compiled against (%d) doesn't support "
-               "'sfcgal_geometry_approximate_medial_axis' function (1.2.0+ required)",
-               POSTGIS_SFCGAL_VERSION);
+       lwpgerror(
+           "The SFCGAL version this PostGIS binary "
+           "was compiled against (%d) doesn't support "
+           "'sfcgal_geometry_approximate_medial_axis' function (1.2.0+ required)",
+           POSTGIS_SFCGAL_VERSION);
        PG_RETURN_NULL();
-#else /* POSTGIS_SFCGAL_VERSION >= 12 */
+#else  /* POSTGIS_SFCGAL_VERSION >= 12 */
        GSERIALIZED *input, *output;
        sfcgal_geometry_t *geom;
        sfcgal_geometry_t *result;
@@ -445,7 +433,6 @@ Datum sfcgal_approximate_medial_axis(PG_FUNCTION_ARGS)
 #endif /* POSTGIS_SFCGAL_VERSION >= 12 */
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_intersection);
 Datum sfcgal_intersection(PG_FUNCTION_ARGS)
 {
@@ -474,7 +461,6 @@ Datum sfcgal_intersection(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(output);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_intersection3D);
 Datum sfcgal_intersection3D(PG_FUNCTION_ARGS)
 {
@@ -513,9 +499,9 @@ Datum sfcgal_difference(PG_FUNCTION_ARGS)
 
        sfcgal_postgis_init();
 
-       input0 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       input0 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
        srid = gserialized_get_srid(input0);
-       input1 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+       input1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
        geom0 = POSTGIS2SFCGALGeometry(input0);
        PG_FREE_IF_COPY(input0, 0);
        geom1 = POSTGIS2SFCGALGeometry(input1);
@@ -531,7 +517,6 @@ Datum sfcgal_difference(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(output);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_difference3D);
 Datum sfcgal_difference3D(PG_FUNCTION_ARGS)
 {
@@ -542,9 +527,9 @@ Datum sfcgal_difference3D(PG_FUNCTION_ARGS)
 
        sfcgal_postgis_init();
 
-       input0 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       input0 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
        srid = gserialized_get_srid(input0);
-       input1 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+       input1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
        geom0 = POSTGIS2SFCGALGeometry(input0);
        PG_FREE_IF_COPY(input0, 0);
        geom1 = POSTGIS2SFCGALGeometry(input1);
@@ -570,9 +555,9 @@ Datum sfcgal_union(PG_FUNCTION_ARGS)
 
        sfcgal_postgis_init();
 
-       input0 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       input0 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
        srid = gserialized_get_srid(input0);
-       input1 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+       input1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
        geom0 = POSTGIS2SFCGALGeometry(input0);
        PG_FREE_IF_COPY(input0, 0);
        geom1 = POSTGIS2SFCGALGeometry(input1);
@@ -588,7 +573,6 @@ Datum sfcgal_union(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(output);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_union3D);
 Datum sfcgal_union3D(PG_FUNCTION_ARGS)
 {
@@ -599,9 +583,9 @@ Datum sfcgal_union3D(PG_FUNCTION_ARGS)
 
        sfcgal_postgis_init();
 
-       input0 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       input0 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
        srid = gserialized_get_srid(input0);
-       input1 = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+       input1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
        geom0 = POSTGIS2SFCGALGeometry(input0);
        PG_FREE_IF_COPY(input0, 0);
        geom1 = POSTGIS2SFCGALGeometry(input1);
@@ -626,7 +610,7 @@ Datum sfcgal_volume(PG_FUNCTION_ARGS)
 
        sfcgal_postgis_init();
 
-       input = (GSERIALIZED*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       input = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
        geom = POSTGIS2SFCGALGeometry(input);
 
        result = sfcgal_geometry_volume(geom);
@@ -665,43 +649,42 @@ Datum sfcgal_minkowski_sum(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(output);
 }
 
-
 PG_FUNCTION_INFO_V1(sfcgal_extrude);
 Datum sfcgal_extrude(PG_FUNCTION_ARGS)
 {
-    GSERIALIZED *input, *output;
-    sfcgal_geometry_t *geom;
-    sfcgal_geometry_t *result;
-    double dx, dy, dz;
-    srid_t srid;
+       GSERIALIZED *input, *output;
+       sfcgal_geometry_t *geom;
+       sfcgal_geometry_t *result;
+       double dx, dy, dz;
+       srid_t srid;
 
-    sfcgal_postgis_init();
+       sfcgal_postgis_init();
 
-    input = PG_GETARG_GSERIALIZED_P(0);
-    srid = gserialized_get_srid(input);
+       input = PG_GETARG_GSERIALIZED_P(0);
+       srid = gserialized_get_srid(input);
 
-    geom = POSTGIS2SFCGALGeometry(input);
-    PG_FREE_IF_COPY(input, 0);
+       geom = POSTGIS2SFCGALGeometry(input);
+       PG_FREE_IF_COPY(input, 0);
 
-    dx = PG_GETARG_FLOAT8(1);
-    dy = PG_GETARG_FLOAT8(2);
-    dz = PG_GETARG_FLOAT8(3);
+       dx = PG_GETARG_FLOAT8(1);
+       dy = PG_GETARG_FLOAT8(2);
+       dz = PG_GETARG_FLOAT8(3);
 
-    result = sfcgal_geometry_extrude(geom, dx, dy, dz);
-    sfcgal_geometry_delete(geom);
+       result = sfcgal_geometry_extrude(geom, dx, dy, dz);
+       sfcgal_geometry_delete(geom);
 
-    output = SFCGALGeometry2POSTGIS(result, 0, srid);
-    sfcgal_geometry_delete(result);
+       output = SFCGALGeometry2POSTGIS(result, 0, srid);
+       sfcgal_geometry_delete(result);
 
-    PG_RETURN_POINTER(output);
+       PG_RETURN_POINTER(output);
 }
 
 PG_FUNCTION_INFO_V1(postgis_sfcgal_version);
 Datum postgis_sfcgal_version(PG_FUNCTION_ARGS)
 {
-        const char *ver = lwgeom_sfcgal_version();
-        text *result = cstring_to_text(ver);
-        PG_RETURN_POINTER(result);
+       const char *ver = lwgeom_sfcgal_version();
+       text *result = cstring_to_text(ver);
+       PG_RETURN_POINTER(result);
 }
 
 PG_FUNCTION_INFO_V1(sfcgal_is_solid);
@@ -709,13 +692,13 @@ Datum sfcgal_is_solid(PG_FUNCTION_ARGS)
 {
        int result;
        GSERIALIZED *input = PG_GETARG_GSERIALIZED_P(0);
-        LWGEOM *lwgeom = lwgeom_from_gserialized(input);
+       LWGEOM *lwgeom = lwgeom_from_gserialized(input);
        PG_FREE_IF_COPY(input, 0);
-       if (! lwgeom)
+       if (!lwgeom)
        {
                elog(ERROR, "sfcgal_is_solid: Unable to deserialize input");
        }
-        result = FLAGS_GET_SOLID( lwgeom->flags );
+       result = FLAGS_GET_SOLID(lwgeom->flags);
 
        lwgeom_free(lwgeom);
 
@@ -728,16 +711,15 @@ Datum sfcgal_make_solid(PG_FUNCTION_ARGS)
        GSERIALIZED *output;
        GSERIALIZED *input = PG_GETARG_GSERIALIZED_P(0);
        LWGEOM *lwgeom = lwgeom_from_gserialized(input);
-       if (! lwgeom)
+       if (!lwgeom)
        {
                elog(ERROR, "sfcgal_make_solid: Unable to deserialize input");
        }
 
-       FLAGS_SET_SOLID( lwgeom->flags, 1);
+       FLAGS_SET_SOLID(lwgeom->flags, 1);
 
-       output = geometry_serialize( lwgeom );
+       output = geometry_serialize(lwgeom);
        lwgeom_free(lwgeom);
        PG_FREE_IF_COPY(input, 0);
        PG_RETURN_POINTER(output);
 }
-
index 16e6988bde2fc9267097c10c6b6cca8231a6fa41..eec9eb6ad9f10adaf399d6a47489f04d191a3699 100644 (file)
  *
  **********************************************************************/
 
-
 #include "../liblwgeom/lwgeom_sfcgal.h"
 
 /* Conversion from GSERIALIZED* to SFCGAL::Geometry */
-sfcgal_geometry_tPOSTGIS2SFCGALGeometry(GSERIALIZED *pglwgeom);
+sfcgal_geometry_t *POSTGIS2SFCGALGeometry(GSERIALIZED *pglwgeom);
 
 /* Conversion from GSERIALIZED* to SFCGAL::PreparedGeometry */
-sfcgal_prepared_geometry_tPOSTGIS2SFCGALPreparedGeometry(GSERIALIZED *pglwgeom);
+sfcgal_prepared_geometry_t *POSTGIS2SFCGALPreparedGeometry(GSERIALIZED *pglwgeom);
 
 /* Conversion from SFCGAL::Geometry to GSERIALIZED */
-GSERIALIZED* SFCGALGeometry2POSTGIS( const sfcgal_geometry_t* geom, int force3D, int SRID );
+GSERIALIZED *SFCGALGeometry2POSTGIS(const sfcgal_geometry_t *geom, int force3D, int SRID);
 
 /* Conversion from SFCGAL::PreparedGeometry to GSERIALIZED */
-GSERIALIZED* SFCGALPreparedGeometry2POSTGIS( const sfcgal_prepared_geometry_t* geom, int force3D );
+GSERIALIZED *SFCGALPreparedGeometry2POSTGIS(const sfcgal_prepared_geometry_t *geom, int force3D);
 
 Datum sfcgal_intersects(PG_FUNCTION_ARGS);
 Datum sfcgal_intersects3D(PG_FUNCTION_ARGS);
@@ -51,6 +50,5 @@ Datum sfcgal_distance3D(PG_FUNCTION_ARGS);
 Datum sfcgal_make_solid(PG_FUNCTION_ARGS);
 Datum sfcgal_is_solid(PG_FUNCTION_ARGS);
 
-
 /* Initialize sfcgal with PostGIS error handlers */
 void sfcgal_postgis_init(void);