PostGIS  2.3.7dev-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  int 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_flip_coordinates(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 
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  int 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);
755  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
756  out_ewkt = lwgeom_to_ewkt(geom);
757  if (strcmp(in_ewkt, out_ewkt))
758  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
759  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
760  lwfree(out_ewkt);
761  lwgeom_free(geom);
762 
763  /* clockwise, fine as is */
764  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
766  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
767  out_ewkt = lwgeom_to_ewkt(geom);
768  if (strcmp(in_ewkt, out_ewkt))
769  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
770  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
771  lwfree(out_ewkt);
772  lwgeom_free(geom);
773 
774  /* counterclockwise shell (must be reversed), mixed-wise holes */
775  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);
777  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))";
778  out_ewkt = lwgeom_to_ewkt(geom);
779  if (strcmp(in_ewkt, out_ewkt))
780  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
781  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
782  lwfree(out_ewkt);
783  lwgeom_free(geom);
784 
785  /* clockwise shell (fine), mixed-wise holes */
786  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);
788  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))";
789  out_ewkt = lwgeom_to_ewkt(geom);
790  if (strcmp(in_ewkt, out_ewkt))
791  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
792  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
793  lwfree(out_ewkt);
794  lwgeom_free(geom);
795 
796  /* clockwise narrow ring, fine as-is */
797  /* NOTE: this is a narrow ring, see ticket #1302 */
798  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
799  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
800  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
801  lwgeom_force_clockwise(geom2);
802 
805  CU_ASSERT( lwgeom_same(geom, geom2) );
806  lwgeom_free(geom);
807  lwgeom_free(geom2);
808 }
809 
810 /*
811  * Test lwgeom_is_empty
812  */
813 static void test_lwgeom_is_empty(void)
814 {
815  LWGEOM *geom;
816 
817  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
818  CU_ASSERT( !lwgeom_is_empty(geom) );
819  lwgeom_free(geom);
820 
821  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
822  CU_ASSERT( lwgeom_is_empty(geom) );
823  lwgeom_free(geom);
824 
825  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
826  CU_ASSERT( lwgeom_is_empty(geom) );
827  lwgeom_free(geom);
828 
829  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
830  CU_ASSERT( lwgeom_is_empty(geom) );
831  lwgeom_free(geom);
832 
833  geom = lwgeom_from_wkt("MULTIPOINT EMPTY", LW_PARSER_CHECK_NONE);
834  CU_ASSERT( lwgeom_is_empty(geom) );
835  lwgeom_free(geom);
836 
837  geom = lwgeom_from_wkt("MULTILINESTRING EMPTY", LW_PARSER_CHECK_NONE);
838  CU_ASSERT( lwgeom_is_empty(geom) );
839  lwgeom_free(geom);
840 
841  geom = lwgeom_from_wkt("MULTIPOLYGON EMPTY", LW_PARSER_CHECK_NONE);
842  CU_ASSERT( lwgeom_is_empty(geom) );
843  lwgeom_free(geom);
844 
845  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);
846  CU_ASSERT( lwgeom_is_empty(geom) );
847  lwgeom_free(geom);
848 
849 }
850 
851 /*
852  * Test lwgeom_same
853  */
854 static void test_lwgeom_same(void)
855 {
856  LWGEOM *geom, *geom2;
857 
858  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
859  CU_ASSERT( lwgeom_same(geom, geom) );
860  lwgeom_add_bbox(geom);
861  CU_ASSERT( lwgeom_same(geom, geom) );
862  lwgeom_free(geom);
863 
864  geom = lwgeom_from_wkt("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))", LW_PARSER_CHECK_NONE);
865  CU_ASSERT( lwgeom_same(geom, geom) );
866  lwgeom_add_bbox(geom);
867  CU_ASSERT( lwgeom_same(geom, geom) );
868  lwgeom_free(geom);
869 
870  geom = lwgeom_from_wkt("LINESTRING(0 0, 2 0)", LW_PARSER_CHECK_NONE);
871  CU_ASSERT( lwgeom_same(geom, geom) );
872  lwgeom_add_bbox(geom);
873  CU_ASSERT( lwgeom_same(geom, geom) );
874  lwgeom_free(geom);
875 
876  geom = lwgeom_from_wkt("MULTILINESTRING((0 0, 2 0))", LW_PARSER_CHECK_NONE);
877  CU_ASSERT( lwgeom_same(geom, geom) );
878  lwgeom_add_bbox(geom);
879  CU_ASSERT( lwgeom_same(geom, geom) );
880  lwgeom_free(geom);
881 
882  geom = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
883  CU_ASSERT( lwgeom_same(geom, geom) );
884  lwgeom_add_bbox(geom);
885  CU_ASSERT( lwgeom_same(geom, geom) );
886  lwgeom_free(geom);
887 
888  geom = lwgeom_from_wkt("MULTIPOINT((0 0),(4 5))", LW_PARSER_CHECK_NONE);
889  CU_ASSERT( lwgeom_same(geom, geom) );
890  lwgeom_add_bbox(geom);
891  CU_ASSERT( lwgeom_same(geom, geom) );
892  lwgeom_free(geom);
893 
894  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
895  CU_ASSERT( lwgeom_same(geom, geom) );
896  lwgeom_add_bbox(geom);
897  CU_ASSERT( lwgeom_same(geom, geom) );
898  lwgeom_free(geom);
899 
900  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
901  CU_ASSERT( lwgeom_same(geom, geom) );
902  lwgeom_add_bbox(geom);
903  CU_ASSERT( lwgeom_same(geom, geom) );
904  lwgeom_free(geom);
905 
906  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
907  CU_ASSERT( lwgeom_same(geom, geom) );
908  lwgeom_free(geom);
909 
910  geom = lwgeom_from_wkt("MULTIPOINT EMPTY", LW_PARSER_CHECK_NONE);
911  CU_ASSERT( lwgeom_same(geom, geom) );
912  lwgeom_free(geom);
913 
914  geom = lwgeom_from_wkt("MULTILINESTRING EMPTY", LW_PARSER_CHECK_NONE);
915  CU_ASSERT( lwgeom_same(geom, geom) );
916  lwgeom_free(geom);
917 
918  geom = lwgeom_from_wkt("MULTIPOLYGON EMPTY", LW_PARSER_CHECK_NONE);
919  CU_ASSERT( lwgeom_same(geom, geom) );
920  lwgeom_free(geom);
921 
922  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);
923  CU_ASSERT( lwgeom_same(geom, geom) );
924  lwgeom_free(geom);
925 
926  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
927  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);
928  CU_ASSERT( ! lwgeom_same(geom, geom2) );
929  lwgeom_free(geom);
930  lwgeom_free(geom2);
931 
932  geom = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
933  geom2 = lwgeom_from_wkt("MULTIPOINT((0 0))", LW_PARSER_CHECK_NONE);
934  CU_ASSERT( ! lwgeom_same(geom, geom2) );
935  lwgeom_free(geom);
936  lwgeom_free(geom2);
937 
938  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
939  geom2 = lwgeom_from_wkt("POINT Z EMPTY", LW_PARSER_CHECK_NONE);
940  CU_ASSERT( ! lwgeom_same(geom, geom2) );
941  lwgeom_free(geom);
942  lwgeom_free(geom2);
943 
944 }
945 
946 /*
947  * Test lwgeom_force_curve
948  */
949 static void test_lwgeom_as_curve(void)
950 {
951  LWGEOM *geom;
952  LWGEOM *geom2;
953  char *in_ewkt, *out_ewkt;
954 
955  geom = lwgeom_from_wkt("LINESTRING(0 0, 10 0)", LW_PARSER_CHECK_NONE);
956  geom2 = lwgeom_as_curve(geom);
957  in_ewkt = "COMPOUNDCURVE((0 0,10 0))";
958  out_ewkt = lwgeom_to_ewkt(geom2);
959  if (strcmp(in_ewkt, out_ewkt))
960  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
961  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
962  lwfree(out_ewkt);
963  lwgeom_free(geom);
964  lwgeom_free(geom2);
965 
966  geom = lwgeom_from_wkt("MULTILINESTRING((0 0, 10 0))", LW_PARSER_CHECK_NONE);
967  geom2 = lwgeom_as_curve(geom);
968  in_ewkt = "MULTICURVE((0 0,10 0))";
969  out_ewkt = lwgeom_to_ewkt(geom2);
970  if (strcmp(in_ewkt, out_ewkt))
971  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
972  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
973  lwfree(out_ewkt);
974  lwgeom_free(geom);
975  lwgeom_free(geom2);
976 
977  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
978  geom2 = lwgeom_as_curve(geom);
979  in_ewkt = "CURVEPOLYGON((0 0,10 0,10 10,0 10,0 0))";
980  out_ewkt = lwgeom_to_ewkt(geom2);
981  if (strcmp(in_ewkt, out_ewkt))
982  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
983  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
984  lwfree(out_ewkt);
985  lwgeom_free(geom);
986  lwgeom_free(geom2);
987 
988  geom = lwgeom_from_wkt("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))", LW_PARSER_CHECK_NONE);
989  geom2 = lwgeom_as_curve(geom);
990  in_ewkt = "MULTISURFACE(((0 0,10 0,10 10,0 10,0 0)))";
991  out_ewkt = lwgeom_to_ewkt(geom2);
992  if (strcmp(in_ewkt, out_ewkt))
993  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
994  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
995  lwfree(out_ewkt);
996  lwgeom_free(geom);
997  lwgeom_free(geom2);
998 
999 }
1000 
1001 static void test_lwline_from_lwmpoint(void)
1002 {
1003  LWLINE *line;
1004  LWMPOINT *mpoint;
1005 
1006 // LWLINE *
1007 // lwline_from_lwmpoint(int srid, LWMPOINT *mpoint)
1008 
1009  mpoint = (LWMPOINT*)lwgeom_from_wkt("MULTIPOINT(0 0, 0 1, 1 1, 1 2, 2 2)", LW_PARSER_CHECK_NONE);
1010  line = lwline_from_lwmpoint(SRID_DEFAULT, mpoint);
1011  CU_ASSERT_EQUAL(line->points->npoints, mpoint->ngeoms);
1012  CU_ASSERT_DOUBLE_EQUAL(lwline_length_2d(line), 4.0, 0.000001);
1013 
1014  lwline_free(line);
1015  lwmpoint_free(mpoint);
1016 }
1017 
1018 /*
1019  * Test lwgeom_scale
1020  */
1021 static void test_lwgeom_scale(void)
1022 {
1023  LWGEOM *geom;
1024  POINT4D factor;
1025  char *out_ewkt;
1026  GBOX *box;
1027 
1028  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);
1029  factor.x = 2; factor.y = 3; factor.z = 4; factor.m = 5;
1030  lwgeom_scale(geom, &factor);
1031  out_ewkt = lwgeom_to_ewkt(geom);
1032  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))");
1033  lwgeom_free(geom);
1034  lwfree(out_ewkt);
1035 
1036  geom = lwgeom_from_wkt("POINT(1 1 1 1)", LW_PARSER_CHECK_NONE);
1037  lwgeom_add_bbox(geom);
1038  factor.x = 2; factor.y = 3; factor.z = 4; factor.m = 5;
1039  lwgeom_scale(geom, &factor);
1040  box = geom->bbox;
1041  ASSERT_DOUBLE_EQUAL(box->xmin, 2);
1042  ASSERT_DOUBLE_EQUAL(box->xmax, 2);
1043  ASSERT_DOUBLE_EQUAL(box->ymin, 3);
1044  ASSERT_DOUBLE_EQUAL(box->ymax, 3);
1045  ASSERT_DOUBLE_EQUAL(box->zmin, 4);
1046  ASSERT_DOUBLE_EQUAL(box->zmax, 4);
1047  ASSERT_DOUBLE_EQUAL(box->mmin, 5);
1048  ASSERT_DOUBLE_EQUAL(box->mmax, 5);
1049  lwgeom_free(geom);
1050 }
1051 
1052 void test_gbox_same_2d(void);
1054 {
1055  LWGEOM* g1 = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
1056  LWGEOM* g2 = lwgeom_from_wkt("LINESTRING(0 0, 0 1, 1 1)", LW_PARSER_CHECK_NONE);
1057  LWGEOM* g3 = lwgeom_from_wkt("LINESTRING(0 0, 1 1.000000000001)", LW_PARSER_CHECK_NONE);
1058 
1059  lwgeom_add_bbox(g1);
1060  lwgeom_add_bbox(g2);
1061  lwgeom_add_bbox(g3);
1062 
1063  CU_ASSERT_TRUE(gbox_same_2d(g1->bbox, g2->bbox));
1064  CU_ASSERT_FALSE(gbox_same_2d(g1->bbox, g3->bbox));
1065 
1066  /* Serializing a GBOX with precise coordinates renders the boxes not strictly equal,
1067  * but still equal according to gbox_same_2d_float.
1068  */
1069  GSERIALIZED* s3 = gserialized_from_lwgeom(g3, NULL);
1070  GBOX s3box;
1071  gserialized_read_gbox_p(s3, &s3box);
1072 
1073  CU_ASSERT_FALSE(gbox_same_2d(g3->bbox, &s3box));
1074  CU_ASSERT_TRUE(gbox_same_2d_float(g3->bbox, &s3box));
1075 
1076  /* The serialized box equals itself by either the exact or closest-float compares */
1077  CU_ASSERT_TRUE(gbox_same_2d(&s3box, &s3box));
1078  CU_ASSERT_TRUE(gbox_same_2d_float(&s3box, &s3box));
1079 
1080  lwgeom_free(g1);
1081  lwgeom_free(g2);
1082  lwgeom_free(g3);
1083  lwfree(s3);
1084 }
1085 
1088 {
1089  uint32_t i;
1090 
1091  char *ewkt[] =
1092  {
1093  "POINT EMPTY",
1094  "LINESTRING EMPTY",
1095  "MULTIPOINT EMPTY",
1096  "MULTIPOINT (EMPTY)",
1097  "MULTILINESTRING EMPTY",
1098  "MULTILINESTRING (EMPTY)"
1099  };
1100 
1101  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1102  {
1103  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1104  GBOX box;
1105  gbox_init(&box);
1106 
1107  GSERIALIZED* gser = gserialized_from_lwgeom(geom, NULL);
1108 
1109  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1110 
1111  CU_ASSERT_EQUAL(LW_FAILURE, gserialized_peek_gbox_p(gser, &box));
1112 
1113  lwgeom_free(geom);
1114  lwfree(gser);
1115  }
1116 }
1117 
1120 {
1121  uint32_t i;
1122 
1123  char *ewkt[] =
1124  {
1125  "POINT (2.2945672355 48.85822923236)",
1126  "POINTZ (2.2945672355 48.85822923236 15)",
1127  "POINTM (2.2945672355 48.85822923236 12)",
1128  "POINT ZM (2.2945672355 48.85822923236 12 2)",
1129  "MULTIPOINT ((-76.45402132523 44.225406213532))",
1130  "MULTIPOINT Z ((-76.45402132523 44.225406213532 112))",
1131  "MULTIPOINT ZM ((-76.45402132523 44.225406213532 112 44))",
1132  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532)",
1133  "LINESTRING Z (2.2945672355 48.85822923236 6, -76.45402132523 44.225406213532 8)",
1134  "LINESTRING ZM (2.2945672355 48.85822923236 3 2, -76.45402132523 44.225406213532 9 4)",
1135  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532))",
1136  "MULTILINESTRING Z ((2.2945672355 48.85822923236 4, -76.45402132523 44.225406213532 3))"
1137  };
1138 
1139  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1140  {
1141  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1142  GBOX box_from_peek;
1143  GBOX box_from_lwgeom;
1144  gbox_init(&box_from_peek);
1145  gbox_init(&box_from_lwgeom);
1146 
1147  GSERIALIZED* gser = gserialized_from_lwgeom(geom, NULL);
1148 
1149  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1150 
1151  lwgeom_calculate_gbox(geom, &box_from_lwgeom);
1152  gserialized_peek_gbox_p(gser, &box_from_peek);
1153 
1154  gbox_float_round(&box_from_lwgeom);
1155 
1156  CU_ASSERT_TRUE(gbox_same(&box_from_peek, &box_from_lwgeom));
1157 
1158  lwgeom_free(geom);
1159  lwfree(gser);
1160  }
1161 }
1162 
1165 {
1166  uint32_t i;
1167 
1168  char *ewkt[] =
1169  {
1170  "MULTIPOINT ((-76.45402132523 44.225406213532), (-72 33))",
1171  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33)",
1172  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33))",
1173  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532), (-72 33, -71 32))"
1174  };
1175 
1176  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1177  {
1178  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1179  GBOX box;
1180  gbox_init(&box);
1181  lwgeom_drop_bbox(geom);
1182 
1183  /* Construct a GSERIALIZED* that doesn't have a box, so that we can test the
1184  * actual logic of the peek function */
1185  size_t expected_size = gserialized_from_lwgeom_size(geom);
1186  GSERIALIZED* gser = lwalloc(expected_size);
1187  uint8_t* ptr = (uint8_t*) gser;
1188 
1189  ptr += 8; // Skip header
1190  gserialized_from_lwgeom_any(geom, ptr);
1191  gser->flags = geom->flags;
1192 
1193  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1194  CU_ASSERT_EQUAL(LW_FAILURE, gserialized_peek_gbox_p(gser, &box));
1195 
1196  lwgeom_free(geom);
1197  lwfree(gser);
1198  }
1199 }
1200 
1201 void test_signum_macro(void);
1203 {
1204  CU_ASSERT_EQUAL(SIGNUM(-5.0),-1);
1205  CU_ASSERT_EQUAL(SIGNUM( 5.0), 1);
1206  CU_ASSERT_EQUAL(SIGNUM( 0.0), 0);
1207  CU_ASSERT_EQUAL(SIGNUM(10) * 5, 5);
1208  CU_ASSERT_EQUAL(SIGNUM(-10) * 5, -5);
1209 }
1210 
1211 /*
1212 ** Used by test harness to register the tests in this file.
1213 */
1214 void libgeom_suite_setup(void);
1216 {
1217  CU_pSuite suite = CU_add_suite("serialization/deserialization", NULL, NULL);
1228  PG_ADD_TEST(suite, test_lwgeom_free);
1230  PG_ADD_TEST(suite, test_f2d);
1235  PG_ADD_TEST(suite, test_lwgeom_same);
1245 }
double x
Definition: liblwgeom.h:351
#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:172
GBOX * bbox
Definition: liblwgeom.h:397
static void test_on_gser_lwgeom_count_vertices(void)
Definition: cu_libgeom.c:426
double m
Definition: liblwgeom.h:351
#define TYPMOD_GET_M(typmod)
Definition: liblwgeom.h:170
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:366
#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:669
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.
int npoints
Definition: liblwgeom.h:370
void test_gbox_same_2d(void)
Definition: cu_libgeom.c:1053
uint8_t type
Definition: liblwgeom.h:502
static void test_gserialized_is_empty(void)
Definition: cu_libgeom.c:320
static void test_lwgeom_scale(void)
Definition: cu_libgeom.c:1021
#define ASSERT_STRING_EQUAL(o, e)
static int gserialized_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Definition: g_serialized.c:219
#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:482
#define TYPMOD_GET_SRID(typmod)
Macros for manipulating the 'typemod' int.
Definition: liblwgeom.h:164
uint8_t flags
Definition: liblwgeom.h:396
double xmax
Definition: liblwgeom.h:292
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
#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:1755
static void test_geometry_type_from_string(void)
Definition: cu_libgeom.c:362
#define SRID_DEFAULT
Definition: liblwgeom.h:194
#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:100
double lwline_length_2d(const LWLINE *line)
Definition: lwline.c:586
static void test_lwgeom_force_clockwise(void)
Definition: cu_libgeom.c:746
float next_float_down(double d)
Definition: lwgeom_api.c:156
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:949
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:33
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:599
LWGEOM * lwgeom_flip_coordinates(LWGEOM *in)
Reverse the X and Y coordinate order.
Definition: lwgeom.c:1471
static void test_lwgeom_free(void)
Definition: cu_libgeom.c:489
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
#define LW_FAILURE
Definition: liblwgeom.h:78
float next_float_up(double d)
Definition: lwgeom_api.c:172
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:665
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:36
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:717
static void do_lwgeom_flip_coordinates(char *in, char *out)
Definition: cu_libgeom.c:515
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
double zmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:293
static void test_serialized_srid(void)
Definition: cu_libgeom.c:127
void libgeom_suite_setup(void)
Definition: cu_libgeom.c:1215
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:51
double xmin
Definition: liblwgeom.h:291
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:1202
static void test_lwgeom_calculate_gbox(void)
Definition: cu_libgeom.c:201
LWLINE * lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint)
Definition: lwline.c:290
#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:813
void test_gserialized_peek_gbox_p_fails_for_unsupported_cases(void)
Definition: cu_libgeom.c:1164
double ymax
Definition: liblwgeom.h:294
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 'flags' 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:191
double z
Definition: liblwgeom.h:351
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:408
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:508
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:790
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define WKT_EXTENDED
Definition: liblwgeom.h:2057
#define FLAGS_SET_BBOX(flags, value)
Definition: liblwgeom.h:147
void test_gserialized_peek_gbox_p_gets_correct_box(void)
Definition: cu_libgeom.c:1119
static void test_lwgeom_flip_coordinates(void)
Definition: cu_libgeom.c:551
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:566
static void test_lwgeom_same(void)
Definition: cu_libgeom.c:854
static void test_lwline_from_lwmpoint(void)
Definition: cu_libgeom.c:1001
static void test_lwgeom_from_gserialized(void)
Definition: cu_libgeom.c:254
double mmin
Definition: liblwgeom.h:297
double zmin
Definition: liblwgeom.h:295
#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:612
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:395
static size_t gserialized_from_lwgeom_any(const LWGEOM *geom, uint8_t *buf)
Definition: g_serialized.c:825
double mmax
Definition: liblwgeom.h:298
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:339
#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:337
#define TYPMOD_GET_Z(typmod)
Definition: liblwgeom.h:168
void * lwalloc(size_t size)
Definition: lwutil.c:227
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1310
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: g_serialized.c:933
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1153
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:199
double y
Definition: liblwgeom.h:351
#define MULTILINETYPE
Definition: liblwgeom.h:88
int ngeoms
Definition: liblwgeom.h:467
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:176
void test_gserialized_peek_gbox_p_no_box_when_empty(void)
Definition: cu_libgeom.c:1087
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:83
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:451
#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:382
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:146
POINTARRAY * points
Definition: liblwgeom.h:421
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:683