6
use Test::More tests => 24;
8
use lib '../lib', 'lib';
9
use Math::Polygon::Calc;
12
{ my ($got, $want, $text) = @_;
14
cmp_ok(scalar(@$got), '==', scalar(@$want), "nr points, $text");
17
my $gotp = polygon_string polygon_start_minxy @$got;
18
my $wantp = polygon_string polygon_start_minxy @$want;
24
# p0 is a single point, not a poly
28
my @cp0a = polygon_beautify @p0;
29
compare_poly(\@cp0a, [], "single point");
32
# p1 is a line, also not a poly
35
my @p1 = ([1,2],[3,5],[1,2]);
36
my @cp1a = polygon_beautify @p1;
37
compare_poly(\@cp1a, [], "line");
43
my @p2 = ( [0,0],[1,2],[2,0],[0,0] );
44
my @cp2a = polygon_beautify @p2;
45
compare_poly(\@cp2a, \@p2, "triangle");
48
# p3 is traingle p2 with x-spike
51
my @p3 = ( [0,0],[1,2],[3,2],[1,2],[2,0],[0,0] );
52
my @cp3a = polygon_beautify @p3;
53
compare_poly(\@cp3a, \@p3, "triangle with spike, no despike");
55
my @cp3b = polygon_beautify {remove_spikes => 1}, @p3;
56
compare_poly(\@cp3b, \@p2, "triangle with spike");
59
# p4 is traingle p2 with y-spike
62
my @p4 = ( [0,0],[1,2],[1,4],[1,2],[2,0],[0,0] );
63
my @cp4a = polygon_beautify @p4;
64
compare_poly(\@cp4a, \@p4, "triangle with spike, no despike");
66
my @cp4b = polygon_beautify {remove_spikes => 1}, @p4;
67
compare_poly(\@cp4b, \@p2, "triangle with spike");
70
# p5 is traingle p2 with combined x+y-spike
73
my @p5 = ( [0,0],[1,2],[1,4],[3,4],[1,4],[1,2],[2,0],[0,0] );
74
my @cp5a = polygon_beautify @p5;
75
compare_poly(\@cp5a, \@p5, "triangle with spike, no despike");
77
my @cp5b = polygon_beautify {remove_spikes => 1}, @p5;
78
compare_poly(\@cp5b, \@p2, "triangle with spike");
81
# p6 is square c(2x2) with extra point at each side
84
my @c = ( [0,0],[0,2],[2,2],[2,0],[0,0] );
85
my @p6 = ( [0,0],[0,1],[0,2],[1,2],[2,2],[2,1],[2,0],[1,0],[0,0] );
86
my @cp6a = polygon_beautify @p6;
87
compare_poly(\@cp6a, \@c, "square with extra points");
90
# p7 has multiple points at one side
93
my @p7 = ( [0,0],[0,0.5],[0,1],[0,1.5],[0,2],[2,2],[2,0],[0,0] );
94
my @cp7a = polygon_beautify @p7;
95
compare_poly(\@cp7a, \@c, "square with many superfluous points");
98
# p8 has multiple points mixed in a side
101
my @p8 = ( [0,0],[0,1.5],[0,1],[0,0.5],[0,2],[2,2],[2,0],[0,0] );
102
my @cp8a = polygon_beautify @p8;
103
compare_poly(\@cp8a, \@c, "square with mixed superfluous points");
106
# p9 contains loads of doubles
109
my @p9 = ( [0,0], [0,0], [0,0], [1,2],[1,2], [3,2],[3,2], [0,0] );
110
my @cp9a = polygon_beautify @p9;
111
compare_poly(\@cp9a, [[0,0],[1,2],[3,2],[0,0]], "doubles");