File: 45simple.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 (90 lines) | stat: -rw-r--r-- 1,948 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
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More tests => 11;

use lib '../lib', 'lib';
use Math::Polygon::Transform;
use Math::Polygon::Calc       qw/polygon_string/;

###
### SAME
###

my @p = ([0,0], [0,0], [1,1], [2,2], [2.1, 2.1], [1.9, 1.85], [0,0.1], [0,0]);

is( polygon_string(polygon_simplify @p)
  , "[0,0], [1,1], [2,2], [2.1,2.1], [1.9,1.85], [0,0.1], [0,0]"
  , 'default'
  );

is( polygon_string(polygon_simplify same => 0.15, @p)
  , "[0,0.05], [1,1], [2.05,2.05], [1.9,1.85], [0,0.05]"
  , 'resolution 0.11'
  );

is( polygon_string(polygon_simplify same => 0.25, @p)
  , "[0,0.05], [1,1], [1.975,1.95], [0,0.05]"
  , 'resolution 0.11'
  );

pop @p;   # @p now not a ring anymore

is( polygon_string(polygon_simplify @p)
  , "[0,0], [1,1], [2,2], [2.1,2.1], [1.9,1.85], [0,0.1]"
  , 'default no ring'
  );

is( polygon_string(polygon_simplify same => 0.15, @p)
  , "[0,0], [1,1], [2.05,2.05], [1.9,1.85], [0,0.1]"
  , 'resolution 0.11 no ring'
  );

is( polygon_string(polygon_simplify same => 0.25, @p)
  , "[0,0], [1,1], [1.975,1.95], [0,0.1]"
  , 'resolution 0.11 no ring'
  );

###
### SLOPE
###

my @q = ( [0,1],[0,4],[4,5],[7,4],[7,1],[3,0],[0,1] );
is( polygon_string(polygon_simplify @q)
  , "[0,1], [0,4], [4,5], [7,4], [7,1], [3,0], [0,1]"
  , 'identity'
  );

is( polygon_string(polygon_simplify slope => 1, @q)
  , "[0,1], [0,4], [7,4], [7,1], [0,1]"
  , 'identity'
  );

###
### Z shape in slope
###

my @r = ( [1,1], [1,4], [1,2], [1,5] );
is( polygon_string(polygon_simplify slope => 0.001, @r)
  , "[1,1], [1,5]"
  , 'simple'
  );
  
###
### Remove blunt angles
###

my @s = ( [0,0], [1,3], [4,3], [5,0], [4,-3], [1,-3], [0,0] );
is( polygon_string(polygon_simplify max_points => 4, @s)
  , "[1,3], [4,3], [4,-3], [1,-3], [1,3]"
  , 'max 4 (ring => 5 left)'
  );
  
pop @s;
is( polygon_string(polygon_simplify max_points => 5, @s)
  , "[0,0], [1,3], [4,3], [4,-3], [1,-3]"
  , 'max 5 (no ring)'
  );