Math-Polygon

 view release on metacpan or  search on metacpan

lib/Math/Polygon/Calc.pm  view on Meta::CPAN

# This code is part of Perl distribution Math-Polygon version 2.00.
# The POD got stripped from this file by OODoc version 3.03.
# For contributors see file ChangeLog.

# This software is copyright (c) 2004-2025 by Mark Overmeer.

# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later

#oodist: *** DO NOT USE THIS VERSION FOR PRODUCTION ***
#oodist: This file contains OODoc-style documentation which will get stripped
#oodist: during its release in the distribution.  You can use this file for
#oodist: testing, however the code of this development version may be broken!

package Math::Polygon::Calc;{
our $VERSION = '2.00';
}

use parent 'Exporter';

use strict;
use warnings;

use Log::Report   'math-polygon';
use List::Util    qw/min max/;
use Scalar::Util  qw/blessed/;

our @EXPORT = qw/
	polygon_area
	polygon_bbox
	polygon_beautify
	polygon_centroid
	polygon_clockwise
	polygon_contains_point
	polygon_counter_clockwise
	polygon_distance
	polygon_equal
	polygon_is_clockwise
	polygon_is_closed
	polygon_perimeter
	polygon_same
	polygon_start_minxy
	polygon_string
	polygon_format
/;

sub polygon_is_closed(@);

#--------------------

sub polygon_string(@) { join ', ', map "[$_->[0],$_->[1]]", @_ }


sub polygon_bbox(@)
{
	(	min( map $_->[0], @_ ),
		min( map $_->[1], @_ ),
		max( map $_->[0], @_ ),
		max( map $_->[1], @_ )
	);
}


sub polygon_area(@)
{	my $area    = 0;
	while(@_ >= 2)
	{	$area += $_[0][0]*$_[1][1] - $_[0][1]*$_[1][0];
		shift;
	}

	abs($area)/2;
}


sub polygon_is_clockwise(@)



( run in 0.721 second using v1.01-cache-2.11-cpan-39bf76dae61 )