WMF/Polygon.pm

filter: Statementstmt 38.3% 33 / 86 Branchbran 10.0% 2 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 8 / 18 Podpod 0.0% 0 / 13 totaltotal 30.9% 44 / 142 CC 12 SCAR 24.1
CC
12
Cov
33%
bounds
42.0
offset
6.0
map
6.0
CRAP 11.2
« WMF/Image.pm ↑ Summary WMF/Rectangle.pm »
1 package Image::WMF::Polygon;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $VERSION = "1.00";
6 1 $DEBUG = 0;
7  
8 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 1 my ($class) = shift;
10 1 my @vertices = @_;
11 1 my $obj = bless {
12 _vertices => [],
13 _xvertices => [],
14 _yvertices => [],
15 _numvertices => 0,
16 }, $class;
17 1 $obj->_initialise(@vertices);
18 1 return $obj;
19 }
20  
21 3 ▶sub addPt {
Subroutine addPt: called CC=4 SCAR=14.5
Pod undocumented
22 3 my ($self,$x,$y) = @_;
23 3 ▶ unless (defined $x && defined $y){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $x and defined $y) 0 3 3
Condition33%1/3
defined $x and defined $y
!ll&&!rl&&r
003
MC/DC0%0/2
defined $x and defined $y
defined $x defined $y
Truth table33%1/3
A and B
A= defined $xB= defined $y
ABresult
0X0
100
111
24 0 die("Cannot create polygon: x/y vertex coordinate number mismatch\n");
25 }
26 3 push (@{$self->{'_xvertices'}},$x);
27 3 push (@{$self->{'_yvertices'}},$y);
28 3 push (@{$self->{'_vertices'}},$x);
29 3 push (@{$self->{'_vertices'}},$y);
30 3 $self->{'_numvertices'}++;
31 3 ▶ print STDERR "Added polygon vertex ",$self->{'_numvertices'},"\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Polygon::DEBUG 0 3 3
32 }
33  
34 0 ▶sub getPt {
Subroutine getPt: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($self,$p) = @_;
36 0 return($self->{'_xvertices'}->[$p],$self->{'_yvertices'}->[$p]);
37 }
38  
39 0 ▶sub toPt {
Subroutine toPt: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ($self,$x,$y) = @_;
41 0 $self->addPt($x,$y);
42 }
43  
44 0 ▶sub setPt {
Subroutine setPt: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my ($self,$p,$x,$y) = @_;
46 0 $self->{'_xvertices'}->[$p] = $x;
47 0 $self->{'_yvertices'}->[$p] = $y;
48 }
49  
50 0 ▶sub vertices {
Subroutine vertices: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ($self) = @_;
52 0 return(@{$self->{'_vertices'}});
53 }
54  
55 1 ▶sub _xvertices {
Subroutine _xvertices: called CC=1 SCAR=0.0
56 1 my ($self) = @_;
57 1 return($self->{'_xvertices'});
58 }
59  
60 1 ▶sub _yvertices {
Subroutine _yvertices: called CC=1 SCAR=0.0
61 1 my ($self) = @_;
62 1 return($self->{'_yvertices'});
63 }
64  
65 2 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod undocumented
66 2 my ($self) = @_;
67 2 return($self->{'_numvertices'});
68 }
69  
70 0 ▶sub bounds {
Subroutine bounds: not called CC=6 SCAR=37.4
Pod undocumented
71 0 my $self = shift;
72 0 my($top,$bottom,$left,$right) = @_;
73 0 $top = 99999999;
74 0 $bottom =-99999999;
75 0 $left = 99999999;
76 0 $right = -99999999;
77 0 my $v;
78 0 ▶ for (my $v=0; $v < scalar(@$self->_vertices);$v++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v < scalar @$self->_vertices) 0 0 0
79 0 ▶ $left = $self->{'_xvertices'}->[$v] if $left > $self->{'_xvertices'}->[$v];
Branch: 1 branch
BranchTrueFalseTotal
if $left > $self->{"_xvertices"}[$v] 0 0 0
80 0 ▶ $right = $self->{'_xvertices'}->[$v] if $right < $self->{'_xvertices'}->[$v];
Branch: 1 branch
BranchTrueFalseTotal
if $right < $self->{"_xvertices"}[$v] 0 0 0
81 0 ▶ $top = $self->{'_yvertices'}->[$v] if $top > $self->{'_yvertices'}->[$v];
Branch: 1 branch
BranchTrueFalseTotal
if $top > $self->{"_yvertices"}[$v] 0 0 0
82 0 ▶ $bottom = $self->{'_yvertices'}->[$v] if $bottom < $self->{'_yvertices'}->[$v];
Branch: 1 branch
BranchTrueFalseTotal
if $bottom < $self->{"_yvertices"}[$v] 0 0 0
83 }
84 0 return ($left,$top,$right,$bottom);
85 }
86  
87 0 ▶sub offset {
Subroutine offset: not called CC=2 SCAR=17.9
Pod undocumented
88 0 my($self,$dh,$dv) = @_;
89 0 my $size = $self->length();
90 0 my($i);
91 0 ▶ for ($i=0;$i<$size;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
92 0 my($x,$y)=$self->getPt($i);
93 0 $self->setPt($i,$x+$dh,$y+$dv);
94 }
95 }
96  
97 0 ▶sub delete { # think this is bugged
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
98 0 my($self,$index) = @_;
99 0 my($xvertex) = splice(@{$self->{'_xvertices'}},$index,1);
100 0 my($yvertex) = splice(@{$self->{'_yvertices'}},$index,1);
101 0 return ($xvertex,$yvertex);
102 }
103  
104 0 ▶sub map {
Subroutine map: not called CC=2 SCAR=17.9
Pod undocumented
105 0 my($self,$srcL,$srcT,$srcR,$srcB,$destL,$destT,$destR,$destB) = @_;
106 0 my($factorV) = ($destB-$destT)/($srcB-$srcT);
107 0 my($factorH) = ($destR-$destL)/($srcR-$srcL);
108 0 my($vertices) = $self->length;
109 0 my($i);
110 0 ▶ for ($i=0;$i<$vertices;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $vertices) 0 0 0
111 0 my($x,$y) = $self->getPt($i);
112 0 $x = int($destL + ($x - $srcL) * $factorH);
113 0 $y = int($destT + ($y - $srcT) * $factorV);
114 0 $self->setPt($i,$x,$y);
115 }
116 }
117  
118 0 ▶sub transform($$$$$$$) {
Subroutine transform: not called CC=2 SCAR=17.9
Pod undocumented
119 # see PostScript Ref. page 154
120 0 my($self, $a, $b, $c, $d, $tx, $ty) = @_;
121 0 my $size = $self->length;
122 0 ▶ for (my $i=0;$i<$size;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
123 0 my($x,$y)=$self->getPt($i);
124 0 $self->setPt($i, $a*$x+$c*$y+$tx, $b*$x+$d*$y+$ty);
125 }
126
127 }
128  
129 0 ▶sub scale {
Subroutine scale: not called CC=1 SCAR=6.9
Pod undocumented
130 0 my($self, $sx, $sy) = @_;
131 0 $self->transform($sx,0,0,$sy,0,0);
132 }
133  
134 1 ▶sub _initialise {
Subroutine _initialise: called CC=1 SCAR=0.0
135 1 my ($self) = shift;
136 }
137  
138 1 1;
« WMF/Image.pm ↑ Summary WMF/Rectangle.pm »