Math-Polygon

 view release on metacpan or  search on metacpan

lib/Math/Polygon.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;{
our $VERSION = '2.00';
}


use strict;
use warnings;

use Log::Report     'math-polygon';

# Include all implementations
use Math::Polygon::Calc;
use Math::Polygon::Clip;
use Math::Polygon::Transform;

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

sub new(@)
{	my $thing = shift;
	my $class = ref $thing || $thing;

	my @points;
	my %options;
	if(ref $thing)
	{	$options{clockwise} = $thing->{MP_clockwise};
	}

	while(@_)
	{	if(ref $_[0] eq 'ARRAY') { push @points, shift }
		else { my $k = shift; $options{$k} = shift }
	}
	$options{_points} = \@points;

	(bless {}, $class)->init(\%options);
}

sub init($$)
{	my ($self, $args) = @_;
	$self->{MP_points}    = $args->{points} || $args->{_points};
	$self->{MP_clockwise} = $args->{clockwise};
	$self->{MP_bbox}      = $args->{bbox};
	$self;
}

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

sub nrPoints() { scalar @{ $_[0]->{MP_points}} }


sub order() { @{ $_[0]->{MP_points}} -1 }


sub points(;$)
{	my ($self, $format) = @_;
	my $points = $self->{MP_points};
	$points    = [ polygon_format $format, @$points ] if $format;
	wantarray ? @$points : $points;
}


sub point(@)
{	my $points = shift->{MP_points};
	wantarray ? @{$points}[@_] : $points->[shift];
}

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

sub bbox()
{	my $self = shift;
	return @{$self->{MP_bbox}} if $self->{MP_bbox};

	my @bbox = polygon_bbox $self->points;
	$self->{MP_bbox} = \@bbox;
	@bbox;



( run in 1.244 second using v1.01-cache-2.11-cpan-483215c6ad5 )