From 9c78109a171703e0a041873c03fb2787f7145a63 Mon Sep 17 00:00:00 2001 From: skuethe Date: Fri, 8 Mar 2019 11:18:04 +0100 Subject: [PATCH 1/3] Add 'h3_is_pentagon' --- NAMESPACE | 1 + R/RcppExports.R | 8 ++++++++ man/h3_is_pentagon.Rd | 17 +++++++++++++++++ src/RcppExports.cpp | 12 ++++++++++++ src/h3_inspection.cpp | 16 ++++++++++++++++ tests/testthat/test_h3_inspection.R | 15 +++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 man/h3_is_pentagon.Rd create mode 100644 tests/testthat/test_h3_inspection.R diff --git a/NAMESPACE b/NAMESPACE index f3f7832..37a20e8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,7 @@ export(h3_distance) export(h3_get_base_cell) export(h3_get_resolution) export(h3_indexes_are_neighbors) +export(h3_is_pentagon) export(h3_is_valid) export(h3_set_to_multi_polygon) export(h3_to_children) diff --git a/R/RcppExports.R b/R/RcppExports.R index 9907016..9613e3a 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -49,6 +49,14 @@ 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) +} + #' Number of unique H3 indexes at the given resolution. #' @param res numeric vector; resolution between 0 and 15 #' @return numeric vector diff --git a/man/h3_is_pentagon.Rd b/man/h3_is_pentagon.Rd new file mode 100644 index 0000000..9169096 --- /dev/null +++ b/man/h3_is_pentagon.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{h3_is_pentagon} +\alias{h3_is_pentagon} +\title{Check whether the given H3 indexes are pentagons.} +\usage{ +h3_is_pentagon(h3Str) +} +\arguments{ +\item{h3Str}{character vector of H3 indexes} +} +\value{ +logical vector +} +\description{ +Check whether the given H3 indexes are pentagons. +} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index cd5d503..019c246 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -107,6 +107,17 @@ 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 +} // num_hexagons NumericVector num_hexagons(NumericVector res); RcppExport SEXP _h3_num_hexagons(SEXP resSEXP) { @@ -268,6 +279,7 @@ 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_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}, diff --git a/src/h3_inspection.cpp b/src/h3_inspection.cpp index d7d6cb6..1020240 100644 --- a/src/h3_inspection.cpp +++ b/src/h3_inspection.cpp @@ -50,3 +50,19 @@ 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; +} diff --git a/tests/testthat/test_h3_inspection.R b/tests/testthat/test_h3_inspection.R new file mode 100644 index 0000000..bcf0e97 --- /dev/null +++ b/tests/testthat/test_h3_inspection.R @@ -0,0 +1,15 @@ +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) +}) From 6ae2a52fbaf700b0592a845f47c3a525affccede Mon Sep 17 00:00:00 2001 From: skuethe Date: Fri, 8 Mar 2019 11:38:26 +0100 Subject: [PATCH 2/3] Add 'h3_is_res_class_iii' --- NAMESPACE | 1 + R/RcppExports.R | 9 +++++++++ man/h3_is_res_class_iii.Rd | 19 +++++++++++++++++++ src/RcppExports.cpp | 12 ++++++++++++ src/h3_inspection.cpp | 17 +++++++++++++++++ tests/testthat/test_h3_inspection.R | 18 ++++++++++++++++++ 6 files changed, 76 insertions(+) create mode 100644 man/h3_is_res_class_iii.Rd diff --git a/NAMESPACE b/NAMESPACE index 37a20e8..8cbfd56 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,7 @@ 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) diff --git a/R/RcppExports.R b/R/RcppExports.R index 9613e3a..a5fad7c 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -57,6 +57,15 @@ 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 diff --git a/man/h3_is_res_class_iii.Rd b/man/h3_is_res_class_iii.Rd new file mode 100644 index 0000000..f987918 --- /dev/null +++ b/man/h3_is_res_class_iii.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{h3_is_res_class_iii} +\alias{h3_is_res_class_iii} +\title{Check whether the given H3 indexes have a resolution +with Class III orientation.} +\usage{ +h3_is_res_class_iii(h3Str) +} +\arguments{ +\item{h3Str}{character vector of H3 indexes} +} +\value{ +logical vector +} +\description{ +Check whether the given H3 indexes have a resolution +with Class III orientation. +} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 019c246..ea2bb1d 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -118,6 +118,17 @@ BEGIN_RCPP 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) { @@ -280,6 +291,7 @@ static const R_CallMethodDef CallEntries[] = { {"_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}, diff --git a/src/h3_inspection.cpp b/src/h3_inspection.cpp index 1020240..5725da3 100644 --- a/src/h3_inspection.cpp +++ b/src/h3_inspection.cpp @@ -66,3 +66,20 @@ LogicalVector h3_is_pentagon(CharacterVector h3Str) { 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; +} diff --git a/tests/testthat/test_h3_inspection.R b/tests/testthat/test_h3_inspection.R index bcf0e97..18453ca 100644 --- a/tests/testthat/test_h3_inspection.R +++ b/tests/testthat/test_h3_inspection.R @@ -13,3 +13,21 @@ test_that("is pentagon", { 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)) +}) From 16d7f56bc4a29995fff5690d05a2e02998d55a63 Mon Sep 17 00:00:00 2001 From: skuethe Date: Fri, 8 Mar 2019 11:42:36 +0100 Subject: [PATCH 3/3] Update DESCRIPTION and NEWS --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1a25058..a5c32e2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "crazycapivara@gmail.com") Maintainer: Stefan Kuethe Description: Provides R bindings for H3 , diff --git a/NEWS.md b/NEWS.md index 4beec97..b5b24e0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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.