Skip to content

Commit

Permalink
add regression tests for "joins bug"; add NEWS item
Browse files Browse the repository at this point in the history
  • Loading branch information
pmur002 committed Aug 22, 2024
1 parent f27443e commit 1309bbc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/inst/NEWS.rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
\title{NEWS file for the vwline package}
\encoding{UTF-8}

\section{Changes in version 0.2-3}{
\itemize{
\item Fix for calculation of joins (outer corners) on closed lines.

The last corner was missing (reduced to bevel), which also produced some
crazy results for some orderings of vertices.

Thanks to James Ward for bug report.
}
}
\section{Changes in version 0.2-2}{
\itemize{
\item Tidying for submission to CRAN.
Expand Down
72 changes: 72 additions & 0 deletions pkg/inst/regression-tests/bug-joins.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

library(vwline)

pdf("bug-joins.pdf", compress=FALSE)

## The bug was that the last corner on a closed line was not being added
## (was reduced to bevel).
## For some orderings of vertices, this also produced weird artifacts.

## make a line with a bend
x <- c(.4, .6, .6)
y <- c(.4, .4, .6)

## define fixed line width
w <- rep(0.04, length(x));

## Bevel corners
grid.newpage()
grid.vwline(x=x, y=y, w=w,
linejoin="bevel",
open=FALSE, gp=grid::gpar(col="black", fill="darkorange"))

## Round corners
grid.newpage()
grid.vwline(x=x, y=y, w=w,
linejoin="round",
open=FALSE, gp=grid::gpar(col="black", fill="darkorange"))

## Reverse order of vertices (round corners)
x2 <- rev(x);
y2 <- rev(y);
grid.newpage()
grid.vwline(x=x2, y=y2, w=w,
linejoin="round",
open=FALSE, gp=grid::gpar(col="black", fill="darkorange"))

## Open version(s)
grid.newpage()
grid.vwline(x=x, y=y, w=w,
linejoin="round",
open=TRUE, gp=grid::gpar(col="black", fill="darkorange"))

grid.newpage()
grid.vwline(x=x2, y=y2, w=w,
linejoin="round",
open=TRUE, gp=grid::gpar(col="black", fill="darkorange"))

## Mitre corners
grid.newpage()
grid.vwline(x=x, y=y, w=w,
linejoin="mitre",
open=FALSE, gp=grid::gpar(col="black", fill="darkorange"))

dev.off()

savedPDF <- system.file("regression-tests", "bug-joins.save.pdf",
package="vwline")
diff <- tools::Rdiff("bug-joins.pdf", savedPDF)

if (diff != 0L) {
## If differences found, generate images of the differences and error out
system("pdfseparate bug-joins.pdf bug-joins-test-pages-%d.pdf")
system(paste0("pdfseparate ", savedPDF, " bug-joins-model-pages-%d.pdf"))
modelFiles <- list.files(pattern="bug-joins-model-pages-.*")
N <- length(modelFiles)
for (i in 1:N) {
system(paste0("compare bug-joins-model-pages-", i, ".pdf ",
"bug-joins-test-pages-", i, ".pdf ",
"bug-joins-diff-pages-", i, ".png"))
}
stop("Regression testing detected differences")
}
Binary file added pkg/inst/regression-tests/bug-joins.save.pdf
Binary file not shown.

0 comments on commit 1309bbc

Please sign in to comment.