Skip to content

Commit

Permalink
handle empty input to xyPathToList() et al; thanks to James Ward for …
Browse files Browse the repository at this point in the history
…th bug report
  • Loading branch information
pmur002 committed Aug 30, 2024
1 parent f731524 commit 4a2d086
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: gridGeometry
Type: Package
Title: Polygon Geometry in 'grid'
Version: 0.4-0
Version: 0.4-1
Authors@R: c(person("Paul", "Murrell", role = c("aut", "cre"),
email = "paul@stat.auckland.ac.nz"),
person("Jack", "Wong", role = "aut"))
Expand Down
8 changes: 8 additions & 0 deletions R/grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## Convert (closed) 'polyclip' polygon result to 'grid' path
xyListPath <- function(x, rule, name=NULL, gp=gpar()) {
## Handle empty 'x'
if (length(x) == 0) {
return(nullGrob(name=name))
}
if (missing(rule)) {
if (is.null(attr(x, "rule")))
rule <- "winding"
Expand All @@ -28,6 +32,10 @@ xyListToPath <- xyListPath

## Convert (closed) 'polyclip' polygon result to 'grid' polygons
xyListPolygon <- function(x, name=NULL, gp=gpar()) {
## Handle empty 'x'
if (length(x) == 0) {
return(nullGrob(name=name))
}
## Remove any coordinate sets that are too short
x <- x[sapply(x, function(c) length(c$x) > 1)]
if (length(x) == 0) {
Expand Down
7 changes: 7 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
\title{NEWS file for the gridGeometry package}
\encoding{UTF-8}

\section{Changes in version 0.4-1}{
\itemize{
\item Handle empty list or \code{NULL} input in
\code{xyListToPolygon()} and \code{xyListToPath()}.
}
}

\section{Changes in version 0.4-0}{
\itemize{
\item New functions \code{grid.polyoffset()} and
Expand Down
12 changes: 12 additions & 0 deletions tests/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,15 @@ gt <- gTree(children=gList(path, rect))
grid.newpage()
grid.reduce(gt, gp=gpar(fill="grey"))

################################################################################
## xyListTo*()

## Check can handle empty list

xyListToLine(NULL)
xyListToPolygon(NULL)
xyListToPath(NULL)

xyListToLine(list())
xyListToPolygon(list())
xyListToPath(list())

0 comments on commit 4a2d086

Please sign in to comment.