diff --git a/DESCRIPTION b/DESCRIPTION index d7d8e34e1..965bbe820 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: spatstat -Version: 1.46-1.007 -Nickname: Ultracrepidarian -Date: 2016-07-15 +Version: 1.46-1.008 +Nickname: Pons Asinorum +Date: 2016-07-16 Title: Spatial Point Pattern Analysis, Model-Fitting, Simulation, Tests Author: Adrian Baddeley , Rolf Turner diff --git a/NAMESPACE b/NAMESPACE index bb0811456..c3ccf74fe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -456,6 +456,16 @@ export("boundingbox.owin") export("boundingbox.ppp") export("boundingbox.solist") export("bounding.box.xy") +export("boundingcentre") +export("boundingcentre.owin") +export("boundingcentre.ppp") +export("boundingcircle") +export("boundingcircle.owin") +export("boundingcircle.ppp") +export("boundingradius") +export("boundingradius.linnet") +export("boundingradius.owin") +export("boundingradius.ppp") export("box3") export("boxx") export("branchlabelfun") @@ -516,12 +526,6 @@ export("chop.tess") export("choptext") export("circdensity") export("circticks") -export("circumcentre") -export("circumcentre.owin") -export("circumcentre.ppp") -export("circumcircle") -export("circumcircle.owin") -export("circumcircle.ppp") export("circumradius") export("circumradius.linnet") export("circumradius.owin") @@ -1393,6 +1397,7 @@ export("mad.test") export("majorminorversion") export("make.even.breaks") export("makefvlabel") +export("makeLinnetTolerance") export("make.parseable") export("makeunits") export("mapSparseEntries") @@ -2841,6 +2846,13 @@ S3method("boundingbox", "im") S3method("boundingbox", "owin") S3method("boundingbox", "ppp") S3method("boundingbox", "solist") +S3method("boundingcentre", "owin") +S3method("boundingcentre", "ppp") +S3method("boundingcircle", "owin") +S3method("boundingcircle", "ppp") +S3method("boundingradius", "linnet") +S3method("boundingradius", "owin") +S3method("boundingradius", "ppp") S3method("by", "im") S3method("by", "ppp") S3method("cbind", "fv") @@ -2852,10 +2864,6 @@ S3method("cdf.test", "mppm") S3method("cdf.test", "ppm") S3method("cdf.test", "ppp") S3method("cdf.test", "slrm") -S3method("circumcentre", "owin") -S3method("circumcentre", "ppp") -S3method("circumcircle", "owin") -S3method("circumcircle", "ppp") S3method("circumradius", "linnet") S3method("circumradius", "owin") S3method("circumradius", "ppp") diff --git a/NEWS b/NEWS index e196eb9f5..b419e4060 100644 --- a/NEWS +++ b/NEWS @@ -1,21 +1,21 @@ - CHANGES IN spatstat VERSION 1.46-1.007 + CHANGES IN spatstat VERSION 1.46-1.008 OVERVIEW o We thank Mehdi Moradi and Jorge Mateu for contributions. - o Circumcentre and circumcircle. - o Non-Gaussian smoothing kernels. o Important bug fix in linearK, linearpcf - o Version nickname: 'Ultracrepidarian' + o Bounding circle of a spatial object. + + o Version nickname: 'Pons Asinorum' NEW FUNCTIONS - o circumcircle, circumcentre + o boundingcircle, boundingcentre Find the smallest circle enclosing a window or point pattern. SIGNIFICANT USER-VISIBLE CHANGES @@ -26,6 +26,9 @@ SIGNIFICANT USER-VISIBLE CHANGES o rcellnumber New argument 'mu'. + o lengths.psp + New argument 'squared'. + o density.ppp, Smooth.ppp Computation accelerated by about 15% in the case where at='points' and kernel='gaussian'. @@ -33,6 +36,9 @@ SIGNIFICANT USER-VISIBLE CHANGES o linearK, linearpcf Accelerated. + o circumradius + This function is now deprecated, in favour of 'boundingradius' + BUG FIXES o linearK, linearpcf, and relatives: diff --git a/R/Kest.R b/R/Kest.R index 9badd7ea8..a458f7433 100755 --- a/R/Kest.R +++ b/R/Kest.R @@ -1,7 +1,7 @@ # # Kest.R Estimation of K function # -# $Revision: 5.118 $ $Date: 2016/04/01 05:55:30 $ +# $Revision: 5.119 $ $Date: 2016/07/16 03:08:23 $ # # # -------- functions ---------------------------------------- @@ -292,7 +292,7 @@ function(X, ..., r=NULL, rmax=NULL, breaks=NULL, wh <- whist(DIJ, breaks$val, edgewt) numKiso <- cumsum(wh) denKiso <- lambda2 * areaW - h <- circumradius(W) + h <- boundingradius(W) numKiso[r >= h] <- NA K <- bind.ratfv(K, data.frame(iso=numKiso), diff --git a/R/boundingcircle.R b/R/boundingcircle.R new file mode 100644 index 000000000..f3eae6e1b --- /dev/null +++ b/R/boundingcircle.R @@ -0,0 +1,69 @@ +#' +#' boundingcircle.R +#' +#' bounding circle and its centre +#' +#' $Revision: 1.5 $ $Date: 2016/07/16 03:07:02 $ +#' + +circumradius <- function(x, ...) { + .Deprecated(boundingradius) + UseMethod("boundingradius") +} +circumradius.owin <- function(x, ...) { + .Deprecated(boundingradius.owin) + boundingradius.owin(x, ...) +} +circumradius.ppp <- function(x, ...) { + .Deprecated(boundingradius.ppp) + boundingradius.ppp(x, ...) +} + +boundingradius <- function(x, ...) { + UseMethod("boundingradius") +} + +boundingcentre <- function(x, ...) { + UseMethod("boundingcentre") +} + +boundingcircle <- function(x, ...) { + UseMethod("boundingcircle") +} + +#' owin + +boundingradius.owin <- function(x, ...) { + sqrt(min(fardist(x, ..., squared=TRUE))) +} + +boundingcentre.owin <- function(x, ...) { + z <- where.min(fardist(x, ..., squared=TRUE)) + Window(z) <- x + return(z) +} + +boundingcircle.owin <- function(x, ...) { + d2 <- fardist(x, ..., squared=TRUE) + z <- where.min(d2) + r <- sqrt(min(d2)) + w <- disc(centre=z, radius=r) + return(w) +} + +#' ppp + +boundingradius.ppp <- function(x, ...) { + boundingradius(convexhull(x), ...) +} + +boundingcentre.ppp <- function(x, ...) { + z <- boundingcentre(convexhull(x), ...) + Window(z) <- Window(x) + return(z) +} + +boundingcircle.ppp <- function(x, ...) { + boundingcircle(convexhull(x), ...) +} + diff --git a/R/circum.R b/R/circum.R deleted file mode 100644 index 985ac528f..000000000 --- a/R/circum.R +++ /dev/null @@ -1,56 +0,0 @@ -#' -#' circum.R -#' -#' circumradius, circumcentre and circumdisc -#' -#' $Revision: 1.2 $ $Date: 2016/07/10 03:22:06 $ -#' - -circumradius <- function(x, ...) { - UseMethod("circumradius") -} - -circumcentre <- function(x, ...) { - UseMethod("circumcentre") -} - -circumcircle <- function(x, ...) { - UseMethod("circumcircle") -} - -#' owin - -circumradius.owin <- function(x, ...) { - sqrt(min(fardist(x, ..., squared=TRUE))) -} - -circumcentre.owin <- function(x, ...) { - z <- where.min(fardist(x, ..., squared=TRUE)) - Window(z) <- x - return(z) -} - -circumcircle.owin <- function(x, ...) { - d2 <- fardist(x, ..., squared=TRUE) - z <- where.min(d2) - r <- sqrt(min(d2)) - w <- disc(centre=z, radius=r) - return(w) -} - -#' ppp - -circumradius.ppp <- function(x, ...) { - circumradius(convexhull(x), ...) -} - -circumcentre.ppp <- function(x, ...) { - z <- circumcentre(convexhull(x), ...) - Window(z) <- Window(x) - return(z) -} - -circumcircle.ppp <- function(x, ...) { - circumcircle(convexhull(x), ...) -} - diff --git a/R/edgeRipley.R b/R/edgeRipley.R index 0fa1c6a10..e36b8dfad 100755 --- a/R/edgeRipley.R +++ b/R/edgeRipley.R @@ -1,7 +1,7 @@ # # edgeRipley.R # -# $Revision: 1.13 $ $Date: 2016/04/25 02:34:40 $ +# $Revision: 1.15 $ $Date: 2016/07/16 03:11:15 $ # # Ripley isotropic edge correction weights # @@ -173,11 +173,11 @@ edge.Ripley <- local({ rmax.Ripley <- function(W) { W <- as.owin(W) if(is.rectangle(W)) - return(circumradius(W)) + return(boundingradius(W)) if(is.polygonal(W) && length(W$bdry) == 1) - return(circumradius(W)) + return(boundingradius(W)) ## could have multiple connected components pieces <- tiles(tess(image=connected(W))) - answer <- sapply(pieces, circumradius) + answer <- sapply(pieces, boundingradius) return(as.numeric(answer)) } diff --git a/R/linearK.R b/R/linearK.R index b86b37e18..24800c4dd 100755 --- a/R/linearK.R +++ b/R/linearK.R @@ -1,7 +1,7 @@ # # linearK # -# $Revision: 1.37 $ $Date: 2016/07/15 12:09:15 $ +# $Revision: 1.38 $ $Date: 2016/07/16 03:08:23 $ # # K function for point pattern on linear network # @@ -122,7 +122,7 @@ linearKengine <- function(X, ..., r=NULL, reweight=NULL, denom=1, Y <- as.ppp(X) W <- Y$window # determine r values - rmaxdefault <- 0.98 * circumradius(L) + rmaxdefault <- 0.98 * boundingradius(L) breaks <- handle.r.b.args(r, NULL, W, rmaxdefault=rmaxdefault) r <- breaks$r rmax <- breaks$max diff --git a/R/linearKmulti.R b/R/linearKmulti.R index 3240225e0..580f314d0 100644 --- a/R/linearKmulti.R +++ b/R/linearKmulti.R @@ -1,7 +1,7 @@ # # linearKmulti # -# $Revision: 1.8 $ $Date: 2016/07/15 12:09:29 $ +# $Revision: 1.9 $ $Date: 2016/07/16 03:08:23 $ # # K functions for multitype point pattern on linear network # @@ -199,7 +199,7 @@ linearKmultiEngine <- function(X, I, J, ..., r=NULL, reweight=NULL, denom=1, XP <- as.ppp(X) W <- as.owin(XP) # determine r values - rmaxdefault <- 0.98 * circumradius(L) + rmaxdefault <- 0.98 * boundingradius(L) breaks <- handle.r.b.args(r, NULL, W, rmaxdefault=rmaxdefault) r <- breaks$r rmax <- breaks$max diff --git a/R/lineardisc.R b/R/lineardisc.R index 85d9d7f9c..b89e6680a 100755 --- a/R/lineardisc.R +++ b/R/lineardisc.R @@ -209,10 +209,21 @@ countends <- function(L, x=locator(1), r, toler=NULL) { } default.linnet.tolerance <- function(L) { + # L could be a linnet or psp if(!is.null(toler <- L$toler)) return(toler) - lenfs <- lengths.psp(as.psp(L)) - toler <- 0.001 * min(lenfs[lenfs > 0]) - toler <- max(sqrt(.Machine$double.xmin), - toler[is.finite(toler)], na.rm=TRUE) + len2 <- lengths.psp(as.psp(L), squared=TRUE) + len2pos <- len2[len2 > 0] + toler <- if(length(len2pos) == 0) 0 else (0.001 * sqrt(min(len2pos))) + toler <- makeLinnetTolerance(toler) return(toler) } + +makeLinnetTolerance <- function(toler) { + max(sqrt(.Machine$double.xmin), + toler[is.finite(toler)], na.rm=TRUE) +} + + + + + diff --git a/R/linearpcf.R b/R/linearpcf.R index f0a7137e5..621f9f101 100755 --- a/R/linearpcf.R +++ b/R/linearpcf.R @@ -1,7 +1,7 @@ # # linearpcf.R # -# $Revision: 1.15 $ $Date: 2016/07/15 12:08:39 $ +# $Revision: 1.16 $ $Date: 2016/07/16 03:08:23 $ # # pair correlation function for point pattern on linear network # @@ -91,7 +91,7 @@ linearpcfengine <- function(X, ..., r=NULL, Y <- as.ppp(X) W <- Y$window # determine r values - rmaxdefault <- 0.98 * circumradius(L) + rmaxdefault <- 0.98 * boundingradius(L) breaks <- handle.r.b.args(r, NULL, W, rmaxdefault=rmaxdefault) r <- breaks$r rmax <- breaks$max diff --git a/R/linearpcfmulti.R b/R/linearpcfmulti.R index 42f97de46..d8f3c4c2b 100644 --- a/R/linearpcfmulti.R +++ b/R/linearpcfmulti.R @@ -1,7 +1,7 @@ # # linearpcfmulti.R # -# $Revision: 1.7 $ $Date: 2016/07/15 12:08:51 $ +# $Revision: 1.8 $ $Date: 2016/07/16 03:08:23 $ # # pair correlation functions for multitype point pattern on linear network # @@ -198,7 +198,7 @@ linearPCFmultiEngine <- function(X, I, J, ..., r=NULL, reweight=NULL, denom=1, XP <- as.ppp(X) W <- as.owin(XP) # determine r values - rmaxdefault <- 0.98 * circumradius(L) + rmaxdefault <- 0.98 * boundingradius(L) breaks <- handle.r.b.args(r, NULL, W, rmaxdefault=rmaxdefault) r <- breaks$r rmax <- breaks$max diff --git a/R/linnet.R b/R/linnet.R index d8e4eaf18..04bd45517 100755 --- a/R/linnet.R +++ b/R/linnet.R @@ -3,7 +3,7 @@ # # Linear networks # -# $Revision: 1.50 $ $Date: 2016/04/25 02:34:40 $ +# $Revision: 1.54 $ $Date: 2016/07/16 02:38:47 $ # # An object of class 'linnet' defines a linear network. # It includes the following components @@ -84,9 +84,12 @@ linnet <- function(vertices, m, edges, sparse=FALSE, warn=TRUE) { yy <- vertices$y lines <- psp(xx[from], yy[from], xx[to], yy[to], window=vertices$window, check=FALSE) + # tolerance + toler <- default.linnet.tolerance(lines) ## pack up out <- list(vertices=vertices, m=m, lines=lines, from=from, to=to, - sparse=sparse, window=vertices$window) + sparse=sparse, window=vertices$window, + toler=toler) class(out) <- c("linnet", class(out)) ## finish ? if(sparse) @@ -100,9 +103,8 @@ linnet <- function(vertices, m, edges, sparse=FALSE, warn=TRUE) { out$dpath <- dpath <- dist2dpath(d) if(warn && any(is.infinite(dpath))) warning("Network is not connected", call.=FALSE) - # pre-compute circumradius and tolerance - out$circumradius <- circumradius(out) - out$toler <- default.linnet.tolerance(out) + # pre-compute bounding radius + out$boundingradius <- boundingradius(out) return(out) } @@ -130,8 +132,9 @@ summary.linnet <- function(object, ...) { sparse = sparse) if(!sparse) { result$diam <- diameter(object) - result$circrad <- circumradius(object) + result$boundrad <- boundingradius(object) } + result$toler <- object$toler class(result) <- c("summary.linnet", class(result)) result } @@ -148,8 +151,10 @@ print.summary.linnet <- function(x, ...) { splat("Maximum vertex degree:", maxdegree) if(sparse) splat("[Sparse matrix representation]") else { splat("Diameter:", signif(diam, dig), unitinfo$plural) - splat("Circumradius:", signif(circrad, dig), unitinfo$plural) + splat("Bounding radius:", signif(boundrad, dig), unitinfo$plural) } + if(!is.null(toler)) + splat("Numerical tolerance:", signif(toler, dig), unitinfo$plural) print(win, prefix="Enclosing window: ") }) return(invisible(NULL)) @@ -248,11 +253,13 @@ as.linnet.linnet <- function(X, ..., sparse) { d[edges] <- sqrt(rowSums((coo[from, 1:2] - coo[to, 1:2])^2)) # compute shortest path distance matrix X$dpath <- dist2dpath(d) - # compute circumradius - X$circumradius <- circumradius(X) + # compute bounding radius + X$boundingradius <- boundingradius(X) X$m <- m X$sparse <- FALSE } + X$circumradius <- NULL + X$toler <- default.linnet.tolerance(X) return(X) } @@ -318,8 +325,13 @@ vertexdegree <- function(x) { } circumradius.linnet <- function(x, ...) { + .Deprecated("boundingradius.linnet") + boundingradius.linnet(x, ...) +} + +boundingradius.linnet <- function(x, ...) { stopifnot(inherits(x, "linnet")) - cr <- x$circumradius + cr <- x$boundingradius %orifnull% x$circumradius if(!is.null(cr)) return(cr) dpath <- x$dpath @@ -382,8 +394,11 @@ scalardilate.linnet <- function(X, f, ...) { Y$window <- scalardilate(X$window, f=f) if(!is.null(X$dpath)) { Y$dpath <- f * X$dpath - Y$circumradius <- f * X$circumradius + Y$boundingradius <- f * (X$boundingradius %orifnull% X$circumradius) + Y$circumradius <- NULL } + if(!is.null(X$toler)) + X$toler <- makeLinnetTolerance(f * X$toler) return(Y) } @@ -398,8 +413,11 @@ affine.linnet <- function(X, mat=diag(c(1,1)), vec=c(0,0), ...) { Y$window <- affine(X$window, mat=mat, vec=vec, ...) if(!is.null(X$dpath)) { Y$dpath <- scal * X$dpath - Y$circumradius <- scal * X$circumradius + Y$boundingradius <- scal * (X$boundingradius %orifnull% X$circumradius) + X$circumradius <- NULL } + if(!is.null(Y$toler)) + Y$toler <- makeLinnetTolerance(scal * Y$toler) } else { # general case vertices <- affine(X$vertices, mat=mat, vec=vec, ...) diff --git a/R/psp.R b/R/psp.R index af5a30eaf..4cb9b807d 100755 --- a/R/psp.R +++ b/R/psp.R @@ -1,7 +1,7 @@ # # psp.R # -# $Revision: 1.83 $ $Date: 2016/07/15 10:21:33 $ +# $Revision: 1.84 $ $Date: 2016/07/16 01:13:41 $ # # Class "psp" of planar line segment patterns # @@ -531,9 +531,10 @@ midpoints.psp <- function(x) { ppp(x=xm, y=ym, window=win, check=FALSE) } -lengths.psp <- function(x) { +lengths.psp <- function(x, squared=FALSE) { verifyclass(x, "psp") - eval(expression(sqrt((x1-x0)^2 + (y1-y0)^2)), envir=x$ends) + lengths2 <- eval(expression((x1-x0)^2 + (y1-y0)^2), envir=x$ends) + return(if(squared) lengths2 else sqrt(lengths2)) } angles.psp <- function(x, directed=FALSE) { diff --git a/R/treebranches.R b/R/treebranches.R index 8958b47d4..ed5e3db40 100644 --- a/R/treebranches.R +++ b/R/treebranches.R @@ -3,7 +3,7 @@ #' #' Label branches in a tree #' -#' $Revision: 1.3 $ $Date: 2015/10/21 09:06:57 $ +#' $Revision: 1.4 $ $Date: 2016/07/16 03:14:51 $ #' compute branch labels for each *vertex* in the tree L @@ -114,9 +114,10 @@ extractbranch.linnet <- function(X, code, labels, ..., which=NULL) { sparse=sparse, window=V$window) class(out) <- c("linnet", class(out)) - #' pre-compute circumradius + #' pre-compute bounding radius if(sparse) - out$circumradius <- circumradius(out) + out$boundingradius <- boundingradius(out) + out$toler <- default.linnet.tolerance(out) attr(out, "which") <- vin return(out) } @@ -169,9 +170,10 @@ deletebranch.linnet <- function(X, code, labels, ...) { sparse=sparse, window=V$window) class(out) <- c("linnet", class(out)) - #' recompute circumradius + #' recompute bounding radius if(sparse) - out$circumradius <- circumradius(out) + out$boundingradius <- boundingradius(out) + out$toler <- default.linnet.tolerance(out) attr(out, "which") <- vkeep return(out) } diff --git a/data/chicago.rda b/data/chicago.rda index 98e80999a..19fc0e9ee 100644 Binary files a/data/chicago.rda and b/data/chicago.rda differ diff --git a/data/dendrite.rda b/data/dendrite.rda index 718f70145..fdfed9749 100644 Binary files a/data/dendrite.rda and b/data/dendrite.rda differ diff --git a/data/simplenet.rda b/data/simplenet.rda index daff8cb63..5d0e34258 100755 Binary files a/data/simplenet.rda and b/data/simplenet.rda differ diff --git a/data/spiders.rda b/data/spiders.rda index ac406746c..4eb9be8db 100644 Binary files a/data/spiders.rda and b/data/spiders.rda differ diff --git a/man/boundingcircle.Rd b/man/boundingcircle.Rd new file mode 100644 index 000000000..6d597cd80 --- /dev/null +++ b/man/boundingcircle.Rd @@ -0,0 +1,85 @@ +\name{boundingcircle} +\alias{boundingradius} +\alias{boundingradius.owin} +\alias{boundingradius.ppp} +\alias{boundingcentre} +\alias{boundingcircle} +\alias{boundingcentre.owin} +\alias{boundingcircle.owin} +\alias{boundingcentre.ppp} +\alias{boundingcircle.ppp} +\title{ + Smallest Enclosing Circle +} +\description{ + Find the smallest circle enclosing a spatial window + or other object. Return its radius, or the location of its centre, + or the circle itself. +} +\usage{ +boundingradius(x, \dots) + +boundingcentre(x, \dots) + +boundingcircle(x, \dots) + +\method{boundingradius}{owin}(x, \dots) + +\method{boundingcentre}{owin}(x, \dots) + +\method{boundingcircle}{owin}(x, \dots) + +\method{boundingradius}{ppp}(x, \dots) + +\method{boundingcentre}{ppp}(x, \dots) + +\method{boundingcircle}{ppp}(x, \dots) +} +\arguments{ + \item{x}{ + A window (object of class \code{"owin"}), or another spatial object. + } + \item{\dots}{ + Arguments passed to \code{\link{as.mask}} to determine the + pixel resolution for the calculation. + } +} +\details{ + The \code{boundingcircle} of a spatial region \eqn{W} is the smallest circle + that contains \eqn{W}. The \code{boundingradius} is the radius of this circle, + and the \code{boundingcentre} is the centre of the circle. + + The functions \code{boundingcircle}, \code{boundingcentre} and + \code{boundingradius} are generic. There are methods + for objects of class \code{"owin"}, \code{"ppp"} and \code{"linnet"}. +} +\value{ + The result of \code{boundingradius} is a single numeric value. + + The result of \code{boundingcentre} is a point pattern containing a + single point. + + The result of \code{boundingcircle} is a window representing the + boundingcircle. +} +\author{ + \adrian +} +\seealso{ + \code{\link{boundingradius.linnet}} +} +\examples{ + boundingradius(letterR) + + plot(grow.rectangle(Frame(letterR), 0.2), main="", type="n") + plot(letterR, add=TRUE, col="grey") + plot(boundingcircle(letterR), add=TRUE, border="green", lwd=2) + plot(boundingcentre(letterR), pch="+", cex=2, col="blue", add=TRUE) + + X <- runifpoint(5) + plot(X) + plot(boundingcircle(X), add=TRUE) + plot(boundingcentre(X), pch="+", cex=2, col="blue", add=TRUE) +} +\keyword{spatial} +\keyword{math} diff --git a/man/circumradius.Rd b/man/circumradius.Rd deleted file mode 100644 index d6ba4b3be..000000000 --- a/man/circumradius.Rd +++ /dev/null @@ -1,85 +0,0 @@ -\name{circumradius} -\alias{circumradius} -\alias{circumcentre} -\alias{circumcircle} -\alias{circumradius.owin} -\alias{circumcentre.owin} -\alias{circumcircle.owin} -\alias{circumradius.ppp} -\alias{circumcentre.ppp} -\alias{circumcircle.ppp} -\title{ - Smallest Enclosing Circle -} -\description{ - Find the smallest circle enclosing a spatial window - or other object. Return its radius, or the location of its centre, - or the circle itself. -} -\usage{ -circumradius(x, \dots) - -circumcentre(x, \dots) - -circumcircle(x, \dots) - -\method{circumradius}{owin}(x, \dots) - -\method{circumcentre}{owin}(x, \dots) - -\method{circumcircle}{owin}(x, \dots) - -\method{circumradius}{ppp}(x, \dots) - -\method{circumcentre}{ppp}(x, \dots) - -\method{circumcircle}{ppp}(x, \dots) -} -\arguments{ - \item{x}{ - A window (object of class \code{"owin"}), or another spatial object. - } - \item{\dots}{ - Arguments passed to \code{\link{as.mask}} to determine the - pixel resolution for the calculation. - } -} -\details{ - The circumcircle of a spatial region \eqn{W} is the smallest circle - that contains \eqn{W}. The circumradius is the radius of this circle, - and the circumcentre is the centre of the circle. - - The functions \code{circumcircle}, \code{circumcentre} and - \code{circumradius} are generic. There are methods - for objects of class \code{"owin"}, \code{"ppp"} and \code{"linnet"}. -} -\value{ - The result of \code{circumradius} is a single numeric value. - - The result of \code{circumcentre} is a point pattern containing a - single point. - - The result of \code{circumcircle} is a window representing the - circumcircle. -} -\author{ - \adrian -} -\seealso{ - \code{\link{circumradius.linnet}} -} -\examples{ - circumradius(letterR) - - plot(grow.rectangle(Frame(letterR), 0.2), main="", type="n") - plot(letterR, add=TRUE, col="grey") - plot(circumcircle(letterR), add=TRUE, border="green", lwd=2) - plot(circumcentre(letterR), pch="+", cex=2, col="blue", add=TRUE) - - X <- runifpoint(5) - plot(X) - plot(circumcircle(X), add=TRUE) - plot(circumcentre(X), pch="+", cex=2, col="blue", add=TRUE) -} -\keyword{spatial} -\keyword{math} diff --git a/man/diameter.linnet.Rd b/man/diameter.linnet.Rd index 349fef634..0b1892cd6 100644 --- a/man/diameter.linnet.Rd +++ b/man/diameter.linnet.Rd @@ -1,17 +1,17 @@ \name{diameter.linnet} -\alias{circumradius.linnet} +\alias{boundingradius.linnet} \alias{diameter.linnet} \title{ - Circumradius and Diameter of a Linear Network + Diameter and Bounding Radius of a Linear Network } \description{ - Compute the circumradius or diameter of a linear network + Compute the diameter or bounding radius of a linear network measured using the shortest path distance. } \usage{ -\method{circumradius}{linnet}(x, \dots) - \method{diameter}{linnet}(x) + +\method{boundingradius}{linnet}(x, \dots) } \arguments{ \item{x}{ @@ -24,30 +24,29 @@ is the maximum value of the shortest-path distance between any two points \eqn{u} and \eqn{v} on the network. - The circumradius of a linear network (in the shortest path distance) + The bounding radius of a linear network (in the shortest path distance) is the minimum value, over all points \eqn{u} on the network, of the maximum shortest-path distance from \eqn{u} to another point \eqn{v} on the network. - The functions \code{\link{circumradius}} and + The functions \code{\link{boundingradius}} and \code{\link{diameter}} are generic; - the functions \code{circumradius.linnet} and \code{diameter.linnet} + the functions \code{boundingradius.linnet} and \code{diameter.linnet} are the methods for objects of class \code{linnet}. } \value{ A single numeric value. } \author{ - \adrian - + \adrian } \seealso{ - \code{\link{circumradius}}, \code{\link{diameter}}, + \code{\link{boundingradius}}, \code{\link{diameter}}, \code{\link{linnet}} } \examples{ diameter(simplenet) - circumradius(simplenet) + boundingradius(simplenet) } \keyword{spatial} \keyword{math} diff --git a/man/lengths.psp.Rd b/man/lengths.psp.Rd index 668387b70..fd4d18c04 100644 --- a/man/lengths.psp.Rd +++ b/man/lengths.psp.Rd @@ -6,12 +6,17 @@ in a line segment pattern. } \usage{ - lengths.psp(x) + lengths.psp(x, squared=FALSE) } \arguments{ \item{x}{ A line segment pattern (object of class \code{"psp"}). } + \item{squared}{ + Logical value indicating whether to return + the squared lengths (\code{squared=TRUE}) + or the lengths themselves (\code{squared=FALSE}, the default). + } } \value{ Numeric vector. @@ -19,6 +24,11 @@ \details{ The length of each line segment is computed and the lengths are returned as a numeric vector. + + Using squared lengths may be more efficient for some purposes, + for example, to find the length of the shortest segment, + \code{sqrt(min(lengths.psp(x, squared=TRUE)))} + is faster than \code{min(lengths.psp(x))}. } \seealso{ \code{\link{summary.psp}}, diff --git a/man/spatstat-deprecated.Rd b/man/spatstat-deprecated.Rd index 618eabacf..0efd0282d 100644 --- a/man/spatstat-deprecated.Rd +++ b/man/spatstat-deprecated.Rd @@ -19,6 +19,10 @@ \alias{dirichlet.network} \alias{dirichlet.vertices} \alias{dirichlet.weights} +\alias{circumradius} +\alias{circumradius.owin} +\alias{circumradius.ppp} +\alias{circumradius.linnet} \title{Deprecated spatstat functions} \description{ Deprecated spatstat functions. @@ -47,6 +51,10 @@ dirichlet.edges(\dots) dirichlet.network(\dots) dirichlet.vertices(\dots) dirichlet.weights(\dots) +circumradius(x, \dots) +\method{circumradius}{owin}(x, \dots) +\method{circumradius}{ppp}(x, \dots) +\method{circumradius}{linnet}(x, \dots) } \details{ @@ -95,5 +103,8 @@ dirichlet.weights(\dots) \code{dirichlet.vertices} is replaced by \code{dirichletVertices}. \code{dirichlet.weights} is replaced by \code{dirichletWeights}. + + \code{circumradius} is replaced by the more appropriately named + \code{boundingradius}. } \keyword{internal} diff --git a/man/spatstat-internal.Rd b/man/spatstat-internal.Rd index 5f18898b0..0786da90c 100644 --- a/man/spatstat-internal.Rd +++ b/man/spatstat-internal.Rd @@ -350,6 +350,7 @@ \alias{logi.engine} \alias{logLik.vblogit} \alias{lty2char} +\alias{makeLinnetTolerance} \alias{maskLaslett} \alias{matsqrt} \alias{matchNameOrPosition} @@ -1220,6 +1221,7 @@ logi.engine(Q, trend, interaction, \dots, VB) \method{logLik}{vblogit}(object, \dots) lty2char(i) +makeLinnetTolerance maskLaslett(X, \dots, eps, dimyx, xy, oldX, verbose, plotit) matsqrt(x) matchNameOrPosition(expected, avail) diff --git a/tests/testsAtoN.R b/tests/testsAtoN.R index 96481451e..e5eceb054 100644 --- a/tests/testsAtoN.R +++ b/tests/testsAtoN.R @@ -933,7 +933,7 @@ local({ # # Tests for lpp code # -# $Revision: 1.6 $ $Date: 2016/02/01 09:44:54 $ +# $Revision: 1.7 $ $Date: 2016/07/16 03:59:27 $ require(spatstat) @@ -1023,6 +1023,27 @@ local({ B <- owin(c(0.1,0.7),c(0.19,0.6)) XB <- X[B] validate.lpp.coords(XB, context="returned by [.lpp") + + ## Tests related to linearK, etc + testcountends <- function(X, r=100, s=1) { + if(s != 1) { + X <- rescale(X, s) + r <- r/s + } + L <- as.linnet(X) + n1 <- countends(L, X[1], r) + n2 <- npoints(lineardisc(L, X[1], r, plotit=FALSE)$endpoints) + if(n1 != n2) + stop(paste("Incorrect result from countends:", + n1, "!=", n2, + paren(paste("scale=", 1/s))), + call.=FALSE) + } + # original scale + X <- unmark(chicago) + testcountends(X) + # finer scale + testcountends(X, s=1000) }) ## diff --git a/vignettes/packagesizes.txt b/vignettes/packagesizes.txt index 428d9797b..2bf0d742a 100644 --- a/vignettes/packagesizes.txt +++ b/vignettes/packagesizes.txt @@ -182,4 +182,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines "2016-05-09" "1.45-2" 977 2478 54 101981 28124 "2016-07-06" "1.46-0" 981 2490 54 102484 28310 "2016-07-08" "1.46-1" 981 2491 54 102573 28310 -"2016-07-15" "1.46-1.007" 981 2505 54 102899 28334 +"2016-07-16" "1.46-1.008" 981 2510 54 102944 28334 diff --git a/vignettes/updates.Rnw b/vignettes/updates.Rnw index cd1c2877d..3b662ba15 100644 --- a/vignettes/updates.Rnw +++ b/vignettes/updates.Rnw @@ -211,6 +211,9 @@ Following is a list of all the functions that have been added. \begin{itemize} + \item \texttt{boundingcircle}, \texttt{boundingcentre}: + Smallest circle enclosing a spatial object. + \item \texttt{split.msr}: Decompose a measure into parts. @@ -613,6 +616,8 @@ listed alphabetically. \item A non-Gaussian kernel can now be specified using the argument \texttt{kernel}. \item Accelerated by about 15\% + in the case where \texttt{at="points"} + and \texttt{kernel="gaussian"}. \end{itemize} @@ -724,10 +729,14 @@ listed alphabetically. a fitted point process model. New arguments \texttt{update}, \texttt{leaveoneout}, \texttt{lambdaX}. + \item \texttt{lengths.psp}: New argument \texttt{squared}. + \item \texttt{leverage.ppm}: For Gibbs models, memory usage has been dramatically reduced, so the code can handle larger datasets and finer quadrature schemes. + \item \texttt{linearK}, \texttt{linearpcf} and relatives: Accelerated. + \item \texttt{linnet}: \begin{itemize} \item @@ -977,8 +986,13 @@ listed alphabetically. New argument \texttt{verbose}. \item \texttt{Smooth.ppp}: - A non-Gaussian kernel can now be specified + \begin{itemize} + \item A non-Gaussian kernel can now be specified using the argument \texttt{kernel}. + \item Accelerated by about 15\% in the case where \texttt{at="points"} + and \texttt{kernel="gaussian"}. + \end{itemize} + \item \texttt{spatstat.options} New options \texttt{fastthin} and \texttt{fastpois}