PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
cu_clip_by_rect.c
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * Copyright (C) 2014 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 "CUnit/Basic.h"
14#include "cu_tester.h"
15
16#include "liblwgeom.h"
17#include "liblwgeom_internal.h"
18
19static void test_lwgeom_clip_by_rect(void)
20{
21 LWGEOM *in, *out;
22 const char *wkt;
23 char *tmp;
24
25 /* Because i don't trust that much prior tests... ;) */
27
28 wkt = "LINESTRING(0 0, 5 5, 10 0)";
30 out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
31 tmp = lwgeom_to_ewkt(out);
32 /* printf("%s\n", tmp); */
33 ASSERT_STRING_EQUAL(tmp, "LINESTRING(5 5,10 0)");
34 lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
35
36 wkt = "LINESTRING EMPTY";
38 out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
39 tmp = lwgeom_to_ewkt(out);
40 /* printf("%s\n", tmp); */
41 ASSERT_STRING_EQUAL(tmp, wkt);
42 lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
43
44 wkt = "MULTIPOINT EMPTY";
46 out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
47 tmp = lwgeom_to_ewkt(out);
48 /* printf("%s\n", tmp); */
49 ASSERT_STRING_EQUAL(tmp, wkt);
50 lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
51
52 wkt = "MULTIPOINT(0 0, 6 6, 7 5)";
54 out = lwgeom_clip_by_rect(in, 5, 0, 10, 10);
55 tmp = lwgeom_to_ewkt(out);
56 /* printf("%s\n", tmp); */
57 ASSERT_STRING_EQUAL(tmp, "MULTIPOINT(6 6,7 5)");
58 lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
59
60 /* Disjoint polygon */
61 wkt = "POLYGON((311017 4773762,311016 4773749,311006 4773744,310990 4773748,310980 4773758,310985 4773771,311003 4773776,311017 4773762))";
63 out = lwgeom_clip_by_rect(in, -80, -80, 80, 80);
64 //tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); lwfree(tmp);
65 CU_ASSERT(lwgeom_is_empty(out));
66 lwgeom_free(out); lwgeom_free(in);
67
68 /* Returns NULL with an invalid polygon (line) */
69 wkt = "POLYGON((1410 2055, 1410 2056, 1410 2057, 1410 2055))";
71 out = lwgeom_clip_by_rect(in, -8.000000, -8.000000, 2056.000000, 2056.000000);
72 CU_ASSERT_PTR_NULL(out);
73 lwgeom_free(in);
74}
75
76/*
77** Used by test harness to register the tests in this file.
78*/
81{
82 CU_pSuite suite = CU_add_suite("clip_by_rectangle", NULL, NULL);
84}
void clip_by_rect_suite_setup(void)
static void test_lwgeom_clip_by_rect(void)
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
#define ASSERT_STRING_EQUAL(o, e)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
Definition lwgeom.c:593
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
This library is the generic geometry handling section of PostGIS.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199