]> granicus.if.org Git - postgis/commitdiff
add cunit and regression tests to simplifyvw and seteffectivearea
authorNicklas Avén <nicklas.aven@jordogskog.no>
Sat, 4 Apr 2015 19:44:20 +0000 (19:44 +0000)
committerNicklas Avén <nicklas.aven@jordogskog.no>
Sat, 4 Apr 2015 19:44:20 +0000 (19:44 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13421 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/Makefile.in
liblwgeom/cunit/cu_effectivearea.c [new file with mode: 0644]
liblwgeom/cunit/cu_tester.c
regress/Makefile.in
regress/simplifyvw.sql [new file with mode: 0644]
regress/simplifyvw_expected [new file with mode: 0644]

index 8008e0468ca67846011c6ea075d029b7488dd543..040b1892769891f5eefa3503f9fdce003c9411c1 100644 (file)
@@ -33,6 +33,7 @@ OBJS= \
        cu_geos.o \
        cu_tree.o \
        cu_measures.o \
+       cu_effectivearea.o \
        cu_node.o \
        cu_clip_by_rect.o \
        cu_libgeom.o \
diff --git a/liblwgeom/cunit/cu_effectivearea.c b/liblwgeom/cunit/cu_effectivearea.c
new file mode 100644 (file)
index 0000000..7293ae5
--- /dev/null
@@ -0,0 +1,80 @@
+/**********************************************************************
+ * $Id$
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.net
+ *
+ * Copyright 2012 Sandro Santilli <strk@keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ *
+ **********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "CUnit/Basic.h"
+
+#include "liblwgeom_internal.h"
+#include "effectivearea.h"
+#include "cu_tester.h"
+
+
+static void do_test_lwgeom_effectivearea(POINTARRAY *pa,double *the_areas,int avoid_collaps)
+{
+
+       int i;
+       EFFECTIVE_AREAS *ea;    
+       
+       ea=initiate_effectivearea(pa);          
+       ptarray_calc_areas(ea,avoid_collaps,1,0);
+
+       for (i=0;i<pa->npoints;i++)
+       {
+               CU_ASSERT_EQUAL(ea->res_arealist[i],the_areas[i]);
+       }
+
+       destroy_effectivearea(ea);
+       
+       
+}
+
+static void do_test_lwgeom_effectivearea_lines(void)
+{
+       LWLINE *the_geom;
+       int avoid_collaps=2;
+       /*Line 1*/
+       the_geom = (LWLINE*)lwgeom_from_wkt("LINESTRING(1 1, 0 1, 0 2, -1 4, -1 4)", LW_PARSER_CHECK_NONE);
+       double the_areas1[]={FLT_MAX,0.5,0.5,0,FLT_MAX};
+       do_test_lwgeom_effectivearea(the_geom->points,the_areas1,avoid_collaps);
+       lwline_free(the_geom);
+       /*Line 2*/
+       the_geom = (LWLINE*)lwgeom_from_wkt("LINESTRING(10 10,12 8, 15 7, 18 7, 20 20, 15 21, 18 22, 10 30, 40 100)", LW_PARSER_CHECK_NONE);
+       double the_areas2[]={FLT_MAX,5,1.5,55,100,4,4,300,FLT_MAX};
+       do_test_lwgeom_effectivearea(the_geom->points,the_areas2,avoid_collaps);
+       lwline_free(the_geom);
+}
+
+
+
+static void do_test_lwgeom_effectivearea_polys(void)
+{
+       LWPOLY *the_geom;
+       int avoid_collaps=4;
+       
+       /*POLYGON 1*/
+       the_geom = (LWPOLY*)lwgeom_from_wkt("POLYGON((10 10,12 8, 15 7, 18 7, 20 20, 15 21, 18 22, 10 30,1 99, 0 100, 10 10))", LW_PARSER_CHECK_NONE);
+       double the_areas1[]={FLT_MAX,5,1.5,55,100,4,4,FLT_MAX,30,FLT_MAX,FLT_MAX};
+       do_test_lwgeom_effectivearea(the_geom->rings[0],the_areas1,avoid_collaps);
+       lwpoly_free(the_geom);
+}
+
+
+void effectivearea_suite_setup(void);
+void effectivearea_suite_setup(void)
+{
+       CU_pSuite suite = CU_add_suite("effectivearea",NULL,NULL);
+       PG_ADD_TEST(suite, do_test_lwgeom_effectivearea_lines);
+       PG_ADD_TEST(suite, do_test_lwgeom_effectivearea_polys);
+}
index d8fb684470526a40f755febf4602c9e8621d1dd6..4e3090cd0ce9f1650c57e6f14ee8e9646f35fe7f 100644 (file)
@@ -37,6 +37,7 @@ extern void in_geojson_suite_setup(void);
 extern void twkb_in_suite_setup(void);
 extern void libgeom_suite_setup(void);
 extern void measures_suite_setup(void);
