Skip to content

Commit

Permalink
Update surface_dist docs to make it clear these are all Euclidean dis…
Browse files Browse the repository at this point in the history
…tances
  • Loading branch information
dfsp-spirit committed May 18, 2021
1 parent 1e2323c commit a7e717c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 16 deletions.
32 changes: 26 additions & 6 deletions R/surface_dist.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Functions for computing Euclidian distance between vertex coordinates.

#' @title Find vertex index closest to given query coordinate.
#' @title Find vertex index closest to given query coordinate using Euclidean distance.
#'
#' @param surface an fs.surface instance or a nx3 numerical matrix representing mesh points.
#'
Expand Down Expand Up @@ -51,42 +52,61 @@ closest.vert.to.point <- function(surface, point_coords) {
}


#' @title Compute Euclidian distance from all mesh vertices to given point.
#' @title Compute Euclidean distance from all mesh vertices to given point.
#'
#' @param surface an fs.surface instance
#'
#' @param point_coords double vector of length 3, the xyz coords of a single point.
#'
#' @return double vector of distances
vertexdists.to.point <- function(surface, point_coords) {
assert.surface(surface);
return(apply(surface$vertices, 1, euclidian.dist, point_coords));
}


#' @title Compute Euclidian distance.
#' @title Compute Euclidean distance.
#'
#' @param x1 numerical vector, coords of first point
#'
#' @param x2 numerical vector, coords of second point
#'
#' @return the Euclidian distance between x1 and x2.
#' @return the Euclidean distance between x1 and x2.
#'
#' @keywords internal
euclidian.dist <- function(x1, x2) sqrt(sum((x1 - x2) ^ 2))


#' @title Compute Euclidian distance between two vertices v1 and v2.
#' @title Stop unless surf is an fs.surface
#'
#' @param surf fs.surface instance or anything else
#'
#' @param param_name character string, used in stop message to identify the parameter.
#'
#' @return Called for the side effect of stopping if surf is not an fs.surface instance.
#'
#' @keywords internal
assert.surface <- function(surface, param_name="surface") {
if(! is.fs.surface(surface)) {
stop(sprintf("Parameter '%s' must be an fs.surface instance.", param_name));
}
return(invisible(NULL));
}


#' @title Compute Euclidean distance between two vertices v1 and v2.
#'
#' @param surface an fs.surface instance
#'
#' @param v1 positive integer, vertex index of v1
#'
#' @param v2 positive integer, vertex index of v2
#'
#' @return double, the Euclidian distance between v1 and v2.
#' @return double, the Euclidean distance between v1 and v2.
#'
#' @export
vertex.euclid.dist <- function(surface, v1, v2) {
assert.surface(surface);
euclidian.dist(surface$vertices[v1, ], surface$vertices[v2, ])
}

Expand Down
20 changes: 20 additions & 0 deletions man/assert.surface.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/closest.vert.to.point.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/euclidian.dist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/vertex.euclid.dist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/vertexdists.to.point.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7e717c

Please sign in to comment.