PostGIS
3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
cu_effectivearea.c
Go to the documentation of this file.
1
/**********************************************************************
2
*
3
* PostGIS - Spatial Types for PostgreSQL
4
* http://postgis.net
5
*
6
* Copyright 2012 Sandro Santilli <strk@kbt.io>
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 "
effectivearea.h
"
20
#include "
cu_tester.h
"
21
22
23
static
void
do_test_lwgeom_effectivearea
(
POINTARRAY
*pa,
double
*the_areas,
int
avoid_collaps)
24
{
25
26
uint32_t i;
27
EFFECTIVE_AREAS
*ea;
28
29
ea=
initiate_effectivearea
(pa);
30
ptarray_calc_areas
(ea,avoid_collaps,1,0);
31
32
for
(i=0;i<pa->
npoints
;i++)
33
{
34
CU_ASSERT_EQUAL(ea->
res_arealist
[i],the_areas[i]);
35
}
36
37
destroy_effectivearea
(ea);
38
39
40
}
41
42
static
void
do_test_lwgeom_effectivearea_lines
(
void
)
43
{
44
LWLINE
*the_geom;
45
int
avoid_collaps=2;
46
/*Line 1*/
47
the_geom = (
LWLINE
*)
lwgeom_from_wkt
(
"LINESTRING(1 1, 0 1, 0 2, -1 4, -1 4)"
,
LW_PARSER_CHECK_NONE
);
48
double
the_areas1[]={FLT_MAX,0.5,0.5,0,FLT_MAX};
49
do_test_lwgeom_effectivearea
(the_geom->
points
,the_areas1,avoid_collaps);
50
lwline_free
(the_geom);
51
/*Line 2*/
52
the_geom = (
LWLINE
*)
lwgeom_from_wkt
(
"LINESTRING(10 10,12 8, 15 7, 18 7, 20 20, 15 21, 18 22, 10 30, 40 100)"
,
LW_PARSER_CHECK_NONE
);
53
double
the_areas2[]={FLT_MAX,5,1.5,55,100,4,4,300,FLT_MAX};
54
do_test_lwgeom_effectivearea
(the_geom->
points
,the_areas2,avoid_collaps);
55
lwline_free
(the_geom);
56
}
57
58
59
60
static
void
do_test_lwgeom_effectivearea_polys
(
void
)
61
{
62
LWPOLY
*the_geom;
63
int
avoid_collaps=4;
64
65
/*POLYGON 1*/
66
the_geom = (
LWPOLY
*)
lwgeom_from_wkt
(
"POLYGON((10 10,12 8, 15 7, 18 7, 20 20, 15 21, 18 22, 10 30,1 99, 0 100, 10 10))"
,
LW_PARSER_CHECK_NONE
);
67
double
the_areas1[]={FLT_MAX,5,1.5,55,100,4,4,FLT_MAX,30,FLT_MAX,FLT_MAX};
68
do_test_lwgeom_effectivearea
(the_geom->
rings
[0],the_areas1,avoid_collaps);
69
lwpoly_free
(the_geom);
70
}
71
72
73
void
effectivearea_suite_setup
(
void
);
74
void
effectivearea_suite_setup
(
void
)
75
{
76
CU_pSuite suite = CU_add_suite(
"effectivearea"
,NULL,NULL);
77
PG_ADD_TEST
(suite,
do_test_lwgeom_effectivearea_lines
);
78
PG_ADD_TEST
(suite,
do_test_lwgeom_effectivearea_polys
);
79
}
do_test_lwgeom_effectivearea
static void do_test_lwgeom_effectivearea(POINTARRAY *pa, double *the_areas, int avoid_collaps)
Definition
cu_effectivearea.c:23
do_test_lwgeom_effectivearea_polys
static void do_test_lwgeom_effectivearea_polys(void)
Definition
cu_effectivearea.c:60
do_test_lwgeom_effectivearea_lines
static void do_test_lwgeom_effectivearea_lines(void)
Definition
cu_effectivearea.c:42
effectivearea_suite_setup
void effectivearea_suite_setup(void)
Definition
cu_effectivearea.c:74
destroy_effectivearea
void destroy_effectivearea(EFFECTIVE_AREAS *ea)
Definition
effectivearea.c:42
ptarray_calc_areas
void ptarray_calc_areas(EFFECTIVE_AREAS *ea, int avoid_collaps, int set_area, double trshld)
We calculate the effective area for the first time.
Definition
effectivearea.c:349
initiate_effectivearea
EFFECTIVE_AREAS * initiate_effectivearea(const POINTARRAY *inpts)
Definition
effectivearea.c:30
effectivearea.h
PG_ADD_TEST
#define PG_ADD_TEST(suite, testfunc)
Definition
liblwgeom/cunit/cu_tester.h:21
LW_PARSER_CHECK_NONE
#define LW_PARSER_CHECK_NONE
Definition
liblwgeom.h:2149
lwpoly_free
void lwpoly_free(LWPOLY *poly)
Definition
lwpoly.c:175
lwgeom_from_wkt
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition
lwin_wkt.c:940
lwline_free
void lwline_free(LWLINE *line)
Definition
lwline.c:67
liblwgeom_internal.h
cu_tester.h
EFFECTIVE_AREAS::res_arealist
double * res_arealist
Definition
effectivearea.h:68
EFFECTIVE_AREAS
Structure to hold pointarray and its arealist.
Definition
effectivearea.h:65
LWLINE::points
POINTARRAY * points
Definition
liblwgeom.h:483
LWLINE
Definition
liblwgeom.h:481
LWPOLY::rings
POINTARRAY ** rings
Definition
liblwgeom.h:519
LWPOLY
Definition
liblwgeom.h:517
POINTARRAY::npoints
uint32_t npoints
Definition
liblwgeom.h:427
POINTARRAY
Definition
liblwgeom.h:426
liblwgeom
cunit
cu_effectivearea.c
Generated by
1.9.8