-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
78 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' Raster image of an x3p surface | ||
#' | ||
#' `image.x3p` expands the generic image method for x3p objects. | ||
#' This image function creates a raster image to show the surface of an x3p file. | ||
#' Due to some inconsistency in the mapping of the origin (0,0), (choice between top left or bottom left) image functions from different packages will result in different images. | ||
#' @param x an x3p object | ||
#' @param ... parameters passed into image | ||
#' @importFrom graphics image | ||
#' @method image x3p | ||
#' @export | ||
#' @examples | ||
#' logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) | ||
#' image(logo) | ||
image.x3p <- function(x, ...) { | ||
graphics::image(x$surface.matrix, ylim = c(1, 0), ...) | ||
} | ||
|
||
|
||
#' Dimension of an x3p object | ||
#' | ||
#' `dim.x3p` expands the generic dim method for x3p objects and returns (mainly) the dimensions of the surface matrix. | ||
#' @param x an x3p object | ||
#' @method dim x3p | ||
#' @returns a vector of length three. The first two integers contain width and height of the surface scan, the third dimension is either 1 or 2, depending on whether there is a mask (2) or not (1). | ||
#' @export | ||
#' @examples | ||
#' logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) | ||
#' dim(logo) | ||
dim.x3p <- function(x) { | ||
matrix_dims <- dim(x$surface.matrix) | ||
z <- 1 | ||
if (!is.null(x$mask)) z <- 2 | ||
c(matrix_dims, z) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ library(x3ptools) | |
|
||
|
||
test_check("x3ptools") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
context("generics_x3p") | ||
|
||
#' | ||
#' dim(logo) | ||
|
||
test_that("dim.x3p works as expected", { | ||
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) | ||
expect_equal(dim(logo), c(741, 419, 1)) | ||
|
||
expect_equal(dim(x3ptest_mask), c(6, 7, 2)) | ||
|
||
}) | ||
|