tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.05k stars 211 forks source link

`add_shadow()` fails with rectangular arrays #278

Closed fisher-j closed 1 year ago

fisher-j commented 1 year ago

Describe the bug Attempting to add shadow to non-square arrays results in the following error:

Error in hillshade[, , 1] * scales::rescale(shadowmap, c(max_darken, 1)) : 
  non-conformable arrays

Session Info

> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base

other attached packages:
[1] rayshader_0.24.10 tmap_3.3-3        stars_0.6-0       abind_1.4-5
[5] sf_1.0-12         dplyr_1.1.1       rgl_1.1.3

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10        lattice_0.20-45    prettyunits_1.1.1  png_0.1-8
 [5] class_7.3-20       digest_0.6.31      foreach_1.5.2      utf8_1.2.3
 [9] R6_2.5.1           e1071_1.7-13       pillar_1.9.0       rlang_1.1.0
[13] progress_1.2.2     raster_3.6-20      magick_2.7.4       htmlwidgets_1.6.2
[17] munsell_0.5.0      proxy_0.4-27       compiler_4.2.1     xfun_0.38
[21] pkgconfig_2.0.3    tmaptools_3.1-1    base64enc_0.1-3    htmltools_0.5.5
[25] tidyselect_1.2.0   tibble_3.2.1       codetools_0.2-18   XML_3.99-0.14
[29] fansi_1.0.4        viridisLite_0.4.1  crayon_1.5.2       grid_4.2.1
[33] jsonlite_1.8.4     lwgeom_0.2-11      lifecycle_1.0.3    DBI_1.1.3
[37] magrittr_2.0.3     units_0.8-1        scales_1.2.1       KernSmooth_2.23-20
[41] cli_3.6.1          renv_0.17.2        leafsync_0.1.0     leaflet_2.1.2
[45] doParallel_1.0.17  sp_1.6-0           generics_0.1.3     vctrs_0.6.1
[49] RColorBrewer_1.1-3 iterators_1.0.14   tools_4.2.1        dichromat_2.0-0.1
[53] rayimage_0.9.1     leafem_0.2.0       glue_1.6.2         hms_1.1.3
[57] crosstalk_1.2.0    parallel_4.2.1     fastmap_1.1.1      yaml_2.3.7
[61] colorspace_2.1-0   terra_1.7-18       sessioninfo_1.2.2  classInt_0.4-9
[65] knitr_1.42

Reproducible Example Please provide a reproducible example that triggers the bug below.

library(rayshader)
#Your code goes below
montereybay_rect <- montereybay[1:540, 1:400]

montereybay_rect |>
  sphere_shade() |>
  add_shadow(texture_shade(montereybay_rect)) |>
  plot_3d(montereybay_rect)
fisher-j commented 1 year ago

I was having trouble installing the GitHub version in my renv environment. I finally copy and pasted the package (which I was able to build in another environment), and this issue is fixed.

Thanks for the great work. I'm really enjoying the fantastic visualizations.