PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
cu_triangulate.c
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * Copyright (C) 2015 Daniel Baston <dbaston@gmail.com>
7 * Copyright (C) 2012 Sandro Santilli <strk@kbt.io>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU General Public Licence. See the COPYING file.
11 *
12 **********************************************************************/
13
14#include "CUnit/Basic.h"
15#include "cu_tester.h"
16
17#include "liblwgeom_internal.h"
18#include "../lwgeom_geos.h"
19
20static void
22{
23 LWGEOM *in, *tmp, *out;
24 char *wkt, *exp_wkt;
25
26 /* Because i don't trust that much prior tests... ;) */
28
29 in = lwgeom_from_wkt("MULTIPOINT(10 0, 20 0, 5 5)", LW_PARSER_CHECK_NONE);
30
31 tmp = lwgeom_delaunay_triangulation(in, 0, 0);
32 lwgeom_free(in);
33 out = lwgeom_normalize(tmp);
34 lwgeom_free(tmp);
35
36 wkt = lwgeom_to_ewkt(out);
37 lwgeom_free(out);
38
39 exp_wkt = "GEOMETRYCOLLECTION(POLYGON((5 5,20 0,10 0,5 5)))";
40 if (strcmp(wkt, exp_wkt))
41 fprintf(stderr, "\nExp: %s\nObt: %s\n", exp_wkt, wkt);
42
43 ASSERT_STRING_EQUAL(wkt, exp_wkt);
44 lwfree(wkt);
45}
46
47static void
49{
50 LWGEOM *in = lwgeom_from_wkt("MULTIPOINT(4 4, 5 5, 6 6)", LW_PARSER_CHECK_NONE);
51
52 LWGEOM *out_boundaries = lwgeom_voronoi_diagram(in, NULL, 0, 0);
53 LWGEOM *out_lines = lwgeom_voronoi_diagram(in, NULL, 0, 1);
54
55 /* For boundaries we get a generic LWCOLLECTION */
56 CU_ASSERT_EQUAL(COLLECTIONTYPE, lwgeom_get_type(out_boundaries));
57 /* For lines we get a MULTILINETYPE */
58 CU_ASSERT_EQUAL(MULTILINETYPE, lwgeom_get_type(out_lines));
59
60 lwgeom_free(in);
61 lwgeom_free(out_boundaries);
62 lwgeom_free(out_lines);
63}
64
65static void
67{
68 LWGEOM *in = lwgeom_from_wkt("MULTIPOINT(4 4, 5 5, 6 6)", LW_PARSER_CHECK_NONE);
69 LWGEOM *for_extent = lwgeom_from_wkt("LINESTRING (-10 -10, 10 10)", LW_PARSER_CHECK_NONE);
70 const GBOX *clipping_extent = lwgeom_get_bbox(for_extent);
71
72 LWGEOM *out = lwgeom_voronoi_diagram(in, clipping_extent, 0, 0);
73 const GBOX *output_extent = lwgeom_get_bbox(out);
74
75 CU_ASSERT_TRUE(gbox_same(clipping_extent, output_extent));
76
77 lwgeom_free(in);
78 lwgeom_free(for_extent);
79 lwgeom_free(out);
80}
81
82static void
83assert_empty_diagram(char *wkt, double tolerance)
84{
86 LWGEOM *out = lwgeom_voronoi_diagram(in, NULL, tolerance, 0);
87
88 CU_ASSERT_TRUE(lwgeom_is_collection(out));
89 CU_ASSERT_EQUAL(COLLECTIONTYPE, lwgeom_get_type(out));
90
91 lwgeom_free(in);
92 lwgeom_free(out);
93}
94
95static void
97{
98 assert_empty_diagram("POLYGON EMPTY", 0);
99 assert_empty_diagram("POINT (1 2)", 0);
100
101 /* This one produces an empty diagram because our two unique points
102 * collapse onto one after considering the tolerance. */
103 assert_empty_diagram("MULTIPOINT (0 0, 0 0.00001)", 0.001);
104}
105
106static int
108{
109 finishGEOS();
110 return 0;
111}
112
113/*
114** Used by test harness to register the tests in this file.
115*/
116void triangulate_suite_setup(void);
117void
static void test_lwgeom_voronoi_diagram(void)
void triangulate_suite_setup(void)
static void test_lwgeom_voronoi_diagram_expected_empty(void)
static int clean_geos_triangulate_suite(void)
static void test_lwgeom_voronoi_diagram_custom_envelope(void)
static void assert_empty_diagram(char *wkt, double tolerance)
static void test_lwgeom_delaunay_triangulation(void)
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition gbox.c:164
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
#define ASSERT_STRING_EQUAL(o, e)
#define COLLECTIONTYPE
Definition liblwgeom.h:108
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
#define MULTILINETYPE
Definition liblwgeom.h:106
LWGEOM * lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int32_t edgeOnly)
Take vertices of a geometry and build a delaunay triangulation on them.
LWGEOM * lwgeom_voronoi_diagram(const LWGEOM *g, const GBOX *env, double tolerance, int output_edges)
Take vertices of a geometry and build the Voronoi diagram.
LWGEOM * lwgeom_normalize(const LWGEOM *geom)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
Definition lwgeom.c:593
void lwfree(void *mem)
Definition lwutil.c:248
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM contains sub-geometries or not This basically just checks that the struct ...
Definition lwgeom.c:1125
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition lwgeom.c:771
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition lwinline.h:141