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


No reviews. Create the first review!.

Details by download location


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.


Too long; didn't read

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

2 ?- britain_arrows(xor).


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.


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.