diff --git a/R/add_padding.R b/R/add_padding.R index 06f7d47..15b108b 100644 --- a/R/add_padding.R +++ b/R/add_padding.R @@ -79,8 +79,6 @@ trim_padding = function(heightmap, pad = 1) { #' #'@description Pads to a rect #' -#'@param heightmap A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. -#'@param pad Number of padding entries #'@return Hillshade with edges trimmed #'@keywords internal pad_to_fit = function(dim, kernel) { @@ -115,7 +113,6 @@ pad_to_fit = function(dim, kernel) { #' #'@description Pads to a rect #' -#'@param dim desired size #'@return Hillshade with edges trimmed #'@keywords internal expand_to_fit = function(dim, kernel) { diff --git a/R/convert_to_native_raster.R b/R/convert_to_native_raster.R index fd80a76..de01df0 100644 --- a/R/convert_to_native_raster.R +++ b/R/convert_to_native_raster.R @@ -3,8 +3,6 @@ #'@description Displays the image in the current device. #' #'@param input Array to get converted to a native raster -#'@param ncol Number of columns -#'@param nrow Number of rows #'@keywords internal convert_to_native_raster = function(input) { ncol = ncol(input) diff --git a/man/convert_to_native_raster.Rd b/man/convert_to_native_raster.Rd index 07a43a5..c8fac4e 100644 --- a/man/convert_to_native_raster.Rd +++ b/man/convert_to_native_raster.Rd @@ -8,10 +8,6 @@ convert_to_native_raster(input) } \arguments{ \item{input}{Array to get converted to a native raster} - -\item{ncol}{Number of columns} - -\item{nrow}{Number of rows} } \description{ Displays the image in the current device. diff --git a/man/expand_to_fit.Rd b/man/expand_to_fit.Rd index 11d17a0..0f5ba76 100644 --- a/man/expand_to_fit.Rd +++ b/man/expand_to_fit.Rd @@ -6,9 +6,6 @@ \usage{ expand_to_fit(dim, kernel) } -\arguments{ -\item{dim}{desired size} -} \value{ Hillshade with edges trimmed } diff --git a/man/pad_to_fit.Rd b/man/pad_to_fit.Rd index edac779..ae30d3c 100644 --- a/man/pad_to_fit.Rd +++ b/man/pad_to_fit.Rd @@ -6,11 +6,6 @@ \usage{ pad_to_fit(dim, kernel) } -\arguments{ -\item{heightmap}{A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.} - -\item{pad}{Number of padding entries} -} \value{ Hillshade with edges trimmed } diff --git a/tests/testthat/test-plot_image.R b/tests/testthat/test-plot_image.R index c2a28e4..36ad2ef 100644 --- a/tests/testthat/test-plot_image.R +++ b/tests/testthat/test-plot_image.R @@ -1,53 +1,55 @@ -# save_test_png = function(code, path) { -# grDevices::png(filename=path, width=500, height=400) -# code -# dev.off() -# path -# } -# -# compare_image = function(path1, path2) { -# image1 = png::readPNG(path1) -# image2 = png::readPNG(path2) -# return(identical(image1, image2)) -# } -# -# run_tests = function(func, argument_grid, plot_prefix="", ...) { -# stopifnot(inherits(argument_grid,"data.frame")) -# for(i in seq_len(nrow(argument_grid))){ -# args = unlist(argument_grid[i,], recursive = FALSE) -# test_filename = sprintf("%s_test%i.png", -# plot_prefix , i) -# path = tempfile(fileext = ".png") -# -# args = append(args, ...) -# # args = append(args, list(filename = path)) -# # browser() -# save_test_png(do.call(func, args = args), path) |> -# suppressMessages() |> -# suppressWarnings() |> -# expect_snapshot_file(name = test_filename, compare = compare_image) -# } -# } -# -# test_that("Checking plot_image", { -# plt_img_args = expand.grid(rotate = list(0,90,180,270), -# draw_grid = list(FALSE, TRUE), -# asp = list(0.5,1,2), -# new_page = list(TRUE, FALSE)) -# -# run_tests("plot_image", plt_img_args, plot_prefix = "plt_img", -# list(input = dragon)) -# }) -# -# test_that("Checking plot_image_grid", { -# plt_img_args = expand.grid(input_list = list(list(dragon, NULL, NULL, dragon)), -# dim = list(c(1,1), -# c(2,2), -# c(1,2), -# c(2,1)), -# draw_grid = list(FALSE, TRUE), -# asp = list(c(0.5,1,2,3))) -# plt_img_args = plt_img_args[-6,] #False positive -# -# run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list()) -# }) +save_test_png = function(code, path) { + grDevices::png(filename=path, width=500, height=400) + code + dev.off() + path +} + +compare_image = function(path1, path2) { + image1 = png::readPNG(path1) + image2 = png::readPNG(path2) + return(identical(image1, image2)) +} + +run_tests = function(func, argument_grid, plot_prefix="", ...) { + stopifnot(inherits(argument_grid,"data.frame")) + for(i in seq_len(nrow(argument_grid))){ + args = unlist(argument_grid[i,], recursive = FALSE) + test_filename = sprintf("%s_test%i.png", + plot_prefix , i) + path = tempfile(fileext = ".png") + + args = append(args, ...) + # args = append(args, list(filename = path)) + # browser() + save_test_png(do.call(func, args = args), path) |> + suppressMessages() |> + suppressWarnings() |> + expect_snapshot_file(name = test_filename, compare = compare_image) + } +} + +test_that("Checking plot_image", { + skip_on_os(c("windows", "linux", "solaris")) + plt_img_args = expand.grid(rotate = list(0,90,180,270), + draw_grid = list(FALSE, TRUE), + asp = list(0.5,1,2), + new_page = list(TRUE, FALSE)) + + run_tests("plot_image", plt_img_args, plot_prefix = "plt_img", + list(input = dragon)) +}) + +test_that("Checking plot_image_grid", { + skip_on_os(c("windows", "linux", "solaris")) + plt_img_args = expand.grid(input_list = list(list(dragon, NULL, NULL, dragon)), + dim = list(c(1,1), + c(2,2), + c(1,2), + c(2,1)), + draw_grid = list(FALSE, TRUE), + asp = list(c(0.5,1,2,3))) + plt_img_args = plt_img_args[-6,] #False positive + + run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list()) +})