Shifts each geometry of x as a whole by a random distance along x and
along y, each drawn uniformly between -amount and amount. This matches
sf::st_jitter() in everything but the random numbers.
Usage
ga_jitter(
x,
amount = NULL,
factor = 0.002,
seed = sample.int(.Machine$integer.max, 1L)
)Details
Without amount, ga_jitter() uses factor times the length of the
diagonal of the box around all of x, as sf does. ga_jitter() treats
coordinates as planar.
ga_jitter() draws the offsets from its own generator, seeded by seed,
two for every row in order. The default seed comes from R's generator, so
set.seed() makes the result repeatable, but ga_jitter() never draws the
numbers sf would.
ga_jitter() keeps the geometry type of x. It returns null for a null
geometry, and for an amount that is NA, negative, or infinite.
Examples
pts <- ga_point(c(0, 10, 10), c(0, 0, 10))
# each point moves by at most 0.5 along each axis
moved <- ga_jitter(pts, amount = 0.5, seed = 1)
as.vector(ga_x(moved)) - c(0, 10, 10)
#> [1] 0.3398737 -0.3860983 0.3883953
# the same seed moves each point the same way
identical(
as.vector(ga_x(ga_jitter(pts, seed = 42))),
as.vector(ga_x(ga_jitter(pts, seed = 42)))
)
#> [1] TRUE