From c6221d45d11649cd829a4028a400fe03cf1d4a6c Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Tue, 24 Oct 2023 22:16:36 +0200 Subject: [PATCH] make polyCub.exact.Gauss() defunct and drop gpclib xrefs (#2) --- DESCRIPTION | 11 ++++----- Makefile | 2 +- NEWS.md | 9 +++++-- R/coerce-gpc-methods.R | 33 +++++++++++++------------- R/plotpolyf.R | 2 +- R/polyCub.exact.Gauss.R | 28 ++++++++++++++++------ R/sfg2gpc.R | 48 ++++++++++++++++++-------------------- R/xylist.R | 2 +- R/zzz.R | 26 +++++++-------------- man/coerce-gpc-methods.Rd | 28 ++++++++++++---------- man/plot_polyregion.Rd | 2 +- man/plotpolyf.Rd | 2 +- man/polyCub-package.Rd | 24 +++++++------------ man/polyCub.Rd | 2 +- man/polyCub.SV.Rd | 2 +- man/polyCub.exact.Gauss.Rd | 20 ++++++++++------ man/polyCub.iso.Rd | 2 +- man/sfg2gpc.Rd | 48 +++++++++++++++++++------------------- man/xylist.Rd | 2 +- vignettes/polyCub.Rmd | 3 ++- 20 files changed, 153 insertions(+), 143 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 95f2049..64aad66 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: polyCub Title: Cubature over Polygonal Domains -Version: 0.8.2 -Date: 2023-10-20 +Version: 0.9.0 +Date: 2023-10-25 Authors@R: c( person("Sebastian", "Meyer", email = "seb.meyer@fau.de", @@ -20,12 +20,10 @@ Description: Numerical integration of continuously differentiable product Gauss cubature (Sommariva and Vianello, 2007, ), the simple two-dimensional midpoint rule - (wrapping 'spatstat.geom' functions), + (wrapping 'spatstat.geom' functions), and adaptive cubature for radially symmetric functions via line integrate() along the polygon boundary (Meyer and Held, 2014, - , Supplement B), - and integration of the bivariate Gaussian density based on - polygon triangulation. + , Supplement B). For simple integration along the axes, the 'cubature' package is more appropriate. License: GPL-2 @@ -44,7 +42,6 @@ Suggests: lattice, mvtnorm, statmod, - gpclib, sf, cubature, knitr, diff --git a/Makefile b/Makefile index 7b77e9e..2139dde 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ endef ## standard --as-cran check with remote checks disabled check: build - _R_CHECK_CRAN_INCOMING_REMOTE_=FALSE _R_CHECK_EXAMPLE_TIMING_THRESHOLD_=2 $R CMD check --as-cran --run-dontrun --timings ${PKG}_${VERSION}.tar.gz + _R_CHECK_CRAN_INCOMING_REMOTE_=FALSE _R_CHECK_EXAMPLE_TIMING_THRESHOLD_=2 $R CMD check --as-cran --timings ${PKG}_${VERSION}.tar.gz ## further option: --use-gct (for better detection of memory bugs/segfaults) @$(check-report-warnings-in-examples) diff --git a/NEWS.md b/NEWS.md index 95eb458..42b9b91 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,12 @@ -polyCub 0.8.2 (UNRELEASED) +polyCub 0.9.0 (2023-10-25) ========================== -* Removed remaining references to archived package +* `polyCub.exact.Gauss()` is defunct. It may be resurrected in future + versions, when a reliable replacement for `gpclib::tristrip()` is + implemented ([#2](https://github.com/bastistician/polyCub/issues/2)). + +* Removed remaining references to archived packages + [**gpclib**](https://CRAN.R-project.org/package=gpclib) and [**rgeos**](https://CRAN.R-project.org/package=rgeos). * **polyCub** now requires R >= 3.2.0. diff --git a/R/coerce-gpc-methods.R b/R/coerce-gpc-methods.R index 3e116ee..ff50ec5 100644 --- a/R/coerce-gpc-methods.R +++ b/R/coerce-gpc-methods.R @@ -12,8 +12,8 @@ #' Conversion between polygonal \code{"owin"} and \code{"gpc.poly"} #' #' Package \pkg{polyCub} implements converters between the classes -#' \code{"\link[spatstat.geom:owin.object]{owin}"} of package \pkg{spatstat.geom} and -#' \code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} of package \pkg{gpclib}. +#' \code{"\link[spatstat.geom:owin.object]{owin}"} of package \CRANpkg{spatstat.geom} +#' and \code{"gpc.poly"} of package \CRANpkg{gpclib}. #' #' @param object an object of class \code{"gpc.poly"} or \code{"owin"}, #' respectively. @@ -33,18 +33,20 @@ #' @keywords spatial methods #' @import methods #' @export -#' @examples -#' if (require("gpclib") && require("spatstat.geom")) { -#' ## use example polygons from -#' example(plotpolyf, ask = FALSE) +#' @examplesIf requireNamespace("spatstat.geom") +#' ## use example polygons from +#' example(plotpolyf, ask = FALSE) +#' letterR # a simple "xylist" #' -#' letterR # a simple "xylist" -#' letterR.owin <- owin(poly = letterR) -#' letterR.gpc_from_owin <- owin2gpc(letterR.owin) -#' letterR.xylist_from_gpc <- xylist(letterR.gpc_from_owin) -#' stopifnot(all.equal(letterR, lapply(letterR.xylist_from_gpc, "[", 1:2))) -#' letterR.owin_from_gpc <- as.owin(letterR.gpc_from_owin) -#' stopifnot(all.equal(letterR.owin, letterR.owin_from_gpc)) +#' letterR.owin <- spatstat.geom::owin(poly = letterR) +#' letterR.gpc_from_owin <- owin2gpc(letterR.owin) +#' ## warns if "gpclib" is unavailable +#' +#' if (is(letterR.gpc_from_owin, "gpc.poly")) { +#' letterR.xylist_from_gpc <- xylist(letterR.gpc_from_owin) +#' stopifnot(all.equal(letterR, lapply(letterR.xylist_from_gpc, `[`, 1:2))) +#' letterR.owin_from_gpc <- gpc2owin(letterR.gpc_from_owin) +#' stopifnot(all.equal(letterR.owin, letterR.owin_from_gpc)) #' } owin2gpc <- function (object) { @@ -110,10 +112,9 @@ as.owin.gpc.poly <- function (W, ...) } -## check for the formal class "gpc.poly" (loading gpclib if necessary) +## check for the formal class "gpc.poly" #' @import methods know_gpc.poly <- function () { - isClass("gpc.poly") || - requireNamespace("gpclib", quietly = TRUE) + isClass("gpc.poly") #|| requireNamespace("gpclib", quietly = TRUE) } diff --git a/R/plotpolyf.R b/R/plotpolyf.R index a7a1d09..10460b0 100644 --- a/R/plotpolyf.R +++ b/R/plotpolyf.R @@ -18,7 +18,7 @@ #' @param polyregion a polygonal domain. #' The following classes are supported: #' \code{"\link[spatstat.geom]{owin}"} from package \pkg{spatstat.geom}, -#' \code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from \pkg{gpclib}, +#' \code{"gpc.poly"} from \pkg{gpclib}, #' \code{"\linkS4class{SpatialPolygons}"}, \code{"\linkS4class{Polygons}"}, #' and \code{"\linkS4class{Polygon}"} from package \pkg{sp}, as well as #' \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} from package \pkg{sf}. diff --git a/R/polyCub.exact.Gauss.R b/R/polyCub.exact.Gauss.R index 2894f11..08f6541 100644 --- a/R/polyCub.exact.Gauss.R +++ b/R/polyCub.exact.Gauss.R @@ -9,23 +9,29 @@ ################################################################################ -#' Quasi-Exact Cubature of the Bivariate Normal Density +#' Quasi-Exact Cubature of the Bivariate Normal Density (DEFUNCT) +#' +#' This cubature method is defunct as of \pkg{polyCub} version 0.9.0. +#' It relied on \code{tristrip()} from package \CRANpkg{gpclib} for polygon +#' triangulation, but that package did not have a \acronym{FOSS} license and +#' was no longer maintained on a mainstream repository.\cr +#' Contributions to resurrect this cubature method are welcome: an alternative +#' implementation for constrained polygon triangulation is needed, see +#' \url{https://github.com/bastistician/polyCub/issues/2}. #' #' The bivariate Gaussian density can be integrated based on a triangulation of #' the (transformed) polygonal domain, using formulae from the #' Abramowitz and Stegun (1972) handbook (Section 26.9, Example 9, pp. 956f.). #' This method is quite cumbersome because the A&S formula is only for triangles -#' where one vertex is the origin (0,0). For each triangle of the -#' \code{\link[gpclib]{tristrip}} we have to check in which of the 6 outer +#' where one vertex is the origin (0,0). For each triangle +#' we have to check in which of the 6 outer #' regions of the triangle the origin (0,0) lies and adapt the signs in the #' formula appropriately: \eqn{(AOB+BOC-AOC)} or \eqn{(AOB-AOC-BOC)} or #' \eqn{(AOB+AOC-BOC)} or \eqn{(AOC+BOC-AOB)} or \ldots. #' However, the most time consuming step is the #' evaluation of \code{\link[mvtnorm]{pmvnorm}}. #' -#' @note Package \pkg{gpclib} is required to produce the \code{tristrip}. -#' -#' @param polyregion a \code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} polygon or +#' @param polyregion a \code{"gpc.poly"} polygon or #' something that can be coerced to this class, e.g., an \code{"owin"} polygon #' (via \code{\link{owin2gpc}}), or an \code{"sfg"} polygon (via #' \code{\link{sfg2gpc}}). @@ -74,6 +80,13 @@ polyCub.exact.Gauss <- function (polyregion, mean = c(0,0), Sigma = diag(2), plot = FALSE) { + ## defunctify with a maintainer-level backdoor for building the vignette + if (!identical(Sys.getenv("R_GPCLIBPERMIT"), "true")) + .Defunct(msg = paste0( + "'polyCub.exact.Gauss' is currently unavailable.\n", + "Contributions are welcome: " + )) + if (inherits(polyregion, "owin")) { polyregion <- owin2gpc(polyregion) } else if (inherits(polyregion, "sfg")) { @@ -92,7 +105,8 @@ polyCub.exact.Gauss <- function (polyregion, mean = c(0,0), Sigma = diag(2), ## triangulation: tristrip() returns a list where each element is a ## coordinate matrix of vertices of triangles - triangleSets <- gpclib::tristrip(polyregion) + ## FIXME: need a reliable tristrip() alternative + triangleSets <- utils::getFromNamespace("tristrip", "gpclib")(polyregion) ### ILLUSTRATION ### if (plot) { diff --git a/R/sfg2gpc.R b/R/sfg2gpc.R index 78836f6..8741353 100644 --- a/R/sfg2gpc.R +++ b/R/sfg2gpc.R @@ -12,9 +12,9 @@ #' Convert polygonal \code{"sfg"} to \code{"gpc.poly"} #' #' Package \pkg{polyCub} implements a converter from class -#' \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} of package \pkg{sf} to -#' \code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} of package -#' \pkg{gpclib} such that \code{\link{polyCub.exact.Gauss}} +#' \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} of package \CRANpkg{sf} +#' to \code{"gpc.poly"} of package \CRANpkg{gpclib} +#' such that \code{\link{polyCub.exact.Gauss}} #' can be used with simple feature polygons. #' #' @param object a \code{"POLYGON"} or \code{"MULTIPOLYGON"} \code{"sfg"} object. @@ -29,29 +29,27 @@ #' @keywords spatial methods #' @import methods #' @export -#' @examples -#' if (require("gpclib") && require("sf")) withAutoprint({ +#' @examplesIf requireNamespace("sf") +#' ## use example polygons from +#' example(plotpolyf, ask = FALSE) +#' letterR # a simple "xylist" #' -#' ## use example polygons from -#' example(plotpolyf, ask = FALSE) -#' -#' letterR # a simple "xylist" -#' letterR.sfg <- st_polygon(lapply(letterR, function(xy) -#' rbind(cbind(xy$x, xy$y), c(xy$x[1], xy$y[1])))) -#' letterR.sfg -#' stopifnot(identical(letterR, xylist(letterR.sfg))) -#' \dontshow{ -#' stopifnot(identical(rep(letterR, 2), -#' xylist(st_multipolygon(list(letterR.sfg, letterR.sfg))))) -#' } -#' ## convert sf "POLYGON" to a "gpc.poly" -#' letterR.gpc_from_sfg <- sfg2gpc(letterR.sfg) -#' letterR.gpc_from_sfg -#' \dontshow{if (requireNamespace("spatstat.geom")) { -#' letterR.xylist_from_gpc <- xylist(letterR.gpc_from_sfg) # with hole info -#' stopifnot(identical(letterR, lapply(letterR.xylist_from_gpc, "[", 1:2))) -#' }} -#' }) +#' letterR.sfg <- sf::st_polygon(lapply(letterR, function(xy) +#' rbind(cbind(xy$x, xy$y), c(xy$x[1], xy$y[1])))) +#' letterR.sfg +#' stopifnot(identical(letterR, xylist(letterR.sfg))) +#' \dontshow{ +#' stopifnot(identical(rep(letterR, 2), +#' xylist(sf::st_multipolygon(list(letterR.sfg, letterR.sfg))))) +#' } +#' ## convert sf "POLYGON" to a "gpc.poly" +#' letterR.gpc_from_sfg <- sfg2gpc(letterR.sfg) +#' letterR.gpc_from_sfg +#' \dontshow{ +#' if (is(letterR.gpc_from_sfg, "gpc.poly") && requireNamespace("spatstat.geom")) { +#' letterR.xylist_from_gpc <- xylist(letterR.gpc_from_sfg) # with hole info +#' stopifnot(identical(letterR, lapply(letterR.xylist_from_gpc, `[`, 1:2))) +#' }} sfg2gpc <- function (object) { assert_polygonal_sfg(object) diff --git a/R/xylist.R b/R/xylist.R index d30ec2f..a29c704 100644 --- a/R/xylist.R +++ b/R/xylist.R @@ -21,7 +21,7 @@ #' following polygon classes: #' \itemize{ #' \item \code{"\link[spatstat.geom:owin.object]{owin}"} from package \pkg{spatstat.geom} -#' \item \code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from package \pkg{gpclib} +#' \item \code{"gpc.poly"} from package \pkg{gpclib} #' \item \code{"\linkS4class{Polygons}"} from package \pkg{sp} #' (as well as \code{"\linkS4class{Polygon}"} and #' \code{"\linkS4class{SpatialPolygons}"}) diff --git a/R/zzz.R b/R/zzz.R index f274912..de547e4 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,7 +1,7 @@ ################################################################################ ### Package Setup ### -### Copyright (C) 2009-2014,2018-2021 Sebastian Meyer +### Copyright (C) 2009-2014,2018-2021,2023 Sebastian Meyer ### ### This file is part of the R package "polyCub", ### free software under the terms of the GNU General Public License, version 2, @@ -33,25 +33,17 @@ #' via line \code{\link{integrate}()} along the polygon boundary #' (Meyer and Held, 2014, Supplement B, Section 2.4). #' } -#' \item{\code{\link{polyCub.exact.Gauss}}:}{ -#' Accurate (but slow) integration of the \emph{bivariate Gaussian density} -#' based on polygon triangulation (via \code{\link[gpclib]{tristrip}} from -#' \pkg{gpclib}) and (numerous) evaluations of cumulative densities (via -#' \code{\link[mvtnorm]{pmvnorm}} from package \pkg{mvtnorm}). -#' Note that there is also a function \code{\link{circleCub.Gauss}} -#' to integrate the \emph{isotropic} Gaussian density over a -#' \emph{circular domain}. #' } -#' } -#' A more detailed description and benchmark experiment of the above cubature -#' methods can be found in the \code{vignette("polyCub")} and in -#' Meyer (2010, Section 3.2). +#' A brief description and benchmark experiment of the above cubature +#' methods can be found in the \code{vignette("polyCub")}. #' -#' @references -#' Abramowitz, M. and Stegun, I. A. (1972). -#' \emph{Handbook of Mathematical Functions with Formulas, Graphs, and -#' Mathematical Tables}. New York: Dover Publications. +#' There is also \code{\link{polyCub.exact.Gauss}}, intended to +#' accurately (but slowly) integrate the \emph{bivariate Gaussian density}; +#' however, this implementation is disabled as of \pkg{polyCub} 0.9.0: +#' it needs a reliable implementation of polygon triangulation. +#' Meyer (2010, Section 3.2) discusses and compares some of these methods. #' +#' @references #' Baddeley, A., Rubak, E. and Turner, R. (2015). #' \emph{Spatial Point Patterns: Methodology and Applications with R}. #' Chapman and Hall/CRC Press, London. diff --git a/man/coerce-gpc-methods.Rd b/man/coerce-gpc-methods.Rd index e4cebc8..2b981a7 100644 --- a/man/coerce-gpc-methods.Rd +++ b/man/coerce-gpc-methods.Rd @@ -29,8 +29,8 @@ respectively. If package \pkg{gpclib} is not available, } \description{ Package \pkg{polyCub} implements converters between the classes -\code{"\link[spatstat.geom:owin.object]{owin}"} of package \pkg{spatstat.geom} and -\code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} of package \pkg{gpclib}. +\code{"\link[spatstat.geom:owin.object]{owin}"} of package \CRANpkg{spatstat.geom} +and \code{"gpc.poly"} of package \CRANpkg{gpclib}. } \note{ The converter \code{owin2gpc} requires the package @@ -40,18 +40,22 @@ i.e. clockwise for normal boundaries and anticlockwise for holes, where, however, the first vertex is \emph{not} repeated! } \examples{ -if (require("gpclib") && require("spatstat.geom")) { - ## use example polygons from - example(plotpolyf, ask = FALSE) +\dontshow{if (requireNamespace("spatstat.geom")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +## use example polygons from +example(plotpolyf, ask = FALSE) +letterR # a simple "xylist" - letterR # a simple "xylist" - letterR.owin <- owin(poly = letterR) - letterR.gpc_from_owin <- owin2gpc(letterR.owin) - letterR.xylist_from_gpc <- xylist(letterR.gpc_from_owin) - stopifnot(all.equal(letterR, lapply(letterR.xylist_from_gpc, "[", 1:2))) - letterR.owin_from_gpc <- as.owin(letterR.gpc_from_owin) - stopifnot(all.equal(letterR.owin, letterR.owin_from_gpc)) +letterR.owin <- spatstat.geom::owin(poly = letterR) +letterR.gpc_from_owin <- owin2gpc(letterR.owin) +## warns if "gpclib" is unavailable + +if (is(letterR.gpc_from_owin, "gpc.poly")) { + letterR.xylist_from_gpc <- xylist(letterR.gpc_from_owin) + stopifnot(all.equal(letterR, lapply(letterR.xylist_from_gpc, `[`, 1:2))) + letterR.owin_from_gpc <- gpc2owin(letterR.gpc_from_owin) + stopifnot(all.equal(letterR.owin, letterR.owin_from_gpc)) } +\dontshow{\}) # examplesIf} } \seealso{ \code{\link{xylist}} diff --git a/man/plot_polyregion.Rd b/man/plot_polyregion.Rd index 3ddd13e..e76bde7 100644 --- a/man/plot_polyregion.Rd +++ b/man/plot_polyregion.Rd @@ -10,7 +10,7 @@ plot_polyregion(polyregion, lwd = 2, add = FALSE) \item{polyregion}{a polygonal domain. The following classes are supported: \code{"\link[spatstat.geom]{owin}"} from package \pkg{spatstat.geom}, -\code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from \pkg{gpclib}, +\code{"gpc.poly"} from \pkg{gpclib}, \code{"\linkS4class{SpatialPolygons}"}, \code{"\linkS4class{Polygons}"}, and \code{"\linkS4class{Polygon}"} from package \pkg{sp}, as well as \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} from package \pkg{sf}. diff --git a/man/plotpolyf.Rd b/man/plotpolyf.Rd index f0b6467..3a61d47 100644 --- a/man/plotpolyf.Rd +++ b/man/plotpolyf.Rd @@ -12,7 +12,7 @@ plotpolyf(polyregion, f, ..., npixel = 100, cuts = 15, \item{polyregion}{a polygonal domain. The following classes are supported: \code{"\link[spatstat.geom]{owin}"} from package \pkg{spatstat.geom}, -\code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from \pkg{gpclib}, +\code{"gpc.poly"} from \pkg{gpclib}, \code{"\linkS4class{SpatialPolygons}"}, \code{"\linkS4class{Polygons}"}, and \code{"\linkS4class{Polygon}"} from package \pkg{sp}, as well as \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} from package \pkg{sf}. diff --git a/man/polyCub-package.Rd b/man/polyCub-package.Rd index 30545b5..2137213 100644 --- a/man/polyCub-package.Rd +++ b/man/polyCub-package.Rd @@ -28,25 +28,17 @@ Adaptive cubature for \emph{radially symmetric functions} via line \code{\link{integrate}()} along the polygon boundary (Meyer and Held, 2014, Supplement B, Section 2.4). } -\item{\code{\link{polyCub.exact.Gauss}}:}{ -Accurate (but slow) integration of the \emph{bivariate Gaussian density} -based on polygon triangulation (via \code{\link[gpclib]{tristrip}} from -\pkg{gpclib}) and (numerous) evaluations of cumulative densities (via -\code{\link[mvtnorm]{pmvnorm}} from package \pkg{mvtnorm}). -Note that there is also a function \code{\link{circleCub.Gauss}} -to integrate the \emph{isotropic} Gaussian density over a -\emph{circular domain}. } -} -A more detailed description and benchmark experiment of the above cubature -methods can be found in the \code{vignette("polyCub")} and in -Meyer (2010, Section 3.2). +A brief description and benchmark experiment of the above cubature +methods can be found in the \code{vignette("polyCub")}. + +There is also \code{\link{polyCub.exact.Gauss}}, intended to +accurately (but slowly) integrate the \emph{bivariate Gaussian density}; +however, this implementation is disabled as of \pkg{polyCub} 0.9.0: +it needs a reliable implementation of polygon triangulation. +Meyer (2010, Section 3.2) discusses and compares some of these methods. } \references{ -Abramowitz, M. and Stegun, I. A. (1972). -\emph{Handbook of Mathematical Functions with Formulas, Graphs, and -Mathematical Tables}. New York: Dover Publications. - Baddeley, A., Rubak, E. and Turner, R. (2015). \emph{Spatial Point Patterns: Methodology and Applications with R}. Chapman and Hall/CRC Press, London. diff --git a/man/polyCub.Rd b/man/polyCub.Rd index 3a07307..0d0b51e 100644 --- a/man/polyCub.Rd +++ b/man/polyCub.Rd @@ -11,7 +11,7 @@ polyCub(polyregion, f, method = c("SV", "midpoint", "iso", "exact.Gauss"), \item{polyregion}{a polygonal domain. The following classes are supported: \code{"\link[spatstat.geom]{owin}"} from package \pkg{spatstat.geom}, -\code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from \pkg{gpclib}, +\code{"gpc.poly"} from \pkg{gpclib}, \code{"\linkS4class{SpatialPolygons}"}, \code{"\linkS4class{Polygons}"}, and \code{"\linkS4class{Polygon}"} from package \pkg{sp}, as well as \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} from package \pkg{sf}. diff --git a/man/polyCub.SV.Rd b/man/polyCub.SV.Rd index 7067c45..d9c7b79 100644 --- a/man/polyCub.SV.Rd +++ b/man/polyCub.SV.Rd @@ -11,7 +11,7 @@ polyCub.SV(polyregion, f, ..., nGQ = 20, alpha = NULL, rotation = FALSE, \item{polyregion}{a polygonal domain. The following classes are supported: \code{"\link[spatstat.geom]{owin}"} from package \pkg{spatstat.geom}, -\code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from \pkg{gpclib}, +\code{"gpc.poly"} from \pkg{gpclib}, \code{"\linkS4class{SpatialPolygons}"}, \code{"\linkS4class{Polygons}"}, and \code{"\linkS4class{Polygon}"} from package \pkg{sp}, as well as \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} from package \pkg{sf}. diff --git a/man/polyCub.exact.Gauss.Rd b/man/polyCub.exact.Gauss.Rd index 4c98869..fceb153 100644 --- a/man/polyCub.exact.Gauss.Rd +++ b/man/polyCub.exact.Gauss.Rd @@ -2,13 +2,13 @@ % Please edit documentation in R/polyCub.exact.Gauss.R \name{polyCub.exact.Gauss} \alias{polyCub.exact.Gauss} -\title{Quasi-Exact Cubature of the Bivariate Normal Density} +\title{Quasi-Exact Cubature of the Bivariate Normal Density (DEFUNCT)} \usage{ polyCub.exact.Gauss(polyregion, mean = c(0, 0), Sigma = diag(2), plot = FALSE) } \arguments{ -\item{polyregion}{a \code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} polygon or +\item{polyregion}{a \code{"gpc.poly"} polygon or something that can be coerced to this class, e.g., an \code{"owin"} polygon (via \code{\link{owin2gpc}}), or an \code{"sfg"} polygon (via \code{\link{sfg2gpc}}).} @@ -37,21 +37,27 @@ quasi-exact (as is the \code{pmvnorm} function). } } \description{ +This cubature method is defunct as of \pkg{polyCub} version 0.9.0. +It relied on \code{tristrip()} from package \CRANpkg{gpclib} for polygon +triangulation, but that package did not have a \acronym{FOSS} license and +was no longer maintained on a mainstream repository.\cr +Contributions to resurrect this cubature method are welcome: an alternative +implementation for constrained polygon triangulation is needed, see +\url{https://github.com/bastistician/polyCub/issues/2}. +} +\details{ The bivariate Gaussian density can be integrated based on a triangulation of the (transformed) polygonal domain, using formulae from the Abramowitz and Stegun (1972) handbook (Section 26.9, Example 9, pp. 956f.). This method is quite cumbersome because the A&S formula is only for triangles -where one vertex is the origin (0,0). For each triangle of the -\code{\link[gpclib]{tristrip}} we have to check in which of the 6 outer +where one vertex is the origin (0,0). For each triangle +we have to check in which of the 6 outer regions of the triangle the origin (0,0) lies and adapt the signs in the formula appropriately: \eqn{(AOB+BOC-AOC)} or \eqn{(AOB-AOC-BOC)} or \eqn{(AOB+AOC-BOC)} or \eqn{(AOC+BOC-AOB)} or \ldots. However, the most time consuming step is the evaluation of \code{\link[mvtnorm]{pmvnorm}}. } -\note{ -Package \pkg{gpclib} is required to produce the \code{tristrip}. -} \examples{ ## a function to integrate (here: isotropic zero-mean Gaussian density) f <- function (s, sigma = 5) diff --git a/man/polyCub.iso.Rd b/man/polyCub.iso.Rd index 9883be0..e489def 100644 --- a/man/polyCub.iso.Rd +++ b/man/polyCub.iso.Rd @@ -15,7 +15,7 @@ polyCub.iso(polyregion, f, intrfr, ..., center, control = list(), \item{polyregion}{a polygonal domain. The following classes are supported: \code{"\link[spatstat.geom]{owin}"} from package \pkg{spatstat.geom}, -\code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from \pkg{gpclib}, +\code{"gpc.poly"} from \pkg{gpclib}, \code{"\linkS4class{SpatialPolygons}"}, \code{"\linkS4class{Polygons}"}, and \code{"\linkS4class{Polygon}"} from package \pkg{sp}, as well as \code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} from package \pkg{sf}. diff --git a/man/sfg2gpc.Rd b/man/sfg2gpc.Rd index 48aab68..982042c 100644 --- a/man/sfg2gpc.Rd +++ b/man/sfg2gpc.Rd @@ -17,9 +17,9 @@ If package \pkg{gpclib} is not available, } \description{ Package \pkg{polyCub} implements a converter from class -\code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} of package \pkg{sf} to -\code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} of package -\pkg{gpclib} such that \code{\link{polyCub.exact.Gauss}} +\code{"\link[sf:st_polygon]{(MULTI)POLYGON}"} of package \CRANpkg{sf} +to \code{"gpc.poly"} of package \CRANpkg{gpclib} +such that \code{\link{polyCub.exact.Gauss}} can be used with simple feature polygons. } \note{ @@ -27,28 +27,28 @@ Package \pkg{gpclib} is required for the formal class definition of a \code{"gpc.poly"}. } \examples{ -if (require("gpclib") && require("sf")) withAutoprint({ +\dontshow{if (requireNamespace("sf")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +## use example polygons from +example(plotpolyf, ask = FALSE) +letterR # a simple "xylist" - ## use example polygons from - example(plotpolyf, ask = FALSE) - - letterR # a simple "xylist" - letterR.sfg <- st_polygon(lapply(letterR, function(xy) - rbind(cbind(xy$x, xy$y), c(xy$x[1], xy$y[1])))) - letterR.sfg - stopifnot(identical(letterR, xylist(letterR.sfg))) - \dontshow{ - stopifnot(identical(rep(letterR, 2), - xylist(st_multipolygon(list(letterR.sfg, letterR.sfg))))) - } - ## convert sf "POLYGON" to a "gpc.poly" - letterR.gpc_from_sfg <- sfg2gpc(letterR.sfg) - letterR.gpc_from_sfg - \dontshow{if (requireNamespace("spatstat.geom")) { - letterR.xylist_from_gpc <- xylist(letterR.gpc_from_sfg) # with hole info - stopifnot(identical(letterR, lapply(letterR.xylist_from_gpc, "[", 1:2))) - }} -}) +letterR.sfg <- sf::st_polygon(lapply(letterR, function(xy) + rbind(cbind(xy$x, xy$y), c(xy$x[1], xy$y[1])))) +letterR.sfg +stopifnot(identical(letterR, xylist(letterR.sfg))) +\dontshow{ +stopifnot(identical(rep(letterR, 2), + xylist(sf::st_multipolygon(list(letterR.sfg, letterR.sfg))))) +} +## convert sf "POLYGON" to a "gpc.poly" +letterR.gpc_from_sfg <- sfg2gpc(letterR.sfg) +letterR.gpc_from_sfg +\dontshow{ +if (is(letterR.gpc_from_sfg, "gpc.poly") && requireNamespace("spatstat.geom")) { + letterR.xylist_from_gpc <- xylist(letterR.gpc_from_sfg) # with hole info + stopifnot(identical(letterR, lapply(letterR.xylist_from_gpc, `[`, 1:2))) +}} +\dontshow{\}) # examplesIf} } \seealso{ \code{\link{xylist}} diff --git a/man/xylist.Rd b/man/xylist.Rd index 69389fc..2b9756b 100644 --- a/man/xylist.Rd +++ b/man/xylist.Rd @@ -54,7 +54,7 @@ The generic function \code{xylist} can deal with the following polygon classes: \itemize{ \item \code{"\link[spatstat.geom:owin.object]{owin}"} from package \pkg{spatstat.geom} -\item \code{"\link[gpclib:gpc.poly-class]{gpc.poly}"} from package \pkg{gpclib} +\item \code{"gpc.poly"} from package \pkg{gpclib} \item \code{"\linkS4class{Polygons}"} from package \pkg{sp} (as well as \code{"\linkS4class{Polygon}"} and \code{"\linkS4class{SpatialPolygons}"}) diff --git a/vignettes/polyCub.Rmd b/vignettes/polyCub.Rmd index c555330..aa23c54 100644 --- a/vignettes/polyCub.Rmd +++ b/vignettes/polyCub.Rmd @@ -14,7 +14,8 @@ knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ## maintainer-mode options for building the vignette: if (USE_GPCLIB <- identical(Sys.getenv("R_GPCLIBPERMIT"), "true")) { - stopifnot(requireNamespace("gpclib")) + if (!requireNamespace("gpclib")) # unavailable in --as-cran checks + USE_GPCLIB <- FALSE } if (DO_BENCHMARK <- USE_GPCLIB && identical(Sys.getenv("NOT_CRAN"), "true")) stopifnot(requireNamespace("microbenchmark"))