diff --git a/data-raw/DATASET.R b/data-raw/DATASET.R index a3f1369..4aef3a7 100644 --- a/data-raw/DATASET.R +++ b/data-raw/DATASET.R @@ -2,13 +2,32 @@ ## Read `h3libapi.h` and write all 'inline' function defs to `init.c` -# lines <- readLines("~/Documents/github/h3lib/inst/include/h3libapi.h") -# fns <- lines[ grepl("inline ", lines) ] -# fns <- gsub("inline ", "", fns) -# fns <- gsub("\\(.*","",fns) -# fns <- gsub(" ", " (*", fns) -# fns <- paste0(fns, ");\n") -# cat(fns) +lines <- readLines("~/Documents/github/h3lib/inst/include/h3libapi.h") +fns <- lines[ grepl("^inline ", lines) ] + +fns <- gsub("inline ", "", fns) + +args <- gsub(".*\\(","", fns) +args <- trimws(gsub("\\) \\{", "", args)) + +## Replace arugments (space, followed by arg, followed by comma) +## with a comma +args <- gsub(" \\w+,", ",", args) + +## remove final argument +args <- gsub("\\w+$","", args) + +## put 'void' back in +args[ nchar(args) == 0 ] <- "void" + +args <- trimws(args) + +types <- trimws(gsub("\\w+$","",fns)) +names <- trimws(gsub("^ {0, }\\w+ ", "", fns)) + +## rebuild +fns <- paste0(types, " (*", names, ")","(", args, ");\n") +cat(fns) stations <- structure(list(stop_id = c("15351", "15353", "19827", "19828", diff --git a/src/init.c b/src/init.c index f76b363..cf58558 100644 --- a/src/init.c +++ b/src/init.c @@ -192,6 +192,79 @@ typedef struct { int j; ///< j component } CoordIJ; +H3Error (*latLngToCell)(const LatLng*, int, H3Index*); +H3Error (*cellToLatLng)(H3Index, LatLng*); +H3Error (*cellToBoundary)(H3Index, CellBoundary*); +H3Error (*maxGridDiskSize)(int, int64_t*); +H3Error (*gridDiskUnsafe)(H3Index, int, H3Index*); +H3Error (*gridDiskDistancesUnsafe)(H3Index, int, H3Index*, int*); +H3Error (*gridDiskDistancesSafe)(H3Index, int, H3Index*, int*); +H3Error (*gridDisksUnsafe)(H3Index*, int, int, H3Index*); +H3Error (*gridDisk)(H3Index, int, H3Index*); +H3Error (*gridDiskDistances)(H3Index, int, H3Index*, int*); +H3Error (*gridRingUnsafe)(H3Index, int, H3Index*); +H3Error (*maxPolygonToCellsSize)(const GeoPolygon*, int, uint32_t, int64_t*); +H3Error (*polygonToCells)(const GeoPolygon*, int, uint32_t, H3Index*); +H3Error (*cellsToLinkedMultiPolygon)(const H3Index*, const int, LinkedGeoPolygon*); +void (*destroyLinkedMultiPolygon)(LinkedGeoPolygon*); +double (*degsToRads)(double); +double (*radsToDegs)(double); +double (*greatCircleDistanceRads)(const LatLng*, const LatLng*); +double (*greatCircleDistanceKm)(const LatLng*, const LatLng*); +double (*greatCircleDistanceM)(const LatLng*, const LatLng*); +H3Error (*getHexagonAreaAvgKm2)(int, double*); +H3Error (*getHexagonAreaAvgM2)(int, double*); +H3Error (*cellAreaRads2)(H3Index, double*); +H3Error (*cellAreaKm2)(H3Index, double*); +H3Error (*cellAreaM2)(H3Index, double*); +H3Error (*getHexagonEdgeLengthAvgKm)(int, double*); +H3Error (*getHexagonEdgeLengthAvgM)(int, double*); +H3Error (*edgeLengthRads)(H3Index, double*); +H3Error (*edgeLengthKm)(H3Index, double*); +H3Error (*edgeLengthM)(H3Index, double*); +H3Error (*getNumCells)(int, int64_t*); +int (*res0CellCount)(void); +H3Error (*getRes0Cells)(H3Index*); +int (*pentagonCount)(void); +H3Error (*getPentagons)(int, H3Index*); +int (*getResolution)(H3Index); +int (*getBaseCellNumber)(H3Index); +H3Error (*stringToH3)(const char*, H3Index*); +int (*isValidCell)(H3Index); +H3Error (*cellToParent)(H3Index, int, H3Index*); +H3Error (*cellToChildrenSize)(H3Index, int, int64_t*); +H3Error (*cellToChildren)(H3Index, int, H3Index*); +H3Error (*cellToCenterChild)(H3Index, int, H3Index*); +H3Error (*cellToChildPos)(H3Index, int, int64_t*); +H3Error (*childPosToCell)(int64_t, H3Index, int, H3Index*); +H3Error (*compactCells)(const H3Index*, H3Index*, const int64_t); +H3Error (*uncompactCellsSize)(const H3Index*, const int64_t, const int, int64_t*); +H3Error (*uncompactCells)(const H3Index*, const int64_t, H3Index*, const int64_t, const int); +int (*isResClassIII)(H3Index); +int (*isPentagon)(H3Index); +H3Error (*maxFaceCount)(H3Index, int*); +H3Error (*getIcosahedronFaces)(H3Index, int*); +H3Error (*areNeighborCells)(H3Index, H3Index, int*); +H3Error (*cellsToDirectedEdge)(H3Index, H3Index, H3Index*); +int (*isValidDirectedEdge)(H3Index); +H3Error (*getDirectedEdgeOrigin)(H3Index, H3Index*); +H3Error (*getDirectedEdgeDestination)(H3Index, H3Index*); +H3Error (*directedEdgeToCells)(H3Index, H3Index*); +H3Error (*originToDirectedEdges)(H3Index, H3Index*); +H3Error (*directedEdgeToBoundary)(H3Index, CellBoundary*); +H3Error (*cellToVertex)(H3Index, int, H3Index*); +H3Error (*cellToVertexes)(H3Index, H3Index*); +H3Error (*vertexToLatLng)(H3Index, LatLng*); +int (*isValidVertex)(H3Index); +H3Error (*gridDistance)(H3Index, H3Index, int64_t*); +H3Error (*gridPathCellsSize)(H3Index, H3Index, int64_t*); +H3Error (*gridPathCells)(H3Index, H3Index, H3Index*); +H3Error (*cellToLocalIj)(H3Index, H3Index, uint32_t, CoordIJ*); +H3Error (*localIjToCell)(H3Index, const CoordIJ*, uint32_t, H3Index*); +Direction (*directionForNeighbor)(H3Index, H3Index); +void (*_geoToClosestFace)(const LatLng*, int*, double*); +void (*h3lib_tests)(void); + void attribute_visible R_init_h3r(DllInfo *info) { R_registerRoutines(info, NULL, callMethods, NULL, NULL);