~ubuntu-branches/ubuntu/utopic/libmath-polygon-perl/utopic

« back to all changes in this revision

Viewing changes to t/12beauty.t

  • Committer: Bazaar Package Importer
  • Author(s): Martin Zobel-Helas
  • Date: 2010-04-09 09:10:33 UTC
  • Revision ID: james.westby@ubuntu.com-20100409091033-gr0lwyteczhwqj6e
Tags: upstream-1.01
ImportĀ upstreamĀ versionĀ 1.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
use Test::More tests => 24;
 
7
 
 
8
use lib '../lib', 'lib';
 
9
use Math::Polygon::Calc;
 
10
 
 
11
sub compare_poly($$$)
 
12
{   my ($got, $want, $text) = @_;
 
13
 
 
14
    cmp_ok(scalar(@$got), '==', scalar(@$want), "nr points, $text");
 
15
    return unless @$want;
 
16
 
 
17
    my $gotp  = polygon_string polygon_start_minxy @$got;
 
18
    my $wantp = polygon_string polygon_start_minxy @$want;
 
19
 
 
20
    is($gotp, $wantp);
 
21
}
 
22
 
 
23
#
 
24
# p0 is a single point, not a poly
 
25
#
 
26
 
 
27
my @p0   = ( [3,4] );
 
28
my @cp0a = polygon_beautify @p0;
 
29
compare_poly(\@cp0a, [], "single point");
 
30
 
 
31
#
 
32
# p1 is a line, also not a poly
 
33
#
 
34
 
 
35
my @p1   = ([1,2],[3,5],[1,2]);
 
36
my @cp1a = polygon_beautify @p1;
 
37
compare_poly(\@cp1a, [], "line");
 
38
 
 
39
#
 
40
# p2 is a triangle
 
41
#
 
42
 
 
43
my @p2   = ( [0,0],[1,2],[2,0],[0,0] );
 
44
my @cp2a = polygon_beautify @p2;
 
45
compare_poly(\@cp2a, \@p2, "triangle");
 
46
 
 
47
#
 
48
# p3 is traingle p2 with x-spike
 
49
#
 
50
 
 
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");
 
54
 
 
55
my @cp3b = polygon_beautify {remove_spikes => 1}, @p3;
 
56
compare_poly(\@cp3b, \@p2, "triangle with spike");
 
57
 
 
58
#
 
59
# p4 is traingle p2 with y-spike
 
60
#
 
61
 
 
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");
 
65
 
 
66
my @cp4b = polygon_beautify {remove_spikes => 1}, @p4;
 
67
compare_poly(\@cp4b, \@p2, "triangle with spike");
 
68
 
 
69
#
 
70
# p5 is traingle p2 with combined x+y-spike
 
71
#
 
72
 
 
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");
 
76
 
 
77
my @cp5b = polygon_beautify {remove_spikes => 1}, @p5;
 
78
compare_poly(\@cp5b, \@p2, "triangle with spike");
 
79
 
 
80
#
 
81
# p6 is square c(2x2) with extra point at each side
 
82
#
 
83
 
 
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");
 
88
 
 
89
#
 
90
# p7 has multiple points at one side
 
91
#
 
92
 
 
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");
 
96
 
 
97
#
 
98
# p8 has multiple points mixed in a side
 
99
#
 
100
 
 
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");
 
104
 
 
105
#
 
106
# p9 contains loads of doubles
 
107
#
 
108
 
 
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");
 
112