File: 12beauty.t

package info (click to toggle)
libmath-polygon-perl 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: perl: 1,598; makefile: 2
file content (112 lines) | stat: -rw-r--r-- 2,629 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/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");

#
# p5 is traingle p2 with combined x+y-spike
#

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

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

#
# p6 is square c(2x2) with extra point at each side
#

my @c    = ( [0,0],[0,2],[2,2],[2,0],[0,0] );
my @p6   = ( [0,0],[0,1],[0,2],[1,2],[2,2],[2,1],[2,0],[1,0],[0,0] );
my @cp6a = polygon_beautify @p6;
compare_poly(\@cp6a, \@c, "square with extra points");

#
# p7 has multiple points at one side
#

my @p7   = ( [0,0],[0,0.5],[0,1],[0,1.5],[0,2],[2,2],[2,0],[0,0] );
my @cp7a = polygon_beautify @p7;
compare_poly(\@cp7a, \@c, "square with many superfluous points");

#
# p8 has multiple points mixed in a side
#

my @p8   = ( [0,0],[0,1.5],[0,1],[0,0.5],[0,2],[2,2],[2,0],[0,0] );
my @cp8a = polygon_beautify @p8;
compare_poly(\@cp8a, \@c, "square with mixed superfluous points");

#
# p9 contains loads of doubles
#

my @p9   = ( [0,0], [0,0], [0,0], [1,2],[1,2], [3,2],[3,2], [0,0] );
my @cp9a = polygon_beautify @p9;
compare_poly(\@cp9a, [[0,0],[1,2],[3,2],[0,0]], "doubles");