Skip to content

Commit

Permalink
add which_side_of_line fn for #103
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Sep 2, 2022
1 parent 367d51c commit 1a30d67
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 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.005
Version: 0.2.15.006
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre")),
person("Andreas", "Petutschnig", role = "aut"),
Expand Down
10 changes: 10 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ rcpp_unique_rownames <- function(xyfrom, xyto, precision = 10L) {
.Call(`_dodgr_rcpp_unique_rownames`, xyfrom, xyto, precision)
}

#' Determine which side of intersecting line a point lies on.
#'
#' @param (ax, ay) Coordinates of one end of line
#' @param (bx, by) Coordinates of other end of line
#' @param (x, y) Coordinates of point
#' @return 0 if point on line, -1 if to the left; +1 if to the right.
#'
#' @noRd
NULL

#' Simple match of points to nearest vertices
#' @noRd
NULL
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.005",
"version": "0.2.15.006",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
15 changes: 15 additions & 0 deletions src/match-points.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#include "match-points.h"

//' Determine which side of intersecting line a point lies on.
//'
//' @param (ax, ay) Coordinates of one end of line
//' @param (bx, by) Coordinates of other end of line
//' @param (x, y) Coordinates of point
//' @return 0 if point on line, -1 if to the left; +1 if to the right.
//'
//' @noRd
int which_side_of_line (const double ax, const double ay,
const double bx, const double by, const double x, const double y)
{
double val = (bx - ax) * (y - ay) - (by - ay) * (x - ax);
return (val > 0) ? 1 : ((val < 0) ? -1 : 0);
}

//' Simple match of points to nearest vertices
//' @noRd
struct OnePointIndex : public RcppParallel::Worker
Expand Down
3 changes: 3 additions & 0 deletions src/match-points.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ constexpr float INFINITE_FLOAT = std::numeric_limits<float>::max ();
constexpr double INFINITE_DOUBLE = std::numeric_limits<double>::max ();
constexpr int INFINITE_INT = std::numeric_limits<int>::max ();

int which_side_of_line (const double ax, const double ay,
const double bx, const double by, const double x, const double y);

Rcpp::IntegerVector rcpp_points_index (const Rcpp::DataFrame &xy,
Rcpp::DataFrame &pts);
Rcpp::IntegerVector rcpp_points_to_edges_par (const Rcpp::DataFrame &graph,
Expand Down

0 comments on commit 1a30d67

Please sign in to comment.