-
Notifications
You must be signed in to change notification settings - Fork 4
Description
I love this package, such a cool idea! For what it's worth, I'm intending to use it to render polygons with inner and/or outer borders. (I'm surprised mapping tools sf don't have options to render inner border to colorize adjacent countries, or counties.) Anyway this package seems like the ideal choice, so I'm converting my previous kludge to use grid and vwline. Winning. :)
I'm posting the issue to make sure you've seen it. I have a workaround - TL;DR use linejoin="bevel"
Test case is below, starting with linejoin="bevel":
library(vwline);
# make a hexagon
aseq <- seq(from=0, to=300, by=60);
xbox <- (cos(aseq/180*pi)/2.2 + 0.5);
ybox <- (sin(aseq/180*pi)/2.2 + 0.5);
# define fixed line width
w <- rep(0.04, length(xbox));
# plot the test case
grid.newpage()
grid.vwline(x=xbox, y=ybox, w=w,
linejoin="bevel",
open=FALSE, gp=grid::gpar(col="gold", fill="darkorange"))
grid.path(x=xbox, y=ybox, gp=gpar(lwd=3, fill=NA))
That works fine. But if using linejoin="round" (default) or linejoin="mitre", they produce graphical glitches:
grid.newpage()
grid.vwline(x=xbox, y=ybox, w=w,
linejoin="round",
open=FALSE, gp=grid::gpar(col="gold", fill="darkorange"))
grid.path(x=xbox, y=ybox, gp=gpar(lwd=3, fill=NA))
(It looks even odder with linejoin="mitre".)
I dug around a bit, and it appears to affect a specific edge case - a common one, but specific.
For my testing, it only occurs with counter-clockwise points, closed polygons open=FALSE, only (or mostly?) on the outer portion of the line, and only for linejoin="round" and linejoin="mitre".
If I reverse the order of points (so it draws clockwise), the problem appears to be gone:
xbox2 <- rev(xbox);
ybox2 <- rev(ybox);
grid.newpage()
grid.vwline(x=xbox2, y=ybox2, w=w,
linejoin="round",
open=FALSE, gp=grid::gpar(col="gold", fill="darkorange"))
grid.path(x=xbox, y=ybox, gp=gpar(lwd=3, fill=NA))
However, it doesn't fully avoid the problem, the bottom-right corner is "bevel" and not "round". (Confirmed by drawing the same with linejoin="mitre" it still shows "bevel" in that corner.) Frankly, I can live with that, if that's as intended.
Fully love the package - I'm going to use "bevel" for time being, but wanted to post some positive feedback from a user, and let you know about the graphical artifacts. And if I've done something wrong on my end, sorry for taking your time!
(PS - Is there an equivalent to grid::grid.path()?)