Skip to content

Commit

Permalink
Merge pull request #15 from crazycapivara/feature/inspection
Browse files Browse the repository at this point in the history
Feature/inspection
  • Loading branch information
crazycapivara authored Mar 8, 2019
2 parents d1d3853 + 16d7f56 commit 6e3fbb2
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: h3
Title: R bindings for H3
Version: 3.3.0
Date: 2019-02-17
Version: 3.3.1
Date: 2019-03-08
Authors@R: person("Stefan","Kuethe", role = c("aut", "cre"), email = "[email protected]")
Maintainer: Stefan Kuethe <[email protected]>
Description: Provides R bindings for H3 <https://uber.github.io/h3/>,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export(h3_distance)
export(h3_get_base_cell)
export(h3_get_resolution)
export(h3_indexes_are_neighbors)
export(h3_is_pentagon)
export(h3_is_res_class_iii)
export(h3_is_valid)
export(h3_set_to_multi_polygon)
export(h3_to_children)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# h3 3.3.1

* Added bindings for `compact`, `edgeLength`, `h3IsPentagon` and `h3IsResClassIII`
* Added _unidirectional edge functions_

# h3 3.3.0

* Added `pkgdown` site.
Expand Down
17 changes: 17 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ h3_get_base_cell <- function(h3Str) {
.Call(`_h3_h3_get_base_cell`, h3Str)
}

#' Check whether the given H3 indexes are pentagons.
#' @param h3Str character vector of H3 indexes
#' @return logical vector
#' @export
h3_is_pentagon <- function(h3Str) {
.Call(`_h3_h3_is_pentagon`, h3Str)
}

#' Check whether the given H3 indexes have a resolution
#' with Class III orientation.
#' @param h3Str character vector of H3 indexes
#' @return logical vector
#' @export
h3_is_res_class_iii <- function(h3Str) {
.Call(`_h3_h3_is_res_class_iii`, h3Str)
}

#' Number of unique H3 indexes at the given resolution.
#' @param res numeric vector; resolution between 0 and 15
#' @return numeric vector
Expand Down
17 changes: 17 additions & 0 deletions man/h3_is_pentagon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/h3_is_res_class_iii.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// h3_is_pentagon
LogicalVector h3_is_pentagon(CharacterVector h3Str);
RcppExport SEXP _h3_h3_is_pentagon(SEXP h3StrSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< CharacterVector >::type h3Str(h3StrSEXP);
rcpp_result_gen = Rcpp::wrap(h3_is_pentagon(h3Str));
return rcpp_result_gen;
END_RCPP
}
// h3_is_res_class_iii
LogicalVector h3_is_res_class_iii(CharacterVector h3Str);
RcppExport SEXP _h3_h3_is_res_class_iii(SEXP h3StrSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< CharacterVector >::type h3Str(h3StrSEXP);
rcpp_result_gen = Rcpp::wrap(h3_is_res_class_iii(h3Str));
return rcpp_result_gen;
END_RCPP
}
// num_hexagons
NumericVector num_hexagons(NumericVector res);
RcppExport SEXP _h3_num_hexagons(SEXP resSEXP) {
Expand Down Expand Up @@ -268,6 +290,8 @@ static const R_CallMethodDef CallEntries[] = {
{"_h3_h3_get_resolution", (DL_FUNC) &_h3_h3_get_resolution, 1},
{"_h3_h3_is_valid", (DL_FUNC) &_h3_h3_is_valid, 1},
{"_h3_h3_get_base_cell", (DL_FUNC) &_h3_h3_get_base_cell, 1},
{"_h3_h3_is_pentagon", (DL_FUNC) &_h3_h3_is_pentagon, 1},
{"_h3_h3_is_res_class_iii", (DL_FUNC) &_h3_h3_is_res_class_iii, 1},
{"_h3_num_hexagons", (DL_FUNC) &_h3_num_hexagons, 1},
{"_h3_hex_area", (DL_FUNC) &_h3_hex_area, 2},
{"_h3_edge_length", (DL_FUNC) &_h3_edge_length, 2},
Expand Down
33 changes: 33 additions & 0 deletions src/h3_inspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,36 @@ NumericVector h3_get_base_cell(CharacterVector h3Str) {

return z;
}

//' Check whether the given H3 indexes are pentagons.
//' @param h3Str character vector of H3 indexes
//' @return logical vector
//' @export
// [[Rcpp::export]]
LogicalVector h3_is_pentagon(CharacterVector h3Str) {
int n = h3Str.size();
LogicalVector z(n);
for (int i = 0; i < n; ++i) {
H3Index h3 = stringToH3(h3Str[i]);
z[i] = h3IsPentagon(h3);
}

return z;
}

//' Check whether the given H3 indexes have a resolution
//' with Class III orientation.
//' @param h3Str character vector of H3 indexes
//' @return logical vector
//' @export
// [[Rcpp::export]]
LogicalVector h3_is_res_class_iii(CharacterVector h3Str) {
int n = h3Str.size();
LogicalVector z(n);
for (int i = 0; i < n; ++i) {
H3Index h3 = stringToH3(h3Str[i]);
z[i] = h3IsResClassIII(h3);
}

return z;
}
33 changes: 33 additions & 0 deletions tests/testthat/test_h3_inspection.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
context("inspection")

test_that("is pentagon", {
# Prepare
all_indexes <- road_safety_greater_manchester[1, ] %>%
geo_to_h3(0) %>%
k_ring(10)

# Act
is_pentagon <- h3_is_pentagon(all_indexes)

# Assert
expect_length(is_pentagon, 122)
expect_equal(sum(is_pentagon), 8)
})

test_that("is res class III", {
# Prepare
indexes_res_0 <- road_safety_greater_manchester[1, ] %>%
geo_to_h3(0) %>%
k_ring()
indexes_res_1 <- road_safety_greater_manchester[1, ] %>%
geo_to_h3(1) %>%
k_ring()

# Act
is_res_class_iii_0 <- h3_is_res_class_iii(indexes_res_0)
is_res_class_iii_1 <- h3_is_res_class_iii(indexes_res_1)

# Assert
expect_false(all(is_res_class_iii_0))
expect_true(all(is_res_class_iii_1))
})

0 comments on commit 6e3fbb2

Please sign in to comment.