PostGIS  2.5.7dev-r@@SVN_REVISION@@
cu_chaikin.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright 2018 Nicklas Avén <nicklas.aven@jordogskog.no>
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 "cu_tester.h"
20 
21 static void do_test_chaikin(char *geom_txt,char *expected, int n_iterations, int preserve_end_points)
22 {
23  LWGEOM *geom_in, *geom_out;
24  char *out_txt;
25  geom_in = lwgeom_from_wkt(geom_txt, LW_PARSER_CHECK_NONE);
26  geom_out = lwgeom_chaikin(geom_in, n_iterations, preserve_end_points);
27  out_txt = lwgeom_to_wkt(geom_out, WKT_EXTENDED, 3, NULL);
28  if(strcmp(expected, out_txt))
29  printf("%s is not equal to %s\n", expected, out_txt);
30  CU_ASSERT_STRING_EQUAL(expected, out_txt)
31  lwfree(out_txt);
32  lwgeom_free(geom_in);
33  lwgeom_free(geom_out);
34  return;
35 }
36 
37 static void do_test_chaikin_lines(void)
38 {
39  /*Simpliest test*/
40  do_test_chaikin("LINESTRING(0 0,8 8,16 0)","LINESTRING(0 0,6 6,10 6,16 0)", 1, 1);
41  /*2 iterations*/
42  do_test_chaikin("LINESTRING(0 0,8 8,16 0)","LINESTRING(0 0,4.5 4.5,7 6,9 6,11.5 4.5,16 0)", 2, 1);
43  /*check so it really ignores preserve_end_points set to off for linestrings*/
44  do_test_chaikin("LINESTRING(0 0,8 8,16 0)","LINESTRING(0 0,4.5 4.5,7 6,9 6,11.5 4.5,16 0)", 2, 0);
45  return;
46 }
47 
48 static void do_test_chaikin_polygons(void)
49 {
50  /*Simpliest test*/
51  do_test_chaikin("POLYGON((0 0,8 8,16 0,0 0))","POLYGON((0 0,6 6,10 6,14 2,12 0,0 0))", 1, 1);
52  /*2 iterations*/
53  do_test_chaikin("POLYGON((0 0,8 8,16 0,0 0))","POLYGON((0 0,4.5 4.5,7 6,9 6,11 5,13 3,13.5 1.5,12.5 0.5,9 0,0 0))", 2, 1);
54  /*2 iterations without preserving end points*/
55  do_test_chaikin("POLYGON((0 0,8 8,16 0,0 0))","POLYGON((3 3,5 5,7 6,9 6,11 5,13 3,13.5 1.5,12.5 0.5,10 0,6 0,3.5 0.5,2.5 1.5,3 3))", 2, 0);
56  return;
57 }
58 
59 
60 void chaikin_suite_setup(void);
62 {
63  CU_pSuite suite = CU_add_suite("chaikin",NULL,NULL);
66 }
void chaikin_suite_setup(void)
Definition: cu_chaikin.c:61
static void do_test_chaikin(char *geom_txt, char *expected, int n_iterations, int preserve_end_points)
Definition: cu_chaikin.c:21
static void do_test_chaikin_lines(void)
Definition: cu_chaikin.c:37
static void do_test_chaikin_polygons(void)
Definition: cu_chaikin.c:48
#define PG_ADD_TEST(suite, testfunc)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
#define WKT_EXTENDED
Definition: liblwgeom.h:2077
LWGEOM * lwgeom_chaikin(const LWGEOM *igeom, int n_iterations, int preserve_endpoint)
Definition: lwchaikins.c:182
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:676
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904