Skip to content

Commit

Permalink
add distances to C++ output of match_pts_to_edge for #103
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Sep 2, 2022
1 parent b90dd1d commit 0a80a48
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dodgr
Title: Distances on Directed Graphs
Version: 0.2.15.008
Version: 0.2.15.009
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre")),
person("Andreas", "Petutschnig", role = "aut"),
Expand Down
9 changes: 8 additions & 1 deletion R/match-points.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,15 @@ match_pts_to_graph <- function (graph, xy, connected = FALSE) {
graph <- graph [, gr_cols]
names (graph) <- names (gr_cols)

res <- rcpp_points_to_edges_par (graph, xy)
index <- seq (nrow (xy))

# rcpp_points_index is 0-indexed, so ...
rcpp_points_to_edges_par (graph, xy) + 1L
graph_index <- as.integer (res [index]) + 1L
# edge_dist not yet used here; see #103
# edge_dist <- res [index + nrow (xy)]

return (graph_index)
}

#' match_points_to_graph
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/ATFutures/dodgr",
"issueTracker": "https://github.com/ATFutures/dodgr/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.2.15.008",
"version": "0.2.15.009",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
6 changes: 5 additions & 1 deletion src/match-points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct OneEdgeIndex : public RcppParallel::Worker
{
double dmin = INFINITE_DOUBLE;
long int jmin = INFINITE_INT;
int which_side = INFINITE_INT;

for (size_t j = 0; j < nxy; j++)
{
Expand Down Expand Up @@ -137,9 +138,12 @@ struct OneEdgeIndex : public RcppParallel::Worker
{
dmin = dij;
jmin = static_cast <long int> (j);
which_side = which_side_of_line (xfr [j], yfr [j],
xto [j], yto [j], pt_x [i], pt_y [i]);
}
}
index [i] = static_cast <double> (jmin);
index [i + npts] = which_side * dmin;
}
}

Expand Down Expand Up @@ -206,7 +210,7 @@ Rcpp::NumericVector rcpp_points_to_edges_par (const Rcpp::DataFrame &graph,
const size_t nxy = static_cast <size_t> (graph.nrow ()),
npts = static_cast <size_t> (pts.nrow ());

Rcpp::NumericVector index (npts);
Rcpp::NumericVector index (npts * 2L);

// Create parallel worker
OneEdgeIndex one_edge_indx (RcppParallel::RVector <double> (ptx),
Expand Down

0 comments on commit 0a80a48

Please sign in to comment.