tests/testthat/test-camera.R

test_that("pan_camera works", {
  p <- ggseg3d() %>%
    pan_camera("right lat")

  expect_true("layoutAttrs" %in% names(p$x))

  expect_equal(p$x$layoutAttrs[[1]]$scene$camera ,
               list(eye = list(x = 2, y = 0, z = 0))
               )

  p <- ggseg3d() %>%
    pan_camera("right medial")

  expect_true("layoutAttrs" %in% names(p$x))

  expect_equal(p$x$layoutAttrs[[1]]$scene$camera ,
               list(eye = list(x = -2.5, y = 0, z = 0))
  )


  p <- ggseg3d() %>%
    pan_camera("left lat")

  expect_true("layoutAttrs" %in% names(p$x))

  expect_equal(p$x$layoutAttrs[[1]]$scene$camera ,
               list(eye = list(x = -2.5, y = 0, z = 0))
  )

  p <- ggseg3d() %>%
    pan_camera("left med")

  expect_true("layoutAttrs" %in% names(p$x))

  expect_equal(p$x$layoutAttrs[[1]]$scene$camera ,
               list(eye = list(x = 2, y = 0, z = 0))
  )

  p <- ggseg3d() %>%
    pan_camera(camera = list(eye = list(x = -3, y = -4, z = -1)))

  expect_true("layoutAttrs" %in% names(p$x))

  expect_equal(p$x$layoutAttrs[[1]]$scene$camera ,
               list(eye = list(x = -3, y = -4, z = -1))
  )
})

Try the ggseg3d package in your browser

Any scripts or data that you put into this service are public.

ggseg3d documentation built on June 1, 2021, 9:08 a.m.