Builder/Matrix.pm

filter: Statementstmt 92.5% 50 / 54 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 4 totaltotal 85.5% 59 / 69 CC 10 SCAR 11.1
CC
10
Cov
90%
multiply
4.1
transpose
4.0
new
3.1
CRAP 3.0
« Builder/Basic/PDF/Filter/ASCIIHexDecode.pm ↑ Summary Builder/Resource/XObject/Form/BarCode/int2of5.pm »
1 #=======================================================================
2 #
3 # PDF::Builder::Matrix
4 # Original Copyright 1995-96 Ulrich Pfeifer.
5 # modified by Alfred Reibenschuh <areibens@cpan.org> for PDF::API2
6 # rewritten by Steve Simms <steve@deefs.net> and licensed under the same
7 # terms as the rest of PDF::API2
8 #
9 #=======================================================================
10 package PDF::Builder::Matrix;
11  
12 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 39 our $VERSION = '3.028'; # VERSION
17 39 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
18  
19 =head1 NAME
20  
21 PDF::Builder::Matrix - Matrix operations library
22  
23 =cut
24  
25 132 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod undocumented
26 132 my $type = shift();
27  
28 132 my $self = [];
29 132 my $col_count = scalar(@{$_[0]});
30 132 foreach my $row (@_) {
31 396 ▶ unless (scalar(@$row) == $col_count) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$row == $col_count) 0 396 396
32 0 carp 'Inconsistent column count in matrix';
33 0 return;
34 }
35 396 push(@{$self}, [@$row]);
36 }
37  
38 132 return bless($self, $type);
39 }
40  
41 # internal routine
42 39 ▶sub transpose {
Subroutine transpose: called CC=4 SCAR=13.9
Pod undocumented
43 39 my $self = shift();
44  
45 39 my @result;
46 my $m;
47  
48 39 for my $col (@{$self->[0]}) {
49 117 push @result, [];
50 }
51 39 for my $row (@$self) {
52 117 $m = 0;
53 117 for my $col (@$row) {
54 351 push @{$result[$m++]}, $col;
55 }
56 }
57  
58 39 return PDF::Builder::Matrix->new(@result);
59 }
60  
61 # internal routine
62 351 ▶sub vector_product {
Subroutine vector_product: called CC=2 SCAR=6.9
Pod undocumented
63 351 my ($a, $b) = @_;
64 351 my $result = 0;
65  
66 351 for my $i (0 .. $#{$a}) {
67 1053 $result += $a->[$i] * $b->[$i];
68 }
69  
70 351 return $result;
71 }
72  
73 # used by Content.pm
74 39 ▶sub multiply {
Subroutine multiply: called CC=4 SCAR=14.1
Pod undocumented
75 39 my $self = shift();
76 39 my $other = shift->transpose();
77  
78 39 my @result;
79  
80 39 ▶ unless ($#{$self->[0]} == $#{$other->[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($#{$$self[0];} == $#{$$other[0];}) 0 39 39
81 0 carp 'Mismatched dimensions in matrix multiplication';
82 0 return;
83 }
84 39 for my $row (@$self) {
85 117 my $result_col = [];
86 117 for my $col (@$other) {
87 351 push @$result_col, vector_product($row,$col);
88 }
89 117 push @result, $result_col;
90 }
91  
92 39 return PDF::Builder::Matrix->new(@result);
93 }
94  
95 39 1;
« Builder/Basic/PDF/Filter/ASCIIHexDecode.pm ↑ Summary Builder/Resource/XObject/Form/BarCode/int2of5.pm »