New upstream version 1.10-0
Andreas Tille
4 years ago
0 | 0 | Package: polyclip |
1 | Version: 1.9-1 | |
2 | Date: 2018-07-25 | |
1 | Version: 1.10-0 | |
2 | Date: 2019-03-13 | |
3 | 3 | Title: Polygon Clipping |
4 | 4 | Authors@R: c(person("Angus", "Johnson", role = "aut", |
5 | 5 | comment="C++ original, http://www.angusj.com/delphi/clipper.php"), |
7 | 7 | email = "Adrian.Baddeley@curtin.edu.au"), |
8 | 8 | person("Kurt", "Hornik", role = "ctb"), |
9 | 9 | 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")) | |
11 | 12 | Maintainer: Adrian Baddeley <Adrian.Baddeley@curtin.edu.au> |
12 | 13 | Depends: R (>= 3.0.0) |
13 | 14 | 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. |
21 | 22 | ByteCompile: true |
22 | 23 | Note: built from Clipper C++ version 6.4.0 |
23 | 24 | NeedsCompilation: yes |
24 | Packaged: 2018-07-25 06:34:32 UTC; adrian | |
25 | Packaged: 2019-03-14 02:16:16 UTC; adrian | |
25 | 26 | Author: Angus Johnson [aut] (C++ original, |
26 | 27 | http://www.angusj.com/delphi/clipper.php), |
27 | 28 | Adrian Baddeley [aut, trl, cre], |
28 | 29 | Kurt Hornik [ctb], |
29 | 30 | Brian D. Ripley [ctb], |
30 | Elliott Sales de Andrade [ctb] | |
31 | Elliott Sales de Andrade [ctb], | |
32 | Paul Murrell [ctb] | |
31 | 33 | 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 | |
1 | 1 | 37524bbc5d7fe03aea01ca24504b3e10 *NAMESPACE |
2 | ee09331bcda4fe0fa5083a132c2d0891 *NEWS | |
2 | 73665bb9596fea5fa59789e108182e35 *NEWS | |
3 | 3 | dee054bf03363f13a034c8b7c319d560 *R/First.R |
4 | 64128cc4b6fbf67371182525360bbfcf *R/clipper.R | |
4 | 0592a5daa3d264800fe805263889a536 *R/clipper.R | |
5 | 5 | 14c7a9772d3b48055cbd8ddd053abbf3 *cleanup |
6 | 6 | 0f418f25e1cd25ed7d0fed7f487d096d *configure |
7 | 7 | a1b9549d277710c34c9fd57e2eb5d453 *configure.ac |
8 | 8 | d41d8cd98f00b204e9800998ecf8427e *configure.win |
9 | 9 | eb4af1e568c5b717a2a731ed417cf5f9 *man/pointinpolygon.Rd |
10 | 215848c9be19696c6ba4bc09eff71cc8 *man/polyclip.Rd | |
10 | 925b3b53c4fd6898419d892476942094 *man/polyclip.Rd | |
11 | 11 | 42c32d9ce87e76d6415660bcce8890c0 *man/polylineoffset.Rd |
12 | 12 | c30b54f6e3c04926235a721032749448 *man/polyminkowski.Rd |
13 | 13 | 3077cd8984bb169ece92b0aba2764d53 *man/polyoffset.Rd |
16 | 16 | 7f5db02b9f569e12d0f2df0ed1b908bb *src/Makevars.win |
17 | 17 | 0258d3c815a6d7b851b2d1dfbeb2afc1 *src/clipper.cpp |
18 | 18 | 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.] | |
0 | 9 | |
1 | 10 | CHANGES IN polyclip VERSION 1.9-1 |
2 | 11 |
63 | 63 | ..., |
64 | 64 | eps, x0, y0, |
65 | 65 | fillA=c("evenodd", "nonzero", "positive", "negative"), |
66 | fillB=c("evenodd", "nonzero", "positive", "negative") | |
66 | fillB=c("evenodd", "nonzero", "positive", "negative"), | |
67 | closed=TRUE | |
67 | 68 | ) { |
68 | 69 | # validate parameters and convert to integer codes |
69 | 70 | op <- match.arg(op) |
81 | 82 | if(validxy(B)) B <- list(B) else |
82 | 83 | stop("Argument B should be a list of lists, each containing vectors x,y") |
83 | 84 | } |
85 | # | |
84 | 86 | # determine value of 'eps' if missing |
85 | 87 | if(missing(eps) || missing(x0) || missing(y0)) { |
86 | 88 | xr <- range(range(unlist(lapply(A, xrange))), |
96 | 98 | B <- ensuredouble(B) |
97 | 99 | storage.mode(ct) <- storage.mode(pftA) <- storage.mode(pftB) <- "integer" |
98 | 100 | storage.mode(x0) <- storage.mode(y0) <- storage.mode(eps) <- "double" |
101 | storage.mode(closed) <- "logical" | |
99 | 102 | ans <- .Call(eCclipbool, |
100 | 103 | A, B, pftA, pftB, ct, |
101 | x0, y0, eps, | |
104 | x0, y0, eps, closed, | |
102 | 105 | PACKAGE="polyclip") |
103 | 106 | return(aspolygonlist(ans)) |
104 | 107 | } |
1 | 1 | \alias{polyclip} |
2 | 2 | \title{Polygon Clipping} |
3 | 3 | \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. | |
5 | 6 | } |
6 | 7 | \usage{ |
7 | 8 | polyclip(A, B, op=c("intersection", "union", "minus", "xor"), |
8 | 9 | \dots, |
9 | 10 | eps, x0, y0, |
10 | 11 | fillA=c("evenodd", "nonzero", "positive", "negative"), |
11 | fillB=c("evenodd", "nonzero", "positive", "negative")) | |
12 | fillB=c("evenodd", "nonzero", "positive", "negative"), | |
13 | closed = TRUE) | |
12 | 14 | } |
13 | 15 | \arguments{ |
14 | 16 | \item{A,B}{ |
15 | 17 | Data specifying polygons. See Details. |
16 | 18 | } |
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 | } | |
18 | 24 | \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 | } | |
22 | 41 | } |
23 | 42 | \value{ |
24 | 43 | Data specifying polygons, in the same format as \code{A} and \code{B}. |
96 | 115 | \code{\link{polylineoffset}}, |
97 | 116 | \code{\link{polyminkowski}} |
98 | 117 | } |
99 | \author{Angus Johnson. | |
118 | \author{ | |
119 | Angus Johnson. | |
100 | 120 | Ported to \R by Adrian Baddeley |
101 | 121 | \email{Adrian.Baddeley@curtin.edu.au}. |
122 | Additional modification by Paul Murrell. | |
102 | 123 | } |
103 | 124 | \examples{ |
104 | 125 | A <- list(list(x=1:10, y=c(1:5,5:1))) |
105 | 126 | 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)) | |
109 | 132 | C <- polyclip(A, B) |
110 | 133 | 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)) | |
111 | 141 | } |
112 | 142 | \references{ |
113 | 143 | Clipper Website: \url{http://www.angusj.com} |
21 | 21 | SEXP ct, |
22 | 22 | SEXP X0, |
23 | 23 | SEXP Y0, |
24 | SEXP Eps); | |
24 | SEXP Eps, | |
25 | SEXP clo); | |
25 | 26 | |
26 | 27 | SEXP Cpolyoffset(SEXP A, |
27 | 28 | SEXP del, |
61 | 62 | |
62 | 63 | static const R_CallMethodDef CallEntries[] = { |
63 | 64 | {"Csimplify", (DL_FUNC) &Csimplify, 5}, |
64 | {"Cclipbool", (DL_FUNC) &Cclipbool, 8}, | |
65 | {"Cclipbool", (DL_FUNC) &Cclipbool, 9}, | |
65 | 66 | {"Cpolyoffset", (DL_FUNC) &Cpolyoffset, 8}, |
66 | 67 | {"Clineoffset", (DL_FUNC) &Clineoffset, 9}, |
67 | 68 | {"Cminksum", (DL_FUNC) &Cminksum, 6}, |
165 | 165 | SEXP ct, |
166 | 166 | SEXP X0, |
167 | 167 | SEXP Y0, |
168 | SEXP Eps | |
168 | SEXP Eps, | |
169 | SEXP clo // whether paths in A are closed | |
169 | 170 | ){ |
170 | 171 | int nA, nB, i, n, m, mi, mitrue; |
172 | bool closed; | |
171 | 173 | double *x, *y, *xx, *yy; |
172 | 174 | SEXP Ai = R_NilValue, Bi = R_NilValue; |
173 | 175 | SEXP out, outi, xouti, youti; |
179 | 181 | // protect arguments from garbage collector |
180 | 182 | PROTECT(A = AS_LIST(A)); |
181 | 183 | PROTECT(B = AS_LIST(B)); |
184 | PROTECT(clo = AS_LOGICAL(clo)); | |
182 | 185 | PROTECT(ct = AS_INTEGER(ct)); |
183 | 186 | PROTECT(pftA = AS_INTEGER(pftA)); |
184 | 187 | PROTECT(pftB = AS_INTEGER(pftB)); |
192 | 195 | |
193 | 196 | // Initialise object containing n polygons |
194 | 197 | Paths polyA(nA), polyB(nB); |
198 | closed = *(LOGICAL_POINTER(clo)); | |
195 | 199 | |
196 | 200 | // Get scale parameters |
197 | 201 | x0 = *(NUMERIC_POINTER(X0)); |
270 | 274 | // perform clipping operation |
271 | 275 | Clipper c; |
272 | 276 | Paths result; |
273 | c.AddPaths(polyA, ptSubject, true); | |
277 | c.AddPaths(polyA, ptSubject, closed); | |
274 | 278 | 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 | } | |
276 | 287 | |
277 | 288 | // number of polygons |
278 | 289 | m = result.size(); |
299 | 310 | } |
300 | 311 | } |
301 | 312 | |
302 | UNPROTECT(9 + 3*m); // 8 arguments + out + m * (outi, xouti, youti) | |
313 | UNPROTECT(10 + 3*m); // 9 arguments + out + m * (outi, xouti, youti) | |
303 | 314 | return(out); |
304 | 315 | } |
305 | 316 | } |