15 #include "CUnit/Basic.h" 89 CU_ASSERT_EQUAL(rv, 0);
109 CU_ASSERT_DOUBLE_EQUAL(d1, 0.0046097720751, 0.0001);
110 CU_ASSERT_DOUBLE_EQUAL(c1.
x, 2047538.599, 0.001);
111 CU_ASSERT_DOUBLE_EQUAL(c1.
y, 7268770.4395, 0.001);
122 #define setpoint(p, x1, y1) {(p).x = (x1); (p).y = (y1);} 408 CU_ASSERT_EQUAL( p.
x, 1.5 );
411 CU_ASSERT_EQUAL( p.
m, 2.5 );
414 CU_ASSERT_EQUAL( p.
z, 3.5 );
451 CU_ASSERT_EQUAL( r.
x, 15.0);
455 CU_ASSERT_EQUAL( r.
y, 21.0);
459 CU_ASSERT_EQUAL( r.
y, 30.0);
463 CU_ASSERT_EQUAL( r.
y, 20.0);
481 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0 1.5,0 2,0 2.5))");
489 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0 3.5,0 4))");
497 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0 0,0 1,0 2,0 2.5))" );
505 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0 0,0 1,0 2,0 3,0 4))" );
513 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0 1,0 2))" );
521 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0 0,0 1,0 2))" );
529 CU_ASSERT_STRING_EQUAL(ewkt,
"GEOMETRYCOLLECTION(POINT(0 0))" );
537 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((2 2 2,1 1 1))" );
547 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((2 2 2,1 1 1))" );
557 CU_ASSERT_STRING_EQUAL(ewkt,
"GEOMETRYCOLLECTION(POINT(1 1 1))" );
567 CU_ASSERT_STRING_EQUAL(ewkt,
"GEOMETRYCOLLECTION(POINT(1 1 1))" );
592 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0 1.5,0 2,0 2.5))");
601 mline = (
LWMLINE*)
lwgeom_from_wkt(
"MULTILINESTRING((1 0,1 1,1 2,1 3,1 4), (0 0,0 1,0 2,0 3,0 4))",
LW_PARSER_CHECK_NONE);
607 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((1 3.5,1 4),(0 3.5,0 4))");
616 mline = (
LWMLINE*)
lwgeom_from_wkt(
"MULTILINESTRING((1 0,1 -1,1 -2,1 -3,1 -4), (0 0,0 1,0 2,0 3,0 4))",
LW_PARSER_CHECK_NONE);
622 CU_ASSERT_STRING_EQUAL(ewkt,
"GEOMETRYCOLLECTION(POINT(1 0),LINESTRING(0 0,0 1,0 2,0 2.5))");
637 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((3 3 3 3,3.5 3.5 3.5 3.5),(3.5 3.5 3.5 4.5,3 3 3 5))");
645 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((2 2 2 2,3 3 3 3,3.5 3.5 3.5 3.5),(3.5 3.5 3.5 4.5,3 3 3 5,2 2 2 6))");
653 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((3 3 3 3,4 4 4 4,3 3 3 5))");
661 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((2 2 2 2,3 3 3 3),(3 3 3 5,2 2 2 6))");
698 CU_ASSERT_STRING_EQUAL(ewkt,
"MULTILINESTRING((0.5 0.5 0.5,1 1 1,1.5 1.5 1.5))" );
719 CU_ASSERT_EQUAL(precision, 20);
727 CU_ASSERT_EQUAL(precision, 3);
735 CU_ASSERT_EQUAL(precision, 7);
745 CU_ASSERT_STRING_EQUAL(geohash,
"s000000000000000");
750 CU_ASSERT_STRING_EQUAL(geohash,
"w000000000000000");
755 CU_ASSERT_STRING_EQUAL(geohash,
"kkqnpkue9ktbpe5");
765 char *geohash = NULL;
770 CU_ASSERT_STRING_EQUAL(geohash,
"ss2r77s0du7p2ewb8hmx");
777 CU_ASSERT_STRING_EQUAL(geohash,
"ss2r77s0du7p2ewb8hmx");
784 CU_ASSERT_STRING_EQUAL(geohash,
"ss0");
791 CU_ASSERT_STRING_EQUAL(geohash,
"ss06g7h");
798 CU_ASSERT_STRING_EQUAL(geohash,
"ss0");
912 unsigned long long rs;
917 CU_ASSERT_EQUAL(gh, rs);
921 CU_ASSERT_EQUAL(gh, rs);
925 CU_ASSERT_EQUAL(gh, rs);
931 double lat[2], lon[2];
935 CU_ASSERT_DOUBLE_EQUAL(lat[0], 48, 1e-11);
936 CU_ASSERT_DOUBLE_EQUAL(lat[1], 48, 1e-11);
937 CU_ASSERT_DOUBLE_EQUAL(lon[0], -126, 1e-11);
938 CU_ASSERT_DOUBLE_EQUAL(lon[1], -126, 1e-11);
955 CU_ASSERT_STRING_EQUAL(ewkt,
"LINESTRING(0 0,0 0)");
964 CU_ASSERT_STRING_EQUAL(ewkt,
"POLYGON((0 0,1 0,1 1,0 0))");
972 CU_ASSERT_EQUAL(l, NULL);
979 CU_ASSERT_EQUAL(l, NULL);
987 CU_ASSERT_STRING_EQUAL(ewkt,
"LINESTRING(0 0,50 1.00001,100 0)");
996 CU_ASSERT_STRING_EQUAL(ewkt,
"LINESTRING(0 0,100 0)");
1019 do_median_dims_check(
"MULTIPOINT ZM ((1 3 4 5), (4 7 8 6), (2 9 1 7), (0 4 4 8), (2 2 3 9))", 3);
1040 passed = passed &&
FP_EQUALS(actual_pt.
x, expected_pt.
x);
1041 passed = passed &&
FP_EQUALS(actual_pt.
y, expected_pt.
y);
1048 CU_ASSERT_TRUE(passed);
1063 do_median_test(
"MULTIPOINT ((0 -1), (0 0), (0 1))",
"POINT (0 0)");
1066 do_median_test(
"MULTIPOINT ((1 -1 3), (1 0 2), (2 1 1))",
"POINT (1 0 2)");
1069 do_median_test(
"MULTIPOINT ((0 -1), (0 0), (0 0), (0 1))",
"POINT (0 0)");
1072 do_median_test(
"MULTIPOINT ((10 10 10), (10 20 10), (20 10 10), (20 20 10), (10 10 20), (10 20 20), (20 10 20), (20 20 20))",
1073 "POINT (15 15 15)");
1092 CU_ASSERT_EQUAL(mpt->
ngeoms,100);
1099 CU_ASSERT_EQUAL(mpt->
ngeoms,1);
1103 CU_ASSERT_EQUAL(mpt, NULL);
1109 geom =
lwgeom_from_wkt(
"MULTIPOLYGON(((10 0,0 10,10 20,20 10,10 0)),((0 0,5 0,5 5,0 5,0 0)))",
LW_PARSER_CHECK_NONE);
1112 CU_ASSERT_EQUAL(mpt->
ngeoms,1000);
1116 CU_ASSERT_EQUAL(mpt->
ngeoms,1);
1126 const int srid = 4326;
1127 const int segments_per_quad = 17;
1139 CU_ASSERT_DOUBLE_EQUAL(g->
xmin, x-r, 0.1);
1140 CU_ASSERT_DOUBLE_EQUAL(g->
xmax, x+r, 0.1);
1141 CU_ASSERT_DOUBLE_EQUAL(g->
ymin, y-r, 0.1);
1142 CU_ASSERT_DOUBLE_EQUAL(g->
ymax, y+r, 0.1);
1150 CU_ASSERT_TRUE(p == NULL);
1154 CU_ASSERT_TRUE(p == NULL);
1158 CU_ASSERT_TRUE(p != NULL);
1164 static int cluster_size = 100;
1165 static int num_clusters = 4;
1166 static double spread = 1.5;
1167 int N = cluster_size * num_clusters;
1174 for (j = 0; j < num_clusters; j++) {
1175 for (i = 0; i < cluster_size; i++)
1177 double u1 = 1.0 * rand() / RAND_MAX;
1178 double u2 = 1.0 * rand() / RAND_MAX;
1179 double z1 = spread * j + sqrt(-2*log2(u1))*cos(2*M_PI*u2);
1180 double z2 = spread * j + sqrt(-2*log2(u1))*sin(2*M_PI*u2);
1196 for (i = 0; i < k; i++)
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
double lw_arc_center(const POINT2D *p1, const POINT2D *p2, const POINT2D *p3, POINT2D *result)
Determines the center of the circle defined by the three given points.
static void test_lwline_crossing_short_lines(void)
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
static void test_lwline_clip_big(void)
static void test_lw_segment_side(void)
static void test_geohash_bbox(void)
static void test_isclosed(void)
static void test_geohash_point_as_int(void)
void lwmline_free(LWMLINE *mline)
int lwline_crossing_direction(const LWLINE *l1, const LWLINE *l2)
Given two lines, characterize how (and if) they cross each other.
#define ASSERT_STRING_EQUAL(o, e)
LWPOINT * lwpoint_make2d(int srid, double x, double y)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
void lwpoint_free(LWPOINT *pt)
void lwgeom_free(LWGEOM *geom)
static void test_lwmline_clip(void)
static void do_median_dims_check(char *wkt, int expected_dims)
void lwline_free(LWLINE *line)
static void test_lw_segment_intersects(void)
static void test_lwpoint_get_ordinate(void)
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
static void test_median_robustness(void)
static void test_lwpoly_construct_circle(void)
void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision)
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
static void test_geohash(void)
static void test_lwline_clip(void)
int lwcompound_is_closed(const LWCOMPOUND *curve)
static int clean_cg_suite(void)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
LWCOLLECTION * lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, double to)
Clip a line based on the from/to range of one of its ordinates.
static void test_geohash_point(void)
void algorithms_suite_setup(void)
static void test_lw_arc_center(void)
static void test_lwline_crossing_bugs(void)
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
int lwgeom_ndims(const LWGEOM *geom)
Return the number of dimensions (2, 3, 4) in a geometry.
#define LW_PARSER_CHECK_NONE
static void test_lwline_crossing_long_lines(void)
void lwmpoint_free(LWMPOINT *mpt)
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
static int init_cg_suite(void)
void lwpoly_free(LWPOLY *poly)
void cu_error_msg_reset()
#define LW_TRUE
Return types for functions with status returns.
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
int lwpoint_getPoint3dz_p(const LWPOINT *point, POINT3DZ *out)
int point_interpolate(const POINT4D *p1, const POINT4D *p2, POINT4D *p, int hasz, int hasm, char ordinate, double interpolation_value)
Given two points, a dimensionality, an ordinate, and an interpolation value generate a new point that...
static void test_kmeans(void)
LWGEOM * lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed)
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
#define SRID_UNKNOWN
Unknown SRID value.
#define PG_ADD_TEST(suite, testfunc)
LWCOLLECTION * lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, double to)
Clip a multi-line based on the from/to range of one of its ordinates.
#define ASSERT_INT_EQUAL(o, e)
LWGEOM_PARSER_RESULT parse_result
static void do_median_test(char *input, char *expected)
int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds)
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, int ngeoms, int k)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
#define FP_TOLERANCE
Floating point comparators.
void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value)
Given a point, ordinate number and value, set that ordinate on the point.
char * geohash_point(double longitude, double latitude, int precision)
static void test_median_handles_3d_correctly(void)
static void test_geohash_precision(void)
unsigned int geohash_point_as_int(POINT2D *pt)
#define setpoint(p, x1, y1)
static void test_lwpoint_set_ordinate(void)
char * lwgeom_geohash(const LWGEOM *lwgeom, int precision)
Calculate the GeoHash (http://geohash.org) string for a geometry.
double lwgeom_area(const LWGEOM *geom)
int lwline_is_closed(const LWLINE *line)
static void test_point_interpolate(void)
static void test_point_density(void)
LWMPOINT * lwgeom_to_points(const LWGEOM *lwgeom, int npoints)
void lwcollection_free(LWCOLLECTION *col)
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
LWPOLY * lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
static void test_lwgeom_simplify(void)
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
void * lwalloc(size_t size)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
int lw_segment_intersects(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2)
returns the kind of CG_SEGMENT_INTERSECTION_TYPE behavior of lineseg 1 (constructed from p1 and p2) a...