From 646e057f00183cfe6ce68126f5e427a51081cdc0 Mon Sep 17 00:00:00 2001 From: Beaudette Date: Wed, 11 Oct 2023 22:28:16 -0700 Subject: [PATCH] minor bug, when mixed color is not in spectral library --- NEWS.md | 3 ++- R/plotColorMixture.R | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 09095ad96..bebc0e4b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ -# aqp 2.0.2 (2023-09-14) +# aqp 2.0.2 (2023-10-11) * new function `col2Munsell()` generalizes and replaces `rgb2munsell()` (thanks Shawn Salley for the suggestion) * new function `warpHorizons()` for warping horizon thickness (inflate/deflate) (thanks Shawn Salley for idea / inspiration) + * fixed minor bug in `plotColorMixture()` when final mixed color does not exist in spectral library # aqp 2.0.1 (2023-09-03) * CRAN release (CRAN check bugfix) diff --git a/R/plotColorMixture.R b/R/plotColorMixture.R index 52867f62c..c97ee0f7e 100644 --- a/R/plotColorMixture.R +++ b/R/plotColorMixture.R @@ -114,6 +114,25 @@ plotColorMixture <- function(x, w = rep(1, times = length(x)) / length(x), mixin # last color is the mixture, # replace reference spectra / munsell chip with actual mixture if(i == length(colors)) { + + # avoid trying to append to a 0-length DF + # if the last color has no reference spectra + if(nrow(z) < 1) { + # pad with NA + z <- z[1:length(mx$spec), ] + + # fill columns with pieces of the closest Munsell + .pm <- parseMunsell(mx$mixed$munsell, convertColors = FALSE) + z$hue <- .pm$hue + z$value <- .pm$value + z$chroma <- .pm$chroma + + ## NOTE: hard-coded spectra wavelengths!! + # fill wavelength column + z$wavelength <- seq(from = 380, to = 730, by = 10) + } + + # save mixed spectra and closest Munsell color z$reflectance <- mx$spec z$munsell <- mx$mixed$munsell }