PostGIS  3.0.0dev-r@@SVN_REVISION@@
cu_libgeom.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2009 Paul Ramsey <pramsey@cleverelephant.ca>
6  *
7  * This is free software; you can redistribute and/or modify it under
8  * the terms of the GNU General Public Licence. See the COPYING file.
9  *
10  **********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "CUnit/Basic.h"
16 
17 #include "liblwgeom_internal.h"
18 #include "g_serialized.c" /* for gserialized_peek_gbox_p */
19 #include "cu_tester.h"
20 
21 static void test_typmod_macros(void)
22 {
23  int32_t typmod = 0;
24  int srid = 4326;
25  int type = 6;
26  int z = 1;
27  int rv;
28 
29  TYPMOD_SET_SRID(typmod,srid);
30  rv = TYPMOD_GET_SRID(typmod);
31  CU_ASSERT_EQUAL(rv, srid);
32 
33  srid = -5005;
34  TYPMOD_SET_SRID(typmod,srid);
35  rv = TYPMOD_GET_SRID(typmod);
36  CU_ASSERT_EQUAL(rv, srid);
37 
38  srid = 999999;
39  TYPMOD_SET_SRID(typmod,srid);
40  rv = TYPMOD_GET_SRID(typmod);
41  CU_ASSERT_EQUAL(rv, srid);
42 
43  srid = -999999;
44  TYPMOD_SET_SRID(typmod,srid);
45  rv = TYPMOD_GET_SRID(typmod);
46  CU_ASSERT_EQUAL(rv, srid);
47 
48  srid = SRID_UNKNOWN;
49  TYPMOD_SET_SRID(typmod,srid);
50  rv = TYPMOD_GET_SRID(typmod);
51  CU_ASSERT_EQUAL(rv, srid);
52 
53  srid = 0;
54  TYPMOD_SET_SRID(typmod,srid);
55  rv = TYPMOD_GET_SRID(typmod);
56  CU_ASSERT_EQUAL(rv, srid);
57 
58  srid = 1;
59  TYPMOD_SET_SRID(typmod,srid);
60  rv = TYPMOD_GET_SRID(typmod);
61  CU_ASSERT_EQUAL(rv, srid);
62 
63  TYPMOD_SET_TYPE(typmod,type);
64  rv = TYPMOD_GET_TYPE(typmod);
65  CU_ASSERT_EQUAL(rv,type);
66 
67  TYPMOD_SET_Z(typmod);
68  rv = TYPMOD_GET_Z(typmod);
69  CU_ASSERT_EQUAL(rv,z);
70 
71  rv = TYPMOD_GET_M(typmod);
72  CU_ASSERT_EQUAL(rv,0);
73 
74 }
75 
76 static void test_flags_macros(void)
77 {
78  uint8_t flags = 0;
79 
80  CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags));
81  FLAGS_SET_Z(flags, 1);
82  CU_ASSERT_EQUAL(1, FLAGS_GET_Z(flags));
83  FLAGS_SET_Z(flags, 0);
84  CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags));
85  CU_ASSERT_EQUAL(0, FLAGS_GET_BBOX(flags));
86 
87  CU_ASSERT_EQUAL(0, FLAGS_GET_M(flags));
88  FLAGS_SET_M(flags, 1);
89  CU_ASSERT_EQUAL(1, FLAGS_GET_M(flags));
90 
91  CU_ASSERT_EQUAL(0, FLAGS_GET_BBOX(flags));
92  FLAGS_SET_BBOX(flags, 1);
93  CU_ASSERT_EQUAL(1, FLAGS_GET_BBOX(flags));
94  CU_ASSERT_EQUAL(0, FLAGS_GET_READONLY(flags));
95 
96  FLAGS_SET_READONLY(flags, 1);
97  CU_ASSERT_EQUAL(1, FLAGS_GET_READONLY(flags));
98  FLAGS_SET_READONLY(flags, 0);
99  CU_ASSERT_EQUAL(0, FLAGS_GET_READONLY(flags));
100 
101  CU_ASSERT_EQUAL(0, FLAGS_GET_GEODETIC(flags));
102  FLAGS_SET_GEODETIC(flags, 1);
103  CU_ASSERT_EQUAL(1, FLAGS_GET_GEODETIC(flags));
104 
105  flags = gflags(1, 0, 1); /* z=1, m=0, geodetic=1 */
106 
107  CU_ASSERT_EQUAL(1, FLAGS_GET_GEODETIC(flags));
108  CU_ASSERT_EQUAL(1, FLAGS_GET_Z(flags));
109  CU_ASSERT_EQUAL(0, FLAGS_GET_M(flags));
110  CU_ASSERT_EQUAL(2, FLAGS_GET_ZM(flags));
111 
112  flags = gflags(1, 1, 1); /* z=1, m=1, geodetic=1 */
113 
114  CU_ASSERT_EQUAL(1, FLAGS_GET_GEODETIC(flags));
115  CU_ASSERT_EQUAL(1, FLAGS_GET_Z(flags));
116  CU_ASSERT_EQUAL(1, FLAGS_GET_M(flags));
117  CU_ASSERT_EQUAL(3, FLAGS_GET_ZM(flags));
118 
119  flags = gflags(0, 1, 0); /* z=0, m=1, geodetic=0 */
120 
121  CU_ASSERT_EQUAL(0, FLAGS_GET_GEODETIC(flags));
122  CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags));
123  CU_ASSERT_EQUAL(1, FLAGS_GET_M(flags));
124  CU_ASSERT_EQUAL(1, FLAGS_GET_ZM(flags));
125 }
126 
127 static void test_serialized_srid(void)
128 {
129  GSERIALIZED s;
130  int32_t srid, rv;
131 
132  srid = 4326;
133  gserialized_set_srid(&s, srid);
134  rv = gserialized_get_srid(&s);
135  CU_ASSERT_EQUAL(rv, srid);
136 
137  srid = -3005;
138  gserialized_set_srid(&s, srid);
139  rv = gserialized_get_srid(&s);
140  //printf("srid=%d rv=%d\n",srid,rv);
141  CU_ASSERT_EQUAL(rv, SRID_UNKNOWN);
142 
143  srid = SRID_UNKNOWN;
144  gserialized_set_srid(&s, srid);
145  rv = gserialized_get_srid(&s);
146  CU_ASSERT_EQUAL(rv, srid);
147 
148  srid = SRID_UNKNOWN;
149  gserialized_set_srid(&s, srid);
150  rv = gserialized_get_srid(&s);
151  CU_ASSERT_EQUAL(rv, srid);
152 
153  srid = 100000;
154  gserialized_set_srid(&s, srid);
155  rv = gserialized_get_srid(&s);
156  CU_ASSERT_EQUAL(rv, srid);
157 }
158 
160 {
161  LWGEOM *g;
162  size_t size = 0;
163 
164  g = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
166  CU_ASSERT_EQUAL( size, 32 );
167  lwgeom_free(g);
168 
169  g = lwgeom_from_wkt("POINT(0 0 0)", LW_PARSER_CHECK_NONE);
171  CU_ASSERT_EQUAL( size, 40 );
172  lwgeom_free(g);
173 
174  g = lwgeom_from_wkt("MULTIPOINT(0 0 0, 1 1 1)", LW_PARSER_CHECK_NONE);
176  CU_ASSERT_EQUAL( size, 80 );
177  lwgeom_free(g);
178 
179  g = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
181  CU_ASSERT_EQUAL( size, 48 );
182  lwgeom_free(g);
183 
184  g = lwgeom_from_wkt("MULTILINESTRING((0 0, 1 1),(0 0, 1 1))", LW_PARSER_CHECK_NONE);
186  CU_ASSERT_EQUAL( size, 96 );
187  lwgeom_free(g);
188 
189  g = lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
191  CU_ASSERT_EQUAL( size, 104 );
192  lwgeom_free(g);
193 
194  g = lwgeom_from_wkt("POLYGON((-1 -1, -1 2, 2 2, 2 -1, -1 -1), (0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
196  CU_ASSERT_EQUAL( size, 184 );
197  lwgeom_free(g);
198 
199 }
200 
201 static void test_lwgeom_calculate_gbox(void)
202 {
203  LWGEOM *g;
204  GBOX b;
205 
206  g = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
208  CU_ASSERT_DOUBLE_EQUAL(b.xmin, 0.0, 0.0000001);
209  lwgeom_free(g);
210 
211  /* Inf = 0x7FF0000000000000 */
212  /* POINT(0 0) = 00 00000001 0000000000000000 0000000000000000 */
213  /* POINT(0 Inf) = 00 00000001 0000000000000000 7FF0000000000000 */
214  g = lwgeom_from_hexwkb("000000000100000000000000007FF0000000000000", LW_PARSER_CHECK_NONE);
216  CU_ASSERT_DOUBLE_EQUAL(b.xmin, 0.0, 0.0000001);
217  CU_ASSERT(isinf(b.ymax));
218  lwgeom_free(g);
219 
220  /* LINESTRING(0 0, 0 Inf) = 00 00000002 00000002 0000000000000000 7FF0000000000000 0000000000000000 0000000000000000 */
221  /* Inf should show up in bbox */
222  g = lwgeom_from_hexwkb("00000000020000000200000000000000007FF000000000000000000000000000000000000000000000", LW_PARSER_CHECK_NONE);
224  CU_ASSERT_DOUBLE_EQUAL(b.xmin, 0.0, 0.0000001);
225  CU_ASSERT(isinf(b.ymax));
226  lwgeom_free(g);
227 
228  /* Geometry with NaN 0101000020E8640000000000000000F8FF000000000000F8FF */
229  /* NaN should show up in bbox for "SRID=4326;POINT(0 NaN)" */
230  g = lwgeom_from_hexwkb("0101000020E86400000000000000000000000000000000F8FF", LW_PARSER_CHECK_NONE);
232  CU_ASSERT(isnan(b.ymax));
233  lwgeom_free(g);
234 
235 }
236 
237 static void test_gbox_serialized_size(void)
238 {
239  uint8_t flags = gflags(0, 0, 0);
240  CU_ASSERT_EQUAL(gbox_serialized_size(flags),16);
241  FLAGS_SET_BBOX(flags, 1);
242  CU_ASSERT_EQUAL(gbox_serialized_size(flags),16);
243  FLAGS_SET_Z(flags, 1);
244  CU_ASSERT_EQUAL(gbox_serialized_size(flags),24);
245  FLAGS_SET_M(flags, 1);
246  CU_ASSERT_EQUAL(gbox_serialized_size(flags),32);
247  FLAGS_SET_GEODETIC(flags, 1);
248  CU_ASSERT_EQUAL(gbox_serialized_size(flags),24);
249 
250 }
251 
252 
253 
255 {
256  LWGEOM *geom;
257  GSERIALIZED *g;
258  char *in_ewkt;
259  char *out_ewkt;
260  size_t i = 0;
261 
262  char *ewkt[] =
263  {
264  "POINT EMPTY",
265  "POINT(0 0.2)",
266  "LINESTRING EMPTY",
267  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
268  "MULTIPOINT EMPTY",
269  "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
270  "SRID=1;MULTILINESTRING EMPTY",
271  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
272  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
273  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
274  "POLYGON EMPTY",
275  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
276  "SRID=4326;POLYGON EMPTY",
277  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
278  "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
279  "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
280  "SRID=4326;MULTIPOLYGON EMPTY",
281  "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
282  "SRID=4326;GEOMETRYCOLLECTION EMPTY",
283  "SRID=4326;GEOMETRYCOLLECTION(POINT EMPTY,MULTIPOLYGON EMPTY)",
284  "MULTICURVE((5 5 1 3,3 5 2 2,3 3 3 1,0 3 1 1),CIRCULARSTRING(0 0 0 0,0.26794 1 3 -2,0.5857864 1.414213 1 2))",
285  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0)),((7 8,10 10,6 14,4 11,7 8)))",
286  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING EMPTY))",
287  };
288 
289  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
290  {
291  LWGEOM* geom2;
292 
293  in_ewkt = ewkt[i];
294  geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
295  lwgeom_add_bbox(geom);
296  if ( geom->bbox ) gbox_float_round(geom->bbox);
297  g = gserialized_from_lwgeom(geom, 0);
298 
299  geom2 = lwgeom_from_gserialized(g);
300  out_ewkt = lwgeom_to_ewkt(geom2);
301 
302  /* printf("\n in = %s\nout = %s\n", in_ewkt, out_ewkt); */
303  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
304 
305  /* either both or none of the bboxes are null */
306  CU_ASSERT( (geom->bbox != NULL) || (geom2->bbox == NULL) );
307 
308  /* either both are null or they are the same */
309  CU_ASSERT(geom->bbox == NULL || gbox_same(geom->bbox, geom2->bbox));
310 
311  lwgeom_free(geom);
312  lwgeom_free(geom2);
313  lwfree(g);
314  lwfree(out_ewkt);
315  }
316 
317 }
318 
319 
320 static void test_gserialized_is_empty(void)
321 {
322  int i = 0;
323  struct gserialized_empty_cases {
324  const char* wkt;
325  int isempty;
326  };
327 
328  struct gserialized_empty_cases cases[] = {
329  { "POINT EMPTY", 1 },
330  { "POINT(1 1)", 0 },
331  { "LINESTRING EMPTY", 1 },
332  { "MULTILINESTRING EMPTY", 1 },
333  { "MULTILINESTRING(EMPTY)", 1 },
334  { "MULTILINESTRING(EMPTY,EMPTY)", 1 },
335  { "MULTILINESTRING(EMPTY,(0 0,1 1))", 0 },
336  { "MULTILINESTRING((0 0,1 1),EMPTY)", 0 },
337  { "MULTILINESTRING(EMPTY,(0 0,1 1),EMPTY)", 0 },
338  { "MULTILINESTRING(EMPTY,EMPTY,EMPTY)", 1 },
339  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY,EMPTY,EMPTY))", 1 },
340  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY),POINT(1 1))", 0 },
341  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY, (0 0)),POINT EMPTY)", 0 },
342  { "GEOMETRYCOLLECTION(POLYGON EMPTY,POINT EMPTY,MULTILINESTRING(EMPTY,EMPTY),POINT EMPTY)", 1 },
343  { "GEOMETRYCOLLECTION(POLYGON EMPTY,GEOMETRYCOLLECTION(POINT EMPTY),MULTILINESTRING(EMPTY,EMPTY),POINT EMPTY)", 1 },
344  { NULL, 0 }
345  };
346 
347  while( cases[i].wkt )
348  {
349  // i = 11;
350  LWGEOM *lw = lwgeom_from_wkt(cases[i].wkt, LW_PARSER_CHECK_NONE);
352  int ie = gserialized_is_empty(g);
353  // printf("%s: we say %d, they say %d\n", cases[i].wkt, cases[i].isempty, ie);
354  CU_ASSERT_EQUAL(ie, cases[i].isempty);
355  lwgeom_free(lw);
356  lwfree(g);
357  i++;
358  }
359 }
360 
361 
363 {
364  int rv;
365  uint8_t type = 0;
366  int z = 0, m = 0;
367  char *str;
368 
369  str = " POINTZ";
370  rv = geometry_type_from_string(str, &type, &z, &m);
371  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
372  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
373  CU_ASSERT_EQUAL(type, POINTTYPE);
374  CU_ASSERT_EQUAL(z, 1);
375  CU_ASSERT_EQUAL(m, 0);
376 
377  str = "LINESTRINGM ";
378  rv = geometry_type_from_string(str, &type, &z, &m);
379  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
380  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
381  CU_ASSERT_EQUAL(type, LINETYPE);
382  CU_ASSERT_EQUAL(z, 0);
383  CU_ASSERT_EQUAL(m, 1);
384 
385  str = "MULTIPOLYGONZM";
386  rv = geometry_type_from_string(str, &type, &z, &m);
387  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
388  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
389  CU_ASSERT_EQUAL(type, MULTIPOLYGONTYPE);
390  CU_ASSERT_EQUAL(z, 1);
391  CU_ASSERT_EQUAL(m, 1);
392 
393  str = " GEOMETRYCOLLECTIONZM ";
394  rv = geometry_type_from_string(str, &type, &z, &m);
395  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
396  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
397  CU_ASSERT_EQUAL(type, COLLECTIONTYPE);
398  CU_ASSERT_EQUAL(z, 1);
399  CU_ASSERT_EQUAL(m, 1);
400 
401  str = " GEOMERYCOLLECTIONZM ";
402  rv = geometry_type_from_string(str, &type, &z, &m);
403  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
404  CU_ASSERT_EQUAL(rv, LW_FAILURE);
405 
406 }
407 
408 static void test_lwgeom_count_vertices(void)
409 {
410  LWGEOM *geom;
411 
412  geom = lwgeom_from_wkt("MULTIPOINT(-1 -1,-1 2.5,2 2,2 -1)", LW_PARSER_CHECK_NONE);
413  CU_ASSERT_EQUAL(lwgeom_count_vertices(geom),4);
414  lwgeom_free(geom);
415 
416  geom = lwgeom_from_wkt("SRID=1;MULTILINESTRING((-1 -131,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))", LW_PARSER_CHECK_NONE);
417  CU_ASSERT_EQUAL(lwgeom_count_vertices(geom),16);
418  lwgeom_free(geom);
419 
420  geom = lwgeom_from_wkt("SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,211 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))", LW_PARSER_CHECK_NONE);
421  CU_ASSERT_EQUAL(lwgeom_count_vertices(geom),30);
422  lwgeom_free(geom);
423 
424 }
425 
427 {
428  LWGEOM *lwgeom;
429  GSERIALIZED *g_ser1;
430  size_t ret_size;
431 
432  lwgeom = lwgeom_from_wkt("MULTIPOINT(-1 -1,-1 2.5,2 2,2 -1,1 1,2 2,4 5)", LW_PARSER_CHECK_NONE);
433  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
434  g_ser1 = gserialized_from_lwgeom(lwgeom, &ret_size);
435  lwgeom_free(lwgeom);
436 
437  lwgeom = lwgeom_from_gserialized(g_ser1);
438  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
439  lwgeom_free(lwgeom);
440 
441  lwgeom = lwgeom_from_gserialized(g_ser1);
442 
443  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
444  lwgeom_free(lwgeom);
445 
446  lwfree(g_ser1);
447 
448 }
449 
450 static void test_lwcollection_extract(void)
451 {
452 
453  LWGEOM *geom;
454  LWCOLLECTION *col;
455 
456  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION(POINT(0 0))", LW_PARSER_CHECK_NONE);
457 
458  col = lwcollection_extract((LWCOLLECTION*)geom, 1);
459  CU_ASSERT_EQUAL(col->type, MULTIPOINTTYPE);
460  lwcollection_free(col);
461 
462  col = lwcollection_extract((LWCOLLECTION*)geom, 2);
463  CU_ASSERT_EQUAL(col->type, MULTILINETYPE);
464  lwcollection_free(col);
465 
466  col = lwcollection_extract((LWCOLLECTION*)geom, 3);
467  CU_ASSERT_EQUAL(col->type, MULTIPOLYGONTYPE);
468  lwcollection_free(col);
469 
470  lwgeom_free(geom);
471 
472  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION EMPTY", LW_PARSER_CHECK_NONE);
473 
474  col = lwcollection_extract((LWCOLLECTION*)geom, 1);
475  CU_ASSERT_EQUAL(col->type, MULTIPOINTTYPE);
476  lwcollection_free(col);
477 
478  col = lwcollection_extract((LWCOLLECTION*)geom, 2);
479  CU_ASSERT_EQUAL(col->type, MULTILINETYPE);
480  lwcollection_free(col);
481 
482  col = lwcollection_extract((LWCOLLECTION*)geom, 3);
483  CU_ASSERT_EQUAL(col->type, MULTIPOLYGONTYPE);
484  lwcollection_free(col);
485 
486  lwgeom_free(geom);
487 }
488 
489 static void test_lwgeom_free(void)
490 {
491  LWGEOM *geom;
492 
493  /* Empty geometries don't seem to free properly (#370) */
494  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION EMPTY", LW_PARSER_CHECK_NONE);
495  CU_ASSERT_EQUAL(geom->type, COLLECTIONTYPE);
496  lwgeom_free(geom);
497 
498  /* Empty geometries don't seem to free properly (#370) */
499  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
500  CU_ASSERT_EQUAL(geom->type, POLYGONTYPE);
501  lwgeom_free(geom);
502 
503  /* Empty geometries don't seem to free properly (#370) */
504  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
505  CU_ASSERT_EQUAL(geom->type, LINETYPE);
506  lwgeom_free(geom);
507 
508  /* Empty geometries don't seem to free properly (#370) */
509  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
510  CU_ASSERT_EQUAL(geom->type, POINTTYPE);
511  lwgeom_free(geom);
512 
513 }
514 
515 static void do_lwgeom_swap_ordinates(char *in, char *out)
516 {
517  LWGEOM *g;
518  char * t;
519  double xmax, ymax;
520  int testbox;
521 
523  lwgeom_add_bbox(g);
524 
525  testbox = (g->bbox != NULL);
526  if ( testbox )
527  {
528  xmax = g->bbox->xmax;
529  ymax = g->bbox->ymax;
530  }
531 
533 
534  if ( testbox )
535  {
536  CU_ASSERT_DOUBLE_EQUAL(g->bbox->xmax, ymax, 0.00001);
537  CU_ASSERT_DOUBLE_EQUAL(g->bbox->ymax, xmax, 0.00001);
538  }
539 
540  t = lwgeom_to_wkt(g, WKT_EXTENDED, 8, NULL);
541  if (t == NULL) fprintf(stderr, "In:%s", in);
542  if (strcmp(t, out))
543  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, t, out);
544 
545  CU_ASSERT_STRING_EQUAL(t, out)
546 
547  lwgeom_free(g);
548  lwfree(t);
549 }
550 
551 static void test_lwgeom_swap_ordinates(void)
552 {
553  /*
554  * 2D geometries types
555  */
557  "POINT(1 2)",
558  "POINT(2 1)"
559  );
560 
562  "LINESTRING(1 2,3 4)",
563  "LINESTRING(2 1,4 3)"
564  );
565 
567  "POLYGON((1 2,3 4,5 6,1 2))",
568  "POLYGON((2 1,4 3,6 5,2 1))"
569  );
570 
572  "POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8))",
573  "POLYGON((2 1,4 3,6 5,2 1),(8 7,10 9,12 11,8 7))"
574  );
575 
577  "MULTIPOINT(1 2,3 4)",
578  "MULTIPOINT(2 1,4 3)"
579  );
580 
582  "MULTILINESTRING((1 2,3 4),(5 6,7 8))",
583  "MULTILINESTRING((2 1,4 3),(6 5,8 7))"
584  );
585 
587  "MULTIPOLYGON(((1 2,3 4,5 6,7 8)),((9 10,11 12,13 14,10 9)))",
588  "MULTIPOLYGON(((2 1,4 3,6 5,8 7)),((10 9,12 11,14 13,9 10)))"
589  );
590 
592  "GEOMETRYCOLLECTION EMPTY",
593  "GEOMETRYCOLLECTION EMPTY"
594  );
595 
597  "GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4,5 6))",
598  "GEOMETRYCOLLECTION(POINT(2 1),LINESTRING(4 3,6 5))"
599  );
600 
602  "GEOMETRYCOLLECTION(POINT(1 2),GEOMETRYCOLLECTION(LINESTRING(3 4,5 6)))",
603  "GEOMETRYCOLLECTION(POINT(2 1),GEOMETRYCOLLECTION(LINESTRING(4 3,6 5)))"
604  );
605 
607  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
608  "CIRCULARSTRING(0 -2,2 0,0 2,2 0,4 2)"
609  );
610 
612  "COMPOUNDCURVE(CIRCULARSTRING(0 1,1 1,1 0),(1 0,0 1))",
613  "COMPOUNDCURVE(CIRCULARSTRING(1 0,1 1,0 1),(0 1,1 0))"
614  );
615 
617  "CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0))",
618  "CURVEPOLYGON(CIRCULARSTRING(0 -2,-1 -1,0 0,-1 1,0 2,2 0,0 -2),(0 -1,0.5 0,0 1,1 0,0 -1))"
619  );
620 
622  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 3))",
623  "MULTICURVE((5 5,5 3,3 3,3 0),CIRCULARSTRING(0 0,1 2,3 2))"
624  );
625 
627  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0)),((7 8,10 10,6 14,4 11,7 8)))",
628  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(0 -2,-1 -1,0 0,-1 1,0 2,2 0,0 -2),(0 -1,0.5 0,0 1,1 0,0 -1)),((8 7,10 10,14 6,11 4,8 7)))"
629  );
630 
631 
632  /*
633  * Ndims
634  */
635 
637  "POINT(1 2 3)",
638  "POINT(2 1 3)"
639  );
640 
642  "POINTM(1 2 3)",
643  "POINTM(2 1 3)"
644  );
645 
647  "POINT(1 2 3 4)",
648  "POINT(2 1 3 4)"
649  );
650 
651 
652  /*
653  * Srid
654  */
655 
657  "SRID=4326;POINT(1 2)",
658  "SRID=4326;POINT(2 1)"
659  );
660 
662  "SRID=0;POINT(1 2)",
663  "POINT(2 1)"
664  );
665 }
666 
667 static void test_f2d(void)
668 {
669  double d = 1000000.123456789123456789;
670  float f;
671  double e;
672 
673  f = next_float_down(d);
674  d = next_float_down(f);
675  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
676 
677  e = (double)f;
678  CU_ASSERT_DOUBLE_EQUAL(f,e, 0.0000001);
679 
680  f = next_float_down(d);
681  d = next_float_down(f);
682  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
683 
684  f = next_float_up(d);
685  d = next_float_up(f);
686  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
687 
688  f = next_float_up(d);
689  d = next_float_up(f);
690  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
691 }
692 
693 /*
694  * This is a test for memory leaks, can't really test
695  * w/out checking with a leak detector (ie: valgrind)
696  *
697  * See http://trac.osgeo.org/postgis/ticket/1102
698  */
699 static void test_lwgeom_clone(void)
700 {
701  size_t i;
702 
703  char *ewkt[] =
704  {
705  "POINT(0 0.2)",
706  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
707  "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
708  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
709  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
710  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
711  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
712  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
713  "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
714  "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
715  "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
716  "MULTICURVE((5 5 1 3,3 5 2 2,3 3 3 1,0 3 1 1),CIRCULARSTRING(0 0 0 0,0.26794 1 3 -2,0.5857864 1.414213 1 2))",
717  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0)),((7 8,10 10,6 14,4 11,7 8)))",
718  "TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))"
719  };
720 
721 
722  for ( i = 0; i < (sizeof ewkt/sizeof(char *)); i++ )
723  {
724  LWGEOM *geom, *cloned;
725  char *in_ewkt;
726  char *out_ewkt;
727 
728  in_ewkt = ewkt[i];
729  geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
730  cloned = lwgeom_clone(geom);
731  out_ewkt = lwgeom_to_ewkt(cloned);
732  if (strcmp(in_ewkt, out_ewkt))
733  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
734  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
735  lwfree(out_ewkt);
736  lwgeom_free(cloned);
737  lwgeom_free(geom);
738  }
739 
740 
741 }
742 
743 /*
744  * Test lwgeom_force_clockwise
745  */
747 {
748  LWGEOM *geom;
749  LWGEOM *geom2;
750  char *in_ewkt, *out_ewkt;
751 
752  /* counterclockwise, must be reversed */
753  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
754  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
756  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
757  out_ewkt = lwgeom_to_ewkt(geom);
758  if (strcmp(in_ewkt, out_ewkt))
759  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
760  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
761  lwfree(out_ewkt);
762  lwgeom_free(geom);
763 
764  /* clockwise, fine as is */
765  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
766  CU_ASSERT_TRUE(lwgeom_is_clockwise(geom));
768  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
769  out_ewkt = lwgeom_to_ewkt(geom);
770  if (strcmp(in_ewkt, out_ewkt))
771  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
772  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
773  lwfree(out_ewkt);
774  lwgeom_free(geom);
775 
776  /* counterclockwise shell (must be reversed), mixed-wise holes */
777  geom = lwgeom_from_wkt("POLYGON((0 0,10 0,10 10,0 10,0 0),(2 2,2 4,4 2,2 2),(6 2,8 2,8 4,6 2))", LW_PARSER_CHECK_NONE);
778  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
780  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 2,8 4,6 2))";
781  out_ewkt = lwgeom_to_ewkt(geom);
782  if (strcmp(in_ewkt, out_ewkt))
783  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
784  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
785  lwfree(out_ewkt);
786  lwgeom_free(geom);
787 
788  /* clockwise shell (fine), mixed-wise holes */
789  geom = lwgeom_from_wkt("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 4,8 2,6 2))", LW_PARSER_CHECK_NONE);
790  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
792  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 2,8 4,6 2))";
793  out_ewkt = lwgeom_to_ewkt(geom);
794  if (strcmp(in_ewkt, out_ewkt))
795  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
796  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
797  lwfree(out_ewkt);
798  lwgeom_free(geom);
799 
800  /* clockwise narrow ring, fine as-is */
801  /* NOTE: this is a narrow ring, see ticket #1302 */
802  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
803  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
804  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
805  lwgeom_force_clockwise(geom2);
806 
809  CU_ASSERT( lwgeom_same(geom, geom2) );
810  lwgeom_free(geom);
811  lwgeom_free(geom2);
812 }
813 
814 /*
815  * Test lwgeom_is_empty
816  */
817 static void test_lwgeom_is_empty(void)
818 {
819  LWGEOM *geom;
820 
821  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
822  CU_ASSERT( !lwgeom_is_empty(geom) );
823  lwgeom_free(geom);
824 
825  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
826  CU_ASSERT( lwgeom_is_empty(geom) );
827  lwgeom_free(geom);
828 
829  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
830  CU_ASSERT( lwgeom_is_empty(geom) );
831  lwgeom_free(geom);
832 
833  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
834  CU_ASSERT( lwgeom_is_empty(geom) );
835  lwgeom_free(geom);
836 
837  geom = lwgeom_from_wkt("MULTIPOINT EMPTY", LW_PARSER_CHECK_NONE);
838  CU_ASSERT( lwgeom_is_empty(geom) );
839  lwgeom_free(geom);
840 
841  geom = lwgeom_from_wkt("MULTILINESTRING EMPTY", LW_PARSER_CHECK_NONE);
842  CU_ASSERT( lwgeom_is_empty(geom) );
843  lwgeom_free(geom);
844 
845  geom = lwgeom_from_wkt("MULTIPOLYGON EMPTY", LW_PARSER_CHECK_NONE);
846  CU_ASSERT( lwgeom_is_empty(geom) );
847  lwgeom_free(geom);
848 
849  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY, POINT EMPTY, LINESTRING EMPTY, POLYGON EMPTY, MULTIPOINT EMPTY, MULTILINESTRING EMPTY, MULTIPOLYGON EMPTY, GEOMETRYCOLLECTION(MULTIPOLYGON EMPTY))", LW_PARSER_CHECK_NONE);
850  CU_ASSERT( lwgeom_is_empty(geom) );
851  lwgeom_free(geom);
852 
853 }
854 
855 /*
856  * Test lwgeom_same
857  */
858 static void test_lwgeom_same(void)
859 {
860  LWGEOM *geom, *geom2;
861 
862  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
863  CU_ASSERT( lwgeom_same(geom, geom) );
864  lwgeom_add_bbox(geom);
865  CU_ASSERT( lwgeom_same(geom, geom) );
866  lwgeom_free(geom);
867 
868  geom = lwgeom_from_wkt("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))", LW_PARSER_CHECK_NONE);
869  CU_ASSERT( lwgeom_same(geom, geom) );
870  lwgeom_add_bbox(geom);
871  CU_ASSERT( lwgeom_same(geom, geom) );
872  lwgeom_free(geom);
873 
874  geom = lwgeom_from_wkt("LINESTRING(0 0, 2 0)", LW_PARSER_CHECK_NONE);
875  CU_ASSERT( lwgeom_same(geom, geom) );
876  lwgeom_add_bbox(geom);
877  CU_ASSERT( lwgeom_same(geom, geom) );
878  lwgeom_free(geom);
879 
880  geom = lwgeom_from_wkt("MULTILINESTRING((0 0, 2 0))", LW_PARSER_CHECK_NONE);
881  CU_ASSERT( lwgeom_same(geom, geom) );
882  lwgeom_add_bbox(geom);
883  CU_ASSERT( lwgeom_same(geom, geom) );
884  lwgeom_free(geom);
885 
886  geom = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
887  CU_ASSERT( lwgeom_same(geom, geom) );
888  lwgeom_add_bbox(geom);
889  CU_ASSERT( lwgeom_same(geom, geom) );
890  lwgeom_free(geom);
891 
892  geom = lwgeom_from_wkt("MULTIPOINT((0 0),(4 5))", LW_PARSER_CHECK_NONE);
893  CU_ASSERT( lwgeom_same(geom, geom) );
894  lwgeom_add_bbox(geom);
895  CU_ASSERT( lwgeom_same(geom, geom) );
896  lwgeom_free(geom);
897 
898  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
899  CU_ASSERT( lwgeom_same(geom, geom) );
900  lwgeom_add_bbox(geom);
901  CU_ASSERT( lwgeom_same(geom, geom) );
902  lwgeom_free(geom);
903 
904  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
905  CU_ASSERT( lwgeom_same(geom, geom) );
906  lwgeom_add_bbox(geom);
907  CU_ASSERT( lwgeom_same(geom, geom) );
908  lwgeom_free(geom);
909 
910  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
911  CU_ASSERT( lwgeom_same(geom, geom) );
912  lwgeom_free(geom);
913 
914  geom = lwgeom_from_wkt("MULTIPOINT EMPTY", LW_PARSER_CHECK_NONE);
915  CU_ASSERT( lwgeom_same(geom, geom) );
916  lwgeom_free(geom);
917 
918  geom = lwgeom_from_wkt("MULTILINESTRING EMPTY", LW_PARSER_CHECK_NONE);
919  CU_ASSERT( lwgeom_same(geom, geom) );
920  lwgeom_free(geom);
921 
922  geom = lwgeom_from_wkt("MULTIPOLYGON EMPTY", LW_PARSER_CHECK_NONE);
923  CU_ASSERT( lwgeom_same(geom, geom) );
924  lwgeom_free(geom);
925 
926  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY, POINT EMPTY, LINESTRING EMPTY, POLYGON EMPTY, MULTIPOINT EMPTY, MULTILINESTRING EMPTY, MULTIPOLYGON EMPTY, GEOMETRYCOLLECTION(MULTIPOLYGON EMPTY))", LW_PARSER_CHECK_NONE);
927  CU_ASSERT( lwgeom_same(geom, geom) );
928  lwgeom_free(geom);
929 
930  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
931  geom2 = lwgeom_from_wkt("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY, POINT EMPTY, LINESTRING EMPTY, POLYGON EMPTY, MULTIPOINT EMPTY, MULTILINESTRING EMPTY, MULTIPOLYGON EMPTY, GEOMETRYCOLLECTION(MULTIPOLYGON EMPTY))", LW_PARSER_CHECK_NONE);
932  CU_ASSERT( ! lwgeom_same(geom, geom2) );
933  lwgeom_free(geom);
934  lwgeom_free(geom2);
935 
936  geom = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
937  geom2 = lwgeom_from_wkt("MULTIPOINT((0 0))", LW_PARSER_CHECK_NONE);
938  CU_ASSERT( ! lwgeom_same(geom, geom2) );
939  lwgeom_free(geom);
940  lwgeom_free(geom2);
941 
942  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
943  geom2 = lwgeom_from_wkt("POINT Z EMPTY", LW_PARSER_CHECK_NONE);
944  CU_ASSERT( ! lwgeom_same(geom, geom2) );
945  lwgeom_free(geom);
946  lwgeom_free(geom2);
947 
948 }
949 
950 /*
951  * Test lwgeom_force_curve
952  */
953 static void test_lwgeom_as_curve(void)
954 {
955  LWGEOM *geom;
956  LWGEOM *geom2;
957  char *in_ewkt, *out_ewkt;
958 
959  geom = lwgeom_from_wkt("LINESTRING(0 0, 10 0)", LW_PARSER_CHECK_NONE);
960  geom2 = lwgeom_as_curve(geom);
961  in_ewkt = "COMPOUNDCURVE((0 0,10 0))";
962  out_ewkt = lwgeom_to_ewkt(geom2);
963  if (strcmp(in_ewkt, out_ewkt))
964  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
965  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
966  lwfree(out_ewkt);
967  lwgeom_free(geom);
968  lwgeom_free(geom2);
969 
970  geom = lwgeom_from_wkt("MULTILINESTRING((0 0, 10 0))", LW_PARSER_CHECK_NONE);
971  geom2 = lwgeom_as_curve(geom);
972  in_ewkt = "MULTICURVE((0 0,10 0))";
973  out_ewkt = lwgeom_to_ewkt(geom2);
974  if (strcmp(in_ewkt, out_ewkt))
975  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
976  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
977  lwfree(out_ewkt);
978  lwgeom_free(geom);
979  lwgeom_free(geom2);
980 
981  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
982  geom2 = lwgeom_as_curve(geom);
983  in_ewkt = "CURVEPOLYGON((0 0,10 0,10 10,0 10,0 0))";
984  out_ewkt = lwgeom_to_ewkt(geom2);
985  if (strcmp(in_ewkt, out_ewkt))
986  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
987  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
988  lwfree(out_ewkt);
989  lwgeom_free(geom);
990  lwgeom_free(geom2);
991 
992  geom = lwgeom_from_wkt("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))", LW_PARSER_CHECK_NONE);
993  geom2 = lwgeom_as_curve(geom);
994  in_ewkt = "MULTISURFACE(((0 0,10 0,10 10,0 10,0 0)))";
995  out_ewkt = lwgeom_to_ewkt(geom2);
996  if (strcmp(in_ewkt, out_ewkt))
997  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
998  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
999  lwfree(out_ewkt);
1000  lwgeom_free(geom);
1001  lwgeom_free(geom2);
1002 
1003 }
1004 
1005 static void test_lwline_from_lwmpoint(void)
1006 {
1007  LWLINE *line;
1008  LWMPOINT *mpoint;
1009 
1010 // LWLINE *
1011 // lwline_from_lwmpoint(int srid, LWMPOINT *mpoint)
1012 
1013  mpoint = (LWMPOINT*)lwgeom_from_wkt("MULTIPOINT(0 0, 0 1, 1 1, 1 2, 2 2)", LW_PARSER_CHECK_NONE);
1014  line = lwline_from_lwmpoint(SRID_DEFAULT, mpoint);
1015  CU_ASSERT_EQUAL(line->points->npoints, mpoint->ngeoms);
1016  CU_ASSERT_DOUBLE_EQUAL(lwline_length_2d(line), 4.0, 0.000001);
1017 
1018  lwline_free(line);
1019  lwmpoint_free(mpoint);
1020 }
1021 
1022 /*
1023  * Test lwgeom_scale
1024  */
1025 static void test_lwgeom_scale(void)
1026 {
1027  LWGEOM *geom;
1028  POINT4D factor;
1029  char *out_ewkt;
1030  GBOX *box;
1031 
1032  geom = lwgeom_from_wkt("SRID=4326;GEOMETRYCOLLECTION(POINT(0 1 2 3),POLYGON((-1 -1 0 1,-1 2.5 0 1,2 2 0 1,2 -1 0 1,-1 -1 0 1),(0 0 1 2,0 1 1 2,1 1 1 2,1 0 2 3,0 0 1 2)),LINESTRING(0 0 0 0, 1 2 3 4))", LW_PARSER_CHECK_NONE);
1033  factor.x = 2; factor.y = 3; factor.z = 4; factor.m = 5;
1034  lwgeom_scale(geom, &factor);
1035  out_ewkt = lwgeom_to_ewkt(geom);
1036  ASSERT_STRING_EQUAL(out_ewkt, "SRID=4326;GEOMETRYCOLLECTION(POINT(0 3 8 15),POLYGON((-2 -3 0 5,-2 7.5 0 5,4 6 0 5,4 -3 0 5,-2 -3 0 5),(0 0 4 10,0 3 4 10,2 3 4 10,2 0 8 15,0 0 4 10)),LINESTRING(0 0 0 0,2 6 12 20))");
1037  lwgeom_free(geom);
1038  lwfree(out_ewkt);
1039 
1040  geom = lwgeom_from_wkt("POINT(1 1 1 1)", LW_PARSER_CHECK_NONE);
1041  lwgeom_add_bbox(geom);
1042  factor.x = 2; factor.y = 3; factor.z = 4; factor.m = 5;
1043  lwgeom_scale(geom, &factor);
1044  box = geom->bbox;
1045  ASSERT_DOUBLE_EQUAL(box->xmin, 2);
1046  ASSERT_DOUBLE_EQUAL(box->xmax, 2);
1047  ASSERT_DOUBLE_EQUAL(box->ymin, 3);
1048  ASSERT_DOUBLE_EQUAL(box->ymax, 3);
1049  ASSERT_DOUBLE_EQUAL(box->zmin, 4);
1050  ASSERT_DOUBLE_EQUAL(box->zmax, 4);
1051  ASSERT_DOUBLE_EQUAL(box->mmin, 5);
1052  ASSERT_DOUBLE_EQUAL(box->mmax, 5);
1053  lwgeom_free(geom);
1054 }
1055 
1056 void test_gbox_same_2d(void);
1058 {
1059  LWGEOM* g1 = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
1060  LWGEOM* g2 = lwgeom_from_wkt("LINESTRING(0 0, 0 1, 1 1)", LW_PARSER_CHECK_NONE);
1061  LWGEOM* g3 = lwgeom_from_wkt("LINESTRING(0 0, 1 1.000000000001)", LW_PARSER_CHECK_NONE);
1062 
1063  lwgeom_add_bbox(g1);
1064  lwgeom_add_bbox(g2);
1065  lwgeom_add_bbox(g3);
1066 
1067  CU_ASSERT_TRUE(gbox_same_2d(g1->bbox, g2->bbox));
1068  CU_ASSERT_FALSE(gbox_same_2d(g1->bbox, g3->bbox));
1069 
1070  /* Serializing a GBOX with precise coordinates renders the boxes not strictly equal,
1071  * but still equal according to gbox_same_2d_float.
1072  */
1073  GSERIALIZED* s3 = gserialized_from_lwgeom(g3, NULL);
1074  GBOX s3box;
1075  gserialized_read_gbox_p(s3, &s3box);
1076 
1077  CU_ASSERT_FALSE(gbox_same_2d(g3->bbox, &s3box));
1078  CU_ASSERT_TRUE(gbox_same_2d_float(g3->bbox, &s3box));
1079 
1080  /* The serialized box equals itself by either the exact or closest-float compares */
1081  CU_ASSERT_TRUE(gbox_same_2d(&s3box, &s3box));
1082  CU_ASSERT_TRUE(gbox_same_2d_float(&s3box, &s3box));
1083 
1084  lwgeom_free(g1);
1085  lwgeom_free(g2);
1086  lwgeom_free(g3);
1087  lwfree(s3);
1088 }
1089 
1092 {
1093  uint32_t i;
1094 
1095  char *ewkt[] =
1096  {
1097  "POINT EMPTY",
1098  "LINESTRING EMPTY",
1099  "MULTIPOINT EMPTY",
1100  "MULTIPOINT (EMPTY)",
1101  "MULTILINESTRING EMPTY",
1102  "MULTILINESTRING (EMPTY)"
1103  };
1104 
1105  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1106  {
1107  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1108  GBOX box;
1109  gbox_init(&box);
1110 
1111  GSERIALIZED* gser = gserialized_from_lwgeom(geom, NULL);
1112 
1113  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1114 
1115  CU_ASSERT_EQUAL(LW_FAILURE, gserialized_peek_gbox_p(gser, &box));
1116 
1117  lwgeom_free(geom);
1118  lwfree(gser);
1119  }
1120 }
1121 
1124 {
1125  uint32_t i;
1126 
1127  char *ewkt[] =
1128  {
1129  "POINT (2.2945672355 48.85822923236)",
1130  "POINTZ (2.2945672355 48.85822923236 15)",
1131  "POINTM (2.2945672355 48.85822923236 12)",
1132  "POINT ZM (2.2945672355 48.85822923236 12 2)",
1133  "MULTIPOINT ((-76.45402132523 44.225406213532))",
1134  "MULTIPOINT Z ((-76.45402132523 44.225406213532 112))",
1135  "MULTIPOINT ZM ((-76.45402132523 44.225406213532 112 44))",
1136  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532)",
1137  "LINESTRING Z (2.2945672355 48.85822923236 6, -76.45402132523 44.225406213532 8)",
1138  "LINESTRING ZM (2.2945672355 48.85822923236 3 2, -76.45402132523 44.225406213532 9 4)",
1139  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532))",
1140  "MULTILINESTRING Z ((2.2945672355 48.85822923236 4, -76.45402132523 44.225406213532 3))"
1141  };
1142 
1143  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1144  {
1145  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1146  GBOX box_from_peek;
1147  GBOX box_from_lwgeom;
1148  gbox_init(&box_from_peek);
1149  gbox_init(&box_from_lwgeom);
1150 
1151  GSERIALIZED* gser = gserialized_from_lwgeom(geom, NULL);
1152 
1153  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1154 
1155  lwgeom_calculate_gbox(geom, &box_from_lwgeom);
1156  gserialized_peek_gbox_p(gser, &box_from_peek);
1157 
1158  gbox_float_round(&box_from_lwgeom);
1159 
1160  CU_ASSERT_TRUE(gbox_same(&box_from_peek, &box_from_lwgeom));
1161 
1162  lwgeom_free(geom);
1163  lwfree(gser);
1164  }
1165 }
1166 
1169 {
1170  uint32_t i;
1171 
1172  char *ewkt[] =
1173  {
1174  "MULTIPOINT ((-76.45402132523 44.225406213532), (-72 33))",
1175  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33)",
1176  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33))",
1177  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532), (-72 33, -71 32))"
1178  };
1179 
1180  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1181  {
1182  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1183  GBOX box;
1184  gbox_init(&box);
1185  lwgeom_drop_bbox(geom);
1186 
1187  /* Construct a GSERIALIZED* that doesn't have a box, so that we can test the
1188  * actual logic of the peek function */
1189  size_t expected_size = gserialized_from_lwgeom_size(geom);
1190  GSERIALIZED* gser = lwalloc(expected_size);
1191  uint8_t* ptr = (uint8_t*) gser;
1192 
1193  ptr += 8; // Skip header
1194  gserialized_from_lwgeom_any(geom, ptr);
1195  gser->flags = geom->flags;
1196 
1197  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1198  CU_ASSERT_EQUAL(LW_FAILURE, gserialized_peek_gbox_p(gser, &box));
1199 
1200  lwgeom_free(geom);
1201  lwfree(gser);
1202  }
1203 }
1204 
1205 void test_signum_macro(void);
1207 {
1208  CU_ASSERT_EQUAL(SIGNUM(-5.0),-1);
1209  CU_ASSERT_EQUAL(SIGNUM( 5.0), 1);
1210  CU_ASSERT_EQUAL(SIGNUM( 0.0), 0);
1211  CU_ASSERT_EQUAL(SIGNUM(10) * 5, 5);
1212  CU_ASSERT_EQUAL(SIGNUM(-10) * 5, -5);
1213 }
1214 
1215 /*
1216 ** Used by test harness to register the tests in this file.
1217 */
1218 void libgeom_suite_setup(void);
1220 {
1221  CU_pSuite suite = CU_add_suite("serialization/deserialization", NULL, NULL);
1232  PG_ADD_TEST(suite, test_lwgeom_free);
1234  PG_ADD_TEST(suite, test_f2d);
1239  PG_ADD_TEST(suite, test_lwgeom_same);
1249 }
double x
Definition: liblwgeom.h:354
#define LINETYPE
Definition: liblwgeom.h:85
#define TYPMOD_GET_TYPE(typmod)
Definition: liblwgeom.h:166
static void test_gserialized_from_lwgeom_size(void)
Definition: cu_libgeom.c:159
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: g_serialized.c:413
GBOX * bbox
Definition: liblwgeom.h:400
static void test_on_gser_lwgeom_count_vertices(void)
Definition: cu_libgeom.c:426
double m
Definition: liblwgeom.h:354
#define TYPMOD_GET_M(typmod)
Definition: liblwgeom.h:170
uint32_t ngeoms
Definition: liblwgeom.h:470
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:386
#define TYPMOD_SET_Z(typmod)
Definition: liblwgeom.h:169
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:676
static void test_typmod_macros(void)
Definition: cu_libgeom.c:21
void lwfree(void *mem)
Definition: lwutil.c:242
#define FLAGS_GET_READONLY(flags)
Definition: liblwgeom.h:143
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void test_gbox_same_2d(void)
Definition: cu_libgeom.c:1057
uint8_t type
Definition: liblwgeom.h:505
static void test_gserialized_is_empty(void)
Definition: cu_libgeom.c:320
static void test_lwgeom_scale(void)
Definition: cu_libgeom.c:1025
#define ASSERT_STRING_EQUAL(o, e)
static int gserialized_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Definition: g_serialized.c:460
#define FLAGS_GET_GEODETIC(flags)
Definition: liblwgeom.h:142
#define POLYGONTYPE
Definition: liblwgeom.h:86
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:547
#define TYPMOD_GET_SRID(typmod)
Macros for manipulating the &#39;typemod&#39; int.
Definition: liblwgeom.h:164
uint8_t flags
Definition: liblwgeom.h:399
double xmax
Definition: liblwgeom.h:295
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1128
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Calculate type integer and dimensional flags from string input.
Definition: g_util.c:163
#define LW_SUCCESS
Definition: liblwgeom.h:79
void lwline_free(LWLINE *line)
Definition: lwline.c:76
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:1961
static void test_geometry_type_from_string(void)
Definition: cu_libgeom.c:362
#define SRID_DEFAULT
Definition: liblwgeom.h:197
void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2)
Swap ordinate values in every vertex of the geometry.
Definition: lwgeom.c:1451
#define FLAGS_GET_ZM(flags)
Definition: liblwgeom.h:152
void gserialized_set_srid(GSERIALIZED *s, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:116
double lwline_length_2d(const LWLINE *line)
Definition: lwline.c:526
static void test_lwgeom_force_clockwise(void)
Definition: cu_libgeom.c:746
float next_float_down(double d)
Definition: lwgeom_api.c:51
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
static void test_lwcollection_extract(void)
Definition: cu_libgeom.c:450
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:148
static void test_lwgeom_as_curve(void)
Definition: cu_libgeom.c:953
static void test_gbox_serialized_size(void)
Definition: cu_libgeom.c:237
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:40
static void test_flags_macros(void)
Definition: cu_libgeom.c:76
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:664
static void test_lwgeom_free(void)
Definition: cu_libgeom.c:489
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwinline.h:172
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
#define LW_FAILURE
Definition: liblwgeom.h:78
float next_float_up(double d)
Definition: lwgeom_api.c:67
unsigned int uint32_t
Definition: uthash.h:78
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:737
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1966
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
Definition: lwgeom.c:37
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:712
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
double zmax
Definition: liblwgeom.h:299
double ymin
Definition: liblwgeom.h:296
static void test_serialized_srid(void)
Definition: cu_libgeom.c:127
void libgeom_suite_setup(void)
Definition: cu_libgeom.c:1219
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:47
double xmin
Definition: liblwgeom.h:294
static void test_f2d(void)
Definition: cu_libgeom.c:667
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:141
void test_signum_macro(void)
Definition: cu_libgeom.c:1206
static void test_lwgeom_calculate_gbox(void)
Definition: cu_libgeom.c:201
LWLINE * lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint)
Definition: lwline.c:284
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
#define PG_ADD_TEST(suite, testfunc)
static void test_lwgeom_is_empty(void)
Definition: cu_libgeom.c:817
void test_gserialized_peek_gbox_p_fails_for_unsupported_cases(void)
Definition: cu_libgeom.c:1168
double ymax
Definition: liblwgeom.h:297
char * s
Definition: cu_in_wkt.c:23
#define TYPMOD_SET_TYPE(typmod, type)
Definition: liblwgeom.h:167
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:139
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition: g_box.c:186
double z
Definition: liblwgeom.h:354
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:473
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:573
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:789
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1219
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define WKT_EXTENDED
Definition: liblwgeom.h:2038
#define FLAGS_SET_BBOX(flags, value)
Definition: liblwgeom.h:147
void test_gserialized_peek_gbox_p_gets_correct_box(void)
Definition: cu_libgeom.c:1123
static void test_lwgeom_clone(void)
Definition: cu_libgeom.c:699
size_t gserialized_from_lwgeom_size(const LWGEOM *geom)
Calculate required memory segment to contain a serialized form of the LWGEOM.
Definition: g_serialized.c:807
static void test_lwgeom_same(void)
Definition: cu_libgeom.c:858
static void test_lwline_from_lwmpoint(void)
Definition: cu_libgeom.c:1005
static void test_lwgeom_from_gserialized(void)
Definition: cu_libgeom.c:254
double mmin
Definition: liblwgeom.h:300
double zmin
Definition: liblwgeom.h:298
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:677
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:398
type
Definition: ovdump.py:41
static size_t gserialized_from_lwgeom_any(const LWGEOM *geom, uint8_t *buf)
double mmax
Definition: liblwgeom.h:301
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
static void do_lwgeom_swap_ordinates(char *in, char *out)
Definition: cu_libgeom.c:515
#define ASSERT_DOUBLE_EQUAL(o, e)
#define TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:165
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition: lwgeom.c:402
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:65
#define TYPMOD_GET_Z(typmod)
Definition: liblwgeom.h:168
void * lwalloc(size_t size)
Definition: lwutil.c:227
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
Definition: g_box.c:194
double y
Definition: liblwgeom.h:354
#define MULTILINETYPE
Definition: liblwgeom.h:88
unsigned char uint8_t
Definition: uthash.h:79
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:171
void test_gserialized_peek_gbox_p_no_box_when_empty(void)
Definition: cu_libgeom.c:1091
static void test_lwgeom_count_vertices(void)
Definition: cu_libgeom.c:408
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:99
size_t gbox_serialized_size(uint8_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form...
Definition: g_box.c:446
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
#define SIGNUM(n)
Macro that returns: -1 if n < 0, 1 if n > 0, 0 if n == 0.
#define FLAGS_SET_READONLY(flags, value)
Definition: liblwgeom.h:149
uint8_t flags
Definition: liblwgeom.h:385
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:146
POINTARRAY * points
Definition: liblwgeom.h:424
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:678
static void test_lwgeom_swap_ordinates(void)
Definition: cu_libgeom.c:551
uint32_t npoints
Definition: liblwgeom.h:373