PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ triangle_parse()

void triangle_parse ( void  )

Definition at line 14 of file cu_surface.c.

15 {
16  LWGEOM *geom;
17  GSERIALIZED *g;
18  char *tmp;
19 
20  cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */
21 
22  /* 2 dims */
23  geom = lwgeom_from_wkt("TRIANGLE((0 1,2 3,4 5,0 1))", LW_PARSER_CHECK_NONE);
24  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
25  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
26  tmp = lwgeom_to_ewkt(geom);
27  CU_ASSERT_STRING_EQUAL("TRIANGLE((0 1,2 3,4 5,0 1))", tmp);
28  lwfree(tmp);
29  lwgeom_free(geom);
30  /* 3DM */
31  geom = lwgeom_from_wkt("TRIANGLEM((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE);
32  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
33  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
34  tmp = lwgeom_to_ewkt(geom);
35  CU_ASSERT_STRING_EQUAL("TRIANGLEM((0 1 2,3 4 5,6 7 8,0 1 2))", tmp);
36  lwfree(tmp);
37  lwgeom_free(geom);
38 
39  /* ERROR: a missing Z values */
40  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7,0 1 2))", LW_PARSER_CHECK_NONE);
41  CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg);
43  lwgeom_free(geom);
44 
45  /* ERROR: non closed rings */
46  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 0 2))", LW_PARSER_CHECK_NONE);
47  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
49  lwgeom_free(geom);
50 
51  /* ERROR: non closed face in Z dim */
52  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 3))", LW_PARSER_CHECK_NONE);
53  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
55  lwgeom_free(geom);
56 
57  /* ERROR: non closed face in Z dim, with a 4D geom */
58  geom = lwgeom_from_wkt("TRIANGLE((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3))", LW_PARSER_CHECK_NONE);
59  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
61  lwgeom_free(geom);
62 
63  /* ERROR: only 3 points in a face */
64  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,0 1 2))", LW_PARSER_CHECK_NONE);
65  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
67  lwgeom_free(geom);
68 
69  /* ERROR: more than 4 points in a face */
70  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,9 10 11,0 1 2))", LW_PARSER_CHECK_NONE);
71  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
73  lwgeom_free(geom);
74 
75  /* ERROR: no interior rings allowed */
76  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)", LW_PARSER_CHECK_NONE);
77  CU_ASSERT_STRING_EQUAL("parse error - invalid geometry", cu_error_msg);
79  lwgeom_free(geom);
80 
81  /* EMPTY face */
82  geom = lwgeom_from_wkt("TRIANGLE EMPTY", LW_PARSER_CHECK_NONE);
83  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
84  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
85  tmp = lwgeom_to_wkt(geom, LW_PARSER_CHECK_NONE, 0, 0);
86  CU_ASSERT_STRING_EQUAL("TRIANGLE EMPTY", tmp);
87  lwfree(tmp);
88  lwgeom_free(geom);
89 
90  /* explicit SRID */
91  geom = lwgeom_from_wkt("SRID=4326;TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE);
92  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
93  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
94  CU_ASSERT_EQUAL(geom->srid, 4326);
95  tmp = lwgeom_to_ewkt(geom);
96  CU_ASSERT_STRING_EQUAL("SRID=4326;TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", tmp);
97  lwfree(tmp);
98  lwgeom_free(geom);
99 
100  /* geography support */
101  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE);
102  g = gserialized_from_lwgeom(geom, 0);
103  CU_ASSERT_EQUAL(gserialized_get_type(g), TRIANGLETYPE);
104  lwgeom_free(geom);
105  lwfree(g);
106 }
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:556
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:676
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define TRIANGLETYPE
Definition: liblwgeom.h:98
uint8_t type
Definition: liblwgeom.h:399
int32_t srid
Definition: liblwgeom.h:402

References cu_error_msg, cu_error_msg_reset(), gserialized_from_lwgeom(), gserialized_get_type(), LW_PARSER_CHECK_NONE, lwfree(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_to_ewkt(), lwgeom_to_wkt(), LWGEOM::srid, TRIANGLETYPE, and LWGEOM::type.

Referenced by surface_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: