Skip to content

Commit

Permalink
removed 256 length check
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed Dec 3, 2020
1 parent 7f804be commit 31672f5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R/palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' get_palette( "viridis" )
#' get_palette( "rainbow" )
#'
#' @return 256 row x 3 column matrix if \code{rgb = TRUE}, otherwise a 256-length vector.
#' @return 3 column matrix if \code{rgb = TRUE}, otherwise a 256-length vector.
#'
#' @export
get_palette <- function( palette, rgb = TRUE ) {
Expand Down
3 changes: 2 additions & 1 deletion inst/include/colourvalues/palette_utils/palette_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ namespace palette_utils {
std::string& palette,
Rcpp::NumericVector& red,
Rcpp::NumericVector& green,
Rcpp::NumericVector& blue ) {
Rcpp::NumericVector& blue
) {

if( palette == "viridis" ) {
red = colourvalues::palette::viridis_red;
Expand Down
2 changes: 1 addition & 1 deletion man/get_palette.Rd

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

10 changes: 6 additions & 4 deletions src/palettes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ using namespace Rcpp;

// [[Rcpp::export]]
Rcpp::NumericMatrix rcpp_get_palette( std::string palette ) {
int n = 256;
Rcpp::NumericVector red( 255.0, n );
Rcpp::NumericVector green( 255.0, n );
Rcpp::NumericVector blue( 255.0, n );

Rcpp::NumericVector red;
Rcpp::NumericVector green;
Rcpp::NumericVector blue;
colourvalues::palette_utils::resolve_palette( palette, red, green, blue );

R_xlen_t n = red.length();

Rcpp::NumericMatrix nm( n, 3 );
nm( Rcpp::_, 0 ) = red * 255;
nm( Rcpp::_, 1 ) = green * 255;
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ test_that("palettes are returned", {
expect_true( length(all_palettes) == 52 )

for( palette in all_palettes ) {
print(palette)
expect_silent( colour_values(1, palette = palette ))
res <- colourvalues::get_palette( palette )
expect_true( ncol( res ) == 3 & nrow( res ) == 256 )
expect_true( ncol( res ) == 3 )

## And call the function directly
res <- eval(parse(text = paste0("colourvalues:::", palette, "()")))
Expand Down

0 comments on commit 31672f5

Please sign in to comment.