n <- 50
set.seed(4)
path <- cbind(rnorm(n), rnorm(n))

op <- par(mfcol = c(1, 2))
## winding and evenodd are different
plot(path, type = "l", main = "winding")
polypath(path, rule = "winding", col = "grey")
plot(path, type = "l", main = "evenodd")
polypath(path, rule = "evenodd", col = "grey")

par(op)

library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
## decompose and triangulate
sfx <- st_sf(geometry = st_sfc(st_polygon(list(rbind(path, path[1, , drop = FALSE])
))), a = 1)
sft <- st_union(sfdct::ct_triangulate(sfx))
plot(sft, col = "grey")

## what if we don't post-process triangles? 
sft <- st_union(sfdct::ct_triangulate(sfx, trim = FALSE))
plot(sft, col = "grey")

## what if we go old school? 

library(spbabel)
library(ggplot2)
ggplot(sptable(sfx), aes(x_, y_, group = branch_, fill = object_)) + ggpolypath::geom_polypath(rule = "winding")

ggplot(sptable(sfx), aes(x_, y_, group = branch_, fill = object_)) + ggpolypath::geom_polypath(rule = "evenodd")