R/fit_into_interval.R

#' Corrects a number to be in a given interval
#' @param x Number to be corrected
#' @param min Lower bound of the interval. If x is lower than min, the function will return min.
#' @param max Upper bound of the interval. If x is higher than max, the function will return max.
#' @return min, x or max depending on whether x was below, between or above both min and max
fit_into_interval <- function(x, min=0, max=255) {
  if(x < min) {
    return(min)
  } else if(x>max) {
    return(max)
  } else {
    return(x)
  }
}
dpcarballo/coloR documentation built on June 1, 2019, 8:14 p.m.