PostGIS  2.5.2dev-r@@SVN_REVISION@@
cu_minimum_bounding_circle.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2015 Daniel Baston
6  *
7  * This is free software; you can redistribute and/or modify it under
8  * the terms of the GNU General Public Licence. See the COPYING file.
9  *
10  **********************************************************************/
11 
12 #include "CUnit/Basic.h"
13 #include "cu_tester.h"
14 #include "../liblwgeom_internal.h"
15 
16 static void mbc_test(LWGEOM* g)
17 {
19  CU_ASSERT_TRUE(result != NULL);
20 
22 
23  POINT2D p;
24  POINT4D p4;
25  while (lwpointiterator_next(it, &p4))
26  {
27  p.x = p4.x;
28  p.y = p4.y;
29 
30  /* We need to store the distance in a variable before the assert so that
31  * it is rounded from its 80-bit representation (on x86) down to 64 bits.
32  * */
33  volatile double d = distance2d_pt_pt(result->center, &p);
34 
35  CU_ASSERT_TRUE(d <= result->radius);
36  }
37 
40 }
41 
42 static void basic_test(void)
43 {
44  uint32_t i;
45 
46  char* inputs[] =
47  {
48  "POLYGON((26426 65078,26531 65242,26075 65136,26096 65427,26426 65078))",
49  "POINT (17 253)",
50  "TRIANGLE ((0 0, 10 0, 10 10, 0 0))",
51  "LINESTRING (17 253, -44 28, 33 11, 26 44)",
52  "MULTIPOINT ((0 0), (0 0), (0 0), (0 0))",
53  "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
54  "LINESTRING (-48546889 37039202, -37039202 -48546889)"
55  };
56 
57  for (i = 0; i < sizeof(inputs)/sizeof(LWGEOM*); i++)
58  {
59  LWGEOM* input = lwgeom_from_wkt(inputs[i], LW_PARSER_CHECK_NONE);
60  mbc_test(input);
61  lwgeom_free(input);
62  }
63 
64 }
65 
66 static void test_empty(void)
67 {
68  LWGEOM* input = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
69 
70  LWBOUNDINGCIRCLE* result = lwgeom_calculate_mbc(input);
71  CU_ASSERT_TRUE(result == NULL);
72 
73  lwgeom_free(input);
74 }
75 
76 /*
77  ** Used by test harness to register the tests in this file.
78  */
81 {
82  CU_pSuite suite = CU_add_suite("minimum_bounding_circle", NULL, NULL);
83  PG_ADD_TEST(suite, basic_test);
84  PG_ADD_TEST(suite, test_empty);
85 }
double x
Definition: liblwgeom.h:354
static void test_empty(void)
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point...
Definition: lwiterator.c:212
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2313
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
static void basic_test(void)
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:244
unsigned int uint32_t
Definition: uthash.h:78
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2004
double x
Definition: liblwgeom.h:330
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:269
static void mbc_test(LWGEOM *g)
#define PG_ADD_TEST(suite, testfunc)
double y
Definition: liblwgeom.h:330
char * inputs[]
Definition: cu_iterator.c:17
POINT2D * center
Definition: liblwgeom.h:1649
void minimum_bounding_circle_suite_setup(void)
double y
Definition: liblwgeom.h:354
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)