static void test_patch_wkb() { int i; int npts = 20; PCPOINTLIST *pl1; PCPATCH_UNCOMPRESSED *pu1, *pu2; PCPATCH *pa1, *pa2, *pa3, *pa4; PCDIMSTATS *pds = NULL; size_t z1, z2; uint8_t *wkb1, *wkb2; char *str; pl1 = pc_pointlist_make(npts); for ( i = 0; i < npts; i++ ) { PCPOINT *pt = pc_point_make(simpleschema); pc_point_set_double_by_name(pt, "x", i*2.123); pc_point_set_double_by_name(pt, "y", i*2.9); pc_point_set_double_by_name(pt, "Z", i*0.3099); pc_point_set_double_by_name(pt, "intensity", 13); pc_pointlist_add_point(pl1, pt); } pa1 = (PCPATCH*)pc_patch_dimensional_from_pointlist(pl1); wkb1 = pc_patch_to_wkb(pa1, &z1); str = hexbytes_from_bytes(wkb1, z1); // printf("str\n%s\n",str); pa2 = pc_patch_from_wkb(simpleschema, wkb1, z1); // printf("pa2\n%s\n",pc_patch_to_string(pa2)); pa3 = pc_patch_compress(pa2, NULL); // printf("pa3\n%s\n",pc_patch_to_string(pa3)); wkb2 = pc_patch_to_wkb(pa3, &z2); pa4 = pc_patch_from_wkb(simpleschema, wkb2, z2); // printf("pa4\n%s\n",pc_patch_to_string(pa4)); pu1 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa1); pu2 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa4); // printf("pu1\n%s\n", pc_patch_to_string((PCPATCH*)pu1)); // printf("pu2\n%s\n", pc_patch_to_string((PCPATCH*)pu2)); CU_ASSERT_EQUAL(pu1->datasize, pu2->datasize); CU_ASSERT_EQUAL(pu1->npoints, pu2->npoints); CU_ASSERT(memcmp(pu1->data, pu2->data, pu1->datasize) == 0); pc_pointlist_free(pl1); pc_patch_free(pa1); pc_patch_free(pa2); pcfree(wkb1); }
static void test_patch_pointn_laz_compression() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000003 npoints // 0000000800000003000000050006 pt1 (XYZi) // 0000000200000003000000040008 pt2 (XYZi) // 0000000200000003000000040009 pt3 (XYZi) char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); char *str; PCPATCH *pa = pc_patch_from_wkb(simpleschema, wkb, hexsize/2); PCPOINTLIST *li = pc_pointlist_from_patch(pa); PCPATCH_LAZPERF* paz = pc_patch_lazperf_from_pointlist(li); PCPOINT *pt = pc_patch_pointn((PCPATCH*) paz, 2); CU_ASSERT(pt != NULL); str = pc_point_to_string(pt); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pt\":[0.02,0.03,0.04,8]}"); pc_patch_free((PCPATCH *)paz); pc_point_free(pt); pcfree(str); pcfree(wkb); pc_patch_free(pa); pc_pointlist_free(li); }
static void test_patch_pointn_ght_compression() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000003 npoints // 0000000800000003000000050006 pt1 (XYZi) // 0000000200000003000000040008 pt2 (XYZi) // 0000000200000003000000040009 pt3 (XYZi) char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); PCPATCH *pa = pc_patch_from_wkb(simpleschema, wkb, hexsize/2); PCPOINTLIST *li = pc_pointlist_from_patch(pa); #ifdef HAVE_LIBGHT PCPATCH_GHT* pag = pc_patch_ght_from_pointlist(li); PCPOINT *pt = pc_patch_pointn((PCPATCH*) pag, 2); CU_ASSERT(pt != NULL); CU_ASSERT_STRING_EQUAL(pc_point_to_string(pt), "{\"pcid\":0,\"pt\":[0.02,0.03,0.04,8]}"); pc_patch_free( (PCPATCH*) pag ); pc_point_free(pt); #endif // free pcfree(wkb); pc_patch_free(pa); pc_pointlist_free(li); }
static void test_patch_pointn_last_first() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000003 npoints // 0000000800000003000000050006 pt1 (XYZi) // 0000000200000003000000040008 pt2 (XYZi) // 0000000200000003000000040009 pt3 (XYZi) char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); char *str; PCPATCH *pa = pc_patch_from_wkb(simpleschema, wkb, hexsize/2); PCPOINT *pt = pc_patch_pointn(pa, -1); str = pc_point_to_string(pt); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pt\":[0.02,0.03,0.04,9]}"); pc_point_free(pt); free(str); pt = pc_patch_pointn(pa, -3); str = pc_point_to_string(pt); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pt\":[0.08,0.03,0.05,6]}"); pc_point_free(pt); free(str); pc_patch_free(pa); pcfree(wkb); }
static void test_sort_patch_is_sorted_no_compression() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000800000003000000050006 pt1 (XYZi) // 0000000200000003000000040008 pt2 (XYZi) // 0000000200000003000000040009 pt3 (XYZi) // init data PCPATCH *pasort; char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2); PCPOINTLIST *li = pc_pointlist_from_patch(pa); const char *X[] = {"X"}; CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, X, 1, PC_FALSE), PC_FALSE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, X, 1, PC_TRUE), PC_FALSE); pasort = pc_patch_sort(pa, X, 1); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort, X, 1, PC_FALSE), PC_FALSE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort, X, 1, PC_TRUE), PC_TRUE); // free pcfree(wkb); pc_patch_free(pa); pc_patch_free(pasort); pc_pointlist_free(li); }
PCPATCH * pc_patch_from_hexwkb(const char *hexwkb, size_t hexlen, FunctionCallInfoData *fcinfo) { PCPATCH *patch; PCSCHEMA *schema; uint32 pcid; uint8 *wkb = bytes_from_hexbytes(hexwkb, hexlen); size_t wkblen = hexlen/2; pcid = wkb_get_pcid(wkb); schema = pc_schema_from_pcid(pcid, fcinfo); patch = pc_patch_from_wkb(schema, wkb, wkblen); pfree(wkb); return patch; }
static void test_sort_simple() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000800000003000000050006 pt1 (XYZi) // 0000000200000001000000040008 pt2 (XYZi) // init data PCPOINTLIST *lisort; PCPATCH *pasort; double d1; double d2; char *hexbuf = "0000000000000000000000000200000008000000030000000500060000000200000001000000040008"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2); PCPOINTLIST *li = pc_pointlist_from_patch(pa); const char *X[] = {"X"}; // check that initial data are not sorted pc_point_get_double_by_name(pc_pointlist_get_point(li, 0), "X", &d1); pc_point_get_double_by_name(pc_pointlist_get_point(li, 1), "X", &d2); CU_ASSERT_DOUBLE_EQUAL(d1, 0.08, precision); CU_ASSERT_DOUBLE_EQUAL(d2, 0.02, precision); // sort on X attribute and check if data are well sorted pasort = pc_patch_sort(pa, X, 1); lisort = pc_pointlist_from_patch(pasort); pc_point_get_double_by_name(pc_pointlist_get_point(lisort, 0), "X", &d1); pc_point_get_double_by_name(pc_pointlist_get_point(lisort, 1), "X", &d2); CU_ASSERT_DOUBLE_EQUAL(d1, 0.02, precision); CU_ASSERT_DOUBLE_EQUAL(d2, 0.08, precision); // free pc_pointlist_free(li); pc_pointlist_free(lisort); pc_patch_free(pa); pc_patch_free(pasort); pcfree(wkb); }
static void test_sort_consistency() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000800000003000000050006 pt1 (XYZi) // 0000000200000001000000040008 pt2 (XYZi) // init data PCPATCH *pasort; char *pastr, *pasortstr; uint8_t *wkbsort; char *hexbuf = "0000000000000000000000000200000008000000030000000500060000000200000001000000040008"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2); PCPOINTLIST *li = pc_pointlist_from_patch(pa); const char *X[] = {"X"}; // sort on X attribute pasort = pc_patch_sort(pa, X, 1); //chek consistency wkbsort = pc_patch_to_wkb(pasort, &hexsize); CU_ASSERT_EQUAL(wkb_get_pcid(wkb), wkb_get_pcid(wkbsort)); CU_ASSERT_EQUAL(wkb_get_npoints(wkb), wkb_get_npoints(wkbsort)); CU_ASSERT_EQUAL(wkb_get_compression(wkb), wkb_get_compression(wkbsort)); pastr = pc_patch_to_string(pa); CU_ASSERT_STRING_EQUAL(pastr, "{\"pcid\":0,\"pts\":[[0.08,0.03,0.05,6],[0.02,0.01,0.04,8]]}"); pasortstr = pc_patch_to_string(pasort); CU_ASSERT_STRING_EQUAL(pasortstr, "{\"pcid\":0,\"pts\":[[0.02,0.01,0.04,8],[0.08,0.03,0.05,6]]}"); // free pcfree(wkb); pcfree(wkbsort); pcfree(pastr); pcfree(pasortstr); pc_patch_free(pasort); pc_patch_free(pa); pc_pointlist_free(li); }
static void test_sort_patch_ndims() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000800000001000000050006 pt1 (XYZi) // 0000000200000003000000040008 pt2 (XYZi) // 0000000200000002000000040008 pt2 (XYZi) // init data PCPATCH *pasort1, *pasort2; char *hexbuf = "00000000000000000000000003000000080000000400000005000600000002000000030000000400080000000200000002000000040009"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2); const char *X[] = {"X"}; const char *Y[] = {"Y"}; const char *X_Y[] = {"X", "Y"}; // test that initial data is not sorted CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, X, 1, PC_FALSE), PC_FALSE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, Y, 1, PC_FALSE), PC_FALSE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, X_Y, 2, PC_FALSE), PC_FALSE); // sort on X attribute and test pasort1 = pc_patch_sort(pa, X, 1); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort1, X, 1, PC_TRUE), PC_TRUE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort1, Y, 1, PC_TRUE), PC_FALSE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort1, X_Y, 2, PC_TRUE), PC_FALSE); // sort on X and Y and tst pasort2 = pc_patch_sort(pa, X_Y, 2); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort2, X, 1, PC_TRUE), PC_TRUE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort2, Y, 1, PC_TRUE), PC_TRUE); CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort2, X_Y, 2, PC_TRUE), PC_TRUE); // free pcfree(wkb); pc_patch_free(pasort1); pc_patch_free(pasort2); pc_patch_free(pa); }
PCPATCH * pc_patch_from_hexwkb(const char *hexwkb, size_t hexlen, FunctionCallInfoData *fcinfo) { PCPATCH *patch; PCSCHEMA *schema; uint32 pcid; uint8 *wkb = bytes_from_hexbytes(hexwkb, hexlen); size_t wkblen = hexlen/2; pcid = wkb_get_pcid(wkb); if ( ! pcid ) elog(ERROR, "%s: pcid is zero", __func__); schema = pc_schema_from_pcid(pcid, fcinfo); if ( ! schema ) elog(ERROR, "%s: unable to look up schema entry", __func__); patch = pc_patch_from_wkb(schema, wkb, wkblen); pfree(wkb); return patch; }
static void test_patch_hex_in() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000200000003000000050006 pt1 (XYZi) // 0000000200000003000000050008 pt2 (XYZi) char *hexbuf = "0000000000000000000000000200000002000000030000000500060000000200000003000000050008"; double d; char *str; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); PCPATCH *pa = pc_patch_from_wkb(simpleschema, wkb, hexsize/2); PCPOINTLIST *pl = pc_pointlist_from_patch(pa); pc_point_get_double_by_name(pc_pointlist_get_point(pl, 0), "X", &d); CU_ASSERT_DOUBLE_EQUAL(d, 0.02, 0.000001); pc_point_get_double_by_name(pc_pointlist_get_point(pl, 1), "Intensity", &d); CU_ASSERT_DOUBLE_EQUAL(d, 8, 0.000001); pc_point_get_double_by_name(&(pa->stats->min), "Intensity", &d); CU_ASSERT_DOUBLE_EQUAL(d, 6, 0.000001); pc_point_get_double_by_name(&(pa->stats->max), "Intensity", &d); CU_ASSERT_DOUBLE_EQUAL(d, 8, 0.000001); pc_point_get_double_by_name(&(pa->stats->avg), "Intensity", &d); CU_ASSERT_DOUBLE_EQUAL(d, 7, 0.000001); str = pc_patch_to_string(pa); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pts\":[[0.02,0.03,0.05,6],[0.02,0.03,0.05,8]]}"); // printf("\n%s\n",str); pcfree(str); pc_pointlist_free(pl); pc_patch_free(pa); pcfree(wkb); }
static void test_sort_stable() { // 00 endian (big) // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000800000003000000050006 pt1 (XYZi) // 0000000200000003000000040008 pt2 (XYZi) // 0000000200000003000000040009 pt3 (XYZi) // init data PCPATCH *pasort; char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009"; size_t hexsize = strlen(hexbuf); uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize); PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2); PCPOINTLIST *li = pc_pointlist_from_patch(pa); const char *dims[] = {"Y"}; // sort on Y attribute pasort = pc_patch_sort(pa, dims, 1); // check that sort is stable char *pastr = pc_patch_to_string(pa); char *pasortstr = pc_patch_to_string(pasort); CU_ASSERT_STRING_EQUAL(pastr, pasortstr); // free free(pastr); free(pasortstr); pcfree(wkb); pc_patch_free(pa); pc_patch_free(pasort); pc_pointlist_free(li); }