PostGIS  2.3.8dev-r@@SVN_REVISION@@
cu_wrapx.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright (C) 2016 Sandro Santilli <strk@kbt.io>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include "CUnit/Basic.h"
14 #include "cu_tester.h"
15 
16 #include "liblwgeom.h"
17 #include "liblwgeom_internal.h"
18 
19 static void test_lwgeom_wrapx(void)
20 {
21  LWGEOM *geom, *ret;
22  char *exp_wkt, *obt_wkt;
23 
24  geom = lwgeom_from_wkt(
25  "POLYGON EMPTY",
27  CU_ASSERT_FATAL(geom != NULL);
28  ret = lwgeom_wrapx(geom, 0, 20);
29  CU_ASSERT_FATAL(ret != NULL);
30  obt_wkt = lwgeom_to_ewkt(ret);
31  exp_wkt = "POLYGON EMPTY";
32  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
33  lwfree(obt_wkt);
34  lwgeom_free(ret);
35  lwgeom_free(geom);
36 
37  geom = lwgeom_from_wkt(
38  "POINT(0 0)",
40  CU_ASSERT_FATAL(geom != NULL);
41  ret = lwgeom_wrapx(geom, 2, 10);
42  CU_ASSERT_FATAL(ret != NULL);
43  obt_wkt = lwgeom_to_ewkt(ret);
44  exp_wkt = "POINT(10 0)";
45  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
46  lwfree(obt_wkt);
47  lwgeom_free(ret);
48  lwgeom_free(geom);
49 
50  geom = lwgeom_from_wkt(
51  "POINT(0 0)",
53  CU_ASSERT_FATAL(geom != NULL);
54  ret = lwgeom_wrapx(geom, 0, 20);
55  CU_ASSERT_FATAL(ret != NULL);
56  obt_wkt = lwgeom_to_ewkt(ret);
57  exp_wkt = "POINT(0 0)";
58  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
59  lwfree(obt_wkt);
60  lwgeom_free(ret);
61  lwgeom_free(geom);
62 
63  geom = lwgeom_from_wkt(
64  "POINT(0 0)",
66  CU_ASSERT_FATAL(geom != NULL);
67  ret = lwgeom_wrapx(geom, 0, -20);
68  CU_ASSERT_FATAL(ret != NULL);
69  obt_wkt = lwgeom_to_ewkt(ret);
70  exp_wkt = "POINT(0 0)";
71  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
72  lwfree(obt_wkt);
73  lwgeom_free(ret);
74  lwgeom_free(geom);
75 
76  geom = lwgeom_from_wkt(
77  "LINESTRING(0 0,10 0)",
79  CU_ASSERT_FATAL(geom != NULL);
80  ret = lwgeom_wrapx(geom, 8, -10);
81  CU_ASSERT_FATAL(ret != NULL);
82  obt_wkt = lwgeom_to_ewkt(ret);
83  exp_wkt = "MULTILINESTRING((0 0,8 0),(-2 0,0 0))";
84  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
85  lwfree(obt_wkt);
86  lwgeom_free(ret);
87  lwgeom_free(geom);
88 
89  geom = lwgeom_from_wkt(
90  "MULTILINESTRING((-5 -2,0 0),(0 0,10 10))",
92  CU_ASSERT_FATAL(geom != NULL);
93  ret = lwgeom_wrapx(geom, 0, 20);
94  CU_ASSERT_FATAL(ret != NULL);
95  obt_wkt = lwgeom_to_ewkt(ret);
96  exp_wkt = "MULTILINESTRING((15 -2,20 0),(0 0,10 10))";
97  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
98  lwfree(obt_wkt);
99  lwgeom_free(ret);
100  lwgeom_free(geom);
101 
102  geom = lwgeom_from_wkt(
103  "MULTIPOLYGON("
104  " ((0 0,10 0,10 10,0 10,0 0),(2 2,4 2,4 4,2 4,2 2)),"
105  " ((0 11,10 11,10 21,0 21,0 11),(2 13,4 13,4 15,2 15,2 13))"
106  ")",
108  CU_ASSERT_FATAL(geom != NULL);
109  ret = lwgeom_wrapx(geom, 2, 20);
110  CU_ASSERT_FATAL(ret != NULL);
111  obt_wkt = lwgeom_to_ewkt(ret);
112  exp_wkt = "GEOMETRYCOLLECTION("
113  "MULTIPOLYGON("
114  "((22 0,20 0,20 10,22 10,22 4,22 2,22 0)),"
115  "((2 10,10 10,10 0,2 0,2 2,4 2,4 4,2 4,2 10))"
116  "),"
117  "MULTIPOLYGON("
118  "((22 11,20 11,20 21,22 21,22 15,22 13,22 11)),"
119  "((2 21,10 21,10 11,2 11,2 13,4 13,4 15,2 15,2 21))"
120  ")"
121  ")";
122  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
123  lwfree(obt_wkt);
124  lwgeom_free(ret);
125  lwgeom_free(geom);
126 
127  geom = lwgeom_from_wkt(
128  "GEOMETRYCOLLECTION("
129  " MULTILINESTRING((-5 -2,0 0),(0 0,10 10)),"
130  " POINT(-5 0),"
131  " POLYGON EMPTY"
132  ")",
134  CU_ASSERT_FATAL(geom != NULL);
135  ret = lwgeom_wrapx(geom, 0, 20);
136  CU_ASSERT_FATAL(ret != NULL);
137  obt_wkt = lwgeom_to_ewkt(ret);
138  exp_wkt = "GEOMETRYCOLLECTION("
139  "MULTILINESTRING((15 -2,20 0),(0 0,10 10)),"
140  "POINT(15 0),"
141  "POLYGON EMPTY"
142  ")";
143  ASSERT_STRING_EQUAL(obt_wkt, exp_wkt);
144  lwfree(obt_wkt);
145  lwgeom_free(ret);
146  lwgeom_free(geom);
147 
148 }
149 
150 
151 /*
152 ** Used by test harness to register the tests in this file.
153 */
154 void wrapx_suite_setup(void);
156 {
157  CU_pSuite suite = CU_add_suite("wrapx", NULL, NULL);
159 }
static void test_lwgeom_wrapx(void)
Definition: cu_wrapx.c:19
void lwfree(void *mem)
Definition: lwutil.c:242
#define ASSERT_STRING_EQUAL(o, e)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:482
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom, double cutx, double amount)
wrap geometry on given cut x value
Definition: lwgeom_wrapx.c:167
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
#define PG_ADD_TEST(suite, testfunc)
void wrapx_suite_setup(void)
Definition: cu_wrapx.c:155
This library is the generic geometry handling section of PostGIS.