+extern void effectivearea_suite_setup(void);
 extern void misc_suite_setup(void);
 extern void node_suite_setup(void);
 extern void out_encoded_polyline_suite_setup(void);
@@ -77,6 +78,7 @@ PG_SuiteSetup setupfuncs[] =
 #endif
        libgeom_suite_setup,
        measures_suite_setup,
+       effectivearea_suite_setup,
        misc_suite_setup,
        node_suite_setup,
        out_encoded_polyline_suite_setup,
index d34211d210baab081706f4457d319bd39e47b7b1..9921dfe12e3fac762e64fb9fda8df36f35ab31ad 100644 (file)
@@ -85,6 +85,7 @@ TESTS = \
        setpoint \
        size \
        simplify \
+       simplifyvw \
        snaptogrid \
        summary \
        affine \
diff --git a/regress/simplifyvw.sql b/regress/simplifyvw.sql
new file mode 100644 (file)
index 0000000..68e16c9
--- /dev/null
@@ -0,0 +1,14 @@
+-- Repeat all tests with the new function names.
+SELECT '1', ST_astext(ST_Simplifyvw('LINESTRING(0 0, 0 10, 0 51, 50 20, 30 20, 7 32)', 2));
+SELECT '2', ST_astext(ST_Simplifyvw('LINESTRING(0 0 3, 0 10 6, 0 51 1, 50 20 6, 30 20 9, 7 32 10)', 100));
+SELECT '3', ST_astext(ST_Simplifyvw('LINESTRINGM(0 0 3, 0 10 6, 0 51 1, 50 20 6, 30 20 9, 7 32 10)', 2));
+SELECT '4', ST_astext(ST_Simplifyvw('LINESTRING(0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6 7, 30 20 9 9, 7 32 10 5)', 100));
+SELECT '5', ST_astext(ST_Simplifyvw('MULTIPOINT(0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6 7, 30 20 9 9, 7 32 10 5)', 20));
+SELECT '6', ST_astext(ST_Simplifyvw('MULTILINESTRING((0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6 7, 30 20 9 9, 7 32 10 5), (0 0 4 3, 1 1 2 3, 20 20 5 30))', 400));
+SELECT '7', ST_astext(ST_Simplifyvw('POLYGON((0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6 7, 30 20 9 9, 7 32 10 5, 0 0 3 2), (1 1 4 3, 1 3 2 3, 18 18 5 30, 1 1 4 3))', 200));
+SELECT '8', ST_astext(ST_Simplifyvw('POLYGON((0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6 7, 30 20 9 9, 7 32 10 5, 0 0 3 2), (1 1 4 3, 1 3 2 3, 18 18 5 30, 1 1 4 3))', 100));
+
+SELECT '9', ST_astext(ST_Simplifyvw('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5))', 20));
+SELECT '10', ST_astext(ST_Simplifyvw('LINESTRING(0 0, 0 10)', 20));
+SELECT '11', ST_astext(ST_Simplifyvw('MULTIPOLYGON(((100 100, 100 130, 130 130, 130 100, 100 100)), ((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5)) )', 20));
+SELECT '12', ST_astext(ST_Simplifyvw('MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5)),((100 100, 100 130, 130 130, 130 100, 100 100)))', 200));
diff --git a/regress/simplifyvw_expected b/regress/simplifyvw_expected
new file mode 100644 (file)
index 0000000..a9ea8d6
--- /dev/null
@@ -0,0 +1,12 @@
+1|LINESTRING(0 0,0 51,50 20,30 20,7 32)
+2|LINESTRING Z (0 0 3,0 51 1,50 20 6,30 20 9,7 32 10)
+3|LINESTRING M (0 0 3,0 51 1,50 20 6,30 20 9,7 32 10)
+4|LINESTRING ZM (0 0 3 2,0 51 1 6,50 20 6 7,30 20 9 9,7 32 10 5)
+5|MULTIPOINT ZM (0 0 3 2,0 10 6 1,0 51 1 6,50 20 6 7,30 20 9 9,7 32 10 5)
+6|MULTILINESTRING ZM ((0 0 3 2,0 51 1 6,50 20 6 7,7 32 10 5),(0 0 4 3,20 20 5 30))
+7|POLYGON ZM ((0 0 3 2,0 51 1 6,50 20 6 7,7 32 10 5,0 0 3 2))
+8|POLYGON ZM ((0 0 3 2,0 51 1 6,50 20 6 7,30 20 9 9,7 32 10 5,0 0 3 2))
+9|POLYGON((0 0,10 0,10 10,0 10,0 0))
+10|LINESTRING(0 0,0 10)
+11|MULTIPOLYGON(((100 100,100 130,130 130,130 100,100 100)),((0 0,10 0,10 10,0 10,0 0)))
+12|MULTIPOLYGON(((0 0,10 10,0 10,0 0)),((100 100,100 130,130 130,130 100,100 100)))