Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "gpc"

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

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
1.0.199b6f896d635d60e4db9b7a503d26c7a70aba11911https://github.com/royratcliffe/gpc/archive/1.0.1.zip
1.1.07e93b2c1edb2df2b83ae3082b411b448f9bc50033https://github.com/royratcliffe/gpc/archive/1.1.0.zip
1.2.034a3d2fca23829ccab23166aa35ce10e7975292638https://github.com/royratcliffe/gpc/archive/1.2.0.zip
a8f73fde233fe2aa3a56faa08e0162c067f91bbe34https://github.com/royratcliffe/gpc.git

Generic Polygon Clipper

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

Too long; didn't read

1 ?- [library(gpc/demos)].
true.

2 ?- britain_arrows(xor).
true.

![snipping](prolog/gpc/britain-arrows-xor.PNG)

Polygon types in Prolog

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

External and hole contours

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.

Modifications to the GPC sources

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.

Building and testing

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.

Contents of pack "gpc"

Pack contains 28 files holding a total of 143K bytes.