Skip to content

Commit 5f7aeef

Browse files
committed
Extension to spatstatLocator
1 parent 6390b86 commit 5f7aeef

File tree

9 files changed

+44
-6
lines changed

9 files changed

+44
-6
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: spatstat.utils
2-
Version: 3.1-5
3-
Date: 2025-07-17
2+
Version: 3.1-5.001
3+
Date: 2025-07-25
44
Title: Utility Functions for 'spatstat'
55
Authors@R: c(person("Adrian", "Baddeley",
66
role = c("aut", "cre"),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export("sideCode")
177177
export("simplenumber")
178178
export("simplify.xypolygon")
179179
export("singlestring")
180+
export("snapxy")
180181
export("sortunique")
181182
export("spatstatLocator")
182183
export("splat")

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
CHANGES IN spatstat.utils VERSION 3.1-5.001
3+
4+
OVERVIEW
5+
6+
o spatstatLocator now supports `snap' behaviour (rounding).
7+
28
CHANGES IN spatstat.utils VERSION 3.1-5
39

410
OVERVIEW

R/locator.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#'
44
#' Replacement for locator()
55
#'
6-
#' $Revision: 1.9 $ $Date: 2023/09/18 08:47:45 $
6+
#' $Revision: 1.10 $ $Date: 2025/07/25 06:12:11 $
77

88
.spatstatLocatorEnv <- new.env()
99

@@ -29,7 +29,8 @@ queueSpatstatLocator <- function(x, y) {
2929
return(nrow(locatorqueue))
3030
}
3131

32-
spatstatLocator <- function(n, type=c("p","l","o","n"), ...) {
32+
spatstatLocator <- function(n, type=c("p","l","o","n"), ...,
33+
snap.step=NULL, snap.origin=c(0,0)) {
3334
#' Replacement for locator()
3435
#' Remedy for failure of locator(type="p") in RStudio
3536
#' Also allows software testing in non-interactive sessions
@@ -40,6 +41,8 @@ spatstatLocator <- function(n, type=c("p","l","o","n"), ...) {
4041
navail <- nrow(locatorqueue)
4142
popoff <- (seq_len(navail) <= n)
4243
result <- locatorqueue[popoff, , drop=FALSE]
44+
if(!is.null(snap.step))
45+
result[,c("x","y")] <- with(result, snapxy(x, y, snap.step, snap.origin))
4346
locatorqueue <- locatorqueue[!popoff, , drop=FALSE]
4447
putSpatstatLocatorQueue(locatorqueue)
4548
return(as.list(result))
@@ -61,6 +64,8 @@ spatstatLocator <- function(n, type=c("p","l","o","n"), ...) {
6164
while(i<=n){
6265
tmp <- locator(n=1)
6366
if(is.null(tmp)) return(res)
67+
if(!is.null(snap.step))
68+
tmp <- with(tmp, snapxy(x, y, snap.step, snap.origin))
6469
if(do.points)
6570
do.call.matched(points.default, append(tmp, argh), extrargs=pointsArgs)
6671
res$x <- c(res$x,tmp$x)
@@ -74,3 +79,11 @@ spatstatLocator <- function(n, type=c("p","l","o","n"), ...) {
7479
return(res)
7580
}
7681

82+
snapxy <- function(x, y, step=c(1,1), origin=c(0,0)) {
83+
step <- ensure2vector(step)
84+
origin <- ensure2vector(origin)
85+
xx <- origin[1] + step[1] * round((x-origin[1])/step[1])
86+
yy <- origin[2] + step[2] * round((y-origin[2])/step[2])
87+
result <- list(x=xx, y=yy)
88+
return(result)
89+
}

inst/doc/packagesizes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
3030
"2025-03-15" "3.1-3" 42 192 0 3650 2429
3131
"2025-05-15" "3.1-4" 42 193 0 3689 2462
3232
"2025-07-17" "3.1-5" 42 194 0 3703 2462
33+
"2025-07-25" "3.1-5.001" 42 195 0 3716 2462

inst/info/packagesizes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
3030
"2025-03-15" "3.1-3" 42 192 0 3650 2429
3131
"2025-05-15" "3.1-4" 42 193 0 3689 2462
3232
"2025-07-17" "3.1-5" 42 194 0 3703 2462
33+
"2025-07-25" "3.1-5.001" 42 195 0 3716 2462

man/macros/defns.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@
5050
%% ROC paper
5151
\newcommand{\rocketAuthors}{\adrian, \ege and \suman}
5252
\newcommand{\rocpapercite}{Baddeley et al (2025)}
53-
\newcommand{\rocpaper}{Baddeley, A., Rubak, E., Rakshit, S. and Nair, G. (2025) ROC curves for spatial point patterns and presence-absence data. \url{https://doi.org/10.48550/arXiv.2506.03414}.}
53+
\newcommand{\rocpaper}{Baddeley, A., Rubak, E., Rakshit, S. and Nair, G. (2025) ROC curves for spatial point patterns and presence-absence data. \doi{10.48550/arXiv.2506.03414}.}
5454
5555

man/spatstat.utils-internal.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
\alias{short.deparse}
7979
\alias{sideCode}
8080
\alias{singlestring}
81+
\alias{snapxy}
8182
\alias{sortunique}
8283
\alias{startinrange}
8384
\alias{strsplitretain}
@@ -189,6 +190,7 @@ sensiblevarname(guess, fallback, maxlen)
189190
short.deparse(x, maxlen)
190191
sideCode(side, what)
191192
singlestring(s, coll)
193+
snapxy(x, y, step, origin)
192194
sortunique(x)
193195
startinrange(x0, dx, r)
194196
strsplitretain(x, split)

man/spatstatLocator.Rd

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
\code{RStudio}.
1010
}
1111
\usage{
12-
spatstatLocator(n, type = c("p", "l", "o", "n"), \dots)
12+
spatstatLocator(n, type = c("p", "l", "o", "n"), \dots,
13+
snap.step=NULL, snap.origin=c(0,0))
1314
}
1415
\arguments{
1516
\item{n}{
@@ -23,6 +24,16 @@ spatstatLocator(n, type = c("p", "l", "o", "n"), \dots)
2324
\item{\dots}{
2425
Additional graphics parameters used to plot the locations.
2526
}
27+
\item{snap.step}{
28+
Optional. Spatial coordinates will be rounded to the nearest
29+
multiple of \code{snap.step}. A positive number specifying the step
30+
length, or a vector of 2 positive numbers specifying step lengths
31+
for the \eqn{x} and \eqn{y} coordinates.
32+
}
33+
\item{snap.origin}{
34+
Optional. Numeric vector of length 2. Coordinates of the origin
35+
that will be used when rounding coordinates.
36+
}
2637
}
2738
\details{
2839
This is a replacement/workaround for the \code{\link{locator}}
@@ -31,6 +42,9 @@ spatstatLocator(n, type = c("p", "l", "o", "n"), \dots)
3142

3243
See \code{\link[graphics]{locator}} for a description of the
3344
behaviour.
45+
46+
If \code{snap.step} is given, then the coordinates of the selected
47+
locations will be rounded to the nearest multiple of \code{snap.step}.
3448
}
3549
\section{Software Testing}{
3650
Programmers may like to know that

0 commit comments

Comments
 (0)