Skip to content

Commit

Permalink
make polyCub.exact.Gauss() defunct and drop gpclib xrefs (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastistician committed Oct 24, 2023
1 parent fc1dba2 commit c6221d4
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 143 deletions.
11 changes: 4 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
Expand All @@ -20,12 +20,10 @@ Description: Numerical integration of continuously differentiable
product Gauss cubature (Sommariva and Vianello, 2007,
<doi:10.1007/s10543-007-0131-2>),
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,
<doi:10.1214/14-AOAS743>, Supplement B),
and integration of the bivariate Gaussian density based on
polygon triangulation.
<doi:10.1214/14-AOAS743>, Supplement B).
For simple integration along the axes, the 'cubature' package
is more appropriate.
License: GPL-2
Expand All @@ -44,7 +42,6 @@ Suggests:
lattice,
mvtnorm,
statmod,
gpclib,
sf,
cubature,
knitr,
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
33 changes: 17 additions & 16 deletions R/coerce-gpc-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion R/plotpolyf.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
28 changes: 21 additions & 7 deletions R/polyCub.exact.Gauss.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}}).
Expand Down Expand Up @@ -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: <https://github.com/bastistician/polyCub/issues/2>"
))

if (inherits(polyregion, "owin")) {
polyregion <- owin2gpc(polyregion)
} else if (inherits(polyregion, "sfg")) {
Expand All @@ -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) {
Expand Down
48 changes: 23 additions & 25 deletions R/sfg2gpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/xylist.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}"})
Expand Down
26 changes: 9 additions & 17 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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.
Expand Down
28 changes: 16 additions & 12 deletions man/coerce-gpc-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot_polyregion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plotpolyf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 8 additions & 16 deletions man/polyCub-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c6221d4

Please sign in to comment.