GithubHelp home page GithubHelp logo

baddstats / polyclip Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 6.0 150 KB

R package polyclip: a port of the Clipper library for polygon geometry

R 4.94% Shell 0.02% M4 2.00% C++ 92.25% C 0.79%
clipper polygon-clipping-algorithm polygon-intersection polygon-union polygon-offsetting polygons r minkowski-sum cran 64-bit

polyclip's Introduction

polyclip

Travis-CI Build Status codecov.io CRAN_Status_Badge Research software impact

This repository holds the contributed R-package polyclip, which is an R port of Angus Johnson's library Clipper for polygon clipping.

Version of Clipper Library

This version of polyclip is derived from Clipper C++ library version 6.4.0 [r496] which was obtained from the Sourceforge repository (click Code then Download snapshot). Minor changes have been made to the C++ code to satisfy the requirements for R packages (namely, data type declarations must be portable, and error messages must go through R's error handler).

Note: If your system already includes the polyclipping library (another derivative of clipper) then that version of the library will be used. That is, the R package polyclip will be compiled against the executable library polyclipping on your system, rather than using the bundled source code of clipper 6.4.0 that comes with the polyclip sources.

Installation

The current official release of polyclip is available on CRAN and can be downloaded and installed automatically using the R command install.packages.

The code in this repository is the development version, which may be newer than the official release. The easiest way to install the development version of polyclip from github is through the remotes package:

require(remotes)
install_github('baddstats/polyclip')

If you don't have remotes installed you should first run

install.packages('remotes')

Bug reports

Users of polyclip are encouraged to report bugs here (go to issues in the menu above, and press new issue to start a new bug report or feature request).

Making your own changes

Feel free to fork polyclip, make changes to the code, and ask us to include them in the package by making a github pull request.

polyclip's People

Contributors

baddstats avatar pmur002 avatar qulogic avatar richierocks avatar rubak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

polyclip's Issues

Upgrade to clipper2?

Just wondering if you've considered upgrading to clipper2. It really is a huge improvement! If so, I would also like to ask whether you'd consider a large-scale restructure through bundling a vendored version of cpp11, instead of current configure files? I would argue the sole advantage there that any bugs in compiling and/or installing would then become effectively shared bugs through being traced back to cpp11, so any problems with your build system would be shared within a much larger community than this package alone.

Here is an example of it in action (using old clipper1). Direct interfaces with ClipperLib remain very similar to your current ones, but no longer need any of the C interfaces to SEXP objects. Your code would be considerably simpler, the package could still remain dependency-free, and as far I see it, there'd only be one potential disadvantage of relying on ongoing functionality of external cpp11 code, but that has the advantage described above, and alleviates the disadvantages of currently fragile build system. Interested to hear your thoughts?

Unable to install ployclip under conda environment, with R 3.6.1

install.packages("polyclip")

Error log:

试开URLhttps://cran.rstudio.com/src/contrib/polyclip_1.10-0.tar.gz'
Content type 'application/x-gzip' length 79619 bytes (77 KB)
==================================================
downloaded 77 KB

* installing *source* package ‘polyclip’ ...
** 成功将‘polyclip’程序包解包并MD5和检查
** using staged installation
compiling under C++11
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `/private/var/folders/_v/vxb6s8jn12d_zpc2_4g3t6bc0000gn/T/RtmpfOOyE6/R.INSTALL3da133a3cdc7/polyclip':
configure: error: cannot run C++ compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
ERROR: configuration failed for packagepolyclip* removing/Users/it00002977/miniconda3/lib/R/library/polyclipWarning in install.packages :
  installation of packagepolycliphad non-zero exit status

The downloaded source packages are in/private/var/folders/_v/vxb6s8jn12d_zpc2_4g3t6bc0000gn/T/RtmpqeYUaU/downloaded_packagesUpdating HTML index of packages in '.Library'
Making 'packages.html' ... done

My conda version: 4.7.11
System info:
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

configure: error: C++ compiler cannot create executables

In "R version 4.2.3 (2023-03-15)" on Ubuntu 22.04.2 LTS, with 'GNU Fortran (Ubuntu 11.3.0-1ubuntu122.04) 11.3.0' and g++ (Ubuntu 11.3.0-1ubuntu122.04) 11.3.0 and gcc (Ubuntu 11.3.0-1ubuntu122.04) 11.3.0 and c++ (Ubuntu 11.3.0-1ubuntu122.04) 11.3.0.
I am trying to install 'polyclip' using these commands in R

require(remotes)
install_github('baddstats/polyclip')

But I get this error message:

install_github('baddstats/polyclip')
Downloading GitHub repo baddstats/polyclip@HEAD
── R CMD build ───────────────────────────────────────────────────────────────────────────
✔ checking for file ‘/tmp/RtmpVrDvtR/remotes2736c10a23e2/baddstats-polyclip-5c5404a/DESCRIPTION’ ...
─ preparing ‘polyclip’:
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ running ‘cleanup’
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘polyclip_1.10-4.tar.gz’

Installing package into ‘/home/hal9000/R/x86_64-pc-linux-gnu-library/4.2’
(as ‘lib’ is unspecified)

  • installing source package ‘polyclip’ ...
    ** using staged installation
    Rscript execution error: No such file or directory
    compiling under C++11
    checking whether the C++ compiler works... no
    configure: error: in /tmp/Rtmp9wfYJH/R.INSTALL27ff8776a7b3e/polyclip': configure: error: C++ compiler cannot create executables See config.log' for more details
    ERROR: configuration failed for package ‘polyclip’
  • removing ‘/home/hal9000/R/x86_64-pc-linux-gnu-library/4.2/polyclip’
  • restoring previous ‘/home/hal9000/R/x86_64-pc-linux-gnu-library/4.2/polyclip’
    Warning message:
    In i.p(...) :
    installation of package ‘/tmp/RtmpVrDvtR/file2736ccf8cfeb/polyclip_1.10-4.tar.gz’ had non-zero exit status

Cannot build CRAN version on Archlinux

It seems I cannot build the latest version of polyclip from CRAN:

polyclip  (1.9-1        -> 1.10-0      ) [CRAN]
* installing *source* package ‘polyclip’ ...
** package ‘polyclip’ successfully unpacked and MD5 sums checked
compiling under C++11
checking whether the C++ compiler works... no
configure: error: in `/tmp/RtmpBWZVcr/R.INSTALL5a5c1b30658f/polyclip':
configure: error: C++ compiler cannot create executables
See `config.log' for more details
ERROR: configuration failed for package ‘polyclip’

All other packages get built properly, do you have any idea why this version cannot compile? My system (ArchLinux) is up to date, using gcc 8.2.1+20181127-1.

EDIT: cannot build GH version either:

Downloading GitHub repo baddstats/polyclip@master
✔  checking for file ‘/tmp/RtmpOQ14Nf/remotes7b0f46cf3775/baddstats-polyclip-b761add/DESCRIPTION’ ...
─  preparing ‘polyclip’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  running ‘cleanup’
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘polyclip_1.10-0.tar.gz’
   
Installing package into ‘/home/adriano/.R_libs’
(as ‘lib’ is unspecified)
* installing *source* package ‘polyclip’ ...
compiling under C++11
checking whether the C++ compiler works... no
configure: error: in `/tmp/RtmpK9z9GQ/R.INSTALL75a631b8e67c/polyclip':
configure: error: C++ compiler cannot create executables
See `config.log' for more details
ERROR: configuration failed for package ‘polyclip’

Undo reversion of .Call() arguments

You may recall that ployclip is used in the Spatial Statistics in R DataCamp course. Last year, when we were making that course, I made some updates to polyclip's .Call() routines to add a PACKAGE argument. This was necessary to make the package work on our platform.

I've just been making some updates to that course and unfortunately, the latest version of polyclip doesn't work. It look like the changes to .Call() were reverted back in March.

f1fff8c#diff-c0145812160455f0558c81a96c08e975

Is there a reason for this? Are you happy to undo the reversion?

Expose PointInPolygon and other helpers

While my own interest is mainly in PointInPolygon, there are other helpers which would be nice to have access to from R, such as Area, Poly2ContainsPoly1, and IntersectPoint

Problem compiling polyclip against system copy of polyclipping

User @iembry posted the following message:

Hi, the CRAN version of polyclip on a GNU/Linux Ubuntu-based distribution has failed for me.

I have not tried the GitHub version yet.

> install.packages("polyclip")
Installing package into ‘library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/polyclip_1.9-0.tar.gz'
Content type 'application/x-gzip' length 78996 bytes (77 KB)
==================================================
downloaded 77 KB

* installing *source* package ‘polyclip’ ...
** package ‘polyclip’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
compiling under C++11
Using PKG_CONFIG: pkg-config
Compiling against system copy of polyclipping library.
configure: creating ./config.status
config.status: creating src/Makevars
** libs
ccache gcc -I"/usr/share/R/include" -DNDEBUG -I/usr/include/polyclipping   -DPOLYCLIP_LONG64="signed long long" -DPOLYCLIP_ULONG64="unsigned long long"     -fpic  -std=gnu99 -Wall -pedantic -c init.c -o init.o
ccache g++ -std=c++11 -I"/usr/share/R/include" -DNDEBUG -I/usr/include/polyclipping   -DPOLYCLIP_LONG64="signed long long" -DPOLYCLIP_ULONG64="unsigned long long"    -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c interface.cpp -o interface.o
ccache g++ -std=c++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o polyclip.so init.o interface.o -lpolyclipping -L/usr/lib/R/lib -lR
installing to library/polyclip/libs
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘polyclip’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object 'library/polyclip/libs/polyclip.so':
  library/polyclip/libs/polyclip.so: undefined symbol: _ZN10ClipperLib12MinkowskiSumERKSt6vectorINS_8IntPointESaIS1_EERKS0_IS3_SaIS3_EERS7_b
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘library/polyclip’

The downloaded source packages are in
        ‘/tmp/Rtmp2qGS9a/downloaded_packages’
Warning message:
In install.packages("polyclip") :
  installation of package ‘polyclip’ had non-zero exit status

conda install error

Hello Team,

It seems under conda environment, it cannot be installed:

installing source package ‘polyclip’ ...
** using staged installation
compiling under C++11
checking whether the C++ compiler works... no
configure: error: in /tmp/RtmpX79Rc1/R.INSTALL7dc05967a6f2/polyclip': configure: error: C++ compiler cannot create executables See config.log' for more details
ERROR: configuration failed for package ‘polyclip’

  • removing ‘/condo/ieg/jianshu/miniconda3_new2/lib/R/library/polyclip’
    Warning message:
    In i.p(...) :
    installation of package ‘/tmp/Rtmp8cATiW/file7d4f6b03cf34/polyclip_1.10-4.tar.gz’ had non-zero exit status

I do have everything including gcc, g++, C++, c++, CC, CC in my conda environment.

Thanks,

Jianshu

Allow B to be open in polyclip()

The addition of the closed argument in polyclip() is great. It would be really nice if it was possible to also allow the B component to be a path instead of a polygon, so that it is possible to cut lines and polygons

Error when compiling package in Ubuntu 16.04

Console output:

  • installing source package ‘polyclip’ ...
    ** package ‘polyclip’ successfully unpacked and MD5 sums checked
    checking for g++... g++
    checking whether the C++ compiler works... yes
    checking for C++ compiler default output file name... a.out
    checking for suffix of executables...
    checking whether we are cross compiling... no
    checking for suffix of object files... o
    checking whether we are using the GNU C++ compiler... yes
    checking whether g++ accepts -g... yes
    compiling under C++11
    Using PKG_CONFIG: pkg-config
    Compiling against bundled copy of clipper library.
    In the clipper library, signed 64-bit integers (cInt)
    will be declared as 'signed long long'
    In the clipper library, unsigned 64-bit integers (cUInt)
    will be declared as 'unsigned long long'
    configure: creating ./config.status
    config.status: creating src/Makevars
    ** libs
    Makevars:3: *** missing separator. Stop.
    ERROR: compilation failed for package ‘polyclip’

Installation failed from CRAN

I am using Microsoft R Open 3.5 on MacOS 10.13.5 and want to install polyclip from CRAN, but it failed. The error log is like the following:

* installing *source* package ‘polyclip’ ...
** package ‘polyclip’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
compiling under C++11
Using PKG_CONFIG: 
Compiling against bundled copy of clipper library.
     In the clipper library, signed 64-bit integers (cInt)
     will be declared as 'signed long long'
     In the clipper library, unsigned 64-bit integers (cUInt)
     will be declared as 'unsigned long long'
configure: creating ./config.status
config.status: creating src/Makevars
** libs
Makevars:3: *** target pattern contains no `%'.  Stop.
ERROR: compilation failed for package ‘polyclip’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5.0-MRO/Resources/library/polyclip’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5.0-MRO/Resources/library/polyclip’
Warning in install.packages :
  installation of package ‘polyclip’ had non-zero exit status

However, if I install the package from GitHub install_github('baddstats/polyclip'), everything works fine. I wonder whether it is because the version on CRAN has some minor issues?

> devtools::install_github('baddstats/polyclip')
Downloading GitHub repo baddstats/polyclip@master
from URL https://api.github.com/repos/baddstats/polyclip/zipball/master
Installing polyclip
'/Library/Frameworks/R.framework/Resources/bin/R'  \
  --no-site-file --no-environ --no-save  \
  --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/1v/wz_prgn52n91b5x1byjxwnl00000gn/T/RtmphT10uh/devtools14e468d99c59/baddstats-polyclip-d5dc5e2'  \
  --library='/Library/Frameworks/R.framework/Versions/3.5.0-MRO/Resources/library'  \
  --install-tests 

* installing *source* package ‘polyclip’ ...
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
compiling under C++11
Using PKG_CONFIG: 
Compiling against bundled copy of clipper library.
     In the clipper library, signed 64-bit integers (cInt)
     will be declared as 'signed long long'
     In the clipper library, unsigned 64-bit integers (cUInt)
     will be declared as 'unsigned long long'
configure: creating ./config.status
config.status: creating src/Makevars
** libs
/usr/local/clang4/bin/clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -DPOLYCLIP_LONG64="signed long long" -DPOLYCLIP_ULONG64="unsigned long long"  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include   -fPIC  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include  -c init.c -o init.o
/usr/local/clang4/bin/clang++ -std=gnu++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -DPOLYCLIP_LONG64="signed long long" -DPOLYCLIP_ULONG64="unsigned long long"  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include -fPIC  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include -c interface.cpp -o interface.o
/usr/local/clang4/bin/clang++ -std=gnu++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -DPOLYCLIP_LONG64="signed long long" -DPOLYCLIP_ULONG64="unsigned long long"  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include -fPIC  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include -c clipper.cpp -o clipper.o
/usr/local/clang4/bin/clang++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib/gcc/7 -o polyclip.so init.o interface.o clipper.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.5.0-MRO/Resources/library/polyclip/libs
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (polyclip)

A Reduce-like interface to polyclip()

I often need to combine multiple shapes, e.g. following a triangulation. With the current API it is only possible to combine two polygons in one go, and I'll end up writing something like

Reduce(function(a, b) {
  polyclip(a, b, op = 'union')
}, polygons)

With many polygons to merge this loop will become a bottleneck and it would be nice if polyclip exposed this api more efficiently...

One idea would be to check if B is NULL and if that is the case then just perform the clipping operation successively on the elements of A

Can't install on CentOS-7

Hello Adrain,

I can't install the polyclip package on R version 3.6.0 running on CentOS-7.

I've tried the following:

  1. install.packages("polyclip")

    which fails with

   Rscript execution error: No such file or directory
   compiling under C++11
   checking whether the C++ compiler works... no
  1. install_github('baddstats/polyclip')

    which fails with

   Rscript execution error: No such file or directory
   compiling under C++11
   checking whether the C++ compiler works... no

  1. install_github('baddstats/[email protected]')

    which gets a little further, but still fails with

   checking for g++... g++
   checking whether the C++ compiler works... yes

   g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -DPOLYCLIP_LONG64="signed long long" -DPOLYCLIP_ULONG64="unsigned long long"  -I/usr/local/include ERROR: no information for variable 'CXX1XFLAGS' -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c clipper.cpp -o clipper.o
   g++: error: ERROR:: No such file or directory
   g++: error: no: No such file or directory
   g++: error: information: No such file or directory
   g++: error: for: No such file or directory
   g++: error: variable: No such file or directory
   g++: error: CXX1XFLAGS: No such file or directory

Notice how an error message seems to be contained in the g++ compile command in failure 3 above.

I downloaded the source to try to configure that. If I look at the config.log file I find strange things like

configure:2057: g++ -V >&5
g++: error: unrecognized command line option '-V'
g++: fatal error: no input files
compilation terminated.
configure:2068: $? = 4
configure:2057: g++ -qversion >&5
g++: error: unrecognized command line option '-qversion'
g++: fatal error: no input files

It seems to be trying to execute g++ -qversion instead of g++ --version. I have

g++ --version
  g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

Do you have any advice on how I might fix these problems?

Thanks,

Paul

Clipping of paths

As it is now, polyclip() consider the input paths closed. Would you consider either making a switch to control how the paths should be considered or make a polylineclip() function as well?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.