Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cpp code #12

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions DESCRIPTION
Expand Up @@ -12,15 +12,18 @@ Description: The concaveman function ports the 'concaveman' (<https://github.com
License: GPL-3
Encoding: UTF-8
LazyData: true
NeedsCompilation: yes
Roxygen: list(markdown = TRUE)
Depends: R (>= 2.10)
Imports: V8,
Imports: V8,
sf,
magrittr,
jsonlite,
dplyr
dplyr,
Rcpp
RoxygenNote: 7.1.0
Suggests: testthat
LinkingTo: Rcpp
URL: https://joelgombin.github.io/concaveman, http://www.github.com/joelgombin/concaveman
BugReports: http://www.github.com/joelgombin/concaveman/issues
SystemRequirements: GDAL (>= 2.0.0), GEOS (>= 3.3.0), PROJ.4 (>= 4.8.0)
SystemRequirements: C++11, GDAL (>= 2.0.0), GEOS (>= 3.3.0), PROJ.4 (>= 4.8.0)
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -3,4 +3,7 @@
S3method(concaveman,matrix)
S3method(concaveman,sf)
export(concaveman)
export(concaveman_rcpp)
importFrom(Rcpp,evalCpp)
importFrom(magrittr,"%>%")
useDynLib(concaveman, .registration = TRUE)
9 changes: 9 additions & 0 deletions R/RcppExports.R
@@ -0,0 +1,9 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' rcpp_concaveman_mat
#' @noRd
rcpp_concaveman_mat <- function(xy, hull_in, concavity, length_threshold) {
.Call(`_concaveman_rcpp_concaveman_mat`, xy, hull_in, concavity, length_threshold)
}

2 changes: 2 additions & 0 deletions R/concaveman-pkg.R
Expand Up @@ -3,6 +3,8 @@
#' This package is a simple R port (through [`V8`](https://github.com/jeroen/v8)) of a [JavaScript library by Vladimir Agafonkin](https://github.com/mapbox/concaveman).
#'
#'
#' @importFrom Rcpp evalCpp
#' @useDynLib concaveman, .registration = TRUE
#' @docType package
#' @name concaveman
NULL
Expand Down
9 changes: 9 additions & 0 deletions R/concaveman.R
Expand Up @@ -54,3 +54,12 @@ concaveman.sf <- function(points, concavity = 2, length_threshold = 0) {
)
}

#' concaveman_rcpp
#'
#' @export
#' @rdname concaveman_rcpp
concaveman_rcpp <- function (xy, concavity = 2, length_threshold = 0) {
index <- grDevices::chull (xy)
index <- c (index, index [1])
rcpp_concaveman_mat (xy, index - 1, concavity, length_threshold)
}