PostGIS  2.4.9dev-r@@SVN_REVISION@@
cu_out_x3d.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2011-2016 Regina Obe
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 "cu_tester.h"
19 
20 static void do_x3d3_test(char * in, char * out, char * srs, int precision, int option)
21 {
22  LWGEOM *g;
23  char * h;
24 
26  h = lwgeom_to_x3d3(g, srs, precision, option, "");
27 
28  if (strcmp(h, out))
29  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
30 
31  CU_ASSERT_STRING_EQUAL(h, out);
32 
33  lwgeom_free(g);
34  lwfree(h);
35 }
36 
37 
38 static void do_x3d3_unsupported(char * in, char * out)
39 {
40  LWGEOM *g;
41  char *h;
42 
44  h = lwgeom_to_x3d3(g, NULL, 0, 0, "");
45 
46  if (strcmp(cu_error_msg, out))
47  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
48  in, cu_error_msg, out);
49 
50  CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
52 
53  lwfree(h);
54  lwgeom_free(g);
55 }
56 
57 
58 static void out_x3d3_test_precision(void)
59 {
60  /* 0 precision, i.e a round */
62  "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
63  "1 1 2",
64  NULL, 0, 0);
65 
66  /* 3 digits precision */
68  "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
69  "1.111 1.111 2.111",
70  NULL, 3, 0);
71 
72  /* 9 digits precision */
74  "POINT(1.2345678901234 1.2345678901234 4.123456789001)",
75  "1.23456789 1.23456789 4.123456789",
76  NULL, 9, 0);
77 
78  /* huge data */
80  "POINT(1E300 -105E-153 4E300)",
81  "1e+300 -0 4e+300",
82  NULL, 0, 0);
83 }
84 
85 
86 static void out_x3d3_test_geoms(void)
87 {
88  /* Linestring */
90  "LINESTRING(0 1 5,2 3 6,4 5 7)",
91  "<LineSet vertexCount='3'><Coordinate point='0 1 5 2 3 6 4 5 7' /></LineSet>",
92  NULL, 0, 0);
93 
94  /* Polygon **/
96  "POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))",
97  "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 4 5 6 7'><Coordinate point='15 10 3 13.536 6.464 3 10 5 3 6.464 6.464 3 5 10 3 6.464 13.536 3 10 15 3 13.536 13.536 3 ' /></IndexedFaceSet>",
98  NULL, 3, 0);
99 
100  /* TODO: Polygon - with internal ring - the answer is clearly wrong */
106  /* 2D MultiPoint */
107  do_x3d3_test(
108  "MULTIPOINT(0 1,2 3,4 5)",
109  "<Polypoint2D point='0 1 2 3 4 5 ' />",
110  NULL, 0, 0);
111 
112  /* 3D MultiPoint */
113  do_x3d3_test(
114  "MULTIPOINT Z(0 1 1,2 3 4,4 5 5)",
115  "<PointSet ><Coordinate point='0 1 1 2 3 4 4 5 5 ' /></PointSet>",
116  NULL, 0, 0);
117  /* 3D Multiline */
118  do_x3d3_test(
119  "MULTILINESTRING Z((0 1 1,2 3 4,4 5 5),(6 7 5,8 9 8,10 11 5))",
120  "<IndexedLineSet coordIndex='0 1 2 -1 3 4 5'><Coordinate point='0 1 1 2 3 4 4 5 5 6 7 5 8 9 8 10 11 5 ' /></IndexedLineSet>",
121  NULL, 0, 0);
122 
123  /* MultiPolygon */
124  do_x3d3_test(
125  "MULTIPOLYGON(((0 1 1,2 3 1,4 5 1,0 1 1)),((6 7 1,8 9 1,10 11 1,6 7 1)))",
126  "<IndexedFaceSet convex='false' coordIndex='0 1 2 -1 3 4 5'><Coordinate point='0 1 1 2 3 1 4 5 1 6 7 1 8 9 1 10 11 1 ' /></IndexedFaceSet>",
127  NULL, 0, 0);
128 
129  /* PolyhedralSurface */
130  do_x3d3_test(
131  "POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)), ((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)), ((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)), ((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)), ((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )",
132  "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 -1 4 5 6 7 -1 8 9 10 11 -1 12 13 14 15 -1 16 17 18 19 -1 20 21 22 23'><Coordinate point='0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 1 1 1 1 0 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1' /></IndexedFaceSet>",
133  NULL, 0, 0);
134 
135  /* TODO: returns garbage at moment correctly implement GeometryCollection -- */
141  /* TODO: Implement Empty GeometryCollection correctly or throw a not-implemented */
147  /* CircularString */
149  "CIRCULARSTRING(-2 0 1,0 2 1,2 0 1,0 2 1,2 4 1)",
150  "lwgeom_to_x3d3: 'CircularString' geometry type not supported");
151 
152  /* CompoundCurve */
154  "COMPOUNDCURVE(CIRCULARSTRING(0 0 1,1 1 1,1 0 1),(1 0 1,0 1 1))",
155  "lwgeom_to_x3d3: 'CompoundCurve' geometry type not supported");
156 
157 }
158 
159 static void out_x3d3_test_option(void)
160 {
161  /* 0 precision, flip coordinates*/
162  do_x3d3_test(
163  "POINT(3.1111111111111 1.1111111111111 2.11111111111111)",
164  "1 3 2",
165  NULL, 0, 1);
166 
167  /* geocoordinate long,lat*/
168  do_x3d3_test(
169  "SRID=4326;POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))",
170  "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 4 5 6 7'><GeoCoordinate geoSystem='\"GD\" \"WE\" \"longitude_first\"' point='15 10 3 13.536 6.464 3 10 5 3 6.464 6.464 3 5 10 3 6.464 13.536 3 10 15 3 13.536 13.536 3 ' /></IndexedFaceSet>",
171  NULL, 3, 2);
172 
173  /* geocoordinate lat long*/
174  do_x3d3_test(
175  "SRID=4326;POLYGON((15 10 3,13.536 6.464 3,10 5 3,6.464 6.464 3,5 10 3,6.464 13.536 3,10 15 3,13.536 13.536 3,15 10 3))",
176  "<IndexedFaceSet convex='false' coordIndex='0 1 2 3 4 5 6 7'><GeoCoordinate geoSystem='\"GD\" \"WE\" \"latitude_first\"' point='10 15 3 6.464 13.536 3 5 10 3 6.464 6.464 3 10 5 3 13.536 6.464 3 15 10 3 13.536 13.536 3 ' /></IndexedFaceSet>",
177  NULL, 3, 3);
178 
179 
180 }
181 
182 
183 /*
184 ** Used by test harness to register the tests in this file.
185 */
186 void out_x3d_suite_setup(void);
188 {
189  CU_pSuite suite = CU_add_suite("x3d_output", NULL, NULL);
193 }
void out_x3d_suite_setup(void)
Definition: cu_out_x3d.c:187
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:60
void lwfree(void *mem)
Definition: lwutil.c:244
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
static void do_x3d3_unsupported(char *in, char *out)
Definition: cu_out_x3d.c:38
static void out_x3d3_test_geoms(void)
Definition: cu_out_x3d.c:86
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
static void do_x3d3_test(char *in, char *out, char *srs, int precision, int option)
Definition: cu_out_x3d.c:20
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
uint8_t precision
Definition: cu_in_twkb.c:25
static void out_x3d3_test_precision(void)
Definition: cu_out_x3d.c:58
static void out_x3d3_test_option(void)
Definition: cu_out_x3d.c:159
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]