Skip to content

Commit

Permalink
move assert.surface func to different source file, add family doc ann…
Browse files Browse the repository at this point in the history
…otation for distance functions
  • Loading branch information
dfsp-spirit committed May 18, 2021
1 parent a7e717c commit 8c9a27b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
15 changes: 15 additions & 0 deletions R/read_fs_surface.R
Original file line number Diff line number Diff line change
Expand Up @@ -1420,3 +1420,18 @@ int.to.col.brainvoyager <- function(int_val) {
}


#' @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));
}
26 changes: 7 additions & 19 deletions R/surface_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#'
#' @return named list with entries: 'vertex_id' integer vector, the index of the closest vertex, and 'dist': double vector, the Euclidian distance to that vertex.
#'
#' @family Euclidean distance util functions
#'
#' @export
#' @importFrom stats dist
closest.vert.to.point <- function(surface, point_coords) {
Expand Down Expand Up @@ -58,6 +60,8 @@ closest.vert.to.point <- function(surface, point_coords) {
#'
#' @param point_coords double vector of length 3, the xyz coords of a single point.
#'
#' @family Euclidean distance util functions
#'
#' @return double vector of distances
vertexdists.to.point <- function(surface, point_coords) {
assert.surface(surface);
Expand All @@ -76,24 +80,6 @@ vertexdists.to.point <- function(surface, point_coords) {
#' @keywords internal
euclidian.dist <- function(x1, x2) sqrt(sum((x1 - x2) ^ 2))


#' @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
Expand All @@ -102,7 +88,9 @@ assert.surface <- function(surface, param_name="surface") {
#'
#' @param v2 positive integer, vertex index of v2
#'
#' @return double, the Euclidean distance between v1 and v2.
#' @return double, the Euclidean distance between v1 and v2
#'
#' @family Euclidean distance util functions
#'
#' @export
vertex.euclid.dist <- function(surface, v1, v2) {
Expand Down
2 changes: 1 addition & 1 deletion man/assert.surface.Rd

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

6 changes: 6 additions & 0 deletions man/closest.vert.to.point.Rd

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

8 changes: 7 additions & 1 deletion man/vertex.euclid.dist.Rd

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

6 changes: 6 additions & 0 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 8c9a27b

Please sign in to comment.