PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
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
16static void mbc_test(LWGEOM* g)
17{
19 CU_ASSERT_TRUE(result != NULL);
20
22
23 POINT2D p;
24 POINT4D p4;
25 char *msg1 = "mbc_test failed (got %.12f should be less than radius %.12f) \n";
26 while (lwpointiterator_next(it, &p4))
27 {
28 p.x = p4.x;
29 p.y = p4.y;
30
31 /* We need to store the distance in a variable before the assert so that
32 * it is rounded from its 80-bit representation (on x86) down to 64 bits.
33 * */
34 volatile double d = distance2d_pt_pt(result->center, &p);
35 if ( (d - result->radius) > 0.0000001 )
36 {
37 printf(msg1, d, result->radius);
38 CU_FAIL();
39 }
40 else
41 {
42 CU_PASS();
43 }
44 }
45
48}
49
50static void basic_test(void)
51{
52 uint32_t i;
53
54 char* inputs[] =
55 {
56 "POLYGON((26426 65078,26531 65242,26075 65136,26096 65427,26426 65078))",
57 "POINT (17 253)",
58 "TRIANGLE ((0 0, 10 0, 10 10, 0 0))",
59 "LINESTRING (17 253, -44 28, 33 11, 26 44)",
60 "MULTIPOINT ((0 0), (0 0), (0 0), (0 0))",
61 "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
62 "LINESTRING (-48546889 37039202, -37039202 -48546889)"
63 };
64
65 for (i = 0; i < sizeof(inputs)/sizeof(LWGEOM*); i++)
66 {
68 mbc_test(input);
69 lwgeom_free(input);
70 }
71
72}
73
74static void test_empty(void)
75{
76 LWGEOM* input = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
77
79 CU_ASSERT_TRUE(result == NULL);
80
81 lwgeom_free(input);
82}
83
84/*
85 ** Used by test harness to register the tests in this file.
86 */
89{
90 CU_pSuite suite = CU_add_suite("minimum_bounding_circle", NULL, NULL);
91 PG_ADD_TEST(suite, basic_test);
92 PG_ADD_TEST(suite, test_empty);
93}
char * inputs[]
Definition cu_iterator.c:17
static void test_empty(void)
void minimum_bounding_circle_suite_setup(void)
static void mbc_test(LWGEOM *g)
static void basic_test(void)
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
#define PG_ADD_TEST(suite, testfunc)
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition measures.c:2344
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition lwiterator.c:243
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:210
LWBOUNDINGCIRCLE * lwgeom_calculate_mbc(const LWGEOM *g)
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition lwiterator.c:268
void lwboundingcircle_destroy(LWBOUNDINGCIRCLE *c)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414