Skip to content

Commit

Permalink
normalised alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed Nov 7, 2020
1 parent f76cbc7 commit 25aa163
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions inst/include/colourvalues/alpha/alpha.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace alpha {
bool normalise
) {

// Rcpp::Rcout << "a1: " << a << std::endl;

if( a.size() < 1 ) {
Rcpp::stop("colourvalues - invalid alpha vector");
}
Expand All @@ -42,15 +44,23 @@ namespace alpha {
// Issue 47
Rcpp::NumericVector alpha = Rcpp::clone( a );
if ( alpha_type == ALPHA_PALETTE ) {
// Rcpp::Rcout << "returning alpha palette " << alpha << std::endl;
return alpha;
}

if ( alpha_type == ALPHA_CONSTANT ) {
if ( alpha[0] >= 0 && alpha[0] < 1 && !normalise ) {
// Rcpp::Rcout << "* 255" << std::endl;
alpha = alpha * 255;
} else if ( alpha[0] > 1 && normalise ) {
//
//double initial_alpha = alpha[0];
//initial_alpha = initial_alpha / 255.0;
alpha = alpha / 255.0;
}

Rcpp::NumericVector alpha_full( 5, alpha[0] ); // initialise with 5 vals (so i can create a spline object);
// Rcpp::Rcout << "returning alpha_full: " << alpha_full << std::endl;
return alpha_full;

} else if ( alpha_type == ALPHA_VECTOR ) {
Expand All @@ -71,8 +81,10 @@ namespace alpha {
for ( i = 0; i < n_alpha; i++ ) {
alpha_fill[i] = alpha[i];
}
// Rcpp::Rcout << "returning alpha_fill: " << alpha_fill << std::endl;
return alpha_fill;
}
// Rcpp::Rcout << "returning alpha: " << alpha << std::endl;
return alpha;
}

Expand Down
4 changes: 2 additions & 2 deletions inst/include/colourvalues/colours/generate_colours.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace generate_colours {

Rcpp::IntegerMatrix na_mat = colourvalues::convert::convert_hex_to_rgb( na_colour );
Rcpp::NumericMatrix na_mat_d = Rcpp::as< Rcpp::NumericMatrix >( na_mat );
na_mat_d = na_mat_d / 255.0;
na_mat_d = na_mat_d / 1.0;
R_xlen_t position_counter = 0;

for( i = 0; i < n; ++i ) {
Expand Down Expand Up @@ -311,7 +311,7 @@ namespace generate_colours {

Rcpp::IntegerMatrix na_mat = colourvalues::convert::convert_hex_to_rgb( na_colour );
Rcpp::NumericMatrix na_mat_d = Rcpp::as< Rcpp::NumericMatrix >( na_mat );
na_mat_d = na_mat_d / 255.0;
na_mat_d = na_mat_d / 1.0;

R_xlen_t position_counter = 0;

Expand Down

0 comments on commit 25aa163

Please sign in to comment.