Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | Generic polygon clipper |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 1.2.0 |
SHA1 sum: | a8f73fde233fe2aa3a56faa08e0162c067f91bbe |
Author: | Roy Ratcliffe <royratcliffe@me.com> |
Maintainer: | Roy Ratcliffe <royratcliffe@me.com> |
Packager: | Roy Ratcliffe <royratcliffe@me.com> |
Home page: | https://github.com/royratcliffe/gpc |
Download URL: | https://github.com/royratcliffe/gpc/releases/*.zip |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
1.0.1 | 99b6f896d635d60e4db9b7a503d26c7a70aba119 | 11 | https://github.com/royratcliffe/gpc/archive/1.0.1.zip |
1.1.0 | 7e93b2c1edb2df2b83ae3082b411b448f9bc5003 | 3 | https://github.com/royratcliffe/gpc/archive/1.1.0.zip |
1.2.0 | 34a3d2fca23829ccab23166aa35ce10e79752926 | 38 | https://github.com/royratcliffe/gpc/archive/1.2.0.zip |
a8f73fde233fe2aa3a56faa08e0162c067f91bbe | 34 | https://github.com/royratcliffe/gpc.git |
Alan Murta of Manchester University, United Kingdom, wrote a very useful [generic two-dimensional polygon clipper][gpc]. Cheers Alan. Nice work. This is a Prolog wrapper for his GPC tool.
[gpc]:http://www.cs.man.ac.uk/~toby/alan/software/gpc.html
1 ?- [library(gpc/demos)]. true. 2 ?- britain_arrows(xor). true.
![snipping](prolog/gpc/britain-arrows-xor.PNG)
Implements polygons as mutable BLOBs. Tempting to make a purely functional interface with no side effects. However, the underlying implementation maintains mutable polygon entities. Decision is to include pure functional predicates (side-effect free) using arity.
Mutability makes some assumptions about threading. Polygons are not thread safe. Provide suitable atomic locking, e.g. using [mutexes][threadsync], if you want to synchronise access to the same polygon across multiple threads.
[threadsync]:http://www.swi-prolog.org/pldoc/man?section=threadsync
The underlying interface uses a flag to indicate the difference
in-between external or internal contours. The Prolog implementation here uses
external and hole functors with a single list argument comprising vertex(X, Y)
elements.
There are no modifications, except to substitute standard memory allocation requests for Prolog allocations. The GPC sources do not permit a redefinition. Consequently, it now also includes the SWI-Prolog header.
The GPC code also uses fscanf()
while ignoring the return value. In other
words, it ignores errors and could fail by seeing random stack-based values that
do not represent true scanned values. Worked around this by quieting the warning
(unused-result
) but also by avoiding use of the gpc_read_polygon()
function.
Note that you can easily attach the pack, build and run it directly from a local repo clone using the following queries. These work on Windows, Mac and Linux. Change `~/Documents/GitHub` to wherever you have cloned the repo; the parent folder, not the repo folder itself.
?- expand_file_name('~/Documents/GitHub', [Packs]), attach_packs(Packs). ?- pack_rebuild(gpc). ?- [library(gpc)]. ?- load_test_files([]). ?- run_tests.
Pack contains 28 files holding a total of 143K bytes.