PostGIS  2.1.10dev-r@@SVN_REVISION@@
cu_out_x3d.c
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: cu_out_x3d.c 13242 2015-02-19 00:22:22Z pramsey $
3  *
4  * PostGIS - Spatial Types for PostgreSQL
5  * http://www.postgis.org
6  * Copyright 2011 Regina Obe
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "CUnit/Basic.h"
17 
18 #include "liblwgeom_internal.h"
19 #include "cu_tester.h"
20 
21 static void do_x3d3_test(char * in, char * out, char * srs, int precision)
22 {
23  LWGEOM *g;
24  char * h;
25 
27  h = lwgeom_to_x3d3(g, srs, precision, 0, "");
28 
29  if (strcmp(h, out))
30  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
31 
32  CU_ASSERT_STRING_EQUAL(h, out);
33 
34  lwgeom_free(g);
35  lwfree(h);
36 }
37 
38 
39 static void do_x3d3_unsupported(char * in, char * out)
40 {
41  LWGEOM *g;
42  char *h;
43 
45  h = lwgeom_to_x3d3(g, NULL, 0, 0, "");
46 
47  if (strcmp(cu_error_msg, out))
48  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
49  in, cu_error_msg, out);
50 
51  CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
53 
54  lwfree(h);
55  lwgeom_free(g);
56 }
57 
58 
59 static void out_x3d3_test_precision(void)
60 {
61  /* 0 precision, i.e a round */
63  "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
64  "1 1 2",
65  NULL, 0);
66 
67  /* 3 digits precision */
69  "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
70  "1.111 1.111 2.111",
71  NULL, 3);
72 
73  /* 9 digits precision */
75  "POINT(1.2345678901234 1.2345678901234 4.123456789001)",
76  "1.23456789 1.23456789 4.123456789",
77  NULL, 9);
78 
79  /* huge data */
81  "POINT(1E300 -105E-153 4E300)'",
82  "1e+300 -0 4e+300",
83  NULL, 0);
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);
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 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);
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);
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);
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);
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 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);
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 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);
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 /*
160 ** Used by test harness to register the tests in this file.
161 */
162 void out_x3d_suite_setup(void);
164 {
165  CU_pSuite suite = CU_add_suite("X3D Output", NULL, NULL);
168 }
static void do_x3d3_test(char *in, char *out, char *srs, int precision)
Definition: cu_out_x3d.c:21
void out_x3d_suite_setup(void)
Definition: cu_out_x3d.c:163
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:49
void lwfree(void *mem)
Definition: lwutil.c:190
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
static void do_x3d3_unsupported(char *in, char *out)
Definition: cu_out_x3d.c:39
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:844
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
static void out_x3d3_test_precision(void)
Definition: cu_out_x3d.c:59
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]