File: cu_force_dims.c

package info (click to toggle)
postgis 3.5.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 69,528 kB
  • sloc: ansic: 162,229; sql: 93,970; xml: 53,139; cpp: 12,646; perl: 5,658; sh: 5,369; makefile: 3,435; python: 1,205; yacc: 447; lex: 151; pascal: 58
file content (118 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**********************************************************************
 *
 * PostGIS - Spatial Types for PostgreSQL
 * http://postgis.net
 *
 * Copyright (C) 2008 Paul Ramsey
 * Copyright (C) 2020 Kristian Thy <thy@42.dk>
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU General Public Licence. See the COPYING file.
 *
 **********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "CUnit/Basic.h"

#include "liblwgeom_internal.h"
#include "cu_tester.h"

static void
test_force_2d(void)
{
	LWGEOM *geom;
	LWGEOM *geom2d;
	char *wkt_out;

	geom = lwgeom_from_wkt("CIRCULARSTRINGM(-5 0 4,0 5 3,5 0 2,10 -5 1,15 0 0)", LW_PARSER_CHECK_NONE);
	geom2d = lwgeom_force_2d(geom);
	wkt_out = lwgeom_to_ewkt(geom2d);
	ASSERT_STRING_EQUAL("CIRCULARSTRING(-5 0,0 5,5 0,10 -5,15 0)", wkt_out);
	lwgeom_free(geom);
	lwgeom_free(geom2d);
	lwfree(wkt_out);

	geom = lwgeom_from_wkt(
	    "GEOMETRYCOLLECTION(POINT(0 0 0),LINESTRING(1 1 1,2 2 2),POLYGON((0 0 1,0 1 1,1 1 1,1 0 1,0 0 1)),CURVEPOLYGON(CIRCULARSTRING(0 0 0,1 1 1,2 2 2,1 1 1,0 0 0)))",
	    LW_PARSER_CHECK_NONE);
	geom2d = lwgeom_force_2d(geom);
	wkt_out = lwgeom_to_ewkt(geom2d);
	ASSERT_STRING_EQUAL(
	    "GEOMETRYCOLLECTION(POINT(0 0),LINESTRING(1 1,2 2),POLYGON((0 0,0 1,1 1,1 0,0 0)),CURVEPOLYGON(CIRCULARSTRING(0 0,1 1,2 2,1 1,0 0)))",
	    wkt_out);
	lwgeom_free(geom);
	lwgeom_free(geom2d);
	lwfree(wkt_out);
}

static void
test_force_3dm(void)
{
	LWGEOM *geom;
	LWGEOM *geom3dm;
	char *wkt_out;

	geom = lwgeom_from_wkt("CIRCULARSTRING(-5 0 4,0 5 3,5 0 2,10 -5 1,15 0 0)", LW_PARSER_CHECK_NONE);
	geom3dm = lwgeom_force_3dm(geom, 1);
	wkt_out = lwgeom_to_ewkt(geom3dm);
	ASSERT_STRING_EQUAL("CIRCULARSTRINGM(-5 0 1,0 5 1,5 0 1,10 -5 1,15 0 1)", wkt_out);
	lwgeom_free(geom);
	lwgeom_free(geom3dm);
	lwfree(wkt_out);
}

static void
test_force_3dz(void)
{
	LWGEOM *geom;
	LWGEOM *geom3dz;
	char *wkt_out;

	geom = lwgeom_from_wkt("CIRCULARSTRING(-5 0,0 5,5 0,10 -5,15 0)", LW_PARSER_CHECK_NONE);
	geom3dz = lwgeom_force_3dz(geom, -99);
	wkt_out = lwgeom_to_ewkt(geom3dz);
	ASSERT_STRING_EQUAL("CIRCULARSTRING(-5 0 -99,0 5 -99,5 0 -99,10 -5 -99,15 0 -99)", wkt_out);
	lwgeom_free(geom);
	lwgeom_free(geom3dz);
	lwfree(wkt_out);

	geom = lwgeom_from_wkt("CIRCULARSTRING(-5 0,0 5,5 0,10 -5,15 0)", LW_PARSER_CHECK_NONE);
	geom3dz = lwgeom_force_3dz(geom, 0.0);
	wkt_out = lwgeom_to_ewkt(geom3dz);
	ASSERT_STRING_EQUAL("CIRCULARSTRING(-5 0 0,0 5 0,5 0 0,10 -5 0,15 0 0)", wkt_out);
	lwgeom_free(geom);
	lwgeom_free(geom3dz);
	lwfree(wkt_out);
}

static void
test_force_4d(void)
{
	LWGEOM *geom;
	LWGEOM *geom4d;
	char *wkt_out;

	geom = lwgeom_from_wkt("POINT(1 2)", LW_PARSER_CHECK_NONE);
	geom4d = lwgeom_force_4d(geom, 3, 4);
	wkt_out = lwgeom_to_ewkt(geom4d);
	ASSERT_STRING_EQUAL("POINT(1 2 3 4)", wkt_out);
	lwgeom_free(geom);
	lwgeom_free(geom4d);
	lwfree(wkt_out);
}

/*
** Used by the test harness to register the tests in this file.
*/
void force_dims_suite_setup(void);
void
force_dims_suite_setup(void)
{
	CU_pSuite suite = CU_add_suite("force_dims", NULL, NULL);
	PG_ADD_TEST(suite, test_force_2d);
	PG_ADD_TEST(suite, test_force_3dm);
	PG_ADD_TEST(suite, test_force_3dz);
	PG_ADD_TEST(suite, test_force_4d);
}