~ubuntu-branches/ubuntu/saucy/libmath-polygon-perl/saucy

« back to all changes in this revision

Viewing changes to lib/Math/Polygon/Calc.pm

  • Committer: Package Import Robot
  • Author(s): Angel Abad, Ansgar Burchardt, Salvatore Bonaccorso, Angel Abad
  • Date: 2011-09-19 19:11:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110919191113-3xcmkbord39bewhb
Tags: 1.02-1
[ Ansgar Burchardt ]
* debian/control: Convert Vcs-* fields to Git.

[ Salvatore Bonaccorso ]
* debian/copyright: Replace DEP5 Format-Specification URL from
  svn.debian.org to anonscm.debian.org URL.

[ Angel Abad ]
* Imported Upstream version 1.02
* debian/copyright:
  - Update debian/* section
  - Update upstream years
* debian/control: Add myself to Uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyrights 2004,2006-2009 by Mark Overmeer.
 
1
# Copyrights 2004,2006-2011 by Mark Overmeer.
2
2
#  For other contributors see ChangeLog.
3
3
# See the manual pages for details on the licensing terms.
4
 
# Pod stripped from pm file by OODoc 1.06.
 
4
# Pod stripped from pm file by OODoc 2.00.
5
5
use strict;
6
6
use warnings;
7
7
 
8
8
package Math::Polygon::Calc;
9
9
use vars '$VERSION';
10
 
$VERSION = '1.01';
 
10
$VERSION = '1.02';
11
11
 
12
12
use base 'Exporter';
13
13
 
25
25
 polygon_start_minxy
26
26
 polygon_string
27
27
 polygon_contains_point
 
28
 polygon_centroid
28
29
/;
29
30
 
30
31
use List::Util    qw/min max/;
298
299
}
299
300
 
300
301
 
 
302
sub polygon_centroid(@)
 
303
{
 
304
    polygon_is_closed(@_)
 
305
        or croak "ERROR: polygon must be closed: begin==end";
 
306
 
 
307
    my ($cx, $cy, $a) = (0, 0, 0);
 
308
    foreach my $i (0..@_-2)
 
309
    {    my $ap = $_[$i][0]*$_[$i+1][1] - $_[$i+1][0]*$_[$i][1];
 
310
         $cx   += ($_[$i][0]+$_[$i+1][0]) * $ap;
 
311
         $cy   += ($_[$i][1]+$_[$i+1][1]) * $ap;
 
312
         $a    += $ap;
 
313
    }
 
314
    my $c = 3*$a; # 6*$a/2;
 
315
    [ $cx/$c, $cy/$c ];
 
316
}
 
317
 
 
318
 
301
319
sub polygon_is_closed(@)
302
320
{   @_ or croak "ERROR: empty polygon is neither closed nor open";
303
321