Skip to content

Commit

Permalink
valgrind sorted #33
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Mar 11, 2024
1 parent 127ecbe commit 10ccdb1
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 128 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ BugReports: https://github.com/symbolixau/h3r/issues
Encoding: UTF-8
LazyData: true
Depends:
h3lib (>= 0.1.3),
h3lib (>= 0.1.4),
R (>= 2.10)
LinkingTo:
h3lib
Suggests:
sfheaders,
tinytest
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export(cellToParent)
export(cellToVertex)
export(cellToVertexes)
export(cellsToDirectedEdge)
export(cellsToMultiPolygon)
export(childPosToCell)
export(compactCells)
export(degsToRads)
Expand Down
50 changes: 25 additions & 25 deletions R/regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,28 @@ polygonToCells <- function(polygons, resolution, isLatLng = TRUE) {
}


#' Cells to GeoPolygons
#'
#' Get the outlines of a set of H3 hexagons, returned in GeoJSON-like
#' MultiPolygon.
#'
#' @param cellSet list of string vectors containing to be H3 cell indexes
#' @inheritParams polygonToCells
#'
#' @return GeoJSON-like MultiPolygon containing the outlines of the set of
#' input H3 hexagons
#'
#' @examples
#'
#' cellsToMultiPolygon(
#' cellSet = list(
#' list(c("872830828ffffff", "87283082effffff"))
#' , list(c("872830828ffffff"))
#' )
#' , 1L
#' )
#'
#' @export
cellsToMultiPolygon <- function(cellSet, isLatLng = TRUE) {
.Call(h3rCellsToMultiPolygon, cellSet, int(isLatLng))
}
# Cells to GeoPolygons
#
# Get the outlines of a set of H3 hexagons, returned in GeoJSON-like
# MultiPolygon.
#
# @param cellSet list of string vectors containing to be H3 cell indexes
# @inheritParams polygonToCells
#
# @return GeoJSON-like MultiPolygon containing the outlines of the set of
# input H3 hexagons
#
# @examples
#
# cellsToMultiPolygon(
# cellSet = list(
# list(c("872830828ffffff", "87283082effffff"))
# , list(c("872830828ffffff"))
# )
# , 1L
# )
#
# @export
# cellsToMultiPolygon <- function(cellSet, isLatLng = TRUE) {
# .Call(h3rCellsToMultiPolygon, cellSet, int(isLatLng))
# }
2 changes: 1 addition & 1 deletion inst/include/h3r.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ SEXP h3rUncompactCells(SEXP h3Sets, SEXP res);

// Regions
SEXP h3rPolygonToCells(SEXP polygonArray, SEXP res, SEXP isLatLng);
SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isGeoJson);
// SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isGeoJson);

// Directed Edges
SEXP h3rAreNeighborCells(SEXP origH3, SEXP destH3);
Expand Down
36 changes: 18 additions & 18 deletions inst/tinytest/test_region.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ expect_equal(polygonToCells(polygon = list(
)
), resolution = c(7L, 6L)), list(c( "872830870ffffff","872830828ffffff","872830876ffffff"), c("862830827ffffff")))

expect_equal(cellsToMultiPolygon(cellSet = list(list(c("872830828ffffff", "87283082effffff")), list(c("862830827ffffff"))), 1L)
, list(list(list(list(matrix(c(37.78404622259876, -122.42708872508096,
37.77226734985154, -122.43458610784572,
37.76173573392154, -122.42576908738396,
37.76298184766421, -122.40945463242251,
37.75244647475626, -122.40063951171169,
37.75368882535418, -122.38432356237523,
37.76546768434345, -122.37681938644465,
37.776004200673846, -122.38563455403627,
37.7747607144902, -122.40195385157608,
37.78529347359728, -122.41077092287513),
ncol = 2, byrow = TRUE)))), list(list(list(matrix(c(37.69973779105049, -122.35658316980643,
37.724533591552756, -122.32525327556627,
37.75740308914818, -122.33536307014123,
37.76546768434345, -122.37681938644465,
37.74066613210137, -122.40813889567379,
37.707805739822945, -122.39801249019256),
ncol = 2, byrow = TRUE))))))
# expect_equal(cellsToMultiPolygon(cellSet = list(list(c("872830828ffffff", "87283082effffff")), list(c("862830827ffffff"))), 1L)
# , list(list(list(list(matrix(c(37.78404622259876, -122.42708872508096,
# 37.77226734985154, -122.43458610784572,
# 37.76173573392154, -122.42576908738396,
# 37.76298184766421, -122.40945463242251,
# 37.75244647475626, -122.40063951171169,
# 37.75368882535418, -122.38432356237523,
# 37.76546768434345, -122.37681938644465,
# 37.776004200673846, -122.38563455403627,
# 37.7747607144902, -122.40195385157608,
# 37.78529347359728, -122.41077092287513),
# ncol = 2, byrow = TRUE)))), list(list(list(matrix(c(37.69973779105049, -122.35658316980643,
# 37.724533591552756, -122.32525327556627,
# 37.75740308914818, -122.33536307014123,
# 37.76546768434345, -122.37681938644465,
# 37.74066613210137, -122.40813889567379,
# 37.707805739822945, -122.39801249019256),
# ncol = 2, byrow = TRUE))))))
33 changes: 0 additions & 33 deletions man/cellsToMultiPolygon.Rd

This file was deleted.

