static void test_point_access() { PCPOINT *pt; int rv; double a1, a2, a3, a4, b1, b2, b3, b4; int idx = 0; pt = pc_point_make(schema); CU_ASSERT( pt != NULL ); /* One at a time */ idx = 0; a1 = 1.5; rv = pc_point_set_double_by_index(pt, idx, a1); rv = pc_point_get_double_by_index(pt, idx, &b1); // printf("d1=%g, d2=%g\n", a1, b1); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); idx = 2; a2 = 1501500.12; rv = pc_point_set_double_by_index(pt, idx, a2); rv = pc_point_get_double_by_index(pt, idx, &b2); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); a3 = 91; rv = pc_point_set_double_by_name(pt, "NumberOfReturns", a3); rv = pc_point_get_double_by_name(pt, "NumberOfReturns", &b3); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); pc_point_free(pt); /* All at once */ pt = pc_point_make(schema); a1 = 1.5; a2 = 1501500.12; a3 = 91; a4 = 200; rv = pc_point_set_double_by_index(pt, 0, a1); rv = pc_point_set_double_by_index(pt, 2, a2); rv = pc_point_set_double_by_name(pt, "NumberOfReturns", a3); rv = pc_point_set_double_by_name(pt, "UserData", a4); rv = pc_point_get_double_by_index(pt, 0, &b1); rv = pc_point_get_double_by_index(pt, 2, &b2); rv = pc_point_get_double_by_name(pt, "NumberOfReturns", &b3); rv = pc_point_get_double_by_name(pt, "UserData", &b4); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001); pc_point_free(pt); }
PCPOINT * pc_point_from_double_array(const PCSCHEMA *s, double *array, uint32_t nelems) { int i; PCPOINT *pt; if ( ! s ) { pcerror("null schema passed into pc_point_from_double_array"); return NULL; } if ( s->ndims != nelems ) { pcerror("number of elements in schema and array differ in pc_point_from_double_array"); return NULL; } /* Reference the external data */ pt = pcalloc(sizeof(PCPOINT)); pt->data = pcalloc(s->size); pt->schema = s; pt->readonly = PC_FALSE; for ( i = 0; i < nelems; i++ ) { if ( PC_FAILURE == pc_point_set_double_by_index(pt, i, array[i]) ) { pcerror("failed to write value into dimension %d in pc_point_from_double_array", i); return NULL; } } return pt; }
static PCPATCH_DIMENSIONAL * pc_patch_dimensional_filter(const PCPATCH_DIMENSIONAL *pdl, const PCBITMAP *map) { int i = 0; PCPATCH_DIMENSIONAL *fpdl = pc_patch_dimensional_clone(pdl); fpdl->stats = pc_stats_clone(pdl->stats); fpdl->npoints = map->nset; for ( i = 0; i < pdl->schema->ndims; i++ ) { PCDOUBLESTAT stats; stats.min = FLT_MAX; stats.max = FLT_MIN; stats.sum = 0; fpdl->bytes[i] = pc_bytes_filter(&(pdl->bytes[i]), map, &stats); /* Save the X/Y stats for use in bounds later */ if ( i == pdl->schema->x_position ) { fpdl->bounds.xmin = stats.min; fpdl->bounds.xmax = stats.max; } else if ( i == pdl->schema->y_position ) { fpdl->bounds.ymin = stats.min; fpdl->bounds.ymax = stats.max; } pc_point_set_double_by_index(&(fpdl->stats->min), i, stats.min); pc_point_set_double_by_index(&(fpdl->stats->max), i, stats.max); pc_point_set_double_by_index(&(fpdl->stats->avg), i, stats.sum/fpdl->npoints); } return fpdl; }
static void test_point_access() { PCPOINT *pt; int rv; double a1, a2, a3, a4, b1, b2, b3, b4; int idx = 0; double *allvals; pt = pc_point_make(schema); CU_ASSERT( pt != NULL ); /* One at a time */ idx = 0; a1 = 1.5; rv = pc_point_set_double_by_index(pt, idx, a1); rv = pc_point_get_double_by_index(pt, idx, &b1); // printf("d1=%g, d2=%g\n", a1, b1); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); idx = 2; a2 = 1501500.12; rv = pc_point_set_double_by_index(pt, idx, a2); rv = pc_point_get_double_by_index(pt, idx, &b2); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); a3 = 91; rv = pc_point_set_double_by_name(pt, "Intensity", a3); rv = pc_point_get_double_by_name(pt, "Intensity", &b3); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); pc_point_free(pt); /* All at once */ pt = pc_point_make(schema); a1 = 1.5; a2 = 1501500.12; a3 = 91; a4 = 200; rv = pc_point_set_double_by_index(pt, 0, a1); rv = pc_point_set_double_by_index(pt, 1, a2); rv = pc_point_set_double_by_name(pt, "Intensity", a3); rv = pc_point_set_double_by_name(pt, "Z", a4); rv = pc_point_get_double_by_index(pt, 0, &b1); rv = pc_point_get_double_by_index(pt, 1, &b2); rv = pc_point_get_double_by_name(pt, "Intensity", &b3); rv = pc_point_get_double_by_name(pt, "Z", &b4); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001); /* as a double array */ rv = pc_point_set_double_by_index(pt, 0, a1); rv = pc_point_set_double_by_index(pt, 1, a2); rv = pc_point_set_double_by_index(pt, 2, a3); rv = pc_point_set_double_by_index(pt, 3, a4); allvals = pc_point_to_double_array(pt); CU_ASSERT_DOUBLE_EQUAL(allvals[0], a1, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(allvals[1], a2, 0.0000001); //printf("allvals[2]:%g\n", allvals[2]); CU_ASSERT_DOUBLE_EQUAL(allvals[2], a3, 0.0000001); //printf("allvals[3]:%g\n", allvals[3]); CU_ASSERT_DOUBLE_EQUAL(allvals[3], a4, 0.0000001); pcfree(allvals); pc_point_free(pt); }
double pc_point_set_y(PCPOINT *pt, double val) { return pc_point_set_double_by_index(pt, pt->schema->y_position, val); }