PostGIS  3.4.0dev-r@@SVN_REVISION@@
cu_boundary.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright (C) 2021 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2021 Aliaksandr Kalinik <kalenik.aliaksandr@gmail.com>
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU General Public Licence. See the COPYING file.
11  *
12  **********************************************************************/
13 
14 #include "CUnit/Basic.h"
15 #include "cu_tester.h"
16 
17 #include "liblwgeom.h"
18 #include "liblwgeom_internal.h"
19 
20 #define BOUNDARY_TEST(wkt_in, wkt_exp) \
21  do \
22  { \
23  LWGEOM *gin, *gout, *gexp; \
24  cu_error_msg_reset(); \
25  gin = lwgeom_from_wkt(wkt_in, LW_PARSER_CHECK_NONE); \
26  CU_ASSERT_PTR_NOT_NULL_FATAL(gin); \
27  gexp = lwgeom_from_wkt(wkt_exp, LW_PARSER_CHECK_NONE); \
28  CU_ASSERT_PTR_NOT_NULL_FATAL(gexp); \
29  gout = lwgeom_boundary(gin); \
30  CU_ASSERT_PTR_NOT_NULL_FATAL(gout); \
31  ASSERT_NORMALIZED_GEOM_SAME(gout, gexp); \
32  lwgeom_free(gout); \
33  lwgeom_free(gexp); \
34  lwgeom_free(gin); \
35  } while (0)
36 
37 static void
39 {
41  "POINT EMPTY",
42  "POINT EMPTY"
43  );
44 
46  "POINT(0 0)",
47  "POINT EMPTY"
48  );
49 
51  "MULTIPOINT EMPTY",
52  "MULTIPOINT EMPTY" /* debatable return type */
53  );
54 
56  "MULTIPOINT(0 0,10 0)",
57  "MULTIPOINT EMPTY" /* debatable return type */
58  );
59 }
60 
61 static void
63 {
65  "LINESTRING EMPTY",
66  "MULTIPOINT EMPTY"
67  );
68 
70  "CIRCULARSTRING EMPTY",
71  "MULTIPOINT EMPTY"
72  );
73 
75  "LINESTRING(0 0, 5 5, 10 0, 0 0)",
76  "MULTIPOINT EMPTY"
77  );
78 
80  "CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0)",
81  "MULTIPOINT EMPTY"
82  );
83 
85  "LINESTRING(0 0, 5 0, 10 0)",
86  "MULTIPOINT(0 0, 10 0)"
87  );
88 
90  "MULTILINESTRING((0 0, 5 0, 10 0),(20 5, 20 6, 20 10))",
91  "MULTIPOINT(0 0, 10 0, 20 5, 20 10)"
92  );
93 
95  "MULTICURVE((1 1 1,0 0 0.5, -1 1 1),(1 1 0.5,0 0 0.5, -1 1 0.5, 1 1 0.5))",
96  "MULTIPOINT(1 1 1,-1 1 1)"
97  );
98 
99 }
100 
101 static void
103 {
105  "POLYGON EMPTY",
106  "MULTILINESTRING EMPTY"
107  );
108 
110  "POLYGON((0 0, 5 5, 10 0, 0 0))",
111  "LINESTRING(0 0, 5 5, 10 0, 0 0)"
112  );
113 
115  "POLYGON((0 0, 5 5, 10 0, 0 0),(3 1,7 1,5 2,3 1))",
116  "MULTILINESTRING((0 0, 5 5, 10 0, 0 0),(3 1,7 1,5 2,3 1))"
117  );
118 
119  /* See https://trac.osgeo.org/postgis/ticket/4961 */
121  "MULTIPOLYGON(((0 0, 5 5, 10 0, 0 0),(3 1,7 1,5 2,3 1)),((20 0,20 5,25 5,20 0)))",
122  "MULTILINESTRING((0 0, 5 5, 10 0, 0 0),(3 1,7 1,5 2,3 1),(20 0,20 5,25 5,20 0))"
123  );
124 
126  "CURVEPOLYGON(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0))",
127  "MULTICURVE(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0))"
128  );
129 
131  "CURVEPOLYGON(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0),(1 1, 3 3, 3 1, 1 1))",
132  "MULTICURVE(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0),(1 1, 3 3, 3 1, 1 1))"
133  );
134 
135 }
136 
137 static void
139 {
141  "TRIANGLE EMPTY",
142  "LINESTRING EMPTY"
143  );
144 
146  "TRIANGLE((1 1, 0 0, -1 1, 1 1))",
147  "LINESTRING(1 1, 0 0, -1 1, 1 1)"
148  );
149 }
150 
151 static void
153 {
155  "TIN EMPTY",
156  "GEOMETRYCOLLECTION EMPTY"
157  );
158 
160  "TIN(((0 0,0 -1,-1 1,0 0)))",
161  "LINESTRING(0 0,0 -1,-1 1,0 0)"
162  );
163 
165  "TIN(((0 0,0 -1,-1 1,0 0)),((0 0,1 0,0 -1,0 0)))",
166  "MULTILINESTRING((0 0,0 -1,-1 1,0 0),(0 0,1 0,0 -1,0 0))"
167  );
168 }
169 
170 static void
172 {
174  "GEOMETRYCOLLECTION EMPTY",
175  "GEOMETRYCOLLECTION EMPTY"
176  );
177 
178  /* See https://trac.osgeo.org/postgis/ticket/4956 */
180  "GEOMETRYCOLLECTION(POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2)),POLYGON((2 2,2 4,4 4,4 2,2 2)))",
181  "MULTILINESTRING((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,4 4,2 4,2 2),(2 2,2 4,4 4,4 2,2 2))"
182  );
183 
185  "GEOMETRYCOLLECTION(TIN(((0 0,0 -1,-1 1,0 0)),((0 0,1 0,0 -1,0 0))),TIN(((10 10,10 20,20 20,10 10))))",
186  "MULTILINESTRING((0 0,0 -1,-1 1,0 0),(0 0,1 0,0 -1,0 0),(10 10,10 20,20 20,10 10))"
187  );
188 
190  "GEOMETRYCOLLECTION(TRIANGLE((1 1, 0 0, -1 1, 1 1)))",
191  "LINESTRING(1 1, 0 0, -1 1, 1 1)"
192  );
193 
195  "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(TRIANGLE((0 0,0 -1,-1 1,0 0)),TRIANGLE((0 0,1 0,0 -1,0 0))),MULTILINESTRING((0 0, 5 0, 10 0),(20 5, 20 6, 20 10)))",
196  "GEOMETRYCOLLECTION(MULTILINESTRING((0 0,0 -1,1 0,0 0),(0 0,-1 1,0 -1,0 0)),MULTIPOINT(20 10,20 5,10 0,0 0))"
197  );
198 
200  "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0)),POINT(1 1),MULTIPOINT(2 2,3 3))",
201  "GEOMETRYCOLLECTION EMPTY"
202  );
203 }
204 
205 void boundary_suite_setup(void);
206 void
208 {
209  CU_pSuite suite = CU_add_suite("boundary", NULL, NULL);
210  PG_ADD_TEST(suite, boundary_point);
211  PG_ADD_TEST(suite, boundary_line);
214  PG_ADD_TEST(suite, boundary_tin);
216 }
static void boundary_tin(void)
Definition: cu_boundary.c:152
static void boundary_collection(void)
Definition: cu_boundary.c:171
static void boundary_line(void)
Definition: cu_boundary.c:62
static void boundary_point(void)
Definition: cu_boundary.c:38
static void boundary_triangle(void)
Definition: cu_boundary.c:138
void boundary_suite_setup(void)
Definition: cu_boundary.c:207
static void boundary_polygon(void)
Definition: cu_boundary.c:102
#define BOUNDARY_TEST(wkt_in, wkt_exp)
Definition: cu_boundary.c:20
#define PG_ADD_TEST(suite, testfunc)
This library is the generic geometry handling section of PostGIS.