]> granicus.if.org Git - postgis/commitdiff
Added ptarray_clone() and ptarray_isclosed2d()
authorSandro Santilli <strk@keybit.net>
Thu, 6 Jan 2005 13:44:45 +0000 (13:44 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 6 Jan 2005 13:44:45 +0000 (13:44 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1231 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/ptarray.c

index 9a27c3b99d4f77d3082d967233811cb22e6bdddf..3b0a9982234f85cbecb5da6e650e0ce42f13efc2 100644 (file)
@@ -313,3 +313,32 @@ ptarray_addPoint(POINTARRAY *pa, char *p, size_t pdims, unsigned int where)
 
        return ret;
 }
+
+/* 
+ * Clone a pointarray 
+ */
+POINTARRAY *
+ptarray_clone(const POINTARRAY *in)
+{
+       POINTARRAY *out = lwalloc(sizeof(POINTARRAY));
+       size_t size;
+
+       out->dims = in->dims;
+       out->npoints = in->npoints;
+
+       size = in->npoints*sizeof(double)*TYPE_NDIMS(in->dims);
+       out->serialized_pointlist = lwalloc(size);
+       memcpy(out->serialized_pointlist, in->serialized_pointlist, size);
+
+       return out;
+}
+
+int
+ptarray_isclosed2d(const POINTARRAY *in)
+{
+       POINT2D *p1, *p2;
+       p1 = (POINT2D *)getPoint(in, 0);
+       p2 = (POINT2D *)getPoint(in, in->npoints-1);
+       if ( p1->x != p2->x || p1->y != p2->y ) return 0;
+       else return 1;
+}