Codebase list r-cran-polyclip / 7f02646
New upstream version 1.10-0 Andreas Tille 4 years ago
7 changed file(s) with 86 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
00 Package: polyclip
1 Version: 1.9-1
2 Date: 2018-07-25
1 Version: 1.10-0
2 Date: 2019-03-13
33 Title: Polygon Clipping
44 Authors@R: c(person("Angus", "Johnson", role = "aut",
55 comment="C++ original, http://www.angusj.com/delphi/clipper.php"),
77 email = "Adrian.Baddeley@curtin.edu.au"),
88 person("Kurt", "Hornik", role = "ctb"),
99 person(c("Brian", "D."), "Ripley", role = "ctb"),
10 person("Elliott", "Sales de Andrade", role="ctb"))
10 person("Elliott", "Sales de Andrade", role="ctb"),
11 person("Paul", "Murrell", role = "ctb"))
1112 Maintainer: Adrian Baddeley <Adrian.Baddeley@curtin.edu.au>
1213 Depends: R (>= 3.0.0)
1314 Description: R port of Angus Johnson's open source library Clipper. Performs polygon clipping operations (intersection, union, set minus, set difference) for polygonal regions of arbitrary complexity, including holes. Computes offset polygons (spatial buffer zones, morphological dilations, Minkowski dilations) for polygonal regions and polygonal lines. Computes Minkowski Sum of general polygons. There is a function for removing self-intersections from polygon data.
2122 ByteCompile: true
2223 Note: built from Clipper C++ version 6.4.0
2324 NeedsCompilation: yes
24 Packaged: 2018-07-25 06:34:32 UTC; adrian
25 Packaged: 2019-03-14 02:16:16 UTC; adrian
2526 Author: Angus Johnson [aut] (C++ original,
2627 http://www.angusj.com/delphi/clipper.php),
2728 Adrian Baddeley [aut, trl, cre],
2829 Kurt Hornik [ctb],
2930 Brian D. Ripley [ctb],
30 Elliott Sales de Andrade [ctb]
31 Elliott Sales de Andrade [ctb],
32 Paul Murrell [ctb]
3133 Repository: CRAN
32 Date/Publication: 2018-07-27 04:30:03 UTC
34 Date/Publication: 2019-03-14 06:20:03 UTC
0 8853e0622d9f66f1cf3c51de6c36e01c *DESCRIPTION
0 9c3f7cc90aa7c36a5c5ef9cfd0bdb5f7 *DESCRIPTION
11 37524bbc5d7fe03aea01ca24504b3e10 *NAMESPACE
2 ee09331bcda4fe0fa5083a132c2d0891 *NEWS
2 73665bb9596fea5fa59789e108182e35 *NEWS
33 dee054bf03363f13a034c8b7c319d560 *R/First.R
4 64128cc4b6fbf67371182525360bbfcf *R/clipper.R
4 0592a5daa3d264800fe805263889a536 *R/clipper.R
55 14c7a9772d3b48055cbd8ddd053abbf3 *cleanup
66 0f418f25e1cd25ed7d0fed7f487d096d *configure
77 a1b9549d277710c34c9fd57e2eb5d453 *configure.ac
88 d41d8cd98f00b204e9800998ecf8427e *configure.win
99 eb4af1e568c5b717a2a731ed417cf5f9 *man/pointinpolygon.Rd
10 215848c9be19696c6ba4bc09eff71cc8 *man/polyclip.Rd
10 925b3b53c4fd6898419d892476942094 *man/polyclip.Rd
1111 42c32d9ce87e76d6415660bcce8890c0 *man/polylineoffset.Rd
1212 c30b54f6e3c04926235a721032749448 *man/polyminkowski.Rd
1313 3077cd8984bb169ece92b0aba2764d53 *man/polyoffset.Rd
1616 7f5db02b9f569e12d0f2df0ed1b908bb *src/Makevars.win
1717 0258d3c815a6d7b851b2d1dfbeb2afc1 *src/clipper.cpp
1818 4d17faf8f89d71d1bbc47e04ef4ea84e *src/clipper.h
19 f39cf6255e43cc3a0f8d536aae965d0b *src/init.c
20 0e50ef71b20acd0560a25f0b5e460d9a *src/interface.cpp
19 2eef7d16e5ddda371b5fa24518f4cfbb *src/init.c
20 6df32a821e4dd8121f078b919ec9d72b *src/interface.cpp
0
1 CHANGES IN polyclip VERSION 1.10-0
2
3 SIGNIFICANT USER-VISIBLE CHANGES
4
5 o polyclip
6 Now handles polygonal lines as well as closed polygons.
7 New argument 'closed' specifies whether A is a closed polygon.
8 [Thanks to Paul Murrell.]
09
110 CHANGES IN polyclip VERSION 1.9-1
211
6363 ...,
6464 eps, x0, y0,
6565 fillA=c("evenodd", "nonzero", "positive", "negative"),
66 fillB=c("evenodd", "nonzero", "positive", "negative")
66 fillB=c("evenodd", "nonzero", "positive", "negative"),
67 closed=TRUE
6768 ) {
6869 # validate parameters and convert to integer codes
6970 op <- match.arg(op)
8182 if(validxy(B)) B <- list(B) else
8283 stop("Argument B should be a list of lists, each containing vectors x,y")
8384 }
85 #
8486 # determine value of 'eps' if missing
8587 if(missing(eps) || missing(x0) || missing(y0)) {
8688 xr <- range(range(unlist(lapply(A, xrange))),
9698 B <- ensuredouble(B)
9799 storage.mode(ct) <- storage.mode(pftA) <- storage.mode(pftB) <- "integer"
98100 storage.mode(x0) <- storage.mode(y0) <- storage.mode(eps) <- "double"
101 storage.mode(closed) <- "logical"
99102 ans <- .Call(eCclipbool,
100103 A, B, pftA, pftB, ct,
101 x0, y0, eps,
104 x0, y0, eps, closed,
102105 PACKAGE="polyclip")
103106 return(aspolygonlist(ans))
104107 }
11 \alias{polyclip}
22 \title{Polygon Clipping}
33 \description{
4 Find intersection, union or set difference of two polygonal regions.
4 Find intersection, union or set difference of two polygonal regions
5 or polygonal lines.
56 }
67 \usage{
78 polyclip(A, B, op=c("intersection", "union", "minus", "xor"),
89 \dots,
910 eps, x0, y0,
1011 fillA=c("evenodd", "nonzero", "positive", "negative"),
11 fillB=c("evenodd", "nonzero", "positive", "negative"))
12 fillB=c("evenodd", "nonzero", "positive", "negative"),
13 closed = TRUE)
1214 }
1315 \arguments{
1416 \item{A,B}{
1517 Data specifying polygons. See Details.
1618 }
17 \item{op}{Set operation to be performed to combine \code{A} and \code{B}.}
19 \item{op}{
20 Set operation to be performed to combine \code{A} and \code{B}.
21 One of the character strings \code{"intersection"},
22 \code{"union"}, \code{"minus"} or \code{"xor"} (partially matched).
23 }
1824 \item{\dots}{Ignored.}
19 \item{eps}{Spatial resolution for coordinates.}
20 \item{x0,y0}{Spatial origin for coordinates.}
21 \item{fillA,fillB}{Polygon-filling rule for \code{A} and \code{B}.}
25 \item{eps}{
26 Spatial resolution for coordinates. A single positive
27 numeric value.
28 }
29 \item{x0,y0}{Spatial origin for coordinates. Numeric values.}
30 \item{fillA,fillB}{
31 Polygon-filling rules for \code{A} and \code{B}.
32 Each argument is one of the character strings
33 \code{"evenodd"}, \code{"nonzero"}, \code{"positive"} or
34 \code{"negative"} (partially matched).
35 }
36 \item{closed}{
37 Logical value specifying whether \code{A} is a
38 closed polygon (\code{closed=TRUE}, the default)
39 or an open polyline (\code{closed=FALSE}).
40 }
2241 }
2342 \value{
2443 Data specifying polygons, in the same format as \code{A} and \code{B}.
96115 \code{\link{polylineoffset}},
97116 \code{\link{polyminkowski}}
98117 }
99 \author{Angus Johnson.
118 \author{
119 Angus Johnson.
100120 Ported to \R by Adrian Baddeley
101121 \email{Adrian.Baddeley@curtin.edu.au}.
122 Additional modification by Paul Murrell.
102123 }
103124 \examples{
104125 A <- list(list(x=1:10, y=c(1:5,5:1)))
105126 B <- list(list(x=c(2,8,8,2),y=c(0,0,10,10)))
106 plot(c(0,10),c(0,10), type="n", axes=FALSE, xlab="", ylab="")
107 polygon(A[[1]])
108 polygon(B[[1]])
127
128 plot(c(0,10),c(0,10), type="n", axes=FALSE,
129 xlab="", ylab="", main="intersection of closed polygons")
130 invisible(lapply(A, polygon))
131 invisible(lapply(B, polygon))
109132 C <- polyclip(A, B)
110133 polygon(C[[1]], lwd=3, col=3)
134
135 plot(c(0,10),c(0,10), type="n", axes=FALSE,
136 xlab="", ylab="", main="intersection of open polyline and closed polygon")
137 invisible(lapply(A, polygon))
138 invisible(lapply(B, polygon))
139 E <- polyclip(A, B, closed=FALSE)
140 invisible(lapply(E, lines, col="purple", lwd=5))
111141 }
112142 \references{
113143 Clipper Website: \url{http://www.angusj.com}
2121 SEXP ct,
2222 SEXP X0,
2323 SEXP Y0,
24 SEXP Eps);
24 SEXP Eps,
25 SEXP clo);
2526
2627 SEXP Cpolyoffset(SEXP A,
2728 SEXP del,
6162
6263 static const R_CallMethodDef CallEntries[] = {
6364 {"Csimplify", (DL_FUNC) &Csimplify, 5},
64 {"Cclipbool", (DL_FUNC) &Cclipbool, 8},
65 {"Cclipbool", (DL_FUNC) &Cclipbool, 9},
6566 {"Cpolyoffset", (DL_FUNC) &Cpolyoffset, 8},
6667 {"Clineoffset", (DL_FUNC) &Clineoffset, 9},
6768 {"Cminksum", (DL_FUNC) &Cminksum, 6},
165165 SEXP ct,
166166 SEXP X0,
167167 SEXP Y0,
168 SEXP Eps
168 SEXP Eps,
169 SEXP clo // whether paths in A are closed
169170 ){
170171 int nA, nB, i, n, m, mi, mitrue;
172 bool closed;
171173 double *x, *y, *xx, *yy;
172174 SEXP Ai = R_NilValue, Bi = R_NilValue;
173175 SEXP out, outi, xouti, youti;
179181 // protect arguments from garbage collector
180182 PROTECT(A = AS_LIST(A));
181183 PROTECT(B = AS_LIST(B));
184 PROTECT(clo = AS_LOGICAL(clo));
182185 PROTECT(ct = AS_INTEGER(ct));
183186 PROTECT(pftA = AS_INTEGER(pftA));
184187 PROTECT(pftB = AS_INTEGER(pftB));
192195
193196 // Initialise object containing n polygons
194197 Paths polyA(nA), polyB(nB);
198 closed = *(LOGICAL_POINTER(clo));
195199
196200 // Get scale parameters
197201 x0 = *(NUMERIC_POINTER(X0));
270274 // perform clipping operation
271275 Clipper c;
272276 Paths result;
273 c.AddPaths(polyA, ptSubject, true);
277 c.AddPaths(polyA, ptSubject, closed);
274278 c.AddPaths(polyB, ptClip, true);
275 c.Execute(cliptype, result, filltypeA, filltypeB);
279
280 if (closed) {
281 c.Execute(cliptype, result, filltypeA, filltypeB);
282 } else {
283 PolyTree polyTreeResult;
284 c.Execute(cliptype, polyTreeResult, filltypeA, filltypeB);
285 OpenPathsFromPolyTree(polyTreeResult, result);
286 }
276287
277288 // number of polygons
278289 m = result.size();
299310 }
300311 }
301312
302 UNPROTECT(9 + 3*m); // 8 arguments + out + m * (outi, xouti, youti)
313 UNPROTECT(10 + 3*m); // 9 arguments + out + m * (outi, xouti, youti)
303314 return(out);
304315 }
305316 }