Math-Polygon
view release on metacpan or search on metacpan
lib/Math/Polygon/Transform.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::Transform;{
our $VERSION = '2.00';
}
use parent 'Exporter';
use strict;
use warnings;
use Log::Report 'math-polygon';
use Math::Trig qw/deg2rad pi rad2deg/;
use POSIX qw/floor/;
our @EXPORT = qw/
polygon_resize
polygon_move
polygon_rotate
polygon_grid
polygon_mirror
polygon_simplify
/;
#--------------------
sub polygon_resize(@)
{ my $args;
if(ref $_[0] eq 'HASH') { $args = shift }
else
{ while(@_ && !ref $_[0])
{ my $key = shift;
$args->{$key} = shift;
}
}
my $sx = $args->{xscale} || $args->{scale} || 1.0;
my $sy = $args->{yscale} || $args->{scale} || 1.0;
return @_ if $sx==1.0 && $sy==1.0;
my ($cx, $cy) = defined $args->{center} ? @{$args->{center}} : (0,0);
$cx || $cy
? map +[ $cx + ($_->[0]-$cx)*$sx, $cy + ($_->[1]-$cy) * $sy ], @_
: map +[ $_->[0]*$sx, $_->[1]*$sy ], @_;
}
sub polygon_move(@)
{ my $args;
if(ref $_[0] eq 'HASH') { $args = shift }
else
{ while(@_ && !ref $_[0])
{ my $key = shift;
$args->{$key} = shift;
}
}
my ($dx, $dy) = ($args->{dx}||0, $args->{dy}||0);
return @_ if $dx==0 && $dy==0;
map +[ $_->[0] +$dx, $_->[1] +$dy ], @_;
}
( run in 1.112 second using v1.01-cache-2.11-cpan-39bf76dae61 )