Distances on Directed Graphs in R
1#include "concaveman.h"
2
3//' rcpp_concaveman
4//' @noRd
5// [[Rcpp::export]]
6Rcpp::DataFrame rcpp_concaveman (Rcpp::DataFrame xy, Rcpp::NumericVector hull_in,
7 const double concavity, const double length_threshold)
8{
9 std::vector <double> x = xy ["x"], y = xy ["y"];
10 const size_t num_points = static_cast <int> (xy.nrow ());
11
12 typedef double T;
13 typedef std::array <T, 2> point_type;
14
15 std::vector <point_type> points (num_points);
16 for (auto i = 0; i < num_points; i++) {
17 points[i] = { x [i], y [i] };
18 }
19
20 std::vector <int> hull = Rcpp::as <std::vector <int> > (hull_in);
21
22 auto concave_points = concaveman <T, 16> (points, hull,
23 concavity, length_threshold);
24
25 Rcpp::NumericVector xout (concave_points.size ()),
26 yout (concave_points.size ());
27 for (int i = 0; i < concave_points.size (); i++)
28 {
29 xout (i) = concave_points [i] [0];
30 yout (i) = concave_points [i] [1];
31 }
32
33 Rcpp::DataFrame res = Rcpp::DataFrame::create (
34 Rcpp::Named ("x") = xout,
35 Rcpp::Named ("y") = yout);
36
37 return res;
38}