Skip to content

Commit d77d514

Browse files
committed
+translation,PointFrame tests
1 parent c13dbab commit d77d514

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

R/trans.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ setMethod("rotate", c("PointFrame", "numeric"), \(x, t, ...) {
133133
#' @importFrom dplyr mutate select
134134
#' @export
135135
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)
136138
y <- NULL # R CMD check
137139
x@data <- x@data |>
138140
mutate(x=x+t[1]) |>

tests/testthat/test-trans.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,26 @@ test_that("translation,labelArray", {
5151
expect_equal(dx[1,], dy[1,]/2)
5252
expect_identical(dx[2,], dy[2,])
5353
})
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

Comments
 (0)