Tag: polygon

Polygon | new package 3.0.4a

The source  package for Polygon 3.0.4 was missing a lot of files. This was caused by a bug in python’s setuptools package. I packaged a new file for version 3.0.4a . The source code was not changed but the contents should be complete now. Sorry for any problems you had with this issue!

Polygon | 2.0.4 & 3.0.4

New versions of my python package Polygon have been released today for python 2 and python 3. The source can be checked out from https://svn.origo.ethz.ch/polygon/tags/2.0.4/ and https://svn.origo.ethz.ch/polygon/tags/3.0.4/ , binary packages will follow in the next days.

The changes include:

  • added a function Utils.gpfInfo() to check files for the number of contours, holes and points and the hole flag
  • updated the documentation about the handling of files with the optional hole flag
  • fixed a bug in the function IO.writeSVG()
  • 3.0.4: fixed a bug in the function IO.encodeBinary()

Polygon used in new VPython

I’m glad to see that the Polygon package is now used by the popular VPython software to support the creation of the new extrusion objects.

The VPython authors even made a special license agreement that allows the use of GPC (and thus Polygon) free of charge for every purpose as part of the VPython distribution:

Polygon is being distributed subject to the following conditions: This distribution contains code from the GPC Library, and/or code resulting from the use of the GPC Library. This usage has been authorized by The University of Manchester, on the understanding that the GPC-related features are used only in the context of this distribution. It is not permitted to extract the GPC code from the distribution as the basis for commercial exploitation, unless a GPC Commercial Use Licence is obtained from The University of Manchester, contact: http://www.cs.man.ac.uk/~toby/gpc/

Polygon | reading and writing gpc files

A user pointed me to a problem when reading and writing gpc files. GPC understands two kinds of files, with or without hole-flags. Polygon supports both formats, but this was not yet documented. When using the Polygon() constructor with a filename or the read() or write() methods you may specify an optional  second boolean argument. It defaults to True (with hole-flags), with False you may read and write the old-style formats without hole-flags.

Caution: the file format will not be checked automatically! When using the wrong settings the coordinates read from file may be incorrect!

The next release of Polygon will contain updated documentation and a function to manually check the format of a gpc file.

Polygon | 2.0.3 & 3.0.3

Versions 2.0.3 and 3.0.3 of this python package have been released today. Both branches 2.0.x (for python 2.x, x>=5) and 3.0.3 (for python 3.x)  will be in sync in the future with identical features and an  almost identical API.

For 2.0.3 only one new function (tileBSP()) was added. Have a look here for more information.

3.0.3 is the first version of the 3.0 branch that has almost all the features of the corresponding 2.0 branch. Support for generic attributes is still missing and the file-like objects are not yet replaced by the new stream functions.

The number of projects, programmers  and companies that use Polygon is still growing.  I’m glad to hear that Polygon may be included in vpython in the near future.



Polygon logo|View all articles regarding Polygon|

Polygon is a Python package that handles polygonal shapes in 2D. It contains Python bindings for gpc, the excellent General Polygon Clipping Library by Alan Murta and some extensions written in C and pure Python. With Polygon you may handle complex polygonal shapes in Python in a very intuitive way. Polygons are simple Python objects, clipping operations are bound to standard operators like +, -, |, & and ^. TriStrips can be constructed from Polygons with a single statement. Functions to compute the area, center point, convex hull, point containment and much more are included.

Points can be organized in tuples or lists. NumPy arrays are also supported but Polygon can be compiled without support for it.

This package was already used to process shapes with more than one million points!

  • License: LGPL (not for gpc itself, see below!)
  • Status: Should be almost stable now, but there may be memory leaks. Malformed files and illegal contours may crash the library and your running Python interpreter! Use Polygon at your own risk or don’t use it at all!
  • gpc-Homepage: http://www.cs.man.ac.uk/~toby/alan/software/

gpc is included in Polygon, you don’t need to download it separately. I made two small changes to gpc:

  1. fixed warnings regarding a printf format string and
  2. made GPC_EPSILON adjustable, this may slow down the clipping a little bit.

The author of gpc (Alan Murta) is not responsible for this distribution! The wrapping and extension code is free software, but the core gpc library is free for non-commercial usage only. The author says:

GPC is free for non-commercial use only. We invite non-commercial users to make a voluntary donation towards the upkeep of GPC. If you wish to use GPC in support of a commercial product, you must obtain an official GPC Commercial Use Licence from The University of Manchester.

Please respect this statement and contact the author (see gpc homepage) if you wish to use this software in commercial projects!

Download, Documentation & Examples

The package can be downloaded from the Python Package Index PyPI:

  • Polygon3 for Python 3.1 and newer
  • Polygon2 for Python 2.6 and 2.7 – old and unmaintained!

The development files as well as documentation and examples are hosted at bitbucket.  There are two different projects:


Operations Example
Reduce Points Example
Tiling Example
Exploded Cookie
Star Cookie Example
Sierpinski Carpet Example (level 5)