[postgis-tickets] r14428 - #3376, make arguments to repeated point removal be const

Paul Ramsey pramsey at cleverelephant.ca
Wed Nov 25 12:31:26 PST 2015


Author: pramsey
Date: 2015-11-25 12:31:26 -0800 (Wed, 25 Nov 2015)
New Revision: 14428

Modified:
   trunk/liblwgeom/liblwgeom.h.in
   trunk/liblwgeom/liblwgeom_internal.h
   trunk/liblwgeom/lwcollection.c
   trunk/liblwgeom/lwgeom.c
   trunk/liblwgeom/lwline.c
   trunk/liblwgeom/lwmpoint.c
   trunk/liblwgeom/lwpoly.c
   trunk/liblwgeom/ptarray.c
   trunk/postgis/lwgeom_functions_basic.c
Log:
#3376, make arguments to repeated point removal be const


Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/liblwgeom.h.in	2015-11-25 20:31:26 UTC (rev 14428)
@@ -1571,7 +1571,7 @@
 /**
 * Remove repeated points!
 */
-extern LWGEOM* lwgeom_remove_repeated_points(LWGEOM *in, double tolerance);
+extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance);
 
 extern char lwtriangle_is_repeated_points(LWTRIANGLE *triangle);
 

Modified: trunk/liblwgeom/liblwgeom_internal.h
===================================================================
--- trunk/liblwgeom/liblwgeom_internal.h	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/liblwgeom_internal.h	2015-11-25 20:31:26 UTC (rev 14428)
@@ -344,12 +344,12 @@
 /* 
 * Repeated points
 */
-POINTARRAY *ptarray_remove_repeated_points_minpoints(POINTARRAY *in, double tolerance, int minpoints);
-POINTARRAY *ptarray_remove_repeated_points(POINTARRAY *in, double tolerance);
-LWGEOM* lwmpoint_remove_repeated_points(LWMPOINT *in, double tolerance);
-LWGEOM* lwline_remove_repeated_points(LWLINE *in, double tolerance);
-LWGEOM* lwcollection_remove_repeated_points(LWCOLLECTION *in, double tolerance);
-LWGEOM* lwpoly_remove_repeated_points(LWPOLY *in, double tolerance);
+POINTARRAY *ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints);
+POINTARRAY *ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance);
+LWGEOM* lwmpoint_remove_repeated_points(const LWMPOINT *in, double tolerance);
+LWGEOM* lwline_remove_repeated_points(const LWLINE *in, double tolerance);
+LWGEOM* lwcollection_remove_repeated_points(const LWCOLLECTION *in, double tolerance);
+LWGEOM* lwpoly_remove_repeated_points(const LWPOLY *in, double tolerance);
 
 /*
 * Closure test

Modified: trunk/liblwgeom/lwcollection.c
===================================================================
--- trunk/liblwgeom/lwcollection.c	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/lwcollection.c	2015-11-25 20:31:26 UTC (rev 14428)
@@ -437,7 +437,7 @@
 }
 
 LWGEOM*
-lwcollection_remove_repeated_points(LWCOLLECTION *coll, double tolerance)
+lwcollection_remove_repeated_points(const LWCOLLECTION *coll, double tolerance)
 {
 	uint32_t i;
 	LWGEOM **newgeoms;

Modified: trunk/liblwgeom/lwgeom.c
===================================================================
--- trunk/liblwgeom/lwgeom.c	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/lwgeom.c	2015-11-25 20:31:26 UTC (rev 14428)
@@ -1404,7 +1404,7 @@
 	return 0;
 }
 
-extern LWGEOM* lwgeom_remove_repeated_points(LWGEOM *in, double tolerance)
+extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance)
 {
 	LWDEBUGF(4, "lwgeom_remove_repeated_points got type %s",
 	         lwtype_name(in->type));
@@ -1436,7 +1436,7 @@
 	case TRIANGLETYPE:
 	case TINTYPE:
 		/* No point is repeated for a single point, or for Triangle or TIN */
