-
-
Notifications
You must be signed in to change notification settings - Fork 295
/
test_geom.c
164 lines (135 loc) · 4.27 KB
/
test_geom.c
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*****************************************************************************
*
* MODULE: Grass PDE Numerical Library
* AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
* soerengebbert <at> gmx <dot> de
*
* PURPOSE: Unit tests for geometry calculations
*
* COPYRIGHT: (C) 2000 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <grass/N_pde.h>
#include <grass/raster3d.h>
#include "test_gpde_lib.h"
/* prototypes */
static int test_geom_data(void);
/* ************************************************************************* */
/* Perform the geom_data unit tests *************************************** */
/* ************************************************************************* */
int unit_test_geom_data(void)
{
int sum = 0;
G_message("\n++ Running geom_data unit tests ++");
sum += test_geom_data();
if (sum > 0)
G_warning("\n-- geom_data unit tests failure --");
else
G_message("\n-- geom_data unit tests finished successfully --");
return sum;
}
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
int test_geom_data(void)
{
struct Cell_head region2d;
RASTER3D_Region region3d;
N_geom_data *geom = NULL;
int sum = 0, i;
double area = 0;
G_get_set_window(®ion2d);
/*Set the defaults */
Rast3d_init_defaults();
/*get the current region */
Rast3d_get_window(®ion3d);
geom = N_alloc_geom_data();
if (!geom) {
G_warning("error in N_alloc_geom_data");
return 1;
}
N_free_geom_data(geom);
geom = NULL;
/* ************ 2d region *************** */
geom = N_init_geom_data_2d(®ion2d, geom);
if (!geom) {
G_warning("error in N_init_geom_data_2d");
return 2;
}
geom = N_init_geom_data_2d(®ion2d, geom);
if (!geom) {
G_warning("error in N_init_geom_data_2d");
return 3;
}
if (geom->dim != 2)
sum++;
if (geom->planimetric == 0 && geom->area == NULL)
sum++;
if (geom->planimetric == 1 && geom->area != NULL)
sum++;
/*get areas */
area = 0.0;
if (geom->planimetric == 0) {
for (i = 0; i < geom->rows; i++)
area += N_get_geom_data_area_of_cell(geom, i);
if (area == 0) {
G_warning("Wrong area calculation in N_init_geom_data_2d");
sum++;
}
}
area = 0.0;
if (geom->planimetric == 1) {
for (i = 0; i < geom->rows; i++)
area += N_get_geom_data_area_of_cell(geom, i);
if (area == 0) {
G_warning("Wrong area calculation in N_get_geom_data_area_of_cell");
sum++;
}
}
N_free_geom_data(geom);
geom = NULL;
/* ************ 3d region *************** */
geom = N_init_geom_data_3d(®ion3d, geom);
if (!geom) {
G_warning("error in N_init_geom_data_3d");
return 2;
}
geom = N_init_geom_data_3d(®ion3d, geom);
if (!geom) {
G_warning("error in N_init_geom_data_3d");
return 3;
}
if (geom->dim != 3)
sum++;
if (geom->planimetric == 0 && geom->area == NULL)
sum++;
if (geom->planimetric == 1 && geom->area != NULL)
sum++;
/*get areas */
area = 0.0;
if (geom->planimetric == 0) {
for (i = 0; i < geom->rows; i++)
area += N_get_geom_data_area_of_cell(geom, i);
if (area == 0) {
G_warning("Wrong area calculation in N_get_geom_data_area_of_cell");
sum++;
}
}
area = 0.0;
if (geom->planimetric == 1) {
for (i = 0; i < geom->rows; i++)
area += N_get_geom_data_area_of_cell(geom, i);
if (area == 0) {
G_warning("Wrong area calculation in N_get_geom_data_area_of_cell");
sum++;
}
}
return sum;
}