PostGIS  2.5.7dev-r@@SVN_REVISION@@
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 
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 
38 
39 
40 }
41 
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 
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);
75 {
76  CU_pSuite suite = CU_add_suite("effectivearea",NULL,NULL);
79 }
static void do_test_lwgeom_effectivearea(POINTARRAY *pa, double *the_areas, int avoid_collaps)
static void do_test_lwgeom_effectivearea_polys(void)
static void do_test_lwgeom_effectivearea_lines(void)
void effectivearea_suite_setup(void)
EFFECTIVE_AREAS * initiate_effectivearea(const POINTARRAY *inpts)
Definition: effectivearea.c:30
void destroy_effectivearea(EFFECTIVE_AREAS *ea)
Definition: effectivearea.c:42
void ptarray_calc_areas(EFFECTIVE_AREAS *ea, int avoid_collaps, int set_area, double trshld)
We calculate the effective area for the first time.
#define PG_ADD_TEST(suite, testfunc)
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:175
void lwline_free(LWLINE *line)
Definition: lwline.c:76
double * res_arealist
Definition: effectivearea.h:68
Structure to hold pointarray and its arealist.
Definition: effectivearea.h:65
POINTARRAY * points
Definition: liblwgeom.h:425
POINTARRAY ** rings
Definition: liblwgeom.h:460
uint32_t npoints
Definition: liblwgeom.h:374
unsigned int uint32_t
Definition: uthash.h:78