API3/Compat/API2/Matrix.pm

filter: Statementstmt 7.6% 8 / 105 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 22.2% 2 / 9 Podpod 0.0% 0 / 7 totaltotal 6.9% 10 / 145 CC 23 SCAR 36.0
CC
23
Cov
6%
solve
90.0
transpose
20.0
multiply
20.0
CRAP 36.6
« API3/Compat/API2/Basic/TTF/Delta.pm ↑ Summary API3/Compat/API2/Page.pm »
1 #=======================================================================
2 # ____ ____ _____ _ ____ ___ ____
3 # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
4 # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
5 # | __/| |_| | _| _ _ / ___ \| __/| | / __/
6 # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
7 #
8 # Copyright 1999-2001 Alfred Reibenschuh <areibens@cpan.org>.
9 #
10 # This library is free software; you can redistribute it
11 # and/or modify it under the same terms as Perl itself.
12 #
13 #=======================================================================
14 #
15 # PDF::API3::Compat::API2::Matrix
16 # Original Copyright 1995-96 Ulrich Pfeifer.
17 # modified by Alfred Reibenschuh <areibens@cpan.org> for PDF::API3::Compat::API2
18 #
19 # $Id: Matrix.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
20 #
21 #=======================================================================
22 package PDF::API3::Compat::API2::Matrix;
23
24 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
25
26 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:16:00 $
27
28 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
29
30 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
31 0 my $type = shift;
32 0 my $self = [];
33 0 my $len = scalar(@{$_[0]});
34 0 for (@_) {
35 0 ▶ return undef if scalar(@{$_}) != $len;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$_;} != $len 0 0 0
36 0 push(@{$self}, [@{$_}]);
37 }
38 0 bless $self, $type;
39 }
40
41 0 ▶sub concat {
Subroutine concat: not called CC=3 SCAR=24.8
Pod undocumented
42 0 my $self = shift;
43 0 my $other = shift;
44 0 my $result = new PDF::API3::Compat::API2::Matrix (@{$self});
45
46 0 ▶ return undef if scalar(@{$self}) != scalar(@{$other});
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self;} != scalar @{$other;} 0 0 0
47 0 for my $i (0 .. $#{$self}) {
48 0 push @{$result->[$i]}, @{$other->[$i]};
49 }
50 0 $result;
51 }
52
53 0 ▶sub transpose {
Subroutine transpose: not called CC=4 SCAR=30.0
Pod undocumented
54 0 my $self = shift;
55 0 my @result;
56 my $m;
57
58 0 for my $col (@{$self->[0]}) {
59 0 push @result, [];
60 }
61 0 for my $row (@{$self}) {
62 0 $m=0;
63 0 for my $col (@{$row}) {
64 0 push(@{$result[$m++]}, $col);
65 }
66 }
67 0 new PDF::API3::Compat::API2::Matrix (@result);
68 }
69
70 0 ▶sub vekpro {
Subroutine vekpro: not called CC=2 SCAR=17.9
Pod undocumented
71 0 my($a, $b) = @_;
72 0 my $result=0;
73
74 0 for my $i (0 .. $#{$a}) {
75 0 $result += $a->[$i] * $b->[$i];
76 }
77 0 $result;
78 }
79
80 0 ▶sub multiply {
Subroutine multiply: not called CC=4 SCAR=30.0
Pod undocumented
81 0 my $self = shift;
82 0 my $other = shift->transpose;
83 0 my @result;
84 my $m;
85
86 0 ▶ return undef if $#{$self->[0]} != $#{$other->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $#{$$self[0];} != $#{$$other[0];} 0 0 0
87 0 for my $row (@{$self}) {
88 0 my $rescol = [];
89 0 for my $col (@{$other}) {
90 0 push(@{$rescol}, vekpro($row,$col));
91 }
92 0 push(@result, $rescol);
93 }
94 0 new PDF::API3::Compat::API2::Matrix (@result);
95 }
96
97
98 0 ▶sub solve {
Subroutine solve: not called CC=9 SCAR=45.0
Pod undocumented
99 0 my $m = new PDF::API3::Compat::API2::Matrix (@{$_[0]});
100 0 my $mr = $#{$m};
101 0 my $mc = $#{$m->[0]};
102 0 my $f;
103 my $try;
104 0 my $k;
105 0 my $i;
106 0 my $j;
107 0 my $eps = 0.000001;
108
109 0 ▶ return undef if $mc <= $mr;
Branch: 1 branch
BranchTrueFalseTotal
if $mc <= $mr 0 0 0
110 0 ▶ ROW: for($i = 0; $i <= $mr; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $mr) 0 0 0
111 0 $try=$i;
112 # make diagonal element nonzero if possible
113 0 ▶ while (abs($m->[$i]->[$i]) < $eps) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $m->[$i][$i] < $eps) 0 0 0
114 0 ▶ last ROW if $try++ > $mr;
Branch: 1 branch
BranchTrueFalseTotal
if $try++ > $mr 0 0 0
115 0 my $row = splice(@{$m},$i,1);
116 0 push(@{$m}, $row);
117 }
118
119 # normalize row
120 0 $f = $m->[$i]->[$i];
121 0 ▶ for($k = 0; $k <= $mc; $k++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $mc) 0 0 0
122 0 $m->[$i]->[$k] /= $f;
123 }
124 # subtract multiple of designated row from other rows
125 0 ▶ for($j = 0; $j <= $mr; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $mr) 0 0 0
126 0 ▶ next if $i == $j;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $j 0 0 0
127 0 $f = $m->[$j]->[$i];
128 0 ▶ for($k = 0; $k <= $mc; $k++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $mc) 0 0 0
129 0 $m->[$j]->[$k] -= $m->[$i]->[$k] * $f;
130 }
131 }
132 }
133 # Answer is in augmented column
134 0 transpose new PDF::API3::Compat::API2::Matrix @{$m->transpose}[$mr+1 .. $mc];
135 }
136
137 0 ▶sub print {
Subroutine print: not called CC=4 SCAR=30.0
Pod undocumented
138 0 my $self = shift;
139
140 0 print STDERR "Matrix: \n";
141 0 ▶ print @_ if scalar(@_);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 0 0 0
142 0 for my $row (@{$self}) {
143 0 for my $col (@{$row}) {
144 0 printf STDERR "%10.5f ", $col;
145 }
146 0 print STDERR "\n";
147 }
148 }
149
150 1 1;
151
152 __END__
« API3/Compat/API2/Basic/TTF/Delta.pm ↑ Summary API3/Compat/API2/Page.pm »