Math-Polygon

 view release on metacpan or  search on metacpan

t/12beauty.t  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More tests => 24;

use lib '../lib', 'lib';
use Math::Polygon::Calc;

sub compare_poly($$$)
{   my ($got, $want, $text) = @_;

    cmp_ok(scalar(@$got), '==', scalar(@$want), "nr points, $text");
    return unless @$want;

    my $gotp  = polygon_string polygon_start_minxy @$got;
    my $wantp = polygon_string polygon_start_minxy @$want;

    is($gotp, $wantp);
}

#
# p0 is a single point, not a poly
#

my @p0   = ( [3,4] );
my @cp0a = polygon_beautify @p0;
compare_poly(\@cp0a, [], "single point");

#
# p1 is a line, also not a poly
#

my @p1   = ([1,2],[3,5],[1,2]);
my @cp1a = polygon_beautify @p1;
compare_poly(\@cp1a, [], "line");

#
# p2 is a triangle
#

my @p2   = ( [0,0],[1,2],[2,0],[0,0] );
my @cp2a = polygon_beautify @p2;
compare_poly(\@cp2a, \@p2, "triangle");

#
# p3 is traingle p2 with x-spike
#

my @p3   = ( [0,0],[1,2],[3,2],[1,2],[2,0],[0,0] );
my @cp3a = polygon_beautify @p3;
compare_poly(\@cp3a, \@p3, "triangle with spike, no despike");

my @cp3b = polygon_beautify {remove_spikes => 1}, @p3;
compare_poly(\@cp3b, \@p2, "triangle with spike");

#
# p4 is traingle p2 with y-spike
#

my @p4   = ( [0,0],[1,2],[1,4],[1,2],[2,0],[0,0] );
my @cp4a = polygon_beautify @p4;
compare_poly(\@cp4a, \@p4, "triangle with spike, no despike");

my @cp4b = polygon_beautify {remove_spikes => 1}, @p4;
compare_poly(\@cp4b, \@p2, "triangle with spike");

#



( run in 2.174 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )