PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
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
20static void do_x3d3_test(char * in, char * out, int precision, int option)
21{
23 lwvarlena_t *v = lwgeom_to_x3d3(g, precision, option, "");
24
26
27 lwgeom_free(g);
28 lwfree(v);
29}
30
31
32static void do_x3d3_unsupported(char * in, char * out)
33{
35 lwvarlena_t *v = lwgeom_to_x3d3(g, 0, 0, "");
36
39
40 lwfree(v);
41 lwgeom_free(g);
42}
43
44
45static void out_x3d3_test_precision(void)
46{
47 /* 0 precision, i.e a round */
49 "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
50 "1 1 2",
51 0, 0);
52
53 /* 3 digits precision */
55 "POINT(1.1111111111111 1.1111111111111 2.11111111111111)",
56 "1.111 1.111 2.111",
57 3, 0);
58
59 /* 9 digits precision */
61 "POINT(1.2345678901234 1.2345678901234 4.123456789001)",
62 "1.23456789 1.23456789 4.123456789",
63 9, 0);
64
65 /* huge data */
66 do_x3d3_test("POINT(1E300 -105E-153 4E300)", "1e+300 -1e-151 4e+300", 0, 0);
67}
68
69
70static void out_x3d3_test_geoms(void)
71{
72 /* Linestring */
74 "LINESTRING(0 1 5,2 3 6,4 5 7)",
75 "<LineSet vertexCount='3'><Coordinate point='0 1 5 2 3 6 4 5 7' /></LineSet>",
76 0, 0);
77
78 /* Polygon **/
80 "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))",
81 "<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>",
82 3, 0);
83
84 /* TODO: Polygon - with internal ring - the answer is clearly wrong */
90 /* 2D MultiPoint */
92 "MULTIPOINT(0 1,2 3,4 5)",
93 "<Polypoint2D point='0 1 2 3 4 5 ' />",
94 0, 0);
95
96 /* 3D MultiPoint */
98 "MULTIPOINT Z(0 1 1,2 3 4,4 5 5)",
99 "<PointSet ><Coordinate point='0 1 1 2 3 4 4 5 5 ' /></PointSet>",
100 0, 0);
101 /* 3D Multiline */
103 "MULTILINESTRING Z((0 1 1,2 3 4,4 5 5),(6 7 5,8 9 8,10 11 5))",
104 "<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>",
105 0, 0);
106
107 /* MultiPolygon */
109 "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)))",
110 "<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>",
111 0, 0);
112
113 /* PolyhedralSurface */
115 "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)) )",
116 "<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>",
117 0, 0);
118
119 /* TODO: returns garbage at moment correctly implement GeometryCollection -- */
125 /* TODO: Implement Empty GeometryCollection correctly or throw a not-implemented */
131 /* CircularString */
133 "CIRCULARSTRING(-2 0 1,0 2 1,2 0 1,0 2 1,2 4 1)",
134 "lwgeom_to_x3d3: 'CircularString' geometry type not supported");
135
136 /* CompoundCurve */
138 "COMPOUNDCURVE(CIRCULARSTRING(0 0 1,1 1 1,1 0 1),(1 0 1,0 1 1))",
139 "lwgeom_to_x3d3: 'CompoundCurve' geometry type not supported");
140
141}
142
143static void out_x3d3_test_option(void)
144{
145 /* 0 precision, flip coordinates*/
147 "POINT(3.1111111111111 1.1111111111111 2.11111111111111)",
148 "1 3 2",
149 0, 1);
150
151 /* geocoordinate long,lat*/
153 "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))",
154 "<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>",
155 3, 2);
156
157 /* geocoordinate lat long*/
159 "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))",
160 "<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>",
161 3, 3);
162}
163
164
165/*
166** Used by test harness to register the tests in this file.
167*/
168void out_x3d_suite_setup(void);
170{
171 CU_pSuite suite = CU_add_suite("x3d_output", NULL, NULL);
175}
static uint8_t precision
Definition cu_in_twkb.c:25
void out_x3d_suite_setup(void)
Definition cu_out_x3d.c:169
static void do_x3d3_unsupported(char *in, char *out)
Definition cu_out_x3d.c:32
static void out_x3d3_test_precision(void)
Definition cu_out_x3d.c:45
static void out_x3d3_test_option(void)
Definition cu_out_x3d.c:143
static void do_x3d3_test(char *in, char *out, int precision, int option)
Definition cu_out_x3d.c:20
static void out_x3d3_test_geoms(void)
Definition cu_out_x3d.c:70
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define ASSERT_VARLENA_EQUAL(v, s)
#define PG_ADD_TEST(suite, testfunc)
#define ASSERT_STRING_EQUAL(o, e)
lwvarlena_t * lwgeom_to_x3d3(const LWGEOM *geom, int precision, int opts, const char *defid)
Definition lwout_x3d.c:37
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940