bodkan / slendr

Population genetic simulations in R 🌍
https://bodkan.net/slendr
Other
54 stars 5 forks source link

Broken check for landscape intersection when population fills the whole world? #68

Closed bodkan closed 2 years ago

bodkan commented 2 years ago

This just came up in my tree sequence spatial inference project. For some reason, creating a population whose range completely overlaps the world boundary leads to error. I don't think I have ever tested an edge (but a very reasonable edge case!) like this, so I bet I messed up some internal sanity check.

square_region <- list(c(0, 0), c(0, 1000),
                      c(1000, 1000), c(0, 1000))

map <- world(
  xrange = c(0, 1000), yrange = c(0, 1000),
  landscape = region(polygon = square_region)
)

pop <- population("pop", map = map, N = 10000, time = 1, polygon = square_region)

plot(pop)

The error is:

Error: No area left for pop after intersection with landscape at time 1
Traceback:

1. plot(pop)
2. plot.slendr(pop)
3. lapply(pop_maps, intersect_features)
4. FUN(X[[i]], ...)
5. stop(sprintf("No area left for %s after intersection with landscape at time %s", 
 .     pop$pop, pop$tmap), call. = FALSE)
bodkan commented 2 years ago

Apparently fixed here. It turned out to be a plotting bug.