R/n_color.R

Defines functions pth_n_color.pth_mat pth_n_color.pth_hex pth_n_color.character pth_n_color.default pth_n_color

Documented in pth_n_color pth_n_color.character pth_n_color.default pth_n_color.pth_hex pth_n_color.pth_mat

#' Number of colors
#'
#' @inheritParams pth_to_cielab
#' @param ... other args (not used)
#'
#' @return `integer` number of colors
#' @examples
#'   pth_n_color(c("#000000", "#663399", "#FFFFFF"))
#' @export
#'
pth_n_color <- function(color, ...) {
  UseMethod("pth_n_color")
}

#' @rdname pth_n_color
#' @export
#'
pth_n_color.default <- function(color, ...) {
  stop(
    glue::glue("No method for class {class(color)}")
  )
}

#' @rdname pth_n_color
#' @export
#'
pth_n_color.character <- function(color, ...) {
  hex <- pth_new_hex(color)
  pth_n_color(hex)
}

#' @rdname pth_n_color
#' @export
#'
pth_n_color.pth_hex <- function(color, ...) {
  length(color)
}

#' @rdname pth_n_color
#' @export
#'
pth_n_color.pth_mat <- function(color, ...) {
  nrow(color)
}
ijlyttle/colorpath documentation built on Sept. 13, 2022, 7:44 p.m.