void fastbitIndex(const char* datasetName, void* data, uint64_t blockSize, FastBitDataType ft, double**keys, uint64_t*nk, int64_t**offsets, uint64_t*no, uint32_t**bms, uint64_t*nb) { long int fastbitErr; fastbitErr = fastbit_iapi_register_array(datasetName, ft, data, blockSize); assertErr(fastbitErr, "failed to register array with", datasetName); fastbitErr = fastbit_iapi_build_index(datasetName, (const char*)gBinningOption); assertErr(fastbitErr, "failed to build idx with ", datasetName); fastbitErr = fastbit_iapi_deconstruct_index(datasetName, keys, nk, offsets, no, bms, nb); assertErr(fastbitErr, "failed with fastbit_iapi_deconstruct on ", datasetName); //printf("nk/no/nb %" PRId64 " %" PRId64 " %" PRId64 "\n", *nk, *no, *nb); fastbit_iapi_free_all(); /*free(offsets); free(keys); free(bms); */ }
TEST_F(CheapRulerTest, along) { for (unsigned i = 0; i < lines.size(); ++i) { auto expected = turf_along[i]; auto actual = ruler.along(lines[i], turf_along_dist[i]); assertErr(expected.x, actual.x, 1e-6); // along longitude assertErr(expected.y, actual.y, 1e-6); // along latitude } }
TEST_F(CheapRulerTest, destination) { for (unsigned i = 0; i < points.size(); ++i) { auto bearing = (i % 360) - 180.; auto expected = turf_destination[i]; auto actual = ruler.destination(points[i], 1.0, bearing); assertErr(expected.x, actual.x, 1e-6); // longitude assertErr(expected.y, actual.y, 1e-6); // latitude } }
TEST_F(CheapRulerTest, bufferPoint) { for (unsigned i = 0; i < points.size(); ++i) { auto expected = turf_bufferPoint[i]; auto actual = milesRuler.bufferPoint(points[i], 0.1); assertErr(expected.min.x, actual.min.x, 2e-7); assertErr(expected.min.x, actual.min.x, 2e-7); assertErr(expected.max.y, actual.max.y, 2e-7); assertErr(expected.max.y, actual.max.y, 2e-7); } }
TEST_F(CheapRulerTest, lineDistance) { for (unsigned i = 0; i < lines.size(); ++i) { auto expected = turf_lineDistance[i]; auto actual = ruler.lineDistance(lines[i]); assertErr(expected, actual, 0.003); } }
TEST_F(CheapRulerTest, bearing) { for (unsigned i = 0; i < points.size() - 1; ++i) { auto expected = turf_bearing[i]; auto actual = ruler.bearing(points[i], points[i + 1]); assertErr(expected, actual, .005); } }
TEST_F(CheapRulerTest, distance) { for (unsigned i = 0; i < points.size() - 1; ++i) { auto expected = turf_distance[i]; auto actual = ruler.distance(points[i], points[i + 1]); assertErr(expected, actual, .003); } }
TEST_F(CheapRulerTest, fromTile) { auto ruler1 = cr::CheapRuler(50.5); auto ruler2 = cr::CheapRuler::fromTile(11041, 15); cr::point p1(30.5, 50.5); cr::point p2(30.51, 50.51); assertErr(ruler1.distance(p1, p2), ruler2.distance(p1, p2), 2e-5); }
TEST_F(CheapRulerTest, lineSlice) { for (unsigned i = 0; i < lines.size(); ++i) { auto line = lines[i]; auto dist = ruler.lineDistance(line); auto start = ruler.along(line, dist * 0.3); auto stop = ruler.along(line, dist * 0.7); auto expected = turf_lineSlice[i]; auto actual = ruler.lineDistance(ruler.lineSlice(start, stop, line)); assertErr(expected, actual, 1e-5); } }
TEST_F(CheapRulerTest, lineSliceAlong) { for (unsigned i = 0; i < lines.size(); ++i) { if (i == 46) { // skip due to Turf bug https://github.com/Turfjs/turf/issues/351 continue; }; auto line = lines[i]; auto dist = ruler.lineDistance(line); auto expected = turf_lineSlice[i]; auto actual = ruler.lineDistance(ruler.lineSliceAlong(dist * 0.3, dist * 0.7, line)); assertErr(expected, actual, 1e-5); } }
TEST_F(CheapRulerTest, area) { for (unsigned i = 0, j = 0; i < lines.size(); ++i) { if (lines[i].size() < 3) { continue; } cr::linear_ring ring; for (auto point : lines[i]) { ring.push_back(point); } ring.push_back(lines[i][0]); auto expected = turf_area[j++]; auto actual = ruler.area(cr::polygon{ ring }); assertErr(expected, actual, 0.003); } }
TEST_F(CheapRulerTest, distanceInMiles) { auto d = ruler.distance({ 30.5, 32.8351 }, { 30.51, 32.8451 }); auto d2 = milesRuler.distance({ 30.5, 32.8351 }, { 30.51, 32.8451 }); assertErr(d / d2, 1.609344, 1e-12); }