yutannihilation / wgpugd

A WebGPU Graphics Device for R
https://yutannihilation.github.io/wgpugd/
Other
45 stars 3 forks source link

Wrong linecap #12

Open yutannihilation opened 2 years ago

yutannihilation commented 2 years ago

Round works, but it seems butt and square doesn't...?

library(wgpugd)
library(ragg)

agg <- function(...) {
  agg_png(width = 7, height = 7, units = "in", ...)
}

do_line <- function(dev) {
  filename <- knitr::fig_path(paste0(deparse(substitute(dev)), ".png"))
  dev(filename = filename)

  a <- pi * 1:3 / 7
  x <- sin(a)
  y <- cos(a)
  col <- c("red", "blue", "green")
  le <- c("round", "butt", "square")

  invisible(lapply(1:3, \(i) {
    grid::grid.lines(
      x = 0.5 + c(-0.35 * x[i], 0.4 * x[i]),
      y = 0.5 + c(-0.35 * y[i], 0.4 * y[i]),
      gp = grid::gpar(
        col  = col[i],
        alpha = 0.5,
        lwd = 50 + 24 * i,
        lineend = le[i],
        linemitre = 10.
      )
    )
  }))

  dev.off()

  knitr::include_graphics(filename)
}

do_line(agg)

do_line(wgpugd)

Created on 2022-02-14 by the reprex package (v2.0.1)