-		return in;
+		return lwgeom_clone_deep(in);
 
 	case CIRCSTRINGTYPE:
 	case COMPOUNDTYPE:
@@ -1444,12 +1444,12 @@
 	case CURVEPOLYTYPE:
 	case MULTISURFACETYPE:
 		/* Dunno how to handle these, will return untouched */
-		return in;
+		return lwgeom_clone_deep(in);
 
 	default:
 		lwnotice("%s: unsupported geometry type: %s",
 		         __func__, lwtype_name(in->type));
-		return in;
+		return lwgeom_clone_deep(in);
 		break;
 	}
 	return 0;

Modified: trunk/liblwgeom/lwline.c
===================================================================
--- trunk/liblwgeom/lwline.c	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/lwline.c	2015-11-25 20:31:26 UTC (rev 14428)
@@ -424,7 +424,7 @@
 }
 
 LWGEOM*
-lwline_remove_repeated_points(LWLINE *lwline, double tolerance)
+lwline_remove_repeated_points(const LWLINE *lwline, double tolerance)
 {
 	POINTARRAY* npts = ptarray_remove_repeated_points_minpoints(lwline->points, tolerance, 2);
 

Modified: trunk/liblwgeom/lwmpoint.c
===================================================================
--- trunk/liblwgeom/lwmpoint.c	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/lwmpoint.c	2015-11-25 20:31:26 UTC (rev 14428)
@@ -76,7 +76,7 @@
 }
 
 LWGEOM*
-lwmpoint_remove_repeated_points(LWMPOINT *mpoint, double tolerance)
+lwmpoint_remove_repeated_points(const LWMPOINT *mpoint, double tolerance)
 {
 	uint32_t nnewgeoms;
 	uint32_t i, j;

Modified: trunk/liblwgeom/lwpoly.c
===================================================================
--- trunk/liblwgeom/lwpoly.c	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/lwpoly.c	2015-11-25 20:31:26 UTC (rev 14428)
@@ -286,7 +286,7 @@
 }
 
 LWGEOM*
-lwpoly_remove_repeated_points(LWPOLY *poly, double tolerance)
+lwpoly_remove_repeated_points(const LWPOLY *poly, double tolerance)
 {
 	uint32_t i;
 	POINTARRAY **newrings;

Modified: trunk/liblwgeom/ptarray.c
===================================================================
--- trunk/liblwgeom/ptarray.c	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/liblwgeom/ptarray.c	2015-11-25 20:31:26 UTC (rev 14428)
@@ -1400,7 +1400,7 @@
  *
  */
 POINTARRAY *
-ptarray_remove_repeated_points_minpoints(POINTARRAY *in, double tolerance, int minpoints)
+ptarray_remove_repeated_points_minpoints(const POINTARRAY *in, double tolerance, int minpoints)
 {
 	POINTARRAY* out;
 	size_t ptsize;
@@ -1451,7 +1451,7 @@
 }
 
 POINTARRAY *
-ptarray_remove_repeated_points(POINTARRAY *in, double tolerance)
+ptarray_remove_repeated_points(const POINTARRAY *in, double tolerance)
 {
 	return ptarray_remove_repeated_points_minpoints(in, tolerance, 2);
 }

Modified: trunk/postgis/lwgeom_functions_basic.c
===================================================================
--- trunk/postgis/lwgeom_functions_basic.c	2015-11-25 20:12:55 UTC (rev 14427)
+++ trunk/postgis/lwgeom_functions_basic.c	2015-11-25 20:31:26 UTC (rev 14428)
@@ -2607,7 +2607,10 @@
 	g_out = geometry_serialize(lwgeom_out);
 
 	if ( lwgeom_out != lwgeom_in )
+	{
 		lwgeom_free(lwgeom_out);
+	}
+
 	lwgeom_free(lwgeom_in);
 
 	PG_FREE_IF_COPY(g_in, 0);



More information about the postgis-tickets mailing list