We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c13dbab commit d77d514Copy full SHA for d77d514
2 files changed
R/trans.R
@@ -133,6 +133,8 @@ setMethod("rotate", c("PointFrame", "numeric"), \(x, t, ...) {
133
#' @importFrom dplyr mutate select
134
#' @export
135
setMethod("translation", c("PointFrame", "numeric"), \(x, t, ...) {
136
+ stopifnot(is.numeric(t), length(t) == 2, all(is.finite(t)))
137
+ if (all(t == 0)) return(x)
138
y <- NULL # R CMD check
139
x@data <- x@data |>
140
mutate(x=x+t[1]) |>
tests/testthat/test-trans.R
@@ -51,3 +51,26 @@ test_that("translation,labelArray", {
51
expect_equal(dx[1,], dy[1,]/2)
52
expect_identical(dx[2,], dy[2,])
53
})
54
+
55
+test_that("translation,PointFrame", {
56
+ x <- point(sd, 1)
57
+ y <- translation(x, c(0,0))
58
+ expect_identical(x, y)
59
+ # invalid
60
+ expect_error(translation(x, numeric(1)))
61
+ expect_error(translation(x, numeric(3)))
62
+ expect_error(translation(x, logical(2)))
63
+ expect_error(translation(x, c(Inf, Inf)))
64
+ expect_error(translation(x, character(2)))
65
+ expect_error(translation(x, NA*numeric(2)))
66
+ # valid
67
+ i <- setdiff(names(x), c("x", "y"))
68
+ f <- \() sample(33, 1)*sample(c(-1, 1), 1)
69
+ replicate(10, \() {
70
+ n <- f(); m <- f()
71
+ y <- translation(x, c(n,m))
72
+ expect_identical(x$x, y$x+n)
73
+ expect_identical(x$y, y$y+m)
74
+ expect_identical(x[,i], y[i])
75
+ })
76
+})
0 commit comments