View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Eric Wilhelm > Math-Geometry-Planar-GPC-Polygon-0.05 > Math::Geometry::Planar::GPC::Polygon



Annotate this POD


New  3
Open  0
Stalled  1
View/Report Bugs
Module Version: 0.05   Source  


Math::Geometry::Planar::GPC::Polygon - OO wrapper to gpc library

Status ^

Successfully used in minor production use under perl 5.6.1 and 5.8.3. Your mileage may vary (see NO WARRANTY.)


  Eric L. Wilhelm
  ewilhelm at sbcglobal dot net

Copyright ^

Copyright 2004 Eric L. Wilhelm

License ^

This module and its C source code (functions.c) are distributed under the same terms as Perl. See the Perl source package for details.

You may use this software under one of the following licenses:

  (1) GNU General Public License
    (found at
  (2) Artistic License
    (found at

The General Polygon Clipping library (gpc.c and gpc.h) is distributed as "free for non-commercial use". See gpc.c for details. A copy of these files has been included with this distribution strictly for convenience purposes, but YOU ARE RESPONSIBLE FOR ADHERING TO BOTH THE GPC LICENSE AND THE LICENSE OF THIS MODULE. Note that the C library is authored by Alan Murta.

You may want to check the GPC home page for a more current version:

Portability ^

This module successfully compiles on i386 and solaris architectures according to the cpan testers results. Hopefully, versions after 0.04 will work on WIN32. I don't have any non-linux machines, so feel free to send patches.


This code comes with ABSOLUTELY NO WARRANTY of any kind.

Changes ^

  0.01 - First public release.
  0.02 - Added API documentation.
  0.03 - Fix to allocation error.
         Possibly Fixed WIN32 compile problem?
  0.04 - Twiddling with WIN32 compile problem (last try)
  0.05 - Corrected license statements.

Constructors ^


Traditional constructor, returns a blessed reference to the underlying C struct.

  use Math::Geometry::Planar::GPC::Polygon;
  my $gpc = Math::Geometry::Planar::GPC::Polygon->new();


An optionally imported constructor, for those of you who don't like to type so much.

  use Math::Geometry::Planar::GPC::Polygon qw(new_gpc);
  my $gpc = new_gpc();

Bound Functions ^

These are the functions provide by the Inline-C code. See functions.c in the source package for intimate details.


Loads a from a file into your gpc object. See the GPC library documentation for details.

  $gpc->from_file($filename, $want_hole);


Writes to a file.

  $gpc->to_file($filename, $want_hole);


Clips the $gpc object to the $othergpc object.

$action may be any of the following:


  $gpc->clip_to($othergpc, $action);

Be wary. This interface may need to change.


Adds a polygon to the gpc object. @points is a list of array references which describe the point of the polygon. $hole is 1 or 0 (0 to not add a hole.)

  $gpc->add_polygon(\@points, $hole);


Gets the polygons from the gpc object. I'm not sure how to tell you if they are holes or not. @pgons will be a list of refs to lists of refs.

  @pgons = $gpc->get_polygons();

Helper Functions ^

Pure-perl implementation from here down.


syntax highlighting: