GithubHelp home page GithubHelp logo

royratcliffe / gpc Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 2.0 90 KB

Prolog wrapper for Generic Polygon Clipper tool

Home Page: https://www.swi-prolog.org/pack/list?p=gpc

License: Other

Makefile 0.38% C 83.85% Prolog 11.89% Gnuplot 3.87%
prolog polygon clipping

gpc's Introduction

Generic Polygon Clipper

Alan Murta of Manchester University, United Kingdom, wrote a very useful generic two-dimensional polygon clipper. Cheers Alan. Nice work. This is a Prolog wrapper for his GPC tool.

Too long; didn't read

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

2 ?- britain_arrows(xor).
true.

snipping

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, 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.

gpc's People

Contributors

royratcliffe avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.