6 changes: 5 additions & 1 deletion src/h3rHierarchy.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ SEXP h3rCompactCells(SEXP h3Sets) {
setSize = Rf_xlength(h3Set);

H3Index cellSet[setSize];
memset(cellSet, H3_INIT, sizeof(cellSet));
memset(cellSet, -1, sizeof(cellSet));
H3Index compactedSet[setSize];
memset(compactedSet, -1, sizeof(compactedSet));

for (j = 0; j < setSize; j++) {
cellSet[j] = sexpStringToH3(h3Set, j);
Expand Down Expand Up @@ -236,6 +237,8 @@ SEXP h3rUncompactCells(SEXP h3Sets, SEXP res) {
setSize = Rf_xlength(h3Set);

H3Index compactedSet[setSize];
memset(compactedSet, -1, sizeof(compactedSet));

ires = _getResolution(res, i);

for (j = 0; j < setSize; j++) {
Expand All @@ -244,6 +247,7 @@ SEXP h3rUncompactCells(SEXP h3Sets, SEXP res) {

h3rError(uncompactCellsSize(compactedSet, setSize, ires, &cellSize), i);
H3Index cellSet[cellSize];
memset(cellSet, -1, sizeof(cellSet));

h3rError(uncompactCells(compactedSet, setSize, cellSet, cellSize, ires), i);

Expand Down
91 changes: 46 additions & 45 deletions src/h3rRegions.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,48 +246,49 @@ SEXP h3rReadMultiPolygon(LinkedGeoPolygon *polygon, int isLatLng) {
}


SEXP singleCellsToMultiPolygon(SEXP h3Sets, int geojson, R_xlen_t idx) {
R_xlen_t n = Rf_xlength(h3Sets);
R_xlen_t i;
int64_t j, setSize;

SEXP out = PROTECT(Rf_allocVector(VECSXP, n));

for (i = 0; i < n; i++) {
SEXP h3Set = VECTOR_ELT(h3Sets, i);
setSize = Rf_xlength(h3Set);

H3Index cellSet[setSize];

for (j = 0; j < setSize; j++) {
cellSet[j] = sexpStringToH3(h3Set, j);
}

LinkedGeoPolygon geoPolygon;

h3rError(cellsToLinkedMultiPolygon(cellSet, setSize, &geoPolygon), idx);

SET_VECTOR_ELT(out, i, h3rReadMultiPolygon(&geoPolygon, geojson));
}

UNPROTECT(1);
return out;
}

SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isLatLng) {
R_xlen_t n = Rf_xlength(h3Sets);
R_xlen_t i ;

int geojson = INTEGER(isLatLng)[0];

SEXP out = PROTECT(Rf_allocVector(VECSXP, n));

for (i = 0; i < n; i++) {
SEXP h3Set = VECTOR_ELT(h3Sets, i);
SEXP multiPolygon = singleCellsToMultiPolygon(h3Set, geojson, i);
SET_VECTOR_ELT(out, i, multiPolygon);
}

UNPROTECT(1);
return out;
}
// SEXP singleCellsToMultiPolygon(SEXP h3Sets, int geojson, R_xlen_t idx) {
// R_xlen_t n = Rf_xlength(h3Sets);
// R_xlen_t i;
// int64_t j, setSize;
//
// SEXP out = PROTECT(Rf_allocVector(VECSXP, n));
//
// for (i = 0; i < n; i++) {
// SEXP h3Set = VECTOR_ELT(h3Sets, i);
// setSize = Rf_xlength(h3Set);
//
// H3Index cellSet[setSize];
// memset(cellSet, -1, sizeof(cellSet));
//
// for (j = 0; j < setSize; j++) {
// cellSet[j] = sexpStringToH3(h3Set, j);
// }
//
// LinkedGeoPolygon geoPolygon;
//
// h3rError(cellsToLinkedMultiPolygon(cellSet, setSize, &geoPolygon), idx);
//
// SET_VECTOR_ELT(out, i, h3rReadMultiPolygon(&geoPolygon, geojson));
// }
//
// UNPROTECT(1);
// return out;
// }
//
// SEXP h3rCellsToMultiPolygon(SEXP h3Sets, SEXP isLatLng) {
// R_xlen_t n = Rf_xlength(h3Sets);
// R_xlen_t i ;
//
// int geojson = INTEGER(isLatLng)[0];
//
// SEXP out = PROTECT(Rf_allocVector(VECSXP, n));
//
// for (i = 0; i < n; i++) {
// SEXP h3Set = VECTOR_ELT(h3Sets, i);
// SEXP multiPolygon = singleCellsToMultiPolygon(h3Set, geojson, i);
// SET_VECTOR_ELT(out, i, multiPolygon);
// }
//
// UNPROTECT(1);
// return out;
// }
1 change: 1 addition & 0 deletions src/h3rTraversal.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ SEXP h3rGridRingUnsafe(SEXP h3, SEXP k) {

h3rError(maxGridDiskSize(length, &maxSize), i);
H3Index result[maxSize];
memset(result, -1, sizeof(result));

h3rError(gridRingUnsafe(h, length, result), i);

Expand Down
4 changes: 2 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static const R_CallMethodDef callMethods[] = {

// Regions
{"h3rPolygonToCells", (DL_FUNC) &h3rPolygonToCells, 3},
{"h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon, 2},
// {"h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon, 2},

// Directed Edges
{"h3rAreNeighborCells", (DL_FUNC) &h3rAreNeighborCells, 2},
Expand Down Expand Up @@ -153,7 +153,7 @@ void attribute_visible R_init_h3r(DllInfo *info)

// Regions
R_RegisterCCallable("h3r", "h3rPolygonToCells", (DL_FUNC) &h3rPolygonToCells);
R_RegisterCCallable("h3r", "h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon);
// R_RegisterCCallable("h3r", "h3rCellsToMultiPolygon", (DL_FUNC) &h3rCellsToMultiPolygon);

// Directed Edges
R_RegisterCCallable("h3r", "h3rAreNeighborCells", (DL_FUNC) &h3rAreNeighborCells);
Expand Down

0 comments on commit 10ccdb1

Please sign in to